Search in sources :

Example 11 with TableView

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

the class CompareWithSelectedRevisionAction method showListPopup.

public static void showListPopup(final List<VcsFileRevision> revisions, final Project project, final Consumer<VcsFileRevision> selectedRevisionConsumer, final boolean showComments) {
    ColumnInfo[] columns = new ColumnInfo[] { REVISION_TABLE_COLUMN, DATE_TABLE_COLUMN, AUTHOR_TABLE_COLUMN };
    for (VcsFileRevision revision : revisions) {
        if (revision.getBranchName() != null) {
            columns = new ColumnInfo[] { REVISION_TABLE_COLUMN, BRANCH_TABLE_COLUMN, DATE_TABLE_COLUMN, AUTHOR_TABLE_COLUMN };
            break;
        }
    }
    final TableView<VcsFileRevision> table = new TableView<>(new ListTableModel<>(columns, revisions, 0));
    table.setShowHorizontalLines(false);
    table.setTableHeader(null);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            VcsFileRevision revision = table.getSelectedObject();
            if (revision != null) {
                selectedRevisionConsumer.consume(revision);
            }
        }
    };
    if (table.getModel().getRowCount() == 0) {
        table.clearSelection();
    }
    new SpeedSearchBase<TableView>(table) {

        @Override
        protected int getSelectedIndex() {
            return table.getSelectedRow();
        }

        @Override
        protected int convertIndexToModel(int viewIndex) {
            return table.convertRowIndexToModel(viewIndex);
        }

        @Override
        protected Object[] getAllElements() {
            return revisions.toArray();
        }

        @Override
        protected String getElementText(Object element) {
            VcsFileRevision revision = (VcsFileRevision) element;
            return revision.getRevisionNumber().asString() + " " + revision.getBranchName() + " " + revision.getAuthor();
        }

        @Override
        protected void selectElement(Object element, String selectedText) {
            VcsFileRevision revision = (VcsFileRevision) element;
            TableUtil.selectRows(myComponent, new int[] { myComponent.convertRowIndexToView(revisions.indexOf(revision)) });
            TableUtil.scrollSelectionToVisible(myComponent);
        }
    };
    table.setMinimumSize(new Dimension(300, 50));
    final PopupChooserBuilder builder = new PopupChooserBuilder(table);
    if (showComments) {
        builder.setSouthComponent(createCommentsPanel(table));
    }
    builder.setTitle(VcsBundle.message("lookup.title.vcs.file.revisions")).setItemChoosenCallback(runnable).setResizable(true).setDimensionServiceKey("Vcs.CompareWithSelectedRevision.Popup").setMinSize(new Dimension(300, 300));
    final JBPopup popup = builder.createPopup();
    popup.showCenteredInCurrentWindow(project);
}
Also used : ColumnInfo(com.intellij.util.ui.ColumnInfo) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) TreeTableView(com.intellij.ui.dualView.TreeTableView) TableView(com.intellij.ui.table.TableView)

Example 12 with TableView

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

the class ShowFeatureUsageStatisticsDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    Splitter splitter = new Splitter(true);
    splitter.setShowDividerControls(true);
    ProductivityFeaturesRegistry registry = ProductivityFeaturesRegistry.getInstance();
    ArrayList<FeatureDescriptor> features = new ArrayList<>();
    for (String id : registry.getFeatureIds()) {
        features.add(registry.getFeatureDescriptor(id));
    }
    final TableView table = new TableView<>(new ListTableModel<>(COLUMNS, features, 0));
    new TableViewSpeedSearch<FeatureDescriptor>(table) {

        @Override
        protected String getItemText(@NotNull FeatureDescriptor element) {
            return element.getDisplayName();
        }
    };
    JPanel controlsPanel = new JPanel(new VerticalFlowLayout());
    Application app = ApplicationManager.getApplication();
    long uptime = System.currentTimeMillis() - app.getStartTime();
    long idleTime = app.getIdleTime();
    final String uptimeS = FeatureStatisticsBundle.message("feature.statistics.application.uptime", ApplicationNamesInfo.getInstance().getFullProductName(), DateFormatUtil.formatDuration(uptime));
    final String idleTimeS = FeatureStatisticsBundle.message("feature.statistics.application.idle.time", DateFormatUtil.formatDuration(idleTime));
    String labelText = uptimeS + ", " + idleTimeS;
    CompletionStatistics stats = ((FeatureUsageTrackerImpl) FeatureUsageTracker.getInstance()).getCompletionStatistics();
    if (stats.dayCount > 0 && stats.sparedCharacters > 0) {
        String total = formatCharacterCount(stats.sparedCharacters, true);
        String perDay = formatCharacterCount(stats.sparedCharacters / stats.dayCount, false);
        labelText += "<br>Code completion has saved you from typing at least " + total + " since " + DateFormatUtil.formatDate(stats.startDate) + " (~" + perDay + " per working day)";
    }
    CumulativeStatistics fstats = ((FeatureUsageTrackerImpl) FeatureUsageTracker.getInstance()).getFixesStats();
    if (fstats.dayCount > 0 && fstats.invocations > 0) {
        labelText += "<br>Quick fixes have saved you from " + fstats.invocations + " possible bugs since " + DateFormatUtil.formatDate(fstats.startDate) + " (~" + fstats.invocations / fstats.dayCount + " per working day)";
    }
    controlsPanel.add(new JLabel(XmlStringUtil.wrapInHtml(labelText)), BorderLayout.NORTH);
    JPanel topPanel = new JPanel(new BorderLayout());
    topPanel.add(controlsPanel, BorderLayout.NORTH);
    topPanel.add(ScrollPaneFactory.createScrollPane(table), BorderLayout.CENTER);
    splitter.setFirstComponent(topPanel);
    final JEditorPane browser = TipUIUtil.createTipBrowser();
    splitter.setSecondComponent(ScrollPaneFactory.createScrollPane(browser));
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            Collection selection = table.getSelection();
            try {
                if (selection.isEmpty()) {
                    browser.read(new StringReader(""), null);
                } else {
                    FeatureDescriptor feature = (FeatureDescriptor) selection.iterator().next();
                    TipUIUtil.openTipInBrowser(feature.getTipFileName(), browser, feature.getProvider());
                }
            } catch (IOException ex) {
                LOG.info(ex);
            }
        }
    });
    return splitter;
}
Also used : ArrayList(java.util.ArrayList) ListSelectionEvent(javax.swing.event.ListSelectionEvent) TableViewSpeedSearch(com.intellij.ui.TableViewSpeedSearch) NotNull(org.jetbrains.annotations.NotNull) StringReader(java.io.StringReader) TableView(com.intellij.ui.table.TableView) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) Splitter(com.intellij.openapi.ui.Splitter) IOException(java.io.IOException) ListSelectionListener(javax.swing.event.ListSelectionListener) Collection(java.util.Collection) Application(com.intellij.openapi.application.Application)

Example 13 with TableView

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

the class JsonSchemaMappingsView method createUI.

private void createUI(final Project project) {
    myProject = project;
    myTableView = new TableView<>();
    myTableView.getTableHeader().setVisible(false);
    myDecorator = ToolbarDecorator.createDecorator(myTableView);
    myDecorator.setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final int[] rows = myTableView.getSelectedRows();
            if (rows != null && rows.length > 0) {
                int cnt = 0;
                for (int row : rows) {
                    myTableView.getListTableModel().removeRow(row - cnt);
                    ++cnt;
                }
                myTableView.getListTableModel().fireTableDataChanged();
                myTreeUpdater.run();
            }
        }
    }).setAddAction(new MyAddActionButtonRunnable(project)).disableUpDownActions();
    mySchemaField = new TextFieldWithBrowseButton();
    SwingHelper.installFileCompletionAndBrowseDialog(myProject, mySchemaField, JsonBundle.message("json.schema.add.schema.chooser.title"), FileChooserDescriptorFactory.createSingleFileDescriptor());
    attachNavigateToSchema();
    myError = SwingHelper.createHtmlLabel("Warning: conflicting mappings. <a href=\"#\">Show details</a>", null, s -> {
        final BalloonBuilder builder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(myErrorText, UIUtil.getBalloonWarningIcon(), MessageType.WARNING.getPopupBackground(), null);
        builder.setDisposable(this);
        builder.setHideOnClickOutside(true);
        builder.setCloseButtonEnabled(true);
        builder.createBalloon().showInCenterOf(myError);
    });
    final FormBuilder builder = FormBuilder.createFormBuilder();
    final JBLabel label = new JBLabel("JSON schema file:");
    builder.addLabeledComponent(label, mySchemaField);
    label.setBorder(JBUI.Borders.empty(0, 10, 0, 10));
    mySchemaField.setBorder(JBUI.Borders.empty(0, 0, 0, 10));
    final JPanel wrapper = new JPanel(new BorderLayout());
    wrapper.setBorder(JBUI.Borders.empty(0, 10, 0, 10));
    myErrorIcon = new JBLabel(UIUtil.getBalloonWarningIcon());
    wrapper.add(myErrorIcon, BorderLayout.WEST);
    wrapper.add(myError, BorderLayout.CENTER);
    builder.addComponent(wrapper);
    builder.addComponentFillVertically(myDecorator.createPanel(), 5);
    myComponent = builder.getPanel();
}
Also used : FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) Getter(com.intellij.openapi.util.Getter) MessageType(com.intellij.openapi.ui.MessageType) ActionListener(java.awt.event.ActionListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) JBLabel(com.intellij.ui.components.JBLabel) ArrayList(java.util.ArrayList) Balloon(com.intellij.openapi.ui.popup.Balloon) JBTextField(com.intellij.ui.components.JBTextField) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) Disposer(com.intellij.openapi.util.Disposer) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) Project(com.intellij.openapi.project.Project) FileUtil(com.intellij.openapi.util.io.FileUtil) AnActionButton(com.intellij.ui.AnActionButton) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) JsonBundle(com.intellij.json.JsonBundle) StringUtil(com.intellij.openapi.util.text.StringUtil) TableView(com.intellij.ui.table.TableView) JBRadioButton(com.intellij.ui.components.JBRadioButton) ActionEvent(java.awt.event.ActionEvent) Disposable(com.intellij.openapi.Disposable) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Nullable(org.jetbrains.annotations.Nullable) CommonShortcuts(com.intellij.openapi.actionSystem.CommonShortcuts) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) com.intellij.util.ui(com.intellij.util.ui) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) JBPanel(com.intellij.ui.components.JBPanel) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) JBLabel(com.intellij.ui.components.JBLabel) AnActionButton(com.intellij.ui.AnActionButton) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder)

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