public static void groupButtons(final GuiEditor editor, final List<RadComponent> selectedComponents) { if (!editor.ensureEditable()) return; String groupName = Messages.showInputDialog(editor.getProject(), UIDesignerBundle.message("group.buttons.name.prompt"), UIDesignerBundle.message("group.buttons.title"), Messages.getQuestionIcon(), editor.getRootContainer().suggestGroupName(), new IdentifierValidator(editor.getProject())); if (groupName == null) return; RadRootContainer rootContainer = editor.getRootContainer(); RadButtonGroup group = rootContainer.createGroup(groupName); for(RadComponent component: selectedComponents) { rootContainer.setGroupForComponent(component, group); } editor.refreshAndSave(true); }
public MyPropertyEditor() { myCbx.setRenderer(new ListCellRendererWrapper<RadButtonGroup>() { @Override public void customize(JList list, RadButtonGroup value, int index, boolean selected, boolean hasFocus) { if (value == null) { setText(UIDesignerBundle.message("button.group.none")); } else if (value == RadButtonGroup.NEW_GROUP) { setText(UIDesignerBundle.message("button.group.new")); } else { setText(value.getName()); } } }); myCbx.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED && e.getItem() == RadButtonGroup.NEW_GROUP) { String newGroupName = myRootContainer.suggestGroupName(); newGroupName = (String)JOptionPane.showInputDialog(myCbx, UIDesignerBundle.message("button.group.name.prompt"), UIDesignerBundle.message("button.group.name.title"), JOptionPane.QUESTION_MESSAGE, null, null, newGroupName); if (newGroupName != null) { RadButtonGroup group = myRootContainer.createGroup(newGroupName); myRootContainer.setGroupForComponent(myComponent, group); updateModel(); } } } }); }
private void updateModel() { RadButtonGroup[] groups = myRootContainer.getButtonGroups(); RadButtonGroup[] allGroups = new RadButtonGroup[groups.length+2]; System.arraycopy(groups, 0, allGroups, 1, groups.length); allGroups [allGroups.length-1] = RadButtonGroup.NEW_GROUP; myCbx.setModel(new DefaultComboBoxModel(allGroups)); myCbx.setSelectedItem(FormEditingUtil.findGroupForComponent(myRootContainer, myComponent)); }
public void run() { RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(myComponent); if (root == null) return; for(RadButtonGroup group: root.getButtonGroups()) { if (group.getName().equals(myGroupName)) { root.setGroupForComponent(myComponent, group); break; } } myEditor.refreshAndSave(true); }
public Object getParentElement(final Object element){ if (element instanceof ComponentTreeStructureRoot) { return null; } else if (element instanceof LwInspectionSuppression[] || element instanceof RadButtonGroup[]) { return myRootElement; } else if (element instanceof LwInspectionSuppression) { return myEditor.getRootContainer().getInspectionSuppressions(); } else if (element instanceof RadButtonGroup) { return myEditor.getRootContainer().getButtonGroups(); } else if (element instanceof ComponentPtr) { // RadContainer is also RadComponent final ComponentPtr ptr = (ComponentPtr)element; if (!ptr.isValid()) return myRootElement; final RadComponent component = ptr.getComponent(); if (component instanceof RadRootContainer) { return myRootElement; } else { return component.getParent() != null ? new ComponentPtr(myEditor, component.getParent(), false) : null; } } else { throw new IllegalArgumentException("unknown element: " + element); } }
@NotNull public NodeDescriptor createDescriptor(final Object element,final NodeDescriptor parentDescriptor){ if(element==myRootElement){ return new RootDescriptor(parentDescriptor,myRootElement); } else if(element instanceof ComponentPtr){ return new ComponentPtrDescriptor(parentDescriptor,(ComponentPtr)element); } else if (element instanceof LwInspectionSuppression[]) { return new SuppressionGroupDescriptor(parentDescriptor, (LwInspectionSuppression[]) element); } else if (element instanceof LwInspectionSuppression) { final LwInspectionSuppression suppression = (LwInspectionSuppression)element; RadComponent target = (RadComponent)(suppression.getComponentId() == null ? null : FormEditingUtil.findComponent(myEditor.getRootContainer(), suppression.getComponentId())); return new SuppressionDescriptor(parentDescriptor, target, suppression); } else if (element instanceof RadButtonGroup[]) { return new ButtonGroupListDescriptor(parentDescriptor, (RadButtonGroup[]) element); } else if (element instanceof RadButtonGroup) { return new ButtonGroupDescriptor(parentDescriptor, (RadButtonGroup) element); } else{ throw new IllegalArgumentException("unknown element: "+element); } }
@Override protected void customize(@NotNull final RadButtonGroup value) { setText(value.getName()); }
public RadButtonGroup getValue(RadComponent component) { final RadRootContainer rootContainer = (RadRootContainer) FormEditingUtil.getRoot(component); return rootContainer == null ? null : (RadButtonGroup) FormEditingUtil.findGroupForComponent(rootContainer, component); }
protected void setValueImpl(RadComponent component, RadButtonGroup value) throws Exception { final RadRootContainer radRootContainer = (RadRootContainer) FormEditingUtil.getRoot(component); assert radRootContainer != null; radRootContainer.setGroupForComponent(component, value); }
@NotNull public PropertyRenderer<RadButtonGroup> getRenderer() { return myRenderer; }
public PropertyEditor<RadButtonGroup> getEditor() { return myEditor; }
public JComponent getComponent(RadComponent component, RadButtonGroup value, InplaceContext inplaceContext) { myComponent = component; myRootContainer = (RadRootContainer) FormEditingUtil.getRoot(myComponent); updateModel(); return myCbx; }
public Object[] getChildElements(final Object element){ if(element==myRootElement){ ArrayList<Object> elements = new ArrayList<Object>(); final RadRootContainer rootContainer=myEditor.getRootContainer(); elements.add(new ComponentPtr(myEditor, rootContainer)); final LwInspectionSuppression[] suppressions = rootContainer.getInspectionSuppressions(); if (suppressions.length > 0) { elements.add(suppressions); } RadButtonGroup[] buttonGroups = rootContainer.getButtonGroups(); if (buttonGroups.length > 0) { elements.add(buttonGroups); } return elements.toArray(); } else if(element instanceof ComponentPtr){ final ComponentPtr ptr=(ComponentPtr)element; LOG.assertTrue(ptr.isValid()); // pointer must be valid final RadComponent component=ptr.getComponent(); if(component instanceof RadContainer){ final RadContainer container=(RadContainer)component; final ComponentPtr[] ptrs=new ComponentPtr[container.getComponentCount()]; for(int i=0;i<ptrs.length;i++){ ptrs[i]=new ComponentPtr(myEditor,container.getComponent(i)); } return ptrs; }else{ return ourEmptyObjectArray; } } else if (element instanceof LwInspectionSuppression[]) { ArrayList<LwInspectionSuppression> result = new ArrayList<LwInspectionSuppression>(); for(LwInspectionSuppression suppression: (LwInspectionSuppression[]) element) { if (suppression.getComponentId() == null || FormEditingUtil.findComponent(myEditor.getRootContainer(), suppression.getComponentId()) != null) { result.add(suppression); } } return ArrayUtil.toObjectArray(result); } else if (element instanceof RadButtonGroup[]) { return (RadButtonGroup[]) element; } else if (element instanceof LwInspectionSuppression || element instanceof RadButtonGroup) { return ArrayUtil.EMPTY_OBJECT_ARRAY; } else{ throw new IllegalArgumentException("unknown element: "+element); } }
public ButtonGroupListDescriptor(final NodeDescriptor parentDescriptor, final RadButtonGroup[] buttonGroups) { super(null, parentDescriptor); myButtonGroups = buttonGroups; }
public ButtonGroupDescriptor(final NodeDescriptor parentDescriptor, final RadButtonGroup group) { super(null, parentDescriptor); myGroup = group; }