Search in sources :

Example 1 with TableView

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

the class ToBeMergedDialog method initUI.

private void initUI() {
    final ListSelectionListener selectionListener = e -> {
        List<SvnChangeList> changeLists = myRevisionsList.getSelectedObjects();
        myAlreadyMerged.clear();
        for (SvnChangeList changeList : changeLists) {
            myAlreadyMerged.addAll(getAlreadyMergedPaths(changeList));
        }
        myRepositoryChangesBrowser.setChangesToDisplay(collectChanges(changeLists, false));
        mySplitter.doLayout();
        myRepositoryChangesBrowser.repaint();
    };
    final MyListCellRenderer listCellRenderer = new MyListCellRenderer();
    myRevisionsList = new TableView<SvnChangeList>() {

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            return listCellRenderer;
        }

        @Override
        public void valueChanged(ListSelectionEvent e) {
            super.valueChanged(e);
            selectionListener.valueChanged(e);
        }
    };
    myRevisionsList.setExpandableItemsEnabled(false);
    new TableViewSpeedSearch<SvnChangeList>(myRevisionsList) {

        @Override
        protected String getItemText(@NotNull SvnChangeList element) {
            return element.getComment();
        }
    };
    myRevisionsList.setModelAndUpdateColumns(myRevisionsModel);
    myRevisionsList.setTableHeader(null);
    myRevisionsList.setShowGrid(false);
    final AbstractBaseTagMouseListener mouseListener = new AbstractBaseTagMouseListener() {

        @Override
        public Object getTagAt(@NotNull MouseEvent e) {
            JTable table = (JTable) e.getSource();
            int row = table.rowAtPoint(e.getPoint());
            int column = table.columnAtPoint(e.getPoint());
            if (row == -1 || column == -1)
                return null;
            listCellRenderer.customizeCellRenderer(table, table.getValueAt(row, column), table.isRowSelected(row));
            return listCellRenderer.myRenderer.getFragmentTagAt(e.getPoint().x - table.getCellRect(row, column, false).x);
        }
    };
    mouseListener.installOn(myRevisionsList);
    myMore100Action = new MoreXAction(100);
    myMore500Action = new MoreXAction(500);
    BorderLayoutPanel panel = JBUI.Panels.simplePanel().addToCenter(ScrollPaneFactory.createScrollPane(myRevisionsList)).addToTop(createToolbar().getComponent());
    mySplitter = new Splitter(false, 0.7f);
    mySplitter.setFirstComponent(panel);
    myRepositoryChangesBrowser = new RepositoryChangesBrowser(myMergeContext.getProject(), Collections.<SvnChangeList>emptyList(), emptyList(), null);
    myRepositoryChangesBrowser.getDiffAction().registerCustomShortcutSet(myRepositoryChangesBrowser.getDiffAction().getShortcutSet(), myRevisionsList);
    setChangesDecorator();
    mySplitter.setSecondComponent(myRepositoryChangesBrowser);
    mySplitter.setDividerWidth(2);
    addRevisionListListeners();
    myPanel.add(mySplitter, BorderLayout.CENTER);
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) MessageType(com.intellij.openapi.ui.MessageType) CommittedChangesTreeBrowser.collectChanges(com.intellij.openapi.vcs.changes.committed.CommittedChangesTreeBrowser.collectChanges) Change(com.intellij.openapi.vcs.changes.Change) MergeChecker(org.jetbrains.idea.svn.mergeinfo.MergeChecker) ColumnInfo(com.intellij.util.ui.ColumnInfo) MergeCalculatorTask.getBunchSize(org.jetbrains.idea.svn.integrate.MergeCalculatorTask.getBunchSize) TableCellRenderer(javax.swing.table.TableCellRenderer) Collections.singletonList(java.util.Collections.singletonList) Task(com.intellij.openapi.progress.Task) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) JBUI(com.intellij.util.ui.JBUI) Collections.synchronizedMap(java.util.Collections.synchronizedMap) CommittedChangeListRenderer(com.intellij.openapi.vcs.changes.committed.CommittedChangeListRenderer) VcsException(com.intellij.openapi.vcs.VcsException) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ContainerUtilRt.newHashSet(com.intellij.util.containers.ContainerUtilRt.newHashSet) TableView(com.intellij.ui.table.TableView) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) Collectors(java.util.stream.Collectors) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SvnChangeList(org.jetbrains.idea.svn.history.SvnChangeList) List(java.util.List) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) AbstractBaseTagMouseListener(com.intellij.openapi.vcs.changes.issueLinks.AbstractBaseTagMouseListener) java.util(java.util) KeyAdapter(java.awt.event.KeyAdapter) ContainerUtil(com.intellij.util.containers.ContainerUtil) MergeCalculatorTask.loadChangeLists(org.jetbrains.idea.svn.integrate.MergeCalculatorTask.loadChangeLists) SvnMergeInfoCache(org.jetbrains.idea.svn.mergeinfo.SvnMergeInfoCache) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) ListTableModel(com.intellij.util.ui.ListTableModel) ContainerUtilRt.emptyList(com.intellij.util.containers.ContainerUtilRt.emptyList) Splitter(com.intellij.openapi.ui.Splitter) ListMergeStatus(org.jetbrains.idea.svn.mergeinfo.ListMergeStatus) ChangeNodeDecorator(com.intellij.openapi.vcs.changes.ui.ChangeNodeDecorator) PopupUtil(com.intellij.openapi.ui.popup.util.PopupUtil) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) ChangesBrowserNodeRenderer(com.intellij.openapi.vcs.changes.ui.ChangesBrowserNodeRenderer) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) RepositoryChangesBrowser(com.intellij.openapi.vcs.changes.committed.RepositoryChangesBrowser) Pair(com.intellij.openapi.util.Pair) ObjectUtils(com.intellij.util.ObjectUtils) ListSelectionListener(javax.swing.event.ListSelectionListener) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) TableCellRenderer(javax.swing.table.TableCellRenderer) MouseEvent(java.awt.event.MouseEvent) Splitter(com.intellij.openapi.ui.Splitter) RepositoryChangesBrowser(com.intellij.openapi.vcs.changes.committed.RepositoryChangesBrowser) SvnChangeList(org.jetbrains.idea.svn.history.SvnChangeList) ListSelectionEvent(javax.swing.event.ListSelectionEvent) NotNull(org.jetbrains.annotations.NotNull) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) ListSelectionListener(javax.swing.event.ListSelectionListener) AbstractBaseTagMouseListener(com.intellij.openapi.vcs.changes.issueLinks.AbstractBaseTagMouseListener) Collections.singletonList(java.util.Collections.singletonList) SvnChangeList(org.jetbrains.idea.svn.history.SvnChangeList) List(java.util.List) ContainerUtilRt.emptyList(com.intellij.util.containers.ContainerUtilRt.emptyList)

