Search in sources :

Example 1 with JavaCodeFragmentTableCellEditor

use of com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor in project intellij-community by JetBrains.

the class GrChangeSignatureDialog method createAdditionalPanels.

@NotNull
@Override
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(              //todo propagate parameters
      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).createPanel();
    //.addExtraAction(myPropExceptionsButton).createPanel();
    panel.setBorder(IdeBorderFactory.createEmptyBorder());
    myExceptionsModel.addTableModelListener(mySignatureUpdater);
    final ArrayList<Pair<String, JPanel>> result = new ArrayList<>();
    final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title");
    result.add(Pair.create(message, panel));
    return result;
}
Also used : ExceptionsTableModel(com.intellij.refactoring.changeSignature.ExceptionsTableModel) ArrayList(java.util.ArrayList) CodeFragmentTableCellRenderer(com.intellij.refactoring.ui.CodeFragmentTableCellRenderer) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) JBTable(com.intellij.ui.table.JBTable) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) JavaCodeFragmentTableCellEditor(com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JavaCodeFragmentTableCellEditor

use of com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor in project intellij-community by JetBrains.

the class JavaChangeSignatureDialog method createAdditionalPanels.

@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, AllIcons.Hierarchy.Caller) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final Ref<JavaCallerChooser> chooser = new Ref<>();
            Consumer<Set<PsiMethod>> callback = 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());
    myExceptionsModel.addTableModelListener(mySignatureUpdater);
    final ArrayList<Pair<String, JPanel>> result = new ArrayList<>();
    final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title");
    result.add(Pair.create(message, panel));
    return result;
}
Also used : JavaCallerChooser(com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser) ArrayList(java.util.ArrayList) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) JBTable(com.intellij.ui.table.JBTable) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) JavaCodeFragmentTableCellEditor(com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor) Ref(com.intellij.openapi.util.Ref) CodeFragmentTableCellRenderer(com.intellij.refactoring.ui.CodeFragmentTableCellRenderer) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with JavaCodeFragmentTableCellEditor

use of com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor in project intellij-community by JetBrains.

the class ChangeClassSignatureDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    myTable = new JBTable(myTableModel);
    myTable.setStriped(true);
    TableColumn nameColumn = myTable.getColumnModel().getColumn(NAME_COLUMN);
    TableColumn boundColumn = myTable.getColumnModel().getColumn(BOUND_VALUE_COLUMN);
    TableColumn valueColumn = myTable.getColumnModel().getColumn(DEFAULT_VALUE_COLUMN);
    Project project = myClass.getProject();
    nameColumn.setCellRenderer(new MyCellRenderer());
    nameColumn.setCellEditor(new StringTableCellEditor(project));
    boundColumn.setCellRenderer(new MyCodeFragmentTableCellRenderer());
    boundColumn.setCellEditor(new JavaCodeFragmentTableCellEditor(project));
    valueColumn.setCellRenderer(new MyCodeFragmentTableCellRenderer());
    valueColumn.setCellEditor(new JavaCodeFragmentTableCellEditor(project));
    myTable.setPreferredScrollableViewportSize(new Dimension(210, myTable.getRowHeight() * 4));
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myTable.getSelectionModel().setSelectionInterval(0, 0);
    myTable.setSurrendersFocusOnKeystroke(true);
    myTable.setCellSelectionEnabled(true);
    myTable.setFocusCycleRoot(true);
    if (myHideDefaultValueColumn) {
        final TableColumn defaultValue = myTable.getColumnModel().getColumn(DEFAULT_VALUE_COLUMN);
        myTable.removeColumn(defaultValue);
        myTable.getModel().addTableModelListener(new TableModelListener() {

            @Override
            public void tableChanged(TableModelEvent e) {
                if (e.getType() == TableModelEvent.INSERT) {
                    myTable.getModel().removeTableModelListener(this);
                    final TableColumnAnimator animator = new TableColumnAnimator(myTable);
                    animator.setStep(20);
                    animator.addColumn(defaultValue, myTable.getWidth() / 2);
                    animator.startAndDoWhenDone(() -> myTable.editCellAt(myTable.getRowCount() - 1, 0));
                    animator.start();
                }
            }
        });
    }
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(SeparatorFactory.createSeparator(RefactoringBundle.message("changeClassSignature.parameters.panel.border.title"), myTable), BorderLayout.NORTH);
    panel.add(ToolbarDecorator.createDecorator(myTable).createPanel(), BorderLayout.CENTER);
    return panel;
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) JBTable(com.intellij.ui.table.JBTable) TableColumn(javax.swing.table.TableColumn) JavaCodeFragmentTableCellEditor(com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor) Project(com.intellij.openapi.project.Project) TableModelListener(javax.swing.event.TableModelListener) StringTableCellEditor(com.intellij.refactoring.ui.StringTableCellEditor)

Aggregations

JavaCodeFragmentTableCellEditor (com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor)3 JBTable (com.intellij.ui.table.JBTable)3 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)2 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 Pair (com.intellij.openapi.util.Pair)2 CodeFragmentTableCellRenderer (com.intellij.refactoring.ui.CodeFragmentTableCellRenderer)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Project (com.intellij.openapi.project.Project)1 Ref (com.intellij.openapi.util.Ref)1 ExceptionsTableModel (com.intellij.refactoring.changeSignature.ExceptionsTableModel)1 JavaCallerChooser (com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser)1 StringTableCellEditor (com.intellij.refactoring.ui.StringTableCellEditor)1 TableModelEvent (javax.swing.event.TableModelEvent)1 TableModelListener (javax.swing.event.TableModelListener)1 TableColumn (javax.swing.table.TableColumn)1