/** * @return component which has dragger. There is only one component with the dargger * at a time. */ @Nullable public static RadComponent getDraggerHost(@NotNull final GuiEditor editor) { final Ref<RadComponent> result = new Ref<RadComponent>(); iterate( editor.getRootContainer(), new ComponentVisitor<RadComponent>() { public boolean visit(final RadComponent component) { if (component.hasDragger()) { result.set(component); return false; } return true; } } ); return result.get(); }
/** * @return all selected component inside the <code>editor</code> */ @NotNull public static ArrayList<RadComponent> getAllSelectedComponents(@NotNull final GuiEditor editor) { final ArrayList<RadComponent> result = new ArrayList<RadComponent>(); iterate( editor.getRootContainer(), new ComponentVisitor<RadComponent>() { public boolean visit(final RadComponent component) { if (component.isSelected()) { result.add(component); } return true; } } ); return result; }
public static void updateStringPropertyValue(GuiEditor editor, RadComponent component, IntroStringProperty prop, StringDescriptor descriptor, String result) { if (descriptor.getBundleName() == null) { prop.setValueEx(component, StringDescriptor.create(result)); } else { final String newKeyName = StringEditorDialog.saveModifiedPropertyValue(editor.getModule(), descriptor, editor.getStringDescriptorLocale(), result, editor.getPsiFile()); if (newKeyName != null) { prop.setValueEx(component, new StringDescriptor(descriptor.getBundleName(), newKeyName)); } } editor.refreshAndSave(false); }
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(); } } }
public QuickFixManager(@Nullable final GuiEditor editor, @NotNull final T component, @NotNull final JViewport viewPort) { myEditor = editor; myComponent = component; myAlarm = new Alarm(); myShowHintRequest = new MyShowHintRequest(this); (new VisibilityWatcherImpl(this, component)).install(myComponent); myComponent.addFocusListener(new FocusListenerImpl(this)); // Alt+Enter new ShowHintAction(this, component); viewPort.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { updateIntentionHintPosition(viewPort); } }); }
public void setEditor(final GuiEditor editor) { if (myEditor != editor) { if (myEditor != null) { myEditor.removeComponentSelectionListener(myComponentSelectionListener); } myEditor = editor; myInspectorTable.setEditor(myEditor); myQuickFixManager.setEditor(myEditor); if (myEditor != null) { myEditor.addComponentSelectionListener(myComponentSelectionListener); } else { if (myCustomPropertiesPanel != null) { myCustomPropertiesPanel.removeChangeListener(myCustomPropertiesChangeListener); } } } }
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 static void doResetValue(final List<RadComponent> selection, final Property property, final GuiEditor editor) { try { if (!editor.ensureEditable()) return; final PropertyInspector propertyInspector = DesignerToolWindowManager.getInstance(editor).getPropertyInspector(); if (propertyInspector.isEditing()) { propertyInspector.stopEditing(); } //noinspection unchecked for(RadComponent component: selection) { //noinspection unchecked if (property.isModified(component)) { //noinspection unchecked property.resetValue(component); component.getDelegee().invalidate(); } } editor.refreshAndSave(false); propertyInspector.repaint(); } catch (Exception e1) { LOG.error(e1); } }
public final void actionPerformed(final AnActionEvent e) { final GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext()); if (editor != null) { final ArrayList<RadComponent> selection = FormEditingUtil.getSelectedComponents(editor); if (myModifying) { if (!editor.ensureEditable()) return; } Runnable runnable = new Runnable() { public void run() { actionPerformed(editor, selection, e); if (myModifying) { editor.refreshAndSave(true); } } }; if (getCommandName() != null) { CommandProcessor.getInstance().executeCommand(editor.getProject(), runnable, getCommandName(), null); } else { runnable.run(); } } }
public SelectionWatcher(final GuiEditor editor) { myEditor = editor; myChangeListener = new MyPropertyChangeListener(); myRootContainer = editor.getRootContainer(); install(myRootContainer); myHierarchyChangeListener = new HierarchyChangeListener() { public void hierarchyChanged() { if (myRootContainer != editor.getRootContainer()) { deinstall(myRootContainer); myRootContainer = editor.getRootContainer(); install(myRootContainer); } } }; editor.addHierarchyChangeListener(myHierarchyChangeListener); }
@Override protected LightToolWindow createContent(@NotNull DesignerEditorPanelFacade designer) { PaletteWindow palettePanel = new PaletteWindow(myProject); palettePanel.refreshPaletteIfChanged((GuiEditor)designer); return createContent(designer, palettePanel, IdeBundle.message("toolwindow.palette"), AllIcons.Toolwindows.ToolWindowPalette, palettePanel, palettePanel, 180, null); }
/** * @param component * @param validate */ public ComponentPtr(@NotNull final GuiEditor editor, @NotNull final RadComponent component, final boolean validate){ myEditor=editor; myId=component.getId(); if (validate) { validate(); if(!isValid()){ throw new IllegalArgumentException("invalid component: "+component); } } else { myComponent = component; } }
@Override protected void updateToolWindow(@Nullable DesignerEditorPanelFacade designer) { myToolWindowPanel.refreshPaletteIfChanged((GuiEditor)designer); if (designer == null) { myToolWindow.setAvailable(false, null); } else { myToolWindow.setAvailable(true, null); myToolWindow.show(null); } }
/** * Selects the component and ensures that the tabbed panes containing the component are * switched to the correct tab. * * @param editor * @param component the component to select. @return true if the component is enclosed in at least one tabbed pane, false otherwise. */ public static boolean selectComponent(final GuiEditor editor, @NotNull final RadComponent component) { boolean hasTab = false; RadComponent parent = component; while (parent.getParent() != null) { if (parent.getParent().getLayoutManager().switchContainerToChild(parent.getParent(), parent)) { hasTab = true; } parent = parent.getParent(); } component.setSelected(true); editor.setSelectionLead(component); return hasTab; }
public void actionPerformed(final AnActionEvent e) { final GuiEditor editor = myManager.getEditor(); if (editor == null) return; // 1. Show light bulb myManager.showIntentionHint(); // 2. Commit possible non committed value and show popup final PropertyInspector propertyInspector = DesignerToolWindowManager.getInstance(myManager.getEditor()).getPropertyInspector(); if(propertyInspector != null && propertyInspector.isEditing()) { propertyInspector.stopEditing(); } myManager.showIntentionPopup(); }
public static void restoreSelection(final GuiEditor editor, final ComponentPtr[] ptrs) { FormEditingUtil.clearSelection(editor.getRootContainer()); for(int i = ptrs.length - 1; i >= 0; i--){ final ComponentPtr ptr = ptrs[i]; ptr.validate(); if(ptr.isValid()){ ptr.getComponent().setSelected(true); } } }
public void selectedComponentChanged(final GuiEditor source) { if(myInsideChange){ // do not react on own events return; } mySelectionHistory.clear(); mySelectionHistory.push(getSelection(source)); }
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) { for(RadComponent c: selection) { RadContainer container = (RadContainer) c; final RadContainer parent = container.getParent(); if (container.getLayoutManager().isGrid()) { flattenGrid(container); } else { flattenSimple(container); } parent.revalidate(); } }
public void setEditor(final GuiEditor editor) { finishEditing(); myEditor = editor; if (myEditor == null) { mySelection.clear(); myProperties.clear(); myModel.fireTableDataChanged(); } }
public Object getData(final String dataId) { if(getClass().getName().equals(dataId)){ return this; } else if(CommonDataKeys.PSI_ELEMENT.is(dataId)){ final IntrospectedProperty introspectedProperty = getSelectedIntrospectedProperty(); if(introspectedProperty == null){ return null; } final PsiClass aClass = getComponentClass(); if(aClass == null){ return null; } final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, introspectedProperty.getName(), false, true); if(getter != null){ return getter; } return PropertyUtil.findPropertySetter(aClass, introspectedProperty.getName(), false, true); } else if (CommonDataKeys.PSI_FILE.is(dataId) && myEditor != null) { return PsiManager.getInstance(myEditor.getProject()).findFile(myEditor.getFile()); } else if (GuiEditor.DATA_KEY.is(dataId)) { return myEditor; } else if (PlatformDataKeys.FILE_EDITOR.is(dataId)) { GuiEditor designer = DesignerToolWindowManager.getInstance(myProject).getActiveFormEditor(); return designer == null ? null : designer.getEditor(); } else if (PlatformDataKeys.HELP_ID.is(dataId)) { return ourHelpID; } else { return null; } }
private static void test(final String oldText, final String newText, final int startOffset, final int endOffset, final String replacement) { final GuiEditor.ReplaceInfo replaceInfo = GuiEditor.findFragmentToChange(oldText, newText); assertEquals(startOffset, replaceInfo.getStartOffset()); assertEquals(endOffset, replaceInfo.getEndOffset()); assertEquals(replacement, replaceInfo.getReplacement()); if (startOffset != -1 || endOffset != -1){ assertEquals(newText, oldText.substring(0, startOffset) + replacement + oldText.substring(endOffset)); } }
public void update(GuiEditor designer) { clearTreeBuilder(); myComponentTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); myComponentTree.setEditor(designer); myPropertyInspector.setEditor(designer); if (designer == null) { myComponentTree.setFormEditor(null); } else { myComponentTree.setFormEditor(designer.getEditor()); myComponentTreeBuilder = new ComponentTreeBuilder(myComponentTree, designer); } }
public void actionPerformed(final ActionEvent e) { // 1. Show editor dialog final GuiEditor guiEditor = DesignerToolWindowManager.getInstance(myProject).getActiveFormEditor(); LOG.assertTrue(guiEditor != null); final StringEditorDialog dialog = new StringEditorDialog( myTfWithButton.getTextField(), getValue(), // we have pass here "live" (modified) value guiEditor.getStringDescriptorLocale(), guiEditor ); CommandProcessor.getInstance().executeCommand( myProject, new Runnable() { public void run() { if (!guiEditor.ensureEditable()) { return; } if (!dialog.showAndGet()) { return; } // 2. Apply new value final StringDescriptor descriptor = dialog.getDescriptor(); if (descriptor == null) { return; } setValue(descriptor); fireValueCommitted(true, false); if (myProperty != null) { myProperty.refreshValue(myComponent); } guiEditor.refreshAndSave(false); } }, UIDesignerBundle.message("command.edit.string.property"), null); }
public static DesignerToolWindow getInstance(GuiEditor designer) { DesignerToolWindowManager manager = getInstance(designer.getProject()); if (manager.isEditorMode()) { return (DesignerToolWindow)manager.getContent(designer); } return manager.myToolWindowPanel; }
@Override protected LightToolWindow createContent(@NotNull DesignerEditorPanelFacade designer) { DesignerToolWindow toolWindowContent = new DesignerToolWindow(myProject); toolWindowContent.update((GuiEditor)designer); return createContent(designer, toolWindowContent, UIDesignerBundle.message("toolwindow.ui.designer.title"), UIDesignerIcons.ToolWindowUIDesigner, toolWindowContent.getToolWindowPanel(), toolWindowContent.getComponentTree(), 320, null); }
public void setSelected(final boolean selected) { if (mySelected != selected) { mySelected = selected; firePropertyChanged(PROP_SELECTED, !mySelected, mySelected); GuiEditor.repaintLayeredPane(this); } }
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) { if (myColumnDelta != 0) { // sort the selection so that move in indexed layout will handle components in correct order Collections.sort(selection, new Comparator<RadComponent>() { public int compare(final RadComponent o1, final RadComponent o2) { int index1 = o1.getParent().indexOfComponent(o1); int index2 = o2.getParent().indexOfComponent(o2); return (index2 - index1) * myColumnDelta; } }); } for(RadComponent c: selection) { c.getParent().getLayoutManager().moveComponent(c, myRowDelta, myColumnDelta, myRowSpanDelta, myColSpanDelta); } }
@Override protected void update(@NotNull GuiEditor editor, final ArrayList<RadComponent> selection, final AnActionEvent e) { e.getPresentation().setEnabled(true); for(RadComponent c: selection) { if (!c.getParent().getLayoutManager().canMoveComponent(c, myRowDelta, myColumnDelta, myRowSpanDelta, myColSpanDelta)) { e.getPresentation().setEnabled(false); return; } } }
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) { final DefaultActionGroup actionGroup = prepareActionGroup(selection); final JComponent selectedComponent = selection.get(0).getDelegee(); final DataContext context = DataManager.getInstance().getDataContext(selectedComponent); final JBPopupFactory factory = JBPopupFactory.getInstance(); final ListPopup popup = factory.createActionGroupPopup(UIDesignerBundle.message("create.listener.title"), actionGroup, context, JBPopupFactory.ActionSelectionAid.NUMBERING, true); FormEditingUtil.showPopupUnderComponent(popup, selection.get(0)); }
public void actionPerformed(final AnActionEvent e) { final GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext()); CaptionSelection selection = CaptionSelection.DATA_KEY.getData(e.getDataContext()); if (editor == null || selection == null || selection.getFocusedIndex() < 0) return; FormEditingUtil.deleteRowOrColumn(editor, selection.getContainer(), selection.getSelection(), selection.isRow()); selection.getContainer().revalidate(); }
public void update(final AnActionEvent e) { final Presentation presentation = e.getPresentation(); final GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext()); if(editor == null){ presentation.setEnabled(false); return; } final SelectionState selectionState = editor.getSelectionState(); selectionState.setInsideChange(true); final Stack<ComponentPtr[]> history = selectionState.getSelectionHistory(); presentation.setEnabled(!history.isEmpty()); }
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) { Processor<ComponentItem> processor = new Processor<ComponentItem>() { public boolean process(final ComponentItem selectedValue) { SwingUtilities.invokeLater(new Runnable() { public void run() { Runnable runnable = new Runnable() { public void run() { for(RadComponent c: selection) { if (!morphComponent(editor, c, selectedValue)) break; } editor.refreshAndSave(true); } }; CommandProcessor.getInstance().executeCommand(editor.getProject(), runnable, UIDesignerBundle.message("morph.component.command"), null); editor.getGlassLayer().requestFocus(); } }); return true; } }; PaletteListPopupStep step = new PaletteListPopupStep(editor, myLastMorphComponent, processor, UIDesignerBundle.message("morph.component.title")); step.hideNonAtomic(); if (selection.size() == 1) { step.hideComponentClass(selection.get(0).getComponentClassName()); } final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step); FormEditingUtil.showPopupUnderComponent(listPopup, selection.get(0)); }
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) { final PropertyInspectorTable inspector = PropertyInspectorTable.DATA_KEY.getData(e.getDataContext()); assert inspector != null; final Property property = inspector.getSelectedProperty(); assert property != null; doResetValue(selection, property, editor); }
protected void update(final GuiEditor editor, final ArrayList<RadComponent> selection, final AnActionEvent e) { PropertyInspectorTable inspector = PropertyInspectorTable.DATA_KEY.getData(e.getDataContext()); if (inspector != null) { final Property selectedProperty = inspector.getSelectedProperty(); //noinspection unchecked e.getPresentation().setEnabled(selectedProperty != null && selection.size() > 0 && inspector.isModifiedForSelection(selectedProperty)); } else { e.getPresentation().setEnabled(false); } }
private static String serializeForCopy(final GuiEditor editor, final List<RadComponent> components) { final XmlWriter writer = new XmlWriter(); writer.startElement(ELEMENT_SERIALIZED, Utils.FORM_NAMESPACE); for (final RadComponent component : components) { final Point shift; if (component.getParent() != null) { shift = SwingUtilities.convertPoint( component.getParent().getDelegee(), component.getX(), component.getY(), editor.getRootContainer().getDelegee() ); } else { shift = new Point(0, 0); } component.getX(); writer.startElement("item"); writer.addAttribute(ATTRIBUTE_X, shift.x); writer.addAttribute(ATTRIBUTE_Y, shift.y); if (component.getParent() != null) { final String parentLayout = component.getParent().getLayoutManager().getName(); if (parentLayout != null) { writer.addAttribute(ATTRIBUTE_PARENT_LAYOUT, parentLayout); } } component.write(writer); writer.endElement(); } writer.endElement(); return writer.getText(); }
PaletteListPopupStep(GuiEditor editor, ComponentItem initialSelection, final Processor<ComponentItem> runnable, final String title) { myInitialSelection = initialSelection; myRunnable = runnable; myProject = editor.getProject(); Palette palette = Palette.getInstance(editor.getProject()); for(GroupItem group: palette.getToolWindowGroups()) { Collections.addAll(myItems, group.getItems()); } myTitle = title; }
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); } }
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) { final ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder(); builder.beginUpdateSelection(); try { FormEditingUtil.iterate(editor.getRootContainer(), new FormEditingUtil.ComponentVisitor() { public boolean visit(final IComponent component) { ((RadComponent) component).setSelected(true); return true; } }); } finally { builder.endUpdateSelection(); } }
public void update(final AnActionEvent e) { final GuiEditor editor = FormEditingUtil.getActiveEditor(e.getDataContext()); if(editor == null){ e.getPresentation().setVisible(false); return; } final VirtualFile file = editor.getFile(); e.getPresentation().setVisible( FileDocumentManager.getInstance().getDocument(file) != null && file.getFileType() == StdFileTypes.GUI_DESIGNER_FORM ); }
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) { RadContainer container = getContainerToPack(selection); if (container != null) { container.getDelegee().setSize(container.getMinimumSize()); container.getDelegee().revalidate(); } }