Exemplo n.º 1
0
  public void reset() {
    final TextWithImports emptyExpressionFragment =
        new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, "");
    ((CardLayout) myMainPanel.getLayout())
        .show(myMainPanel, myRenderer == null ? EMPTY_PANEL_ID : DATA_PANEL_ID);
    if (myRenderer == null) {
      return;
    }
    final String className = myRenderer.getClassName();
    myClassNameField.setText(className);
    final ValueLabelRenderer labelRenderer = myRenderer.getLabelRenderer();
    final ChildrenRenderer childrenRenderer = myRenderer.getChildrenRenderer();
    final NodeRendererSettings rendererSettings = NodeRendererSettings.getInstance();

    if (rendererSettings.isBase(labelRenderer)) {
      myRbDefaultLabel.setSelected(true);
      myLabelEditor.setText(emptyExpressionFragment);
    } else {
      myRbExpressionLabel.setSelected(true);
      myLabelEditor.setText(((LabelRenderer) labelRenderer).getLabelExpression());
    }

    if (rendererSettings.isBase(childrenRenderer)) {
      myRbDefaultChildrenRenderer.setSelected(true);
      myChildrenEditor.setText(emptyExpressionFragment);
      myChildrenExpandedEditor.setText(emptyExpressionFragment);
      getTableModel().clear();
    } else if (childrenRenderer instanceof ExpressionChildrenRenderer) {
      myRbExpressionChildrenRenderer.setSelected(true);
      final ExpressionChildrenRenderer exprRenderer = (ExpressionChildrenRenderer) childrenRenderer;
      myChildrenEditor.setText(exprRenderer.getChildrenExpression());
      myChildrenExpandedEditor.setText(exprRenderer.getChildrenExpandable());
      getTableModel().clear();
    } else {
      myRbListChildrenRenderer.setSelected(true);
      myChildrenEditor.setText(emptyExpressionFragment);
      myChildrenExpandedEditor.setText(emptyExpressionFragment);
      if (childrenRenderer instanceof EnumerationChildrenRenderer) {
        getTableModel().init(((EnumerationChildrenRenderer) childrenRenderer).getChildren());
      } else {
        getTableModel().clear();
      }
    }

    updateEnabledState();
    updateContext(className);
  }
Exemplo n.º 2
0
  public JComponent createComponent() {
    final JPanel panel = new JPanel(new GridBagLayout());
    myClassNameField =
        new TextFieldWithBrowseButton(
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                PsiClass psiClass =
                    DebuggerUtils.getInstance()
                        .chooseClassDialog(
                            DebuggerBundle.message(
                                "title.compound.renderer.configurable.choose.renderer.reference.type"),
                            myProject);
                if (psiClass != null) {
                  myClassNameField.setText(JVMNameUtil.getNonAnonymousClassName(psiClass));
                }
              }
            });
    myClassNameField
        .getTextField()
        .addFocusListener(
            new FocusAdapter() {
              public void focusLost(FocusEvent e) {
                final String qName = myClassNameField.getText();
                updateContext(qName);
              }
            });

    myRbDefaultLabel =
        new JRadioButton(
            DebuggerBundle.message("label.compound.renderer.configurable.use.default.renderer"));
    myRbExpressionLabel =
        new JRadioButton(
            DebuggerBundle.message("label.compound.renderer.configurable.use.expression"));
    final ButtonGroup labelButtonsGroup = new ButtonGroup();
    labelButtonsGroup.add(myRbDefaultLabel);
    labelButtonsGroup.add(myRbExpressionLabel);

    myRbDefaultChildrenRenderer =
        new JRadioButton(
            DebuggerBundle.message("label.compound.renderer.configurable.use.default.renderer"));
    myRbExpressionChildrenRenderer =
        new JRadioButton(
            DebuggerBundle.message("label.compound.renderer.configurable.use.expression"));
    myRbListChildrenRenderer =
        new JRadioButton(
            DebuggerBundle.message("label.compound.renderer.configurable.use.expression.list"));
    final ButtonGroup childrenButtonGroup = new ButtonGroup();
    childrenButtonGroup.add(myRbDefaultChildrenRenderer);
    childrenButtonGroup.add(myRbExpressionChildrenRenderer);
    childrenButtonGroup.add(myRbListChildrenRenderer);

    myLabelEditor = new DebuggerExpressionTextField(myProject, null, "ClassLabelExpression");
    myChildrenEditor = new DebuggerExpressionTextField(myProject, null, "ClassChildrenExpression");
    myChildrenExpandedEditor =
        new DebuggerExpressionTextField(myProject, null, "ClassChildrenExpression");
    myChildrenListEditor = createChildrenListEditor();

    final ItemListener updateListener =
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            updateEnabledState();
          }
        };
    myRbExpressionLabel.addItemListener(updateListener);
    myRbListChildrenRenderer.addItemListener(updateListener);
    myRbExpressionChildrenRenderer.addItemListener(updateListener);

    panel.add(
        new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.apply.to")),
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));
    panel.add(
        myClassNameField,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(4, 0, 0, 0),
            0,
            0));

    panel.add(
        new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.when.rendering")),
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(20, 0, 0, 0),
            0,
            0));
    panel.add(
        myRbDefaultLabel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    panel.add(
        myRbExpressionLabel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    panel.add(
        myLabelEditor,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 30, 0, 0),
            0,
            0));

    panel.add(
        new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.when.expanding")),
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(20, 0, 0, 0),
            0,
            0));
    panel.add(
        myRbDefaultChildrenRenderer,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    panel.add(
        myRbExpressionChildrenRenderer,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    panel.add(
        myChildrenEditor,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 30, 0, 0),
            0,
            0));
    myExpandedLabel =
        new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.test.can.expand"));
    panel.add(
        myExpandedLabel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(4, 30, 0, 0),
            0,
            0));
    panel.add(
        myChildrenExpandedEditor,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 30, 0, 0),
            0,
            0));
    panel.add(
        myRbListChildrenRenderer,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 10, 0, 0),
            0,
            0));
    panel.add(
        myChildrenListEditor,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(4, 30, 0, 0),
            0,
            0));

    myMainPanel = new JPanel(new CardLayout());
    myMainPanel.add(new JPanel(), EMPTY_PANEL_ID);
    myMainPanel.add(panel, DATA_PANEL_ID);
    return myMainPanel;
  }
