Search in sources :

Example 1 with ComponentPtr

use of com.intellij.uiDesigner.componentTree.ComponentPtr in project intellij-community by JetBrains.

the class SelectionState method restoreSelection.

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);
        }
    }
}
Also used : ComponentPtr(com.intellij.uiDesigner.componentTree.ComponentPtr)

Example 2 with ComponentPtr

use of com.intellij.uiDesigner.componentTree.ComponentPtr in project intellij-community by JetBrains.

the class SelectionState method getSelection.

public static ComponentPtr[] getSelection(final GuiEditor editor) {
    final ArrayList<RadComponent> selection = FormEditingUtil.getAllSelectedComponents(editor);
    final ComponentPtr[] ptrs = new ComponentPtr[selection.size()];
    for (int i = selection.size() - 1; i >= 0; i--) {
        ptrs[i] = new ComponentPtr(editor, selection.get(i));
    }
    return ptrs;
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ComponentPtr(com.intellij.uiDesigner.componentTree.ComponentPtr)

Example 3 with ComponentPtr

use of com.intellij.uiDesigner.componentTree.ComponentPtr in project intellij-community by JetBrains.

the class GuiEditor method readFromFile.

/**
   * Creates and sets new <code>RadRootContainer</code>
   *
   * @param keepSelection if true, the GUI designer tries to preserve the selection state after reload.
   */
public void readFromFile(final boolean keepSelection) {
    try {
        ComponentPtr[] selection = null;
        Map<String, String> tabbedPaneSelectedTabs = null;
        if (keepSelection) {
            selection = SelectionState.getSelection(this);
            tabbedPaneSelectedTabs = saveTabbedPaneSelectedTabs();
        }
        Locale oldLocale = null;
        if (myRootContainer != null) {
            oldLocale = myRootContainer.getStringDescriptorLocale();
        }
        final String text = myDocument.getText();
        final ClassLoader classLoader = LoaderFactory.getInstance(getProject()).getLoader(myFile);
        final LwRootContainer rootContainer = Utils.getRootContainer(text, new CompiledClassPropertiesProvider(classLoader));
        final RadRootContainer container = XmlReader.createRoot(this, rootContainer, classLoader, oldLocale);
        setRootContainer(container);
        if (keepSelection) {
            SelectionState.restoreSelection(this, selection);
            restoreTabbedPaneSelectedTabs(tabbedPaneSelectedTabs);
        }
        myInvalid = false;
        myCardLayout.show(myCardPanel, CARD_VALID);
        refresh();
    } catch (Exception exc) {
        Throwable original = exc;
        while (original instanceof InvocationTargetException) {
            original = original.getCause();
        }
        showInvalidCard(original);
    } catch (final LinkageError exc) {
        showInvalidCard(exc);
    }
}
Also used : Locale(java.util.Locale) CompiledClassPropertiesProvider(com.intellij.uiDesigner.lw.CompiledClassPropertiesProvider) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) LwRootContainer(com.intellij.uiDesigner.lw.LwRootContainer) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ComponentPtr(com.intellij.uiDesigner.componentTree.ComponentPtr)

Example 4 with ComponentPtr

use of com.intellij.uiDesigner.componentTree.ComponentPtr in project intellij-community by JetBrains.

the class ExpandSelectionAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext());
    assert editor != null;
    final SelectionState selectionState = editor.getSelectionState();
    selectionState.setInsideChange(true);
    ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder();
    if (builder != null) {
        builder.beginUpdateSelection();
    }
    final Stack<ComponentPtr[]> history = selectionState.getSelectionHistory();
    try {
        final ComponentPtr[] ptrs = history.peek();
        for (int i = ptrs.length - 1; i >= 0; i--) {
            // Skip invalid components
            final ComponentPtr ptr = ptrs[i];
            ptr.validate();
            if (!ptr.isValid()) {
                continue;
            }
            // Extend selection
            final RadComponent component = ptr.getComponent();
            final RadContainer parent = component.getParent();
            if (parent == null) {
                // skip components without parents
                continue;
            }
            boolean shouldSelectParent = true;
            for (int j = parent.getComponentCount() - 1; j >= 0; j--) {
                final RadComponent sibling = parent.getComponent(j);
                if (!sibling.isSelected()) {
                    shouldSelectParent = false;
                    sibling.setSelected(true);
                }
            }
            if (shouldSelectParent) {
                parent.setSelected(true);
            }
        }
        // Store new selection
        history.push(SelectionState.getSelection(editor));
    } finally {
        if (builder != null) {
            builder.endUpdateSelection();
        }
        selectionState.setInsideChange(false);
    }
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) ComponentPtr(com.intellij.uiDesigner.componentTree.ComponentPtr) SelectionState(com.intellij.uiDesigner.SelectionState) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) ComponentTreeBuilder(com.intellij.uiDesigner.componentTree.ComponentTreeBuilder)

Aggregations

ComponentPtr (com.intellij.uiDesigner.componentTree.ComponentPtr)4 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)2 SelectionState (com.intellij.uiDesigner.SelectionState)1 ComponentTreeBuilder (com.intellij.uiDesigner.componentTree.ComponentTreeBuilder)1 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)1 CompiledClassPropertiesProvider (com.intellij.uiDesigner.lw.CompiledClassPropertiesProvider)1 LwRootContainer (com.intellij.uiDesigner.lw.LwRootContainer)1 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)1 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Locale (java.util.Locale)1