From 204d99dac078953aec7e4ffecf7ae2da8d65ef31 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Sun, 10 May 2015 12:30:52 +0200 Subject: [PATCH] IG: drop telemetry, project component and application component --- .../src/META-INF/InspectionGadgets.xml | 11 -- .../src/com/siyeh/ig/BaseInspection.java | 29 +-- .../telemetry/InspectionGadgetsTelemetry.java | 74 -------- .../siyeh/ig/telemetry/InspectionRunTime.java | 57 ------ .../com/siyeh/ig/InspectionGadgetsPlugin.java | 77 -------- .../ig/InspectionGadgetsProjectComponent.java | 71 ------- .../ig/telemetry/ResetTelemetryAction.java | 44 ----- .../siyeh/ig/telemetry/TelemetryDisplay.java | 177 ------------------ .../ig/telemetry/TelemetryToolWindow.java | 82 -------- .../telemetry/UpdateTelemetryViewAction.java | 43 ----- 10 files changed, 1 insertion(+), 664 deletions(-) delete mode 100644 plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/telemetry/InspectionGadgetsTelemetry.java delete mode 100644 plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/telemetry/InspectionRunTime.java delete mode 100644 plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java delete mode 100644 plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsProjectComponent.java delete mode 100644 plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/ResetTelemetryAction.java delete mode 100644 plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryDisplay.java delete mode 100644 plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryToolWindow.java delete mode 100644 plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/UpdateTelemetryViewAction.java diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml index 0bec30a07106..72abb63674a9 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml @@ -2728,15 +2728,4 @@ level="WARNING" implementationClass="com.siyeh.ig.visibility.LambdaParameterHidingMemberVariableInspection"/> - - - com.siyeh.ig.InspectionGadgetsPlugin - - - - - com.siyeh.ig.InspectionGadgetsProjectComponent - - - diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspection.java index 0f2165d31473..2e3e0231a280 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2015 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package com.siyeh.ig; import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInspection.BaseJavaBatchLocalInspectionTool; import com.intellij.codeInspection.InspectionProfileEntry; -import com.intellij.codeInspection.LocalInspectionToolSession; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.codeInspection.ex.InspectionProfileImpl; import com.intellij.openapi.diagnostic.Logger; @@ -30,7 +29,6 @@ import com.intellij.psi.PsiFile; import com.intellij.ui.DocumentAdapter; import com.intellij.util.ReflectionUtil; import com.intellij.util.ui.UIUtil; -import com.siyeh.ig.telemetry.InspectionGadgetsTelemetry; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -47,7 +45,6 @@ public abstract class BaseInspection extends BaseJavaBatchLocalInspectionTool { private static final Logger LOG = Logger.getInstance("#com.siyeh.ig.BaseInspection"); private String m_shortName = null; - private long timestamp = -1L; @Override @NotNull @@ -188,30 +185,6 @@ public abstract class BaseInspection extends BaseJavaBatchLocalInspectionTool { } } - @Override - public void inspectionStarted(@NotNull LocalInspectionToolSession session, boolean isOnTheFly) { - super.inspectionStarted(session, isOnTheFly); - if (InspectionGadgetsTelemetry.isEnabled()) { - timestamp = System.currentTimeMillis(); - } - } - - @Override - public void inspectionFinished(@NotNull LocalInspectionToolSession session, - @NotNull ProblemsHolder problemsHolder) { - super.inspectionFinished(session, problemsHolder); - if (InspectionGadgetsTelemetry.isEnabled()) { - if (timestamp < 0L) { - LOG.warn("finish reported without corresponding start"); - return; - } - final long end = System.currentTimeMillis(); - final String displayName = getDisplayName(); - InspectionGadgetsTelemetry.getInstance().reportRun(displayName, end - timestamp); - timestamp = -1L; - } - } - public static boolean isInspectionEnabled(@NonNls String shortName, PsiElement context) { final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(context.getProject()); final InspectionProfileImpl profile = (InspectionProfileImpl)profileManager.getInspectionProfile(); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/telemetry/InspectionGadgetsTelemetry.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/telemetry/InspectionGadgetsTelemetry.java deleted file mode 100644 index 9e3f2ff2e0c9..000000000000 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/telemetry/InspectionGadgetsTelemetry.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.siyeh.ig.telemetry; - -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -public class InspectionGadgetsTelemetry { - private static final InspectionGadgetsTelemetry telemetry = new InspectionGadgetsTelemetry(); - private static volatile boolean telemetryEnabled = false; - - private final ConcurrentMap inspectionRunTimes = - new ConcurrentHashMap(); - - public List buildList() { - if (inspectionRunTimes.isEmpty()) { - return Collections.emptyList(); - } - return new ArrayList(inspectionRunTimes.values()); - } - - public void reportRun(String inspectionID, long runTime) { - InspectionRunTime inspectionRunTime = - inspectionRunTimes.get(inspectionID); - if (inspectionRunTime == null) { - inspectionRunTime = new InspectionRunTime(inspectionID); - final InspectionRunTime oldValue = - inspectionRunTimes.putIfAbsent(inspectionID, - inspectionRunTime); - if (oldValue != null) { - inspectionRunTime = oldValue; - } - } - inspectionRunTime.addRunTime(runTime); - } - - public void reset() { - inspectionRunTimes.clear(); - } - - public static boolean isEnabled() { - return telemetryEnabled; - } - - public static void setEnabled(boolean enabled) { - telemetryEnabled = enabled; - if (telemetryEnabled) { - telemetry.reset(); - } - } - - @NotNull - public static InspectionGadgetsTelemetry getInstance() { - return telemetry; - } -} \ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/telemetry/InspectionRunTime.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/telemetry/InspectionRunTime.java deleted file mode 100644 index a77b1a2a9a18..000000000000 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/telemetry/InspectionRunTime.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2010-2011 Bas Leijdekkers - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.siyeh.ig.telemetry; - -class InspectionRunTime { - - private final String inspectionName; - - private long totalRunTime = 0L; - private int runCount = 0; - - public InspectionRunTime(String inspectionName) { - this.inspectionName = inspectionName; - } - - public void addRunTime(long runTime) { - synchronized (this) { - totalRunTime += runTime; - runCount++; - } - } - - public double getAverageRunTime() { - synchronized (this) { - return (double)totalRunTime / (double)runCount; - } - } - - public String getInspectionName() { - return inspectionName; - } - - public int getRunCount() { - synchronized (this) { - return runCount; - } - } - - public long getTotalRunTime() { - synchronized (this) { - return totalRunTime; - } - } -} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java b/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java deleted file mode 100644 index a21f451572fa..000000000000 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java +++ /dev/null @@ -1,77 +0,0 @@ -/* -* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package com.siyeh.ig; - -import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.ApplicationComponent; -import com.intellij.openapi.util.registry.Registry; -import com.intellij.openapi.util.registry.RegistryValue; -import com.intellij.openapi.util.registry.RegistryValueListener; -import com.intellij.util.Consumer; -import com.siyeh.ig.telemetry.InspectionGadgetsTelemetry; -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings({"OverlyCoupledClass", - "OverlyCoupledMethod", - "OverlyLongMethod", - "ClassWithTooManyMethods"}) -public class InspectionGadgetsPlugin implements ApplicationComponent { - public static boolean getUpToDateTelemetryEnabled(@NotNull final Consumer consumer, @NotNull Disposable disposable) { - final RegistryValue registryValue = Registry.get("inspectionGadgets.telemetry.enabled"); - registryValue.addListener(new RegistryValueListener.Adapter() { - @Override - public void afterValueChanged(RegistryValue value) { - consumer.consume(Boolean.valueOf(value.asBoolean())); - } - }, disposable); - return registryValue.asBoolean(); - } - - public static InspectionGadgetsPlugin getInstance() { - return ApplicationManager.getApplication().getComponent(InspectionGadgetsPlugin.class); - } - - @Override - public void disposeComponent() {} - - @Override - @NotNull - public String getComponentName() { - return "InspectionGadgets"; - } - - @NotNull - public InspectionGadgetsTelemetry getTelemetry() { - return InspectionGadgetsTelemetry.getInstance(); - } - - @Override - public void initComponent() { - boolean telemetryEnabled = getUpToDateTelemetryEnabled(new Consumer() { - @Override - public void consume(Boolean value) { - boolean enabled = value.booleanValue(); - InspectionGadgetsTelemetry.setEnabled(enabled); - } - }, ApplicationManager.getApplication()); - InspectionGadgetsTelemetry.setEnabled(telemetryEnabled); - } - - public boolean isTelemetryEnabled() { - return InspectionGadgetsTelemetry.isEnabled(); - } -} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsProjectComponent.java b/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsProjectComponent.java deleted file mode 100644 index 0fe587adce46..000000000000 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsProjectComponent.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.siyeh.ig; - -import com.intellij.openapi.components.ProjectComponent; -import com.intellij.openapi.project.Project; -import com.intellij.util.Consumer; -import com.siyeh.ig.telemetry.InspectionGadgetsTelemetry; -import com.siyeh.ig.telemetry.TelemetryToolWindow; -import org.jetbrains.annotations.NotNull; - -public class InspectionGadgetsProjectComponent implements ProjectComponent { - private final Project project; - - public InspectionGadgetsProjectComponent(Project project) { - this.project = project; - } - - @Override - public void projectOpened() { - final InspectionGadgetsPlugin inspectionGadgetsPlugin = InspectionGadgetsPlugin.getInstance(); - final InspectionGadgetsTelemetry telemetry = inspectionGadgetsPlugin.getTelemetry(); - final boolean telemetryEnabled = InspectionGadgetsPlugin.getUpToDateTelemetryEnabled(new Consumer() { - @Override - public void consume(Boolean value) { - final boolean telemetryEnabled = value.booleanValue(); - if (telemetryEnabled) { - final TelemetryToolWindow toolWindow = new TelemetryToolWindow(telemetry); - toolWindow.register(project); - } - else { - TelemetryToolWindow.unregister(project); - } - } - }, project); - if (telemetryEnabled) { - final TelemetryToolWindow toolWindow = new TelemetryToolWindow(telemetry); - toolWindow.register(project); - } - } - - @Override - public void projectClosed() { - TelemetryToolWindow.unregister(project); - } - - @Override - @NotNull - public String getComponentName() { - return "InspectionGadgetsProjectComponent"; - } - - @Override - public void initComponent() {} - - @Override - public void disposeComponent() {} -} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/ResetTelemetryAction.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/ResetTelemetryAction.java deleted file mode 100644 index 0aaaf05bac75..000000000000 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/ResetTelemetryAction.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.siyeh.ig.telemetry; - -import com.intellij.CommonBundle; -import com.intellij.icons.AllIcons; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.siyeh.InspectionGadgetsBundle; - -class ResetTelemetryAction extends AnAction { - - private final InspectionGadgetsTelemetry telemetry; - private final TelemetryDisplay display; - - ResetTelemetryAction(InspectionGadgetsTelemetry telemetry, - TelemetryDisplay display) { - super(CommonBundle.message("button.reset"), - InspectionGadgetsBundle.message( - "action.reset.telemetry.description"), - AllIcons.Actions.Reset); - this.telemetry = telemetry; - this.display = display; - } - - @Override - public void actionPerformed(AnActionEvent event) { - telemetry.reset(); - display.update(telemetry.buildList()); - } -} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryDisplay.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryDisplay.java deleted file mode 100644 index 562fecfee3db..000000000000 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryDisplay.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.siyeh.ig.telemetry; - -import com.intellij.ui.ScrollPaneFactory; -import com.intellij.ui.TableSpeedSearch; -import com.intellij.ui.table.JBTable; -import com.intellij.util.ui.ColumnInfo; -import com.intellij.util.ui.ListTableModel; -import com.siyeh.InspectionGadgetsBundle; - -import javax.swing.*; -import java.text.NumberFormat; -import java.util.Comparator; -import java.util.List; - -class TelemetryDisplay { - - private final JScrollPane scrollPane; - private final ListTableModel tableModel; - - public TelemetryDisplay(InspectionGadgetsTelemetry telemetry) { - tableModel = new ListTableModel(createColumns(), - telemetry.buildList(), 0); - final JTable table = new JBTable(tableModel); - new TableSpeedSearch(table); - scrollPane = ScrollPaneFactory.createScrollPane(table); - } - - private static ColumnInfo[] createColumns() { - final Comparator nameComparator = - new Comparator() { - - @Override - public int compare(InspectionRunTime runTime1, - InspectionRunTime runTime2) { - return runTime1.getInspectionName().compareToIgnoreCase( - runTime2.getInspectionName()); - } - }; - final Comparator runCountComparator = - new Comparator() { - - @Override - public int compare(InspectionRunTime runTime1, - InspectionRunTime runTime2) { - return runTime1.getRunCount() - runTime2.getRunCount(); - } - }; - final Comparator totalRunTimeComparator = - new Comparator() { - - @Override - public int compare(InspectionRunTime runTime1, - InspectionRunTime runTime2) { - final long totalRunTime1 = runTime1.getTotalRunTime(); - final long totalRunTime2 = runTime2.getTotalRunTime(); - if (totalRunTime1 < totalRunTime2) { - return -1; - } - else if (totalRunTime1 > totalRunTime2) { - return 1; - } - else { - return 0; - } - } - }; - final Comparator averageRunTimeComparator = - new Comparator() { - - @Override - public int compare(InspectionRunTime runTime1, - InspectionRunTime runTime2) { - final double averageRunTime1 = - runTime1.getAverageRunTime(); - final double averageRunTime2 = - runTime2.getAverageRunTime(); - if (averageRunTime1 < averageRunTime2) { - return -1; - } - else if (averageRunTime1 > averageRunTime2) { - return 1; - } - else { - return 0; - } - } - }; - return new ColumnInfo[]{ - new ColumnInfo( - InspectionGadgetsBundle.message( - "telemetry.table.column.inspection.name")) { - @Override - public String valueOf(InspectionRunTime inspectionRunTime) { - return inspectionRunTime.getInspectionName(); - } - - @Override - public Comparator getComparator() { - return nameComparator; - } - }, - new ColumnInfo( - InspectionGadgetsBundle.message( - "telemetry.table.column.run.count")) { - @Override - public Integer valueOf( - InspectionRunTime inspectionRunTime) { - return Integer.valueOf(inspectionRunTime.getRunCount()); - } - - @Override - public Comparator getComparator() { - return runCountComparator; - } - }, - new ColumnInfo( - InspectionGadgetsBundle.message( - "telemetry.table.column.total.time")) { - @Override - public Long valueOf(InspectionRunTime inspectionRunTime) { - return Long.valueOf( - inspectionRunTime.getTotalRunTime()); - } - - @Override - public Comparator getComparator() { - return totalRunTimeComparator; - } - }, - new ColumnInfo( - InspectionGadgetsBundle.message( - "telemetry.table.column.average.time")) { - - private final NumberFormat format = - NumberFormat.getNumberInstance(); - - { - format.setMaximumFractionDigits(2); - format.setMinimumFractionDigits(2); - } - - @Override - public String valueOf(InspectionRunTime inspectionRunTime) { - return format.format(inspectionRunTime.getAverageRunTime()); - } - - @Override - public Comparator getComparator() { - return averageRunTimeComparator; - } - } - }; - } - - public JComponent getContentPane() { - return scrollPane; - } - - public void update(List inspectionRunTimes) { - tableModel.setItems(inspectionRunTimes); - } -} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryToolWindow.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryToolWindow.java deleted file mode 100644 index e91c34897eb4..000000000000 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryToolWindow.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.siyeh.ig.telemetry; - -import com.intellij.openapi.actionSystem.ActionManager; -import com.intellij.openapi.actionSystem.ActionToolbar; -import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.wm.ToolWindow; -import com.intellij.openapi.wm.ToolWindowAnchor; -import com.intellij.openapi.wm.ToolWindowManager; -import com.intellij.ui.JBColor; -import com.intellij.ui.content.Content; -import com.intellij.ui.content.ContentFactory; -import com.intellij.ui.content.ContentManager; -import com.siyeh.InspectionGadgetsBundle; -import org.jetbrains.annotations.NonNls; - -import javax.swing.*; -import java.awt.*; - -public class TelemetryToolWindow { - - @NonNls - private static final String TOOL_WINDOW_ID = "IG Telemetry"; - - private final JPanel contentPanel; - - public TelemetryToolWindow(InspectionGadgetsTelemetry telemetry) { - final TelemetryDisplay telemetryDisplay = - new TelemetryDisplay(telemetry); - final DefaultActionGroup toolbarGroup = new DefaultActionGroup(); - toolbarGroup.add( - new UpdateTelemetryViewAction(telemetry, telemetryDisplay)); - toolbarGroup.add(new ResetTelemetryAction(telemetry, telemetryDisplay)); - final ActionManager actionManager = ActionManager.getInstance(); - final ActionToolbar toolbar = - actionManager.createActionToolbar(TOOL_WINDOW_ID, - toolbarGroup, true); - contentPanel = new JPanel(new BorderLayout()); - contentPanel.setBackground(JBColor.GRAY); - final JComponent toolbarComponent = toolbar.getComponent(); - contentPanel.add(toolbarComponent, BorderLayout.NORTH); - final JComponent displayContentPane = telemetryDisplay.getContentPane(); - contentPanel.add(displayContentPane, BorderLayout.CENTER); - } - - public void register(Project project) { - final ToolWindowManager toolWindowManager = - ToolWindowManager.getInstance(project); - final ToolWindow toolWindow = - toolWindowManager.registerToolWindow(TOOL_WINDOW_ID, false, - ToolWindowAnchor.LEFT); - toolWindow.setTitle(InspectionGadgetsBundle.message( - "telemetry.toolwindow.title")); - final ContentManager contentManager = toolWindow.getContentManager(); - final ContentFactory contentFactory = contentManager.getFactory(); - final Content content = contentFactory.createContent(contentPanel, - "", true); - contentManager.addContent(content); - toolWindow.setAvailable(true, null); - } - - public static void unregister(Project project) { - final ToolWindowManager toolWindowManager = - ToolWindowManager.getInstance(project); - toolWindowManager.unregisterToolWindow(TOOL_WINDOW_ID); - } -} \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/UpdateTelemetryViewAction.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/UpdateTelemetryViewAction.java deleted file mode 100644 index 3c5300559258..000000000000 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/UpdateTelemetryViewAction.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.siyeh.ig.telemetry; - -import com.intellij.CommonBundle; -import com.intellij.icons.AllIcons; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.siyeh.InspectionGadgetsBundle; - -class UpdateTelemetryViewAction extends AnAction { - - private final InspectionGadgetsTelemetry telemetry; - private final TelemetryDisplay telemetryDisplay; - - UpdateTelemetryViewAction(InspectionGadgetsTelemetry telemetry, - TelemetryDisplay telemetryDisplay) { - super(CommonBundle.message("action.refresh"), - InspectionGadgetsBundle.message( - "action.telemetry.refresh.description"), - AllIcons.Actions.Refresh); - this.telemetry = telemetry; - this.telemetryDisplay = telemetryDisplay; - } - - @Override - public void actionPerformed(AnActionEvent event) { - telemetryDisplay.update(telemetry.buildList()); - } -}