Example 2 with TableView

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

the class TestNGConfigurationEditor method createView.

private void createView() {
    commonParametersPanel.add(commonJavaParameters, BorderLayout.CENTER);
    classField.setComponent(new EditorTextFieldWithBrowseButton(project, true, new JavaCodeFragment.VisibilityChecker() {

        @Override
        public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) {
            if (declaration instanceof PsiClass && place.getParent() instanceof PsiJavaCodeReferenceElement) {
                return Visibility.VISIBLE;
            }
            try {
                if (declaration instanceof PsiClass && new TestClassBrowser(project, TestNGConfigurationEditor.this).getFilter().isAccepted((PsiClass) declaration)) {
                    return Visibility.VISIBLE;
                }
            } catch (MessageInfoException e) {
                return Visibility.NOT_VISIBLE;
            }
            return Visibility.NOT_VISIBLE;
        }
    }));
    final EditorTextFieldWithBrowseButton methodEditorTextField = new EditorTextFieldWithBrowseButton(project, true, JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE, PlainTextLanguage.INSTANCE.getAssociatedFileType());
    methodField.setComponent(methodEditorTextField);
    groupField.setComponent(new TextFieldWithBrowseButton.NoPathCompletion());
    suiteField.setComponent(new TextFieldWithBrowseButton());
    packageField.setVisible(true);
    packageField.setEnabled(true);
    packageField.setComponent(new EditorTextFieldWithBrowseButton(project, false));
    TextFieldWithBrowseButton outputDirectoryButton = new TextFieldWithBrowseButton();
    outputDirectory.setComponent(outputDirectoryButton);
    outputDirectoryButton.addBrowseFolderListener("TestNG", "Select test output directory", project, FileChooserDescriptorFactory.createSingleFolderDescriptor());
    moduleClasspath.setEnabled(true);
    moduleClasspath.setComponent(new ModulesComboBox());
    propertiesTableModel = new TestNGParametersTableModel();
    listenerModel = new TestNGListenersTableModel();
    TextFieldWithBrowseButton textFieldWithBrowseButton = new TextFieldWithBrowseButton();
    propertiesFile.setComponent(textFieldWithBrowseButton);
    FileChooserDescriptor propertiesFileDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile virtualFile, boolean showHidden) {
            if (!showHidden && virtualFile.getName().charAt(0) == '.')
                return false;
            return virtualFile.isDirectory() || "properties".equals(virtualFile.getExtension());
        }
    };
    textFieldWithBrowseButton.addBrowseFolderListener("TestNG", "Select .properties file for test properties", project, propertiesFileDescriptor);
    propertiesTableView = new TableView(propertiesTableModel);
    myPropertiesPanel.add(ToolbarDecorator.createDecorator(propertiesTableView).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            propertiesTableModel.addParameter();
            int index = propertiesTableModel.getRowCount() - 1;
            propertiesTableView.setRowSelectionInterval(index, index);
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            int idx = propertiesTableView.getSelectedRow() - 1;
            for (int row : propertiesTableView.getSelectedRows()) {
                propertiesTableModel.removeProperty(row);
            }
            if (idx > -1)
                propertiesTableView.setRowSelectionInterval(idx, idx);
        }
    }).disableUpDownActions().createPanel(), BorderLayout.CENTER);
    myListenersList = new JBList(listenerModel);
    myListenersPanel.add(ToolbarDecorator.createDecorator(myListenersList).setAddAction(new AddActionButtonRunnable()).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            int idx = myListenersList.getSelectedIndex() - 1;
            for (int row : myListenersList.getSelectedIndices()) {
                listenerModel.removeListener(row);
            }
            if (idx > -1)
                myListenersList.setSelectedIndex(idx);
        }
    }).setAddActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            return !project.isDefault();
        }
    }).disableUpDownActions().createPanel(), BorderLayout.CENTER);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) MessageInfoException(com.theoryinpractice.testng.MessageInfoException) ModulesComboBox(com.intellij.application.options.ModulesComboBox) TestClassBrowser(com.theoryinpractice.testng.configuration.browser.TestClassBrowser) JBList(com.intellij.ui.components.JBList) TableView(com.intellij.ui.table.TableView)

Example 3 with TableView

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

the class DualView method createFlatComponent.

private Component createFlatComponent(DualViewColumnInfo[] columns) {
    ArrayList<ColumnInfo> shownColumns = new ArrayList<>();
    for (DualViewColumnInfo column : columns) {
        if (column.shouldBeShownIsTheTable()) {
            shownColumns.add(column);
        }
    }
    ListTableModel flatModel = new ListTableModel(shownColumns.toArray(new ColumnInfo[shownColumns.size()]));
    //noinspection unchecked
    myFlatView = new TableView(flatModel) {

        public TableCellRenderer getCellRenderer(int row, int column) {
            return createWrappedRenderer(super.getCellRenderer(row, column));
        }

        @NotNull
        @Override
        public Component prepareRenderer(@NotNull TableCellRenderer renderer, int row, int column) {
            final Component c = super.prepareRenderer(renderer, row, column);
            if (c instanceof JComponent && !myFlatView.getCellSelectionEnabled()) {
                ((JComponent) c).setBorder(null);
            }
            return c;
        }

        @Override
        public void doLayout() {
            try {
                mySuppressStore = true;
                super.doLayout();
            } finally {
                mySuppressStore = false;
            }
        }

        @Override
        public void updateColumnSizes() {
        // suppress automatic layout, use stored values instead
        }
    };
    myFlatView.setCellSelectionEnabled(false);
    myFlatView.setColumnSelectionAllowed(false);
    myFlatView.setRowSelectionAllowed(true);
    refreshFlatModel();
    JPanel result = new JPanel(new BorderLayout());
    result.add(ScrollPaneFactory.createScrollPane(myFlatView), BorderLayout.CENTER);
    return result;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) ArrayList(java.util.ArrayList) ColumnInfo(com.intellij.util.ui.ColumnInfo) NotNull(org.jetbrains.annotations.NotNull) ListTableModel(com.intellij.util.ui.ListTableModel) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) BaseTableView(com.intellij.ui.table.BaseTableView) TableView(com.intellij.ui.table.TableView)

Example 4 with TableView

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

the class FileHistoryColumnWrapper method getMaxValue.

@Nullable
private String getMaxValue(@NotNull String columnHeader) {
    TableView table = getDualView().getFlatView();
    if (table.getRowCount() == 0)
        return null;
    final Enumeration<TableColumn> columns = table.getColumnModel().getColumns();
    int idx = 0;
    while (columns.hasMoreElements()) {
        TableColumn column = columns.nextElement();
        if (columnHeader.equals(column.getHeaderValue())) {
            break;
        }
        ++idx;
    }
    if (idx >= table.getColumnModel().getColumnCount() - 1)
        return null;
    final FontMetrics fm = table.getFontMetrics(table.getFont().deriveFont(Font.BOLD));
    final Object header = table.getColumnModel().getColumn(idx).getHeaderValue();
    double maxValue = fm.stringWidth((String) header);
    String value = (String) header;
    for (int i = 0; i < table.getRowCount(); i++) {
        final Object at = table.getValueAt(i, idx);
        if (at instanceof String) {
            final int newWidth = fm.stringWidth((String) at);
            if (newWidth > maxValue) {
                maxValue = newWidth;
                value = (String) at;
            }
        }
    }
    return value + "ww";
}
Also used : TableColumn(javax.swing.table.TableColumn) TableView(com.intellij.ui.table.TableView) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with TableView

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

the class FileHistoryPanelImpl method setupDualView.

private void setupDualView(@NotNull DefaultActionGroup group) {
    myDualView.setShowGrid(true);
    PopupHandler.installPopupHandler(myDualView.getTreeView(), group, ActionPlaces.UPDATE_POPUP, ActionManager.getInstance());
    PopupHandler.installPopupHandler(myDualView.getFlatView(), group, ActionPlaces.UPDATE_POPUP, ActionManager.getInstance());
    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
        IdeFocusManager.getGlobalInstance().requestFocus(myDualView, true);
    });
    myDualView.addListSelectionListener(e -> updateMessage());
    myDualView.setRootVisible(false);
    myDualView.expandAll();
    final TreeCellRenderer defaultCellRenderer = myDualView.getTree().getCellRenderer();
    final Getter<VcsHistorySession> sessionGetter = () -> myHistorySession;
    myDualView.setTreeCellRenderer(new MyTreeCellRenderer(defaultCellRenderer, sessionGetter));
    myDualView.setCellWrapper(new MyCellWrapper(sessionGetter));
    myDualView.installDoubleClickHandler(new MyDiffAction());
    final TableView flatView = myDualView.getFlatView();
    TableViewModel sortableModel = flatView.getTableViewModel();
    sortableModel.setSortable(true);
    final RowSorter<? extends TableModel> rowSorter = flatView.getRowSorter();
    if (rowSorter != null) {
        rowSorter.setSortKeys(Collections.singletonList(new RowSorter.SortKey(0, SortOrder.DESCENDING)));
    }
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) TableViewModel(com.intellij.util.ui.TableViewModel) TableView(com.intellij.ui.table.TableView) TreeTableView(com.intellij.ui.dualView.TreeTableView)

Aggregations

TableView (com.intellij.ui.table.TableView)13 NotNull (org.jetbrains.annotations.NotNull)6 JTableFixture (org.fest.swing.fixture.JTableFixture)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 MessageType (com.intellij.openapi.ui.MessageType)2 Splitter (com.intellij.openapi.ui.Splitter)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ColumnInfo (com.intellij.util.ui.ColumnInfo)2 ListTableModel (com.intellij.util.ui.ListTableModel)2 KeyAdapter (java.awt.event.KeyAdapter)2 KeyEvent (java.awt.event.KeyEvent)2 ArrayList (java.util.ArrayList)2 TableCellRenderer (javax.swing.table.TableCellRenderer)2 JTableCellFixture (org.fest.swing.fixture.JTableCellFixture)2 ModulesComboBox (com.intellij.application.options.ModulesComboBox)1 AllIcons (com.intellij.icons.AllIcons)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 JsonBundle (com.intellij.json.JsonBundle)1 Disposable (com.intellij.openapi.Disposable)1