
com.intellij.uiDesigner.propertyInspector.editors.ComponentEditor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ui-designer Show documentation
Show all versions of ui-designer Show documentation
A packaging of the IntelliJ Community Edition ui-designer library.
This is release number 1 of trunk branch 142.
The newest version!
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner.propertyInspector.editors;
import com.intellij.openapi.util.Condition;
import com.intellij.uiDesigner.FormEditingUtil;
import com.intellij.uiDesigner.lw.IComponent;
import com.intellij.uiDesigner.propertyInspector.renderers.ComponentRenderer;
import com.intellij.uiDesigner.propertyInspector.InplaceContext;
import com.intellij.uiDesigner.radComponents.RadComponent;
import com.intellij.uiDesigner.radComponents.RadContainer;
import javax.swing.*;
import java.util.ArrayList;
/**
* @author yole
*/
public class ComponentEditor extends ComboBoxPropertyEditor {
private final Class myPropertyType;
private final Condition myFilter;
private String myOldValue;
public ComponentEditor(final Class propertyType, final Condition filter) {
myPropertyType = propertyType;
myFilter = filter;
myCbx.setRenderer(new ComponentRenderer());
}
public JComponent getComponent(RadComponent component, String value, InplaceContext inplaceContext) {
RadComponent[] components = collectFilteredComponents(component);
// components [0] = null ()
myCbx.setModel(new DefaultComboBoxModel(components));
myOldValue = value;
if (value == null || myOldValue.length() == 0) {
myCbx.setSelectedIndex(0);
}
else {
for(int i=1; i result = new ArrayList();
result.add(null);
RadContainer container = component.getParent();
while(container.getParent() != null) {
container = container.getParent();
}
FormEditingUtil.iterate(container, new FormEditingUtil.ComponentVisitor() {
public boolean visit(final IComponent component) {
RadComponent radComponent = (RadComponent) component;
final JComponent delegee = radComponent.getDelegee();
if (!myPropertyType.isInstance(delegee)) {
return true;
}
if (myFilter == null || myFilter.value(radComponent)) {
result.add(radComponent);
}
return true;
}
});
return result.toArray(new RadComponent[result.size()]);
}
@Override
public String getValue() throws Exception {
final RadComponent selection = (RadComponent)myCbx.getSelectedItem();
if (selection == null) {
return myOldValue == null ? null : "";
}
return selection.getId();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy