Search in sources :

Example 1 with Property

use of com.intellij.designer.model.Property in project intellij-community by JetBrains.

the class InplaceEditingLayer method finishEditing.

private void finishEditing(boolean commit) {
    myDesigner.getSurfaceArea().removeSelectionListener(mySelectionListener);
    if (myInplaceComponent != null) {
        if (commit) {
            myDesigner.getToolProvider().execute(() -> {
                int size = myProperties.size();
                for (int i = 0; i < size; i++) {
                    Property property = myProperties.get(i);
                    Object oldValue = property.getValue(myRadComponent);
                    Object newValue = myEditors.get(i).getValue();
                    if (!Comparing.equal(oldValue, newValue)) {
                        property.setValue(myRadComponent, newValue);
                    }
                }
            }, DesignerBundle.message("command.set.property.value"), true);
        }
        for (PropertyEditor editor : myEditors) {
            editor.removePropertyEditorListener(myEditorListener);
        }
        removeInplaceComponent();
        myFocusWatcher.deinstall(myInplaceComponent);
        myInplaceComponent = null;
    }
    myRadComponent = null;
    myProperties = null;
    myEditors = null;
    myDesigner.getPreferredFocusedComponent().requestFocusInWindow();
    disableEvents(AWTEvent.MOUSE_EVENT_MASK);
    repaint();
}
Also used : PropertyEditor(com.intellij.designer.propertyTable.PropertyEditor) Property(com.intellij.designer.model.Property)

Example 2 with Property

use of com.intellij.designer.model.Property in project intellij-community by JetBrains.

the class InplaceEditingLayer method startEditing.

public void startEditing(@Nullable InplaceContext inplaceContext) {
    try {
        List<RadComponent> selection = myDesigner.getSurfaceArea().getSelection();
        if (selection.size() != 1) {
            return;
        }
        myRadComponent = selection.get(0);
        myProperties = myRadComponent.getInplaceProperties();
        if (myProperties.isEmpty()) {
            myRadComponent = null;
            myProperties = null;
            return;
        }
        myInplaceComponent = new JPanel(new GridLayoutManager(myProperties.size(), 2));
        myInplaceComponent.setBorder(new LineMarginBorder(5, 5, 5, 5));
        new AnAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                finishEditing(false);
            }
        }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, myInplaceComponent);
        myEditors = new ArrayList<>();
        JComponent componentToFocus = null;
        Font font = null;
        if (inplaceContext == null) {
            inplaceContext = new InplaceContext();
        }
        int row = 0;
        for (Property property : myProperties) {
            JLabel label = new JLabel(property.getName() + ":");
            if (font == null) {
                font = label.getFont().deriveFont(Font.BOLD);
            }
            label.setFont(font);
            myInplaceComponent.add(label, new GridConstraints(row, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, 0, 0, null, null, null));
            PropertyEditor editor = property.getEditor();
            myEditors.add(editor);
            JComponent component = editor.getComponent(myRadComponent, myDesigner, property.getValue(myRadComponent), inplaceContext);
            myInplaceComponent.add(component, new GridConstraints(row++, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, 0, null, null, null));
            if (componentToFocus == null) {
                componentToFocus = editor.getPreferredFocusedComponent();
            }
        }
        for (PropertyEditor editor : myEditors) {
            editor.addPropertyEditorListener(myEditorListener);
        }
        Rectangle bounds = myRadComponent.getBounds(this);
        Dimension size = myInplaceComponent.getPreferredSize();
        myPreferredWidth = Math.max(size.width, bounds.width);
        myInplaceComponent.setBounds(bounds.x, bounds.y, myPreferredWidth, size.height);
        add(myInplaceComponent);
        myDesigner.getSurfaceArea().addSelectionListener(mySelectionListener);
        if (componentToFocus == null) {
            componentToFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(myInplaceComponent);
        }
        if (componentToFocus == null) {
            componentToFocus = myInplaceComponent;
        }
        if (componentToFocus.requestFocusInWindow()) {
            myFocusWatcher.install(myInplaceComponent);
        } else {
            grabFocus();
            final JComponent finalComponentToFocus = componentToFocus;
            ApplicationManager.getApplication().invokeLater(() -> {
                finalComponentToFocus.requestFocusInWindow();
                myFocusWatcher.install(myInplaceComponent);
            });
        }
        enableEvents(AWTEvent.MOUSE_EVENT_MASK);
        repaint();
    } catch (Throwable e) {
        LOG.error(e);
    }
}
Also used : RadComponent(com.intellij.designer.model.RadComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) LineMarginBorder(com.intellij.designer.designSurface.feedbacks.LineMarginBorder) PropertyEditor(com.intellij.designer.propertyTable.PropertyEditor) InplaceContext(com.intellij.designer.propertyTable.InplaceContext) Property(com.intellij.designer.model.Property)

