Search in sources :

Example 31 with JBTable

use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.

the class CodeStyleImportsPanelBase method resetLayoutSettings.

public void resetLayoutSettings(ImportsLayoutSettings settings) {
    myCbUseFQClassNames.setSelected(settings.isUseFqClassNames());
    myCbUseSingleClassImports.setSelected(settings.isUseSingleClassImports());
    myCbInsertInnerClassImports.setSelected(settings.isInsertInnerClassImports());
    myClassCountField.setText(Integer.toString(settings.getClassCountToUseImportOnDemand()));
    myNamesCountField.setText(Integer.toString(settings.getNamesCountToUseImportOnDemand()));
    myImportLayoutPanel.getImportLayoutList().copyFrom(settings.getImportLayoutTable());
    myPackageList.copyFrom(settings.getPackagesToUseImportOnDemand());
    myImportLayoutPanel.getCbLayoutStaticImportsSeparately().setSelected(settings.isLayoutStaticImportsSeparately());
    final JBTable importLayoutTable = myImportLayoutPanel.getImportLayoutTable();
    AbstractTableModel model = (AbstractTableModel) importLayoutTable.getModel();
    model.fireTableDataChanged();
    model = (AbstractTableModel) myPackageTable.getModel();
    model.fireTableDataChanged();
    if (importLayoutTable.getRowCount() > 0) {
        importLayoutTable.getSelectionModel().setSelectionInterval(0, 0);
    }
    if (myPackageTable.getRowCount() > 0) {
        myPackageTable.getSelectionModel().setSelectionInterval(0, 0);
    }
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel) JBTable(com.intellij.ui.table.JBTable)

Example 32 with JBTable

use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.

the class TableWithButtons method createUIComponents.

private void createUIComponents() {
    myTable = new JBTable(myModel);
    myTable.setPreferredScrollableViewportSize(new Dimension(450, myTable.getRowHeight() * 8));
}
Also used : JBTable(com.intellij.ui.table.JBTable)

Example 33 with JBTable

use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.

the class PropertiesComponent method init.

public void init() {
    setLayout(new BorderLayout());
    myTable = new JBTable();
    myTextArea = new JTextArea(0, 0);
    myTextArea.setEditable(false);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable);
    mySplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, scrollPane, ScrollPaneFactory.createScrollPane(myTextArea));
    add(mySplitPane, BorderLayout.CENTER);
    add(createToolbar(), BorderLayout.WEST);
    final DefaultTableModel model = new DefaultTableModel(createTableModel(new HashMap<>()), new Object[] { "Name", "Value" }) {

        public boolean isCellEditable(final int row, final int column) {
            return false;
        }
    };
    myTable.setModel(model);
    myTable.setShowVerticalLines(true);
    myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myTable.getSelectionModel().addListSelectionListener(e -> {
        int index = myTable.getSelectedRow();
        if (index >= 0) {
            Object value = myTable.getValueAt(index, 1);
            if (value instanceof String) {
                myTextArea.setText(((String) value));
            } else {
                myTextArea.setText("");
            }
        } else {
            myTextArea.setText("");
        }
    });
    myPopupActionGroup = createPopup();
    PopupHandler.installPopupHandler(myTable, myPopupActionGroup, ActionPlaces.UNKNOWN, ActionManager.getInstance());
    PopupHandler.installPopupHandler(scrollPane, myPopupActionGroup, ActionPlaces.UNKNOWN, ActionManager.getInstance());
    final Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_CLOSE_ACTIVE_TAB);
    myCloseAction.registerCustomShortcutSet(new CustomShortcutSet(shortcuts), this);
    myRefreshAction.registerCustomShortcutSet(CommonShortcuts.getRerun(), this);
}
Also used : HashMap(com.intellij.util.containers.HashMap) DefaultTableModel(javax.swing.table.DefaultTableModel) JBTable(com.intellij.ui.table.JBTable)

Example 34 with JBTable

use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.

the class ConfigureClientPropertiesDialog method createCenterPanel.

@Nullable
protected JComponent createCenterPanel() {
    myClassTree = new Tree();
    myClassTree.setRootVisible(false);
    myClassTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            final TreePath leadSelectionPath = e.getNewLeadSelectionPath();
            if (leadSelectionPath == null)
                return;
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) leadSelectionPath.getLastPathComponent();
            mySelectedClass = (Class) node.getUserObject();
            updateSelectedProperties();
        }
    });
    myClassTree.setCellRenderer(new ColoredTreeCellRenderer() {

        public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
            if (node.getUserObject() instanceof Class) {
                Class cls = (Class) node.getUserObject();
                if (cls != null) {
                    append(cls.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
                }
            }
        }
    });
    fillClassTree();
    myPropertiesTable = new JBTable();
    myPropertiesTable.setModel(myTableModel);
    mySplitter = new JBSplitter("ConfigureClientPropertiesDialog.splitterProportion", 0.5f);
    mySplitter.setFirstComponent(ToolbarDecorator.createDecorator(myClassTree).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            ClassNameInputDialog dlg = new ClassNameInputDialog(myProject, mySplitter);
            dlg.show();
            if (dlg.getExitCode() == OK_EXIT_CODE) {
                String className = dlg.getClassName();
                if (className.length() == 0)
                    return;
                final Class aClass;
                try {
                    aClass = Class.forName(className);
                } catch (ClassNotFoundException ex) {
                    Messages.showErrorDialog(mySplitter, UIDesignerBundle.message("client.properties.class.not.found", className), UIDesignerBundle.message("client.properties.title"));
                    return;
                }
                if (!JComponent.class.isAssignableFrom(aClass)) {
                    Messages.showErrorDialog(mySplitter, UIDesignerBundle.message("client.properties.class.not.component", className), UIDesignerBundle.message("client.properties.title"));
                    return;
                }
                myManager.addClientPropertyClass(className);
                fillClassTree();
            }
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            if (mySelectedClass != null) {
                myManager.removeClientPropertyClass(mySelectedClass);
                fillClassTree();
            }
        }
    }).setToolbarPosition(SystemInfo.isMac ? ActionToolbarPosition.BOTTOM : ActionToolbarPosition.RIGHT).createPanel());
    mySplitter.setSecondComponent(ToolbarDecorator.createDecorator(myPropertiesTable).disableUpDownActions().setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            AddClientPropertyDialog dlg = new AddClientPropertyDialog(myProject);
            dlg.show();
            if (dlg.getExitCode() == OK_EXIT_CODE) {
                ClientPropertiesManager.ClientProperty[] props = myManager.getClientProperties(mySelectedClass);
                for (ClientPropertiesManager.ClientProperty prop : props) {
                    if (prop.getName().equalsIgnoreCase(dlg.getEnteredProperty().getName())) {
                        Messages.showErrorDialog(mySplitter, UIDesignerBundle.message("client.properties.already.defined", prop.getName()), UIDesignerBundle.message("client.properties.title"));
                        return;
                    }
                }
                myManager.addConfiguredProperty(mySelectedClass, dlg.getEnteredProperty());
                updateSelectedProperties();
            }
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            int row = myPropertiesTable.getSelectedRow();
            if (row >= 0 && row < mySelectedProperties.length) {
                myManager.removeConfiguredProperty(mySelectedClass, mySelectedProperties[row].getName());
                updateSelectedProperties();
                if (mySelectedProperties.length > 0) {
                    if (row >= mySelectedProperties.length)
                        row--;
                    myPropertiesTable.getSelectionModel().setSelectionInterval(row, row);
                }
            }
        }
    }).createPanel());
    return mySplitter;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSelectionListener(javax.swing.event.TreeSelectionListener) JBTable(com.intellij.ui.table.JBTable) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with JBTable

use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.

the class EditVariableDialog method createVariablesTable.

private JComponent createVariablesTable() {
    final String[] names = { CodeInsightBundle.message("templates.dialog.edit.variables.table.column.name"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.expression"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.default.value"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.skip.if.defined") };
    // Create a model of the data.
    TableModel dataModel = new VariablesModel(names);
    // Create the table
    myTable = new JBTable(dataModel);
    myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myTable.setPreferredScrollableViewportSize(new Dimension(500, myTable.getRowHeight() * 8));
    myTable.getColumn(names[0]).setPreferredWidth(120);
    myTable.getColumn(names[1]).setPreferredWidth(200);
    myTable.getColumn(names[2]).setPreferredWidth(200);
    myTable.getColumn(names[3]).setPreferredWidth(100);
    if (myVariables.size() > 0) {
        myTable.getSelectionModel().setSelectionInterval(0, 0);
    }
    Predicate<Macro> isAcceptableInContext = macro -> myContextTypes.stream().anyMatch(macro::isAcceptableInContext);
    Stream<String> availableMacroNames = Arrays.stream(MacroFactory.getMacros()).filter(isAcceptableInContext).map(Macro::getPresentableName).sorted();
    Set<String> uniqueNames = availableMacroNames.collect(Collectors.toCollection(LinkedHashSet::new));
    ComboBox comboField = new ComboBox();
    uniqueNames.forEach(comboField::addItem);
    comboField.setEditable(true);
    DefaultCellEditor cellEditor = new DefaultCellEditor(comboField);
    cellEditor.setClickCountToStart(1);
    myTable.getColumn(names[1]).setCellEditor(cellEditor);
    myTable.setRowHeight(comboField.getPreferredSize().height);
    JTextField textField = new JTextField();
    /*textField.addMouseListener(
      new PopupHandler(){
        public void invokePopup(Component comp,int x,int y){
          showCellPopup((JTextField)comp,x,y);
        }
      }
    );*/
    cellEditor = new DefaultCellEditor(textField);
    cellEditor.setClickCountToStart(1);
    myTable.setDefaultEditor(String.class, cellEditor);
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTable).disableAddAction().disableRemoveAction();
    return decorator.createPanel();
}
Also used : java.util(java.util) Document(com.intellij.openapi.editor.Document) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) TableCellEditor(javax.swing.table.TableCellEditor) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CommonBundle(com.intellij.CommonBundle) AbstractTableModel(javax.swing.table.AbstractTableModel) TemplateContextType(com.intellij.codeInsight.template.TemplateContextType) TableModel(javax.swing.table.TableModel) ComboBox(com.intellij.openapi.ui.ComboBox) Predicate(java.util.function.Predicate) Editor(com.intellij.openapi.editor.Editor) Collectors(java.util.stream.Collectors) MacroFactory(com.intellij.codeInsight.template.macro.MacroFactory) java.awt(java.awt) CommandProcessor(com.intellij.openapi.command.CommandProcessor) HelpManager(com.intellij.openapi.help.HelpManager) JBTable(com.intellij.ui.table.JBTable) List(java.util.List) Stream(java.util.stream.Stream) Macro(com.intellij.codeInsight.template.Macro) EditableModel(com.intellij.util.ui.EditableModel) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) Macro(com.intellij.codeInsight.template.Macro) ComboBox(com.intellij.openapi.ui.ComboBox) JBTable(com.intellij.ui.table.JBTable) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Aggregations

JBTable (com.intellij.ui.table.JBTable)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)8 DefaultTableModel (javax.swing.table.DefaultTableModel)8 NotNull (org.jetbrains.annotations.NotNull)7 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)6 Nullable (org.jetbrains.annotations.Nullable)6 JBLabel (com.intellij.ui.components.JBLabel)5 ActionEvent (java.awt.event.ActionEvent)5 AbstractTableModel (javax.swing.table.AbstractTableModel)5 TableColumn (javax.swing.table.TableColumn)5 TableColumnModel (javax.swing.table.TableColumnModel)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)4 Project (com.intellij.openapi.project.Project)4 JBScrollPane (com.intellij.ui.components.JBScrollPane)4 MouseEvent (java.awt.event.MouseEvent)4 List (java.util.List)4 StringUtil (com.intellij.openapi.util.text.StringUtil)3 JavaCodeFragmentTableCellEditor (com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor)3 UsageInfo (com.intellij.usageView.UsageInfo)3