public void propertyChange(final PropertyChangeEvent e) { if(RadComponent.PROP_SELECTED.equals(e.getPropertyName())){ final Boolean selected = (Boolean)e.getNewValue(); selectionChanged((RadComponent)e.getSource(), selected.booleanValue()); } else if(RadContainer.PROP_CHILDREN.equals(e.getPropertyName())){ final RadComponent[] oldChildren = (RadComponent[])e.getOldValue(); for(int i = oldChildren.length - 1; i >= 0; i--){ deinstall(oldChildren[i]); } final RadComponent[] newChildren = (RadComponent[])e.getNewValue(); for(int i = newChildren.length - 1; i >= 0; i--){ install(newChildren[i]); } } }
private static void calcSelectedComponentsImpl(final ArrayList<RadComponent> result, final RadContainer container) { if (container.isSelected()) { if (container.getParent() != null) { // ignore RadRootContainer result.add(container); return; } } for (int i = 0; i < container.getComponentCount(); i++) { final RadComponent component = container.getComponent(i); if (component instanceof RadContainer) { calcSelectedComponentsImpl(result, (RadContainer)component); } else { if (component.isSelected()) { result.add(component); } } } }
private void renderComponent(@Nullable final RadComponent target, boolean selected) { clear(); final SimpleTextAttributes baseAttributes = selected ? SimpleTextAttributes.SELECTED_SIMPLE_CELL_ATTRIBUTES : SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES; if (target == null) { append(UIDesignerBundle.message("component.none"), baseAttributes); return; } setIcon(ComponentTree.getComponentIcon(target)); String binding = target.getBinding(); if (binding != null) { append(binding, baseAttributes); } else { final String componentTitle = target.getComponentTitle(); if (componentTitle != null && componentTitle.length() > "\"\"".length()) { append(componentTitle, baseAttributes); } else { append(target.getComponentClass().getSimpleName(), selected ? SimpleTextAttributes.SELECTED_SIMPLE_CELL_ATTRIBUTES : SimpleTextAttributes.GRAYED_ATTRIBUTES); } } }
public static void selectComponents(final GuiEditor editor, List<RadComponent> components) { if (components.size() > 0) { RadComponent component = components.get(0); ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder(); if (builder == null) { // race condition when handling event? return; } builder.beginUpdateSelection(); try { clearSelection((RadContainer)getRoot(component)); for (RadComponent aComponent : components) { selectComponent(editor, aComponent); } } finally { builder.endUpdateSelection(); } } }
private DefaultActionGroup prepareActionGroup(final List<RadComponent> selection) { final DefaultActionGroup actionGroup = new DefaultActionGroup(); final EventSetDescriptor[] eventSetDescriptors; try { BeanInfo beanInfo = Introspector.getBeanInfo(selection.get(0).getComponentClass()); eventSetDescriptors = beanInfo.getEventSetDescriptors(); } catch (IntrospectionException e) { LOG.error(e); return null; } EventSetDescriptor[] sortedDescriptors = new EventSetDescriptor[eventSetDescriptors.length]; System.arraycopy(eventSetDescriptors, 0, sortedDescriptors, 0, eventSetDescriptors.length); Arrays.sort(sortedDescriptors, new Comparator<EventSetDescriptor>() { public int compare(final EventSetDescriptor o1, final EventSetDescriptor o2) { return o1.getListenerType().getName().compareTo(o2.getListenerType().getName()); } }); for(EventSetDescriptor descriptor: sortedDescriptors) { actionGroup.add(new MyCreateListenerAction(selection, descriptor)); } return actionGroup; }
private static boolean isSpaceBelowEmpty(final RadComponent component, boolean incrementRow) { final GridConstraints constraints = component.getConstraints(); int startRow = constraints.getCell(incrementRow) + constraints.getSpan(incrementRow); int endRow = constraints.getCell(incrementRow) + constraints.getSpan(incrementRow)*2 + component.getParent().getGridLayoutManager().getGapCellCount(); if (endRow > component.getParent().getGridCellCount(incrementRow)) { return false; } for(int row=startRow; row < endRow; row++) { for(int col=constraints.getCell(!incrementRow); col < constraints.getCell(!incrementRow) + constraints.getSpan(!incrementRow); col++) { if (component.getParent().getComponentAtGrid(incrementRow, row, col) != null) { return false; } } } return true; }
private static void selectComponentsInRange(final RadComponent component, final RadComponent anchor) { final GridConstraints c1 = component.getConstraints(); final GridConstraints c2 = anchor.getConstraints(); int startRow = Math.min(c1.getRow(), c2.getRow()); int startCol = Math.min(c1.getColumn(), c2.getColumn()); int endRow = Math.max(c1.getRow() + c1.getRowSpan(), c2.getRow() + c2.getRowSpan()); int endCol = Math.max(c1.getColumn() + c1.getColSpan(), c2.getColumn() + c2.getColSpan()); for(int row=startRow; row<endRow; row++) { for(int col=startCol; col<endCol; col++) { RadComponent c = anchor.getParent().getComponentAtGrid(row, col); if (c != null) { c.setSelected(true); } } } }
private void markRectangle( final RadComponent component, final Rectangle rectangle, final Component coordinateOriginComponent ){ if (!(component instanceof RadRootContainer) && !component.equals(myComponent)) { final Rectangle bounds = component.getBounds(); final Point point = SwingUtilities.convertPoint(component.getDelegee().getParent(), bounds.x, bounds.y, coordinateOriginComponent); bounds.setLocation(point); if(rectangle.intersects(bounds)){ component.setSelected(true); return; } } if (component instanceof RadContainer){ final RadContainer container = (RadContainer)component; // [anton] it is very important to iterate through a STORED array because setSelected can // change order of components so iteration via getComponent(i) is incorrect final RadComponent[] components = container.getComponents(); for (RadComponent component1 : components) { markRectangle(component1, rectangle, coordinateOriginComponent); } } }
private static void refreshImpl(final RadComponent component) { if (component.getParent() != null) { final Dimension size = component.getSize(); final int oldWidth = size.width; final int oldHeight = size.height; Util.adjustSize(component.getDelegee(), component.getConstraints(), size); if (oldWidth != size.width || oldHeight != size.height) { if (component.getParent().isXY()) { component.setSize(size); } component.getDelegee().invalidate(); } } if (component instanceof RadContainer) { component.refresh(); final RadContainer container = (RadContainer)component; for (int i = container.getComponentCount() - 1; i >= 0; i--) { refreshImpl(container.getComponent(i)); } } }
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); }
private void restoreTabbedPaneSelectedTabs(final Map<String, String> tabbedPaneSelectedTabs) { FormEditingUtil.iterate(getRootContainer(), new FormEditingUtil.ComponentVisitor() { public boolean visit(final IComponent component) { if (component instanceof RadTabbedPane) { RadTabbedPane tabbedPane = (RadTabbedPane)component; String selectedTabId = tabbedPaneSelectedTabs.get(tabbedPane.getId()); if (selectedTabId != null) { for (RadComponent c : tabbedPane.getComponents()) { if (c.getId().equals(selectedTabId)) { tabbedPane.selectTab(c); break; } } } } return true; } }); }
public JComponent getComponent(final RadComponent ignored, final Integer value, final InplaceContext inplaceContext) { // Find pair if (value == null) { getCbx().setSelectedItem(null); return getCbx(); } final ComboBoxModel model = getCbx().getModel(); for (int i = model.getSize() - 1; i >= 0; i--) { final Pair pair = (Pair)model.getElementAt(i); if (pair.myValue == value.intValue()) { getCbx().setSelectedIndex(i); return getCbx(); } } throw new IllegalArgumentException("unknown value: " + value); }
@Override public void processDrop(final GuiEditor editor, final RadComponent[] components, final GridConstraints[] constraintsToAdjust, final ComponentDragObject dragObject) { RadAbstractGridLayoutManager gridLayout = myContainer.getGridLayoutManager(); if (myContainer.getGridRowCount() == 0 && myContainer.getGridColumnCount() == 0) { gridLayout.insertGridCells(myContainer, 0, false, true, true); gridLayout.insertGridCells(myContainer, 0, true, true, true); } super.processDrop(editor, components, constraintsToAdjust, dragObject); Palette palette = Palette.getInstance(editor.getProject()); ComponentItem hSpacerItem = palette.getItem(HSpacer.class.getName()); ComponentItem vSpacerItem = palette.getItem(VSpacer.class.getName()); InsertComponentProcessor icp = new InsertComponentProcessor(editor); if (myXPart == 0) { insertSpacer(icp, hSpacerItem, GridInsertMode.ColumnAfter); } if (myXPart == 2) { insertSpacer(icp, hSpacerItem, GridInsertMode.ColumnBefore); } if (myYPart == 0) { insertSpacer(icp, vSpacerItem, GridInsertMode.RowAfter); } if (myYPart == 2) { insertSpacer(icp, vSpacerItem, GridInsertMode.RowBefore); } }
@Override public void importSnapshotValue(final SnapshotContext context, final JComponent component, final RadComponent radComponent) { // exclude property from snapshot import to avoid exceptions because of not imported model if (!getName().equals(SwingProperties.SELECTED_INDEX)) { super.importSnapshotValue(context, component, radComponent); } }
private void fillOriginalConstraints() { // Store original constraints and parents. This information is required // to restore initial state if drag is canceled. myOriginalConstraints = new GridConstraints[mySelection.size()]; myOriginalBounds = new Rectangle[mySelection.size()]; myOriginalParents = new RadContainer[mySelection.size()]; for (int i1 = 0; i1 < mySelection.size(); i1++) { final RadComponent component = mySelection.get(i1); myOriginalConstraints[i1] = component.getConstraints().store(); myOriginalBounds[i1] = component.getBounds(); myOriginalParents[i1] = component.getParent(); } }
protected void processMouseEvent(final MouseEvent e) { if (e.getID() == MouseEvent.MOUSE_PRESSED) { myPressPoint = e.getPoint(); } else if (e.getID() == MouseEvent.MOUSE_RELEASED) { if (!myDragStarted) { RadComponent component = FormEditingUtil.getRadComponentAt(myEditor.getRootContainer(), e.getX(), e.getY()); if (component != null) { if (UIUtil.isControlKeyDown(e)) { component.setSelected(!component.isSelected()); } } } } else if (e.getID() == MouseEvent.MOUSE_DRAGGED) { if (!myDragStarted) { if ((Math.abs(e.getX() - myPressPoint.getX()) > TREMOR || Math.abs(e.getY() - myPressPoint.getY()) > TREMOR)) { ArrayList<InputEvent> eventList = new ArrayList<InputEvent>(); eventList.add(e); myDragGestureRecognizer.setTriggerEvent(e); DragGestureEvent dge = new DragGestureEvent(myDragGestureRecognizer, UIUtil.isControlKeyDown(e) ? DnDConstants.ACTION_COPY : DnDConstants.ACTION_MOVE, myPressPoint, eventList); myDragStarted = true; myEditor.getDropTargetListener().setUseDragDelta(true); dge.startDrag(null, DraggedComponentList.pickupSelection(myEditor, e.getPoint()), myDragSourceListener); } } } }
/** * @param x in editor pane coordinates * @param y in editor pane coordinates */ public static RadComponent getRadComponentAt(final RadRootContainer rootContainer, final int x, final int y) { Point location = new Point(x, y); SwingUtilities.convertPointToScreen(location, rootContainer.getDelegee()); Component c = getDeepestEmptyComponentAt(rootContainer.getDelegee(), location); if (c == null) { c = SwingUtilities.getDeepestComponentAt(rootContainer.getDelegee(), x, y); } RadComponent result = null; while (c != null) { if (c instanceof JComponent) { final RadComponent component = (RadComponent)((JComponent)c).getClientProperty(RadComponent.CLIENT_PROP_RAD_COMPONENT); if (component != null) { if (result == null) { result = component; } else { final Point p = SwingUtilities.convertPoint(rootContainer.getDelegee(), x, y, c); if (Painter.getResizeMask(component, p.x, p.y) != 0) { result = component; } } } } c = c.getParent(); } return result; }
private static RadContainer getContainerToPack(final List<RadComponent> selection) { if (selection.size() != 1 || !(selection.get(0) instanceof RadContainer)) { return null; } RadContainer container = (RadContainer)selection.get(0); if (!container.getParent().isXY()) { return null; } return container; }
/** * This method synchronizes selection in the tree with the selected * RadComponent in the component hierarchy */ private void syncSelection() { // Found selected components final RadContainer rootContainer=myEditor.getRootContainer(); final ArrayList<RadComponent> selection = new ArrayList<RadComponent>(); FormEditingUtil.iterate( rootContainer, new FormEditingUtil.ComponentVisitor<RadComponent>() { public boolean visit(final RadComponent component) { if(component.isSelected()){ selection.add(component); } return true; } } ); if(selection.size() == 0){ // If there is no selected component in the hierarchy, then // we have to select RadRootContainer selection.add(rootContainer); } final ComponentPtr[] componentPtrs = new ComponentPtr[selection.size()]; for (int i = 0; i < selection.size(); i++) { componentPtrs [i] = new ComponentPtr(myEditor, selection.get(i)); } // Set selection in the tree select(componentPtrs, null); // Notify the ComponentTree that selected component changed myEditor.fireSelectedComponentChanged(); }
private void removeDragger() { final RadComponent oldDraggerHost = FormEditingUtil.getDraggerHost(myEditor); if (oldDraggerHost != null) { oldDraggerHost.setDragger(false); myEditor.repaintLayeredPane(); } }
public void performPaste(@NotNull final DataContext dataContext) { final String serializedComponents = getSerializedComponents(); if (serializedComponents == null) { return; } final ArrayList<RadComponent> componentsToPaste = new ArrayList<RadComponent>(); final TIntArrayList xs = new TIntArrayList(); final TIntArrayList ys = new TIntArrayList(); loadComponentsToPaste(myEditor, serializedComponents, xs, ys, componentsToPaste); myEditor.getMainProcessor().startPasteProcessor(componentsToPaste, xs, ys); }
public FormEditorErrorCollector(final GuiEditor editor, final RadComponent component) { myEditor = editor; myComponent = component; myFormPsiFile = PsiManager.getInstance(editor.getProject()).findFile(editor.getFile()); InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(editor.getProject()); myProfile = profileManager.getInspectionProfile(); }
public void dragOver(DropTargetDragEvent dtde) { try { if (myComponentDragObject == null) { dtde.rejectDrag(); return; } final int dx = dtde.getLocation().x - myLastPoint.x; final int dy = dtde.getLocation().y - myLastPoint.y; if (myDraggedComponentsCopy != null && myDraggedComponentList != null) { for (RadComponent aMySelection : myDraggedComponentsCopy) { aMySelection.shift(dx, dy); } } myLastPoint = dtde.getLocation(); myEditor.getDragLayer().repaint(); ComponentDropLocation location = myGridInsertProcessor.processDragEvent(dtde.getLocation(), myComponentDragObject); ComponentTree componentTree = DesignerToolWindowManager.getInstance(myEditor).getComponentTree(); if (!location.canDrop(myComponentDragObject) || (myDraggedComponentList != null && FormEditingUtil.isDropOnChild(myDraggedComponentList, location))) { if (componentTree != null) { componentTree.setDropTargetComponent(null); } dtde.rejectDrag(); } else { if (componentTree != null) { componentTree.setDropTargetComponent(location.getContainer()); } dtde.acceptDrag(dtde.getDropAction()); } } catch (Exception e) { LOG.error(e); } }
@Override public String getValue() throws Exception { final RadComponent selection = (RadComponent)myCbx.getSelectedItem(); if (selection == null) { return myOldValue == null ? null : ""; } return selection.getId(); }
private RadRootContainer createFormSnapshot(final JComponent component) { SnapshotContext context = new SnapshotContext(); final RadComponent radComponent = RadComponent.createSnapshotComponent(context, component); if (radComponent != null) { radComponent.setBounds(new Rectangle(new Point(10, 10), component.getPreferredSize())); context.getRootContainer().addComponent(radComponent); context.postProcess(); } return context.getRootContainer(); }
@Override public void importSnapshotValue(final SnapshotContext context, final JComponent component, final RadComponent radComponent) { if (getName().equals(SwingProperties.MINIMUM_SIZE) || getName().equals(SwingProperties.MAXIMUM_SIZE) || getName().equals(SwingProperties.PREFERRED_SIZE)) { return; } super.importSnapshotValue(context, component, radComponent); }
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); } }
private void selectOrExtend(final RadComponent component) { if (myExtend) { FormEditingUtil.selectComponent(myEditor, component); } else { FormEditingUtil.selectSingleComponent(myEditor, component); } }
protected void invokeSetter(final RadComponent component, final Object value) throws IllegalAccessException, InvocationTargetException { if (myStoreAsClient) { component.putClientProperty(INTRO_PREFIX + getName(), value); } else { myWriteMethod.setAccessible(true); myWriteMethod.invoke(component.getDelegee(), value); } }
public boolean canDrop(final ComponentDragObject dragObject) { // If target point doesn't belong to any cell and column then do not allow drop. if (myRow == -1 || myColumn == -1) { LOG.debug("RadContainer.canDrop=false because no cell at mouse position"); return false; } int colSpan = 1; // allow drop any (NxM) component to cell (1x1) int rowSpan = 1; for(int i=0; i<dragObject.getComponentCount(); i++) { int relativeCol = dragObject.getRelativeCol(i); int relativeRow = dragObject.getRelativeRow(i); LOG.debug("checking component: relativeRow" + relativeRow + ", relativeCol" + relativeCol + ", colSpan=" + colSpan + ", rowSpan=" + rowSpan); if (myRow + relativeRow < 0 || myColumn + relativeCol < 0 || myRow + relativeRow + rowSpan > myContainer.getGridRowCount() || myColumn + relativeCol + colSpan > myContainer.getGridColumnCount()) { LOG.debug("RadContainer.canDrop=false because range is outside grid: row=" + (myRow +relativeRow) + ", col=" + (myColumn +relativeCol) + ", colSpan=" + colSpan + ", rowSpan=" + rowSpan); return false; } final RadComponent componentInRect = findOverlappingComponent(myRow + relativeRow, myColumn + relativeCol, rowSpan, colSpan); if (componentInRect != null) { LOG.debug("GridDropLocation.canDrop=false because found component " + componentInRect.getId() + " in rect (row=" + (myRow +relativeRow) + ", col=" + (myColumn +relativeCol) + ", rowSpan=" + rowSpan + ", colSpan=" + colSpan + ")"); return false; } } LOG.debug("canDrop=true"); return true; }
@Override public void resetValue(final RadComponent component) throws Exception { AlignPropertyProvider provider = getAlignPropertyProvider(component); if (provider != null) { provider.resetAlignment(component, myHorizontal); } else { final ComponentItem item = component.getPalette().getItem(component.getComponentClassName()); if (item != null) { setValueEx(component, Utils.alignFromConstraints(item.getDefaultConstraints(), myHorizontal)); } } }
private void refreshProperties() { final Ref<Boolean> anythingModified = new Ref<Boolean>(); FormEditingUtil.iterate(myRootContainer, new FormEditingUtil.ComponentVisitor() { public boolean visit(final IComponent component) { final RadComponent radComponent = (RadComponent)component; boolean componentModified = false; for (IProperty prop : component.getModifiedProperties()) { if (prop instanceof IntroStringProperty) { IntroStringProperty strProp = (IntroStringProperty)prop; componentModified = strProp.refreshValue(radComponent) || componentModified; } } if (component instanceof RadContainer) { componentModified = ((RadContainer)component).updateBorder() || componentModified; } if (component.getParentContainer() instanceof RadTabbedPane) { componentModified = ((RadTabbedPane)component.getParentContainer()).refreshChildTitle(radComponent) || componentModified; } if (componentModified) { anythingModified.set(Boolean.TRUE); } return true; } }); if (!anythingModified.isNull()) { refresh(); DesignerToolWindow designerToolWindow = DesignerToolWindowManager.getInstance(this); ComponentTree tree = designerToolWindow.getComponentTree(); if (tree != null) tree.repaint(); PropertyInspector inspector = designerToolWindow.getPropertyInspector(); if (inspector != null) inspector.synchWithTree(true); } }
@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); } }
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) { final ListPopup groupPopup = JBPopupFactory.getInstance() .createActionGroupPopup(UIDesignerBundle.message("surround.with.popup.title"), myActionGroup, e.getDataContext(), JBPopupFactory.ActionSelectionAid.ALPHA_NUMBERING, true); final JComponent component = (JComponent)e.getData(PlatformDataKeys.CONTEXT_COMPONENT); if (component instanceof ComponentTree) { groupPopup.show(JBPopupFactory.getInstance().guessBestPopupLocation(component)); } else { RadComponent selComponent = selection.get(0); FormEditingUtil.showPopupUnderComponent(groupPopup, selComponent); } }
private static boolean canCreateListener(final ArrayList<RadComponent> selection) { if (selection.size() == 0) return false; final RadRootContainer root = (RadRootContainer)FormEditingUtil.getRoot(selection.get(0)); if (root.getClassToBind() == null) return false; String componentClass = selection.get(0).getComponentClassName(); for(RadComponent c: selection) { if (!c.getComponentClassName().equals(componentClass) || c.getBinding() == null) return false; if (BindingProperty.findBoundField(root, c.getBinding()) == null) return false; } return true; }
protected void setValueImpl(final RadComponent component,final Integer value) throws Exception{ //noinspection unchecked Object parentValue = myParent.getValue(component); if (parentValue == null) { parentValue = myTemplateValue; } else { final Method method = parentValue.getClass().getMethod(METHOD_CLONE, ArrayUtil.EMPTY_CLASS_ARRAY); parentValue = method.invoke(parentValue); } parentValue.getClass().getField(myFieldName).setInt(parentValue, value.intValue()); //noinspection unchecked myParent.setValue(component, parentValue); }
private void moveToFirstComponent(final JComponent rootContainerDelegee) { final int[] minX = new int[]{Integer.MAX_VALUE}; final int[] minY = new int[]{Integer.MAX_VALUE}; final Ref<RadComponent> componentToBeSelected = new Ref<RadComponent>(); FormEditingUtil.iterate( myEditor.getRootContainer(), new FormEditingUtil.ComponentVisitor<RadComponent>() { public boolean visit(final RadComponent component) { if (component instanceof RadAtomicComponent) { final JComponent _delegee = component.getDelegee(); final Point p = SwingUtilities.convertPoint( _delegee, new Point(0, 0), rootContainerDelegee ); if(minX[0] > p.x || minY[0] > p.y){ minX[0] = p.x; minY[0] = p.y; componentToBeSelected.set(component); } } return true; } } ); if(!componentToBeSelected.isNull()){ FormEditingUtil.selectComponent(myEditor, componentToBeSelected.get()); } }
@Override public JComponent getComponent(final RadComponent component, final Boolean value, final InplaceContext inplaceContext) { JCheckBox result = (JCheckBox) super.getComponent(component, value, inplaceContext); final boolean customCreateRequired = component.isCustomCreateRequired(); if (customCreateRequired) { result.setEnabled(false); result.setSelected(true); } else { result.setEnabled(true); } return result; }
@Override public boolean appliesToSelection(final List<RadComponent> selection) { if (selection.size() > 1) { // possible "enabled" state may be different for(RadComponent c: selection) { if (c.isCustomCreateRequired()) { return false; } } } return true; }
public final void update(AnActionEvent e) { GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext()); if (editor == null) { e.getPresentation().setVisible(false); e.getPresentation().setEnabled(false); } else { e.getPresentation().setVisible(true); e.getPresentation().setEnabled(true); final ArrayList<RadComponent> selection = FormEditingUtil.getSelectedComponents(editor); update(editor, selection, e); } }