Example 3 with Property

use of com.intellij.designer.model.Property in project intellij-community by JetBrains.

the class ShowJavadoc method setEnabled.

private static void setEnabled(RadPropertyTable table, AnActionEvent e, Presentation presentation) {
    Property property = table.getSelectionProperty();
    presentation.setEnabled(property != null && !table.isEditing() && (property.getJavadocElement() != null || !StringUtil.isEmpty(property.getJavadocText())) && (e == null || e.getProject() != null));
}
Also used : Property(com.intellij.designer.model.Property)

Example 4 with Property

use of com.intellij.designer.model.Property in project intellij-community by JetBrains.

the class ShowJavadoc method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
        return;
    }
    DocumentationManager documentationManager = DocumentationManager.getInstance(project);
    final DocumentationComponent component = new DocumentationComponent(documentationManager);
    final Property property = myTable.getSelectionProperty();
    if (property == null) {
        return;
    }
    PsiElement javadocElement = property.getJavadocElement();
    ActionCallback callback;
    if (javadocElement == null) {
        callback = new ActionCallback();
        component.setText(property.getJavadocText(), null, true);
    } else {
        callback = documentationManager.queueFetchDocInfo(javadocElement, component);
    }
    callback.doWhenProcessed(() -> {
        JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component).setProject(project).setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(DesignerBundle.message("designer.properties.javadoc.title", property.getName())).setCancelCallback(() -> {
            Disposer.dispose(component);
            return Boolean.TRUE;
        }).createPopup();
        component.setHint(hint);
        Disposer.register(hint, component);
        hint.show(new RelativePoint(myTable.getParent(), new Point(0, 0)));
    });
    if (javadocElement == null) {
        callback.setDone();
    }
}
Also used : Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) ActionCallback(com.intellij.openapi.util.ActionCallback) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup) Property(com.intellij.designer.model.Property) PsiElement(com.intellij.psi.PsiElement)

Example 5 with Property

use of com.intellij.designer.model.Property in project intellij-community by JetBrains.

the class PropertyTable method setValueAtRow.

private boolean setValueAtRow(int row, final Object newValue) {
    final Property property = myProperties.get(row);
    final Object[] oldValue = new Object[1];
    boolean isNewValue;
    try {
        oldValue[0] = getValue(property);
        isNewValue = !Comparing.equal(oldValue[0], newValue);
        if (newValue == null && oldValue[0] instanceof String && ((String) oldValue[0]).length() == 0) {
            isNewValue = false;
        }
    } catch (Throwable e) {
        isNewValue = true;
    }
    boolean isSetValue = true;
    final boolean[] needRefresh = new boolean[1];
    if (isNewValue) {
        isSetValue = doSetValue(() -> {
            for (PropertiesContainer component : myContainers) {
                property.setValue(component, newValue);
                needRefresh[0] |= property.needRefreshPropertyList(component, oldValue[0], newValue);
            }
        });
    }
    if (isSetValue) {
        if (property.needRefreshPropertyList() || needRefresh[0]) {
            update(myContainers, null, property.closeEditorDuringRefresh());
        } else {
            myModel.fireTableRowsUpdated(row, row);
        }
    }
    return isSetValue;
}
Also used : PropertiesContainer(com.intellij.designer.model.PropertiesContainer) Property(com.intellij.designer.model.Property)

Aggregations

Property (com.intellij.designer.model.Property)15 PropertiesContainer (com.intellij.designer.model.PropertiesContainer)2 PropertyEditor (com.intellij.designer.propertyTable.PropertyEditor)2 DocumentationComponent (com.intellij.codeInsight.documentation.DocumentationComponent)1 DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)1 LineMarginBorder (com.intellij.designer.designSurface.feedbacks.LineMarginBorder)1 RadComponent (com.intellij.designer.model.RadComponent)1 InplaceContext (com.intellij.designer.propertyTable.InplaceContext)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Project (com.intellij.openapi.project.Project)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 ActionCallback (com.intellij.openapi.util.ActionCallback)1 PsiElement (com.intellij.psi.PsiElement)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)1