Ejemplo n.º 1
0
  public RegistryUi() {
    myContent.setLayout(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP));

    myModel = new MyTableModel();
    myTable = new JBTable(myModel);
    myTable.setCellSelectionEnabled(true);
    myTable.setEnableAntialiasing(true);
    final MyRenderer r = new MyRenderer();

    final TableColumn c0 = myTable.getColumnModel().getColumn(0);
    c0.setCellRenderer(r);
    c0.setMaxWidth(RESTART_ICON.getIconWidth() + 12);
    c0.setMinWidth(RESTART_ICON.getIconWidth() + 12);
    c0.setHeaderValue(null);

    final TableColumn c1 = myTable.getColumnModel().getColumn(1);
    c1.setCellRenderer(r);
    c1.setHeaderValue("Key");

    final TableColumn c2 = myTable.getColumnModel().getColumn(2);
    c2.setCellRenderer(r);
    c2.setHeaderValue("Value");
    c2.setCellEditor(new MyEditor());
    myTable.setStriped(true);

    myDescriptionLabel = new JTextArea(3, 50);
    myDescriptionLabel.setEditable(false);
    final JScrollPane label = ScrollPaneFactory.createScrollPane(myDescriptionLabel);
    final JPanel descriptionPanel = new JPanel(new BorderLayout());
    descriptionPanel.add(label, BorderLayout.CENTER);
    descriptionPanel.setBorder(
        IdeBorderFactory.createTitledBorder("Description", false, false, true));

    myContent.add(ScrollPaneFactory.createScrollPane(myTable), BorderLayout.CENTER);
    myContent.add(descriptionPanel, BorderLayout.SOUTH);

    myTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) return;

                final int selected = myTable.getSelectedRow();
                if (selected != -1) {
                  final RegistryValue value = myModel.getRegistryValue(selected);
                  String desc = value.getDescription();
                  if (value.isRestartRequired()) {
                    String required = "Requires IDE restart.";
                    if (desc.endsWith(".")) {
                      desc += required;
                    } else {
                      desc += (". " + required);
                    }
                  }
                  myDescriptionLabel.setText(desc);
                } else {
                  myDescriptionLabel.setText(null);
                }
              }
            });

    myRestoreDefaultsAction = new RestoreDefaultsAction();

    final DefaultActionGroup tbGroup = new DefaultActionGroup();
    tbGroup.add(new EditAction());
    tbGroup.add(new RevertAction());

    final ActionToolbar tb =
        ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, tbGroup, true);
    tb.setTargetComponent(myTable);

    myContent.add(tb.getComponent(), BorderLayout.NORTH);
    new TableSpeedSearch(myTable).setComparator(new SpeedSearchComparator(false));
  }
  @NotNull
  protected List<Pair<String, JPanel>> createAdditionalPanels() {
    // this method is invoked before constructor body
    myExceptionsModel = new ExceptionsTableModel(myMethod.getMethod().getThrowsList());
    myExceptionsModel.setTypeInfos(myMethod.getMethod());

    final JBTable table = new JBTable(myExceptionsModel);
    table.setStriped(true);
    table.setRowHeight(20);
    table
        .getColumnModel()
        .getColumn(0)
        .setCellRenderer(new CodeFragmentTableCellRenderer(myProject));
    final JavaCodeFragmentTableCellEditor cellEditor =
        new JavaCodeFragmentTableCellEditor(myProject);
    cellEditor.addDocumentListener(
        new DocumentAdapter() {
          @Override
          public void documentChanged(DocumentEvent e) {
            final int row = table.getSelectedRow();
            final int col = table.getSelectedColumn();
            myExceptionsModel.setValueAt(cellEditor.getCellEditorValue(), row, col);
            updateSignature();
          }
        });
    table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().setSelectionInterval(0, 0);
    table.setSurrendersFocusOnKeystroke(true);

    myPropExceptionsButton =
        new AnActionButton(
            RefactoringBundle.message("changeSignature.propagate.exceptions.title"),
            null,
            PlatformIcons.NEW_EXCEPTION) {
          @Override
          public void actionPerformed(AnActionEvent e) {
            final Ref<JavaCallerChooser> chooser = new Ref<JavaCallerChooser>();
            Consumer<Set<PsiMethod>> callback =
                new Consumer<Set<PsiMethod>>() {
                  @Override
                  public void consume(Set<PsiMethod> psiMethods) {
                    myMethodsToPropagateExceptions = psiMethods;
                    myExceptionPropagationTree = chooser.get().getTree();
                  }
                };
            chooser.set(
                new JavaCallerChooser(
                    myMethod.getMethod(),
                    myProject,
                    RefactoringBundle.message("changeSignature.exception.caller.chooser"),
                    myExceptionPropagationTree,
                    callback));
            chooser.get().show();
          }
        };
    myPropExceptionsButton.setShortcut(CustomShortcutSet.fromString("alt X"));

    final JPanel panel =
        ToolbarDecorator.createDecorator(table)
            .addExtraAction(myPropExceptionsButton)
            .createPanel();
    panel.setBorder(IdeBorderFactory.createEmptyBorder(0));

    myExceptionsModel.addTableModelListener(mySignatureUpdater);

    final ArrayList<Pair<String, JPanel>> result = new ArrayList<Pair<String, JPanel>>();
    final String message =
        RefactoringBundle.message("changeSignature.exceptions.panel.border.title");
    result.add(Pair.create(message, panel));
    return result;
  }