Exemplo n.º 3
0
  private JComponent createChildrenListEditor() {
    final MyTableModel tableModel = new MyTableModel();
    myTable = new Table(tableModel);
    myListChildrenEditor =
        new DebuggerExpressionTextField(myProject, null, "NamedChildrenConfigurable");

    final TableColumn exprColumn = myTable.getColumnModel().getColumn(EXPRESSION_TABLE_COLUMN);
    exprColumn.setCellEditor(
        new AbstractTableCellEditor() {
          public Object getCellEditorValue() {
            return myListChildrenEditor.getText();
          }

          public Component getTableCellEditorComponent(
              JTable table, Object value, boolean isSelected, int row, int column) {
            myListChildrenEditor.setText((TextWithImports) value);
            return myListChildrenEditor;
          }
        });
    exprColumn.setCellRenderer(
        new DefaultTableCellRenderer() {
          public Component getTableCellRendererComponent(
              JTable table,
              Object value,
              boolean isSelected,
              boolean hasFocus,
              int row,
              int column) {
            final TextWithImports textWithImports = (TextWithImports) value;
            String text = (textWithImports != null) ? textWithImports.toString() : "";
            return super.getTableCellRendererComponent(
                table, text, isSelected, hasFocus, row, column);
          }
        });

    myAddButton = new JButton(DebuggerBundle.message("button.add"));
    myRemoveButton = new JButton(DebuggerBundle.message("button.remove"));
    myUpButton = new JButton(DebuggerBundle.message("button.move.up"));
    myDownButton = new JButton(DebuggerBundle.message("button.move.down"));

    myAddButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            tableModel.addRow("", DebuggerUtils.getInstance().createExpressionWithImports(""));
          }
        });

    myRemoveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int selectedRow = myTable.getSelectedRow();
            if (selectedRow >= 0 && selectedRow < myTable.getRowCount()) {
              getTableModel().removeRow(selectedRow);
            }
          }
        });

    myDownButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            TableUtil.moveSelectedItemsDown(myTable);
          }
        });

    myUpButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            TableUtil.moveSelectedItemsUp(myTable);
          }
        });

    myTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                int selectedRow = myTable.getSelectedRow();
                myRemoveButton.setEnabled(selectedRow != -1);
                myUpButton.setEnabled(selectedRow > 0);
                myDownButton.setEnabled(selectedRow < myTable.getRowCount() - 1);
              }
            });

    final JPanel panel =
        new JPanel(new GridBagLayout()) {
          public void setEnabled(boolean enabled) {
            super.setEnabled(enabled);
            myTable.setEnabled(enabled);
            myAddButton.setEnabled(enabled);
            myRemoveButton.setEnabled(enabled);
            myUpButton.setEnabled(enabled);
            myDownButton.setEnabled(enabled);
          }
        };
    final JScrollPane scrollPane = new JScrollPane(myTable);
    panel.add(
        scrollPane,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            4,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    panel.add(
        myAddButton,
        new GridBagConstraints(
            1,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 4, 4, 0),
            0,
            0));
    panel.add(
        myRemoveButton,
        new GridBagConstraints(
            1,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 4, 4, 0),
            0,
            0));
    panel.add(
        myUpButton,
        new GridBagConstraints(
            1,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 4, 4, 0),
            0,
            0));
    panel.add(
        myDownButton,
        new GridBagConstraints(
            1,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 4, 4, 0),
            0,
            0));

    return panel;
  }