/** * Invoked by reflection */ public Palette(Project project) { myProject = project; myLafManagerListener = project == null ? null : new MyLafManagerListener(); myClass2Properties = new HashMap<Class, IntrospectedProperty[]>(); myClassName2Item = new HashMap<String, ComponentItem>(); myGroups = new ArrayList<GroupItem>(); if (project != null) { mySpecialGroup.setReadOnly(true); mySpecialGroup.addItem(ComponentItem.createAnyComponentItem(project)); } if (myLafManagerListener != null) { LafManager.getInstance().addLafManagerListener(myLafManagerListener); } }
public void run() { if (!myEditor.ensureEditable()) { return; } Runnable runnable = new Runnable() { public void run() { final Palette palette = Palette.getInstance(myEditor.getProject()); IntrospectedProperty[] props = palette.getIntrospectedProperties(myLabel); boolean modified = false; for(IntrospectedProperty prop: props) { if (prop.getName().equals(SwingProperties.LABEL_FOR) && prop instanceof IntroComponentProperty) { IntroComponentProperty icp = (IntroComponentProperty) prop; icp.setValueEx(myLabel, myComponent.getId()); modified = true; break; } } if (modified) myEditor.refreshAndSave(false); } }; CommandProcessor.getInstance().executeCommand(myEditor.getProject(), runnable, UIDesignerBundle.message("inspection.no.label.for.command"), null); }
public void initDefaultProperties(@NotNull final ComponentItem item) { final IntrospectedProperty[] properties = getPalette().getIntrospectedProperties(this); for (final IntrospectedProperty property : properties) { final Object initialValue = item.getInitialValue(property); if (initialValue != null) { try { //noinspection unchecked property.setValue(this, initialValue); } catch (Exception e) { throw new RuntimeException(e); } } } myConstraints.restore(item.getDefaultConstraints()); }
protected final void writeProperties(final XmlWriter writer) { writer.startElement(UIFormXmlConstants.ELEMENT_PROPERTIES); try { final IntrospectedProperty[] introspectedProperties = getPalette().getIntrospectedProperties(this); for (final IntrospectedProperty property : introspectedProperties) { if (isMarkedAsModified(property)) { final Object value = property.getValue(this); if (value != null) { writer.startElement(property.getName()); try { //noinspection unchecked property.write(value, writer); } finally { writer.endElement(); } } } } } finally { writer.endElement(); // properties } writeClientProperties(writer); }
public void loadLwProperty(final LwComponent lwComponent, final LwIntrospectedProperty lwProperty, final IntrospectedProperty property) { myLoadingProperties = true; try { try { final Object value = lwComponent.getPropertyValue(lwProperty); //noinspection unchecked property.setValue(this, value); } catch (Exception e) { LOG.error(e); //TODO[anton,vova]: show error and continue to load form } } finally { myLoadingProperties = false; } }
/** * @return introspected property with the given <code>name</code> of the * specified <code>class</code>. The method returns <code>null</code> if there is no * property with the such name. */ @Nullable public IntrospectedProperty getIntrospectedProperty(@NotNull final RadComponent component, @NotNull final String name) { final IntrospectedProperty[] properties = getIntrospectedProperties(component); for (final IntrospectedProperty property : properties) { if (name.equals(property.getName())) { return property; } } return null; }
/** * @return "inplace" property for the component with the specified class. * <b>DO NOT USE THIS METHOD DIRECTLY</b>. Use {@link RadComponent#getInplaceProperty(int, int) } * instead. */ @Nullable public IntrospectedProperty getInplaceProperty(@NotNull final RadComponent component) { final String inplaceProperty = Properties.getInstance().getInplaceProperty(component.getComponentClass()); final IntrospectedProperty[] properties = getIntrospectedProperties(component); for (int i = properties.length - 1; i >= 0; i--) { final IntrospectedProperty property = properties[i]; if (property.getName().equals(inplaceProperty)) { return property; } } return null; }
@Override public void lookAndFeelChanged(final LafManager source) { for (final IntrospectedProperty[] properties : myClass2Properties.values()) { LOG.assertTrue(properties != null); for (int j = properties.length - 1; j >= 0; j--) { updateUI(properties[j]); } } }
public IProperty[] getModifiedProperties() { IntrospectedProperty[] props = getPalette().getIntrospectedProperties(this); ArrayList<IProperty> result = new ArrayList<IProperty>(); for (IntrospectedProperty prop : props) { if (isMarkedAsModified(prop)) { result.add(prop); } } return result.toArray(new IProperty[result.size()]); }
/** Invoked by reflection */ public Palette(Project project) { myProject = project; myLafManagerListener = new MyLafManagerListener(); myClass2Properties = new HashMap<Class, IntrospectedProperty[]>(); myClassName2Item = new HashMap<String, ComponentItem>(); myGroups = new ArrayList<GroupItem>(); if (project != null) { mySpecialGroup.setReadOnly(true); mySpecialGroup.addItem(ComponentItem.createAnyComponentItem(project)); } LafManager.getInstance().addLafManagerListener(myLafManagerListener); }
/** * @return introspected property with the given <code>name</code> of the * specified <code>class</code>. The method returns <code>null</code> if there is no * property with the such name. */ @Nullable public IntrospectedProperty getIntrospectedProperty(@NotNull final RadComponent component, @NotNull final String name){ final IntrospectedProperty[] properties = getIntrospectedProperties(component); for (final IntrospectedProperty property: properties) { if (name.equals(property.getName())) { return property; } } return null; }
/** * @return "inplace" property for the component with the specified class. * <b>DO NOT USE THIS METHOD DIRECTLY</b>. Use {@link com.intellij.uiDesigner.radComponents.RadComponent#getInplaceProperty(int, int) } * instead. */ @Nullable public IntrospectedProperty getInplaceProperty(@NotNull final RadComponent component) { final String inplaceProperty = Properties.getInstance().getInplaceProperty(component.getComponentClass()); final IntrospectedProperty[] properties = getIntrospectedProperties(component); for (int i = properties.length - 1; i >= 0; i--) { final IntrospectedProperty property = properties[i]; if(property.getName().equals(inplaceProperty)){ return property; } } return null; }
public void lookAndFeelChanged(final LafManager source) { for (final IntrospectedProperty[] properties : myClass2Properties.values()) { LOG.assertTrue(properties != null); for (int j = properties.length - 1; j >= 0; j--) { updateUI(properties[j]); } } }
/** Invoked by reflection */ public Palette(Project project) { myProject = project; myLafManagerListener = new MyLafManagerListener(); myClass2Properties = new HashMap<Class, IntrospectedProperty[]>(); myClassName2Item = new HashMap<String, ComponentItem>(); myGroups = new ArrayList<GroupItem>(); if (project != null) { mySpecialGroup.setReadOnly(true); mySpecialGroup.addItem(ComponentItem.createAnyComponentItem(project)); } }
@NotNull public IntrospectedProperty[] getIntrospectedProperties(@NotNull final RadComponent component) { return getIntrospectedProperties(component.getComponentClass(), component.getDelegee().getClass()); }
private static boolean morphComponent(final GuiEditor editor, final RadComponent oldComponent, ComponentItem targetItem) { targetItem = InsertComponentProcessor.replaceAnyComponentItem(editor, targetItem, "Morph to Non-Palette Component"); if (targetItem == null) { return false; } final RadComponent newComponent = InsertComponentProcessor.createInsertedComponent(editor, targetItem); if (newComponent == null) return false; newComponent.setBinding(oldComponent.getBinding()); newComponent.setCustomLayoutConstraints(oldComponent.getCustomLayoutConstraints()); newComponent.getConstraints().restore(oldComponent.getConstraints()); updateBoundFieldType(editor, oldComponent, targetItem); final IProperty[] oldProperties = oldComponent.getModifiedProperties(); final Palette palette = Palette.getInstance(editor.getProject()); for(IProperty prop: oldProperties) { IntrospectedProperty newProp = palette.getIntrospectedProperty(newComponent, prop.getName()); if (newProp == null || !prop.getClass().equals(newProp.getClass())) continue; Object oldValue = prop.getPropertyValue(oldComponent); try { //noinspection unchecked newProp.setValue(newComponent, oldValue); } catch (Exception e) { // ignore } } retargetComponentProperties(editor, oldComponent, newComponent); final RadContainer parent = oldComponent.getParent(); int index = parent.indexOfComponent(oldComponent); parent.removeComponent(oldComponent); parent.addComponent(newComponent, index); newComponent.setSelected(true); if (oldComponent.isDefaultBinding()) { final String text = FormInspectionUtil.getText(newComponent.getModule(), newComponent); if (text != null) { String binding = BindingProperty.suggestBindingFromText(newComponent, text); if (binding != null) { new BindingProperty(newComponent.getProject()).setValueEx(newComponent, binding); } } newComponent.setDefaultBinding(true); } return true; }
public void actionPerformed(final AnActionEvent e) { final PropertyInspectorTable inspector = PropertyInspectorTable.DATA_KEY.getData(e.getDataContext()); final IntrospectedProperty introspectedProperty = inspector.getSelectedIntrospectedProperty(); final PsiClass aClass = inspector.getComponentClass(); final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, introspectedProperty.getName(), false, true); LOG.assertTrue(getter != null); final PsiMethod setter = PropertyUtil.findPropertySetter(aClass, introspectedProperty.getName(), false, true); LOG.assertTrue(setter != null); final DocumentationManager documentationManager = DocumentationManager.getInstance(aClass.getProject()); final DocumentationComponent component1 = new DocumentationComponent(documentationManager); final DocumentationComponent component2 = new DocumentationComponent(documentationManager); final Disposable disposable = Disposer.newDisposable(); final TabbedPaneWrapper tabbedPane = new TabbedPaneWrapper(disposable); tabbedPane.addTab(UIDesignerBundle.message("tab.getter"), component1); tabbedPane.addTab(UIDesignerBundle.message("tab.setter"), component2); documentationManager.fetchDocInfo(getter, component1); documentationManager.queueFetchDocInfo(setter, component2).doWhenProcessed(new Runnable() { public void run() { final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), component1) .setDimensionServiceKey(aClass.getProject(), DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false) .setResizable(true) .setMovable(true) .setRequestFocus(true) .setTitle(UIDesignerBundle.message("property.javadoc.title", introspectedProperty.getName())) .createPopup(); component1.setHint(hint); component2.setHint(hint); Disposer.register(hint, component1); Disposer.register(hint, component2); Disposer.register(hint, disposable); hint.show(new RelativePoint(inspector, new Point(0,0))); //component1.requestFocus(); } }); }
public I18nizeFormPropertyQuickFix(final GuiEditor editor, final String name, final RadComponent component, final IntrospectedProperty property) { super(editor, name, component); myProperty = property; }
@RequiredDispatchThread @Override public void actionPerformed(@NotNull final AnActionEvent e) { final PropertyInspectorTable inspector = e.getData(PropertyInspectorTable.DATA_KEY); final IntrospectedProperty introspectedProperty = inspector.getSelectedIntrospectedProperty(); final PsiClass aClass = inspector.getComponentClass(); final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, introspectedProperty.getName(), false, true); LOG.assertTrue(getter != null); final PsiMethod setter = PropertyUtil.findPropertySetter(aClass, introspectedProperty.getName(), false, true); LOG.assertTrue(setter != null); final DocumentationManager documentationManager = DocumentationManager.getInstance(aClass.getProject()); final DocumentationComponent component1 = new DocumentationComponent(documentationManager); final DocumentationComponent component2 = new DocumentationComponent(documentationManager); final Disposable disposable = Disposer.newDisposable(); final TabbedPaneWrapper tabbedPane = new TabbedPaneWrapper(disposable); tabbedPane.addTab(UIDesignerBundle.message("tab.getter"), component1); tabbedPane.addTab(UIDesignerBundle.message("tab.setter"), component2); documentationManager.fetchDocInfo(getter, component1); documentationManager.queueFetchDocInfo(setter, component2).doWhenProcessed(new Runnable() { @Override public void run() { final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), component1).setDimensionServiceKey(aClass.getProject(), DocumentationManager .JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(UIDesignerBundle.message("property.javadoc.title", introspectedProperty .getName())).createPopup(); component1.setHint(hint); component2.setHint(hint); Disposer.register(hint, component1); Disposer.register(hint, component2); Disposer.register(hint, disposable); hint.show(new RelativePoint(inspector, new Point(0, 0))); //component1.requestFocus(); } }); }
/** * The method returns initial value of the property. Term * "initial" means that just after creation of RadComponent * all its properties are set into initial values. * The method returns <code>null</code> if the * initial property is not defined. Unfortunately we cannot * put this method into the constuctor of <code>RadComponent</code>. * The problem is that <code>RadComponent</code> is used in the * code genaration and code generation doesn't depend on any * <code>ComponentItem</code>, so we need to initialize <code>RadComponent</code> * in all places where it's needed explicitly. */ public Object getInitialValue(final IntrospectedProperty property){ return myPropertyName2initialValue.get(property.getName()); }