Search in sources :

Example 1 with StringTableCellEditor

use of com.intellij.refactoring.ui.StringTableCellEditor 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)

Example 2 with StringTableCellEditor

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

the class AutomaticRenamingDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myTable.setModel(myTableModel);
    myTableModel.getSpaceAction().register();
    myTableModel.addTableModelListener(e -> handleChanges());
    myTable.addMouseListener(new PopupHandler() {

        @Override
        public void invokePopup(Component comp, int x, int y) {
            final int[] selectionRows = myTable.getSelectedRows();
            if (selectionRows != null) {
                compoundPopup().show(comp, x, y);
            }
        }
    });
    final TableColumnModel columnModel = myTable.getColumnModel();
    columnModel.getColumn(CHECK_COLUMN).setCellRenderer(new BooleanTableCellRenderer());
    TableUtil.setupCheckboxColumn(columnModel.getColumn(CHECK_COLUMN));
    columnModel.getColumn(NEW_NAME_COLUMN).setCellEditor(new StringTableCellEditor(myProject));
    mySelectAllButton.addActionListener(e -> {
        for (int i = 0; i < myShouldRename.length; i++) {
            myShouldRename[i] = true;
        }
        fireDataChanged();
    });
    myUnselectAllButton.addActionListener(e -> {
        for (int i = 0; i < myShouldRename.length; i++) {
            myShouldRename[i] = false;
        }
        fireDataChanged();
    });
    myListSelectionListener = e -> {
        myUsageFileLabel.setText("");
        int index = myTable.getSelectionModel().getLeadSelectionIndex();
        if (index != -1) {
            PsiNamedElement element = myRenames[index];
            UsageInfo usageInfo = new UsageInfo(element);
            myUsagePreviewPanel.updateLayout(Collections.singletonList(usageInfo));
            final PsiFile containingFile = element.getContainingFile();
            if (containingFile != null) {
                final VirtualFile virtualFile = containingFile.getVirtualFile();
                if (virtualFile != null) {
                    myUsageFileLabel.setText(virtualFile.getName());
                }
            }
        } else {
            myUsagePreviewPanel.updateLayout(null);
        }
    };
    myTable.getSelectionModel().addListSelectionListener(myListSelectionListener);
    myPanelForPreview.add(myUsagePreviewPanel, BorderLayout.CENTER);
    myUsagePreviewPanel.updateLayout(null);
    myPanelForPreview.add(myUsageFileLabel, BorderLayout.NORTH);
    mySplitPane.setDividerLocation(0.5);
    GuiUtils.replaceJSplitPaneWithIDEASplitter(myPanel);
    if (myTableModel.getRowCount() != 0) {
        myTable.getSelectionModel().addSelectionInterval(0, 0);
    }
    return myPanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PopupHandler(com.intellij.ui.PopupHandler) PsiNamedElement(com.intellij.psi.PsiNamedElement) TableColumnModel(javax.swing.table.TableColumnModel) StringTableCellEditor(com.intellij.refactoring.ui.StringTableCellEditor) PsiFile(com.intellij.psi.PsiFile) BooleanTableCellRenderer(com.intellij.ui.BooleanTableCellRenderer) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

StringTableCellEditor (com.intellij.refactoring.ui.StringTableCellEditor)2 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 PsiNamedElement (com.intellij.psi.PsiNamedElement)1 JavaCodeFragmentTableCellEditor (com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor)1 BooleanTableCellRenderer (com.intellij.ui.BooleanTableCellRenderer)1 PopupHandler (com.intellij.ui.PopupHandler)1 JBTable (com.intellij.ui.table.JBTable)1 UsageInfo (com.intellij.usageView.UsageInfo)1 TableModelEvent (javax.swing.event.TableModelEvent)1 TableModelListener (javax.swing.event.TableModelListener)1 TableColumn (javax.swing.table.TableColumn)1 TableColumnModel (javax.swing.table.TableColumnModel)1