Search in sources :

Example 1 with TableViewSpeedSearch

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

Aggregations

Application (com.intellij.openapi.application.Application)1 Splitter (com.intellij.openapi.ui.Splitter)1 VerticalFlowLayout (com.intellij.openapi.ui.VerticalFlowLayout)1 TableViewSpeedSearch (com.intellij.ui.TableViewSpeedSearch)1 TableView (com.intellij.ui.table.TableView)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 NotNull (org.jetbrains.annotations.NotNull)1