Search in sources :

Example 1 with TextWithImports

use of com.intellij.debugger.engine.evaluation.TextWithImports in project intellij-community by JetBrains.

the class CompoundRendererConfigurable method createChildrenListEditor.

private JComponent createChildrenListEditor(JavaDebuggerEditorsProvider editorsProvider) {
    final MyTableModel tableModel = new MyTableModel();
    myTable = new JBTable(tableModel);
    myListChildrenEditor = new XDebuggerExpressionEditor(myProject, editorsProvider, "NamedChildrenConfigurable", null, XExpressionImpl.EMPTY_EXPRESSION, false, false, false);
    JComponent editorComponent = myListChildrenEditor.getComponent();
    AbstractTableCellEditor editor = new AbstractTableCellEditor() {

        @Override
        public Object getCellEditorValue() {
            return TextWithImportsImpl.fromXExpression(myListChildrenEditor.getExpression());
        }

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
            myListChildrenEditor.setExpression(TextWithImportsImpl.toXExpression((TextWithImports) value));
            return editorComponent;
        }
    };
    editorComponent.registerKeyboardAction(e -> editor.stopCellEditing(), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    editorComponent.registerKeyboardAction(e -> editor.cancelCellEditing(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    TableColumn exprColumn = myTable.getColumnModel().getColumn(EXPRESSION_TABLE_COLUMN);
    exprColumn.setCellEditor(editor);
    exprColumn.setCellRenderer(new DefaultTableCellRenderer() {

        @NotNull
        @Override
        public Component getTableCellRendererComponent(@NotNull JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            final TextWithImports textWithImports = (TextWithImports) value;
            final String text = (textWithImports != null) ? textWithImports.getText() : "";
            return super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);
        }
    });
    return ToolbarDecorator.createDecorator(myTable).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            tableModel.addRow("", DebuggerUtils.getInstance().createExpressionWithImports(""));
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            int selectedRow = myTable.getSelectedRow();
            if (selectedRow >= 0 && selectedRow < myTable.getRowCount()) {
                getTableModel().removeRow(selectedRow);
            }
        }
    }).setMoveUpAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.moveSelectedItemsUp(myTable);
        }
    }).setMoveDownAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.moveSelectedItemsDown(myTable);
        }
    }).createPanel();
}
Also used : XDebuggerExpressionEditor(com.intellij.xdebugger.impl.ui.XDebuggerExpressionEditor) JBTable(com.intellij.ui.table.JBTable) TableColumn(javax.swing.table.TableColumn) NotNull(org.jetbrains.annotations.NotNull) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports)

Example 2 with TextWithImports

use of com.intellij.debugger.engine.evaluation.TextWithImports in project intellij-community by JetBrains.

the class CompoundRendererConfigurable method reset.

public void reset() {
    final TextWithImports emptyExpressionFragment = new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, "");
    ((CardLayout) getLayout()).show(this, myRenderer == null ? EMPTY_PANEL_ID : DATA_PANEL_ID);
    if (myRenderer == null) {
        return;
    }
    final String className = myRenderer.getClassName();
    myClassNameField.setText(className);
    updateContext(className);
    final ValueLabelRenderer labelRenderer = myRenderer.getLabelRenderer();
    final ChildrenRenderer childrenRenderer = myRenderer.getChildrenRenderer();
    myShowTypeCheckBox.setSelected(myRenderer.isShowType());
    if (myRenderer.isBaseRenderer(labelRenderer)) {
        myLabelEditor.setExpression(TextWithImportsImpl.toXExpression(emptyExpressionFragment));
        myRbDefaultLabel.setSelected(true);
    } else {
        myRbExpressionLabel.setSelected(true);
        myLabelEditor.setExpression(TextWithImportsImpl.toXExpression(((LabelRenderer) labelRenderer).getLabelExpression()));
    }
    getTableModel().clear();
    myAppendDefaultChildren.setSelected(false);
    if (myRenderer.isBaseRenderer(childrenRenderer)) {
        myRbDefaultChildrenRenderer.setSelected(true);
        myChildrenEditor.setExpression(TextWithImportsImpl.toXExpression(emptyExpressionFragment));
        myChildrenExpandedEditor.setExpression(TextWithImportsImpl.toXExpression(emptyExpressionFragment));
    } else if (childrenRenderer instanceof ExpressionChildrenRenderer) {
        myRbExpressionChildrenRenderer.setSelected(true);
        final ExpressionChildrenRenderer exprRenderer = (ExpressionChildrenRenderer) childrenRenderer;
        myChildrenEditor.setExpression(TextWithImportsImpl.toXExpression(exprRenderer.getChildrenExpression()));
        myChildrenExpandedEditor.setExpression(TextWithImportsImpl.toXExpression(exprRenderer.getChildrenExpandable()));
    } else {
        myRbListChildrenRenderer.setSelected(true);
        myChildrenEditor.setExpression(TextWithImportsImpl.toXExpression(emptyExpressionFragment));
        myChildrenExpandedEditor.setExpression(TextWithImportsImpl.toXExpression(emptyExpressionFragment));
        if (childrenRenderer instanceof EnumerationChildrenRenderer) {
            EnumerationChildrenRenderer enumerationRenderer = (EnumerationChildrenRenderer) childrenRenderer;
            getTableModel().init(enumerationRenderer.getChildren());
            myAppendDefaultChildren.setSelected(enumerationRenderer.isAppendDefaultChildren());
        }
    }
    updateEnabledState();
}
Also used : TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl)

Example 3 with TextWithImports

use of com.intellij.debugger.engine.evaluation.TextWithImports in project intellij-community by JetBrains.

the class DebuggerTreeCreatorImpl method createDescriptorByNode.

@Override
public void createDescriptorByNode(Object node, final ResultConsumer<Pair<NodeDescriptorImpl, String>> resultConsumer) {
    if (node instanceof DebuggerTreeNodeImpl) {
        final DebuggerTreeNodeImpl debuggerTreeNode = (DebuggerTreeNodeImpl) node;
        final DebuggerContextImpl context = DebuggerManagerEx.getInstanceEx(myProject).getContext();
        context.getDebugProcess().getManagerThread().schedule(new DebuggerContextCommandImpl(context) {

            @Override
            public void threadAction() {
                try {
                    final TextWithImports evaluationText = DebuggerTreeNodeExpression.createEvaluationText(debuggerTreeNode, context);
                    resultConsumer.onSuccess(Pair.create(debuggerTreeNode.getDescriptor(), evaluationText.getText()));
                } catch (EvaluateException e) {
                    resultConsumer.onFailure(e);
                }
            }
        });
    }
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl)

Example 4 with TextWithImports

use of com.intellij.debugger.engine.evaluation.TextWithImports in project intellij-community by JetBrains.

the class DebuggerTreeNodeExpression method createEvaluationText.

public static TextWithImports createEvaluationText(final DebuggerTreeNodeImpl node, final DebuggerContextImpl context) throws EvaluateException {
    final EvaluateException[] ex = new EvaluateException[] { null };
    final TextWithImports textWithImports = PsiDocumentManager.getInstance(context.getProject()).commitAndRunReadAction((Computable<TextWithImports>) () -> {
        try {
            final PsiExpression expressionText = getEvaluationExpression(node, context);
            if (expressionText != null) {
                return new TextWithImportsImpl(expressionText);
            }
        } catch (EvaluateException e) {
            ex[0] = e;
        }
        return null;
    });
    if (ex[0] != null) {
        throw ex[0];
    }
    return textWithImports;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl)

Example 5 with TextWithImports

use of com.intellij.debugger.engine.evaluation.TextWithImports in project intellij-community by JetBrains.

the class CustomFieldInplaceEditor method doOKAction.

@Override
public void doOKAction() {
    List<Pair<String, TextWithImports>> children = getRendererChildren();
    TextWithImports newText = TextWithImportsImpl.fromXExpression(myExpressionEditor.getExpression());
    if (myDescriptor == null) {
        children.add(0, Pair.create("", newText));
    } else {
        int index = myDescriptor.getEnumerationIndex();
        children.set(index, Pair.create(children.get(index).first, newText));
    }
    myTree.putClientProperty(XDebuggerTreeRestorer.SELECTION_PATH_PROPERTY, createDummySelectionTreePath(newText.getText(), (XDebuggerTreeNode) myNode.getParent()));
    XDebuggerUtilImpl.rebuildTreeAndViews(myTree);
    super.doOKAction();
}
Also used : TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports) XDebuggerTreeNode(com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode) Pair(com.intellij.openapi.util.Pair)

Aggregations

TextWithImports (com.intellij.debugger.engine.evaluation.TextWithImports)13 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)3 TextWithImportsImpl (com.intellij.debugger.engine.evaluation.TextWithImportsImpl)2 PsiElement (com.intellij.psi.PsiElement)2 Element (org.jdom.Element)2 SourcePosition (com.intellij.debugger.SourcePosition)1 CodeFragmentFactory (com.intellij.debugger.engine.evaluation.CodeFragmentFactory)1 EvaluationContextImpl (com.intellij.debugger.engine.evaluation.EvaluationContextImpl)1 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)1 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)1 UserExpressionData (com.intellij.debugger.impl.descriptors.data.UserExpressionData)1 LocalVariableProxyImpl (com.intellij.debugger.jdi.LocalVariableProxyImpl)1 DebuggerTreeNodeImpl (com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl)1 Pair (com.intellij.openapi.util.Pair)1 JBTable (com.intellij.ui.table.JBTable)1 AbstractTableCellEditor (com.intellij.util.ui.AbstractTableCellEditor)1 XSourcePosition (com.intellij.xdebugger.XSourcePosition)1 XDebuggerExpressionEditor (com.intellij.xdebugger.impl.ui.XDebuggerExpressionEditor)1 XDebuggerTreeNode (com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode)1 ArrayList (java.util.ArrayList)1