Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Ferrazzutti2014-04-01 21:02:55 +0000
committerAndrew Ferrazzutti2014-04-17 21:02:31 +0000
commitb57b7f64276ca9a7310406739368546a88e9d4e7 (patch)
treeb4d40f1e82992ca93499bdedb5c2b7b3f877a2a7 /systemtap
parent52e18ca5cd9700f2a09f4919d36f4fa627db8d9b (diff)
downloadorg.eclipse.linuxtools-b57b7f64276ca9a7310406739368546a88e9d4e7.tar.gz
org.eclipse.linuxtools-b57b7f64276ca9a7310406739368546a88e9d4e7.tar.xz
org.eclipse.linuxtools-b57b7f64276ca9a7310406739368546a88e9d4e7.zip
Linuxtools: Standardize saving graphs as images.
Make SaveChartAction provided by dataviewers public, to allow other plugins to use it instead of each needing their own implementation of chart saving. Also, replace the plugin-specific implementations of chart saving in Massif and Systemtap with this one, and for SystemTap, migrate from using Actions to Commands. Change-Id: If2fe9dbfc10f51da1c8943eb67e98a9b7debc6dc Signed-off-by: Andrew Ferrazzutti <aferrazz@redhat.com> Reviewed-on: https://git.eclipse.org/r/24463
Diffstat (limited to 'systemtap')
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/META-INF/MANIFEST.MF3
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/icons/actions/chart-save.pngbin0 -> 694 bytes
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/icons/actions/save_wiz.gifbin639 -> 0 bytes
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/plugin.properties6
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/plugin.xml56
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/actions/SaveGraphImageAction.java225
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/handlers/SaveGraphImageHandler.java73
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/localization.properties6
8 files changed, 97 insertions, 272 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/META-INF/MANIFEST.MF b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/META-INF/MANIFEST.MF
index 922a76e588..88a0114c49 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/META-INF/MANIFEST.MF
+++ b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/META-INF/MANIFEST.MF
@@ -19,6 +19,7 @@ Require-Bundle: org.eclipse.linuxtools.systemtap.graphing.core,
org.eclipse.core.runtime,
org.eclipse.ui.forms,
org.swtchart,
- org.eclipse.linuxtools.dataviewers.piechart
+ org.eclipse.linuxtools.dataviewers.piechart,
+ org.eclipse.linuxtools.dataviewers.charts
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/icons/actions/chart-save.png b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/icons/actions/chart-save.png
new file mode 100644
index 0000000000..358429abcc
--- /dev/null
+++ b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/icons/actions/chart-save.png
Binary files differ
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/icons/actions/save_wiz.gif b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/icons/actions/save_wiz.gif
deleted file mode 100644
index 499dd0ca60..0000000000
--- a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/icons/actions/save_wiz.gif
+++ /dev/null
Binary files differ
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/plugin.properties b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/plugin.properties
index 7bec15bf82..75ecc7bc06 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/plugin.properties
+++ b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/plugin.properties
@@ -9,8 +9,4 @@ category.file.name=File
category.file.desc=SystemTap Graphing file operations
command.save.name=Save Graph
-command.save.desc=Save graph as image
-
-actionset.graph.name=Graph Display Action Set
-action.save.name=Save Graph
-action.save.desc=Save graph as image \ No newline at end of file
+command.save.desc=Save graph as image \ No newline at end of file
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/plugin.xml b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/plugin.xml
index 48df6e1175..65a4644217 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/plugin.xml
+++ b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/plugin.xml
@@ -13,15 +13,6 @@
id="org.eclipse.linuxtools.generic.prefs.graphing.graph"
class="org.eclipse.linuxtools.internal.systemtap.graphing.ui.preferences.GraphPreferencePage"
category="org.eclipse.linuxtools.generic.prefs.graphing"/>
- </extension>
-
- <extension
- point="org.eclipse.core.runtime.preferences">
- <initializer class="org.eclipse.linuxtools.internal.systemtap.graphing.ui.preferences.PreferenceInitializer"/>
- </extension>
-
- <extension
- point="org.eclipse.ui.preferencePages">
<page
name="%preference.graphing.name"
class="org.eclipse.linuxtools.internal.systemtap.graphing.ui.preferences.GraphingPreferencePage"
@@ -44,36 +35,31 @@
name="%command.save.name"
description="%command.save.desc"
categoryId="org.eclipse.linuxtools.systemtap.graphing.ui.category.file"
- id="org.eclipse.linuxtools.systemtap.graphing.ui.commands.SaveGraphImage"/>
+ id="org.eclipse.linuxtools.systemtap.graphing.ui.commands.SaveGraphImage"
+ defaultHandler="org.eclipse.linuxtools.internal.systemtap.graphing.ui.handlers.SaveGraphImageHandler"/>
</extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="toolbar:org.eclipse.linuxtools.systemtap.ui.ide.toolbar?after=chartGroup">
+ <command
+ commandId="org.eclipse.linuxtools.systemtap.graphing.ui.commands.SaveGraphImage"
+ label="%command.save.name"
+ icon="icons/actions/chart-save.png">
+ <visibleWhen checkEnabled="true"/>
+ </command>
+ </menuContribution>
+ </extension>
<extension
- point="org.eclipse.ui.actionSets">
- <actionSet
- label="actionset.graph.name"
- visible="false"
- id="org.eclipse.linuxtools.systemtap.graphing.ui.GraphingActionSet">
- <action
- label="%action.save.name"
- tooltip="%action.save.desc"
- id="org.eclipse.linuxtools.systemtap.graphing.ui.actions.SaveGraphImage"
- icon="icons/actions/save_wiz.gif"
- toolbarPath="org.eclipse.ui.workbench.file/save.ext"
- class="org.eclipse.linuxtools.internal.systemtap.graphing.ui.actions.SaveGraphImageAction"
- definitionId="org.eclipse.linuxtools.systemtap.graphing.ui.commands.SaveGraphImage"
- style="push"
- state="false"/>
- </actionSet>
+ point="org.eclipse.ui.editors">
+ <editor
+ class="org.eclipse.linuxtools.systemtap.graphing.ui.views.GraphSelectorEditor"
+ default="false"
+ id="org.eclipse.linuxtools.systemtap.graphing.ui.views.GraphSelectorEditor"
+ name="Graphs">
+ </editor>
</extension>
- <extension
- point="org.eclipse.ui.editors">
- <editor
- class="org.eclipse.linuxtools.systemtap.graphing.ui.views.GraphSelectorEditor"
- default="false"
- id="org.eclipse.linuxtools.systemtap.graphing.ui.views.GraphSelectorEditor"
- name="Graphs">
- </editor>
- </extension>
</plugin>
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/actions/SaveGraphImageAction.java b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/actions/SaveGraphImageAction.java
deleted file mode 100644
index 6ee87dc769..0000000000
--- a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/actions/SaveGraphImageAction.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
- *******************************************************************************/
-
-package org.eclipse.linuxtools.internal.systemtap.graphing.ui.actions;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.linuxtools.internal.systemtap.graphing.ui.Localization;
-import org.eclipse.linuxtools.systemtap.graphing.ui.GraphDisplaySet;
-import org.eclipse.linuxtools.systemtap.graphing.ui.charts.AbstractChartBuilder;
-import org.eclipse.linuxtools.systemtap.graphing.ui.views.GraphSelectorEditor;
-import org.eclipse.linuxtools.systemtap.graphing.ui.widgets.ExceptionErrorDialog;
-import org.eclipse.linuxtools.systemtap.structures.listeners.ITabListener;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.ImageLoader;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.IWorkbenchWindowActionDelegate;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * This action is designed to allow for saving of the graph in the active window.
- * It will let the user select the location to save the image, and then save it as
- * a jpg image.
- * @author Ryan Morse
- * @since 3.0 Migrated from .ui.graphing package.
- */
-public class SaveGraphImageAction extends Action implements IWorkbenchWindowActionDelegate {
- @Override
- public void init(IWorkbenchWindow window) {
- fWindow = window;
- }
-
- /**
- * This is the main method of the action. It handles getting the active graph,
- * prompting the user for a location to save the image to, and then actually doing
- * the save.
- * @param act The action that fired this method.
- */
- @Override
- public void run(IAction act) {
- AbstractChartBuilder g = getGraph();
- try {
- PlatformUI.getWorkbench().getDisplay().update();
- } catch(SWTException swte) {
- ExceptionErrorDialog.openError(Localization.getString("SaveGraphImageAction.UnableToSaveGraph"), swte); //$NON-NLS-1$
- }
- if(null == g) {
- displayError(Localization.getString("SaveGraphImageAction.CanNotGetGraph")); //$NON-NLS-1$
- return;
- }
-
- ImageData image = getImage(g);
- if(null == image) {
- displayError(Localization.getString("SaveGraphImageAction.CanNotCreateImage")); //$NON-NLS-1$
- return;
- }
-
- String path = getFile();
- if(null == path) {
- return;
- }
-
- save(image, path);
- }
-
- /**
- * This method retreives the active graph from the GraphSelectorView. If no
- * graph is active it will return null.
- * @return The IGraph in tha active display set.
- */
- private AbstractChartBuilder getGraph() {
- IViewPart ivp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(GraphSelectorEditor.ID);
- AbstractChartBuilder g = null;
-
- GraphDisplaySet gds = ((GraphSelectorEditor)ivp).getActiveDisplaySet();
- if(null != gds) {
- g = gds.getActiveGraph();
- }
- return g;
- }
-
- /**
- * This method converts the Graph into an actual image.
- * @param canvas The graph that needs to be converted to an image
- * @return The Image that was generated by the supplied Graph.
- */
- private ImageData getImage(AbstractChartBuilder canvas) {
- GC gc = new GC(canvas);
- Image image = new Image(canvas.getDisplay(), canvas.getSize().x, canvas.getSize().y);
- gc.copyArea(image, 0, 0);
- gc.dispose();
-
- ImageData data = image.getImageData();
- image.dispose();
- return data;
- }
-
- /**
- * This method will display a dialog box for the user to select a
- * location to save the graph image.
- * @return The String location selected to save the image to.
- */
- private String getFile() {
- FileDialog dialog= new FileDialog(fWindow.getShell(), SWT.SAVE);
- dialog.setText(Localization.getString("SaveGraphImageAction.NewFile")); //$NON-NLS-1$
- return dialog.open();
- }
-
- /**
- * This method will perform the save operation to store the generated
- * image as an image file on the computer
- * @param image The image data generated from the graph
- * @param path The location to create the new file in and save to.
- */
- private void save(ImageData image, String path) {
- ImageLoader loader = new ImageLoader();
- loader.data = new ImageData[] {image};
- loader.save(path, SWT.IMAGE_JPEG);
- }
-
- /**
- * This method will display the error message to the user in the case
- * that something went wrong.
- * @param message The message that should be shown in the error dialog.
- */
- private void displayError(String message) {
- MessageDialog.openWarning(fWindow.getShell(), Localization.getString("SaveGraphImageAction.Problem"), message); //$NON-NLS-1$
- }
-
- /**
- * This method is used to generate the checks to see it this button
- * should be enabled or not.
- */
- @Override
- public void selectionChanged(IAction a, ISelection s) {
- action = a;
- action.setEnabled(false);
- buildEnablementChecks();
- }
-
- /**
- * This method is used to generate the checks to see it this button
- * should be enabled or not.
- */
- private void buildEnablementChecks() {
- IViewPart ivp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(GraphSelectorEditor.ID);
- if(null != ivp) {
- final GraphSelectorEditor gsv = (GraphSelectorEditor)ivp;
- gsv.addTabListener(new ITabListener() {
- @Override
- public void tabClosed() {
- if(null == gsv.getActiveDisplaySet() || null == gsv.getActiveDisplaySet().getActiveGraph()) {
- action.setEnabled(false);
- }
- }
-
- @Override
- public void tabOpened() {
- gsv.getActiveDisplaySet().addTabListener(new ITabListener() {
- @Override
- public void tabClosed() {
- if(null == gsv.getActiveDisplaySet().getActiveGraph()) {
- action.setEnabled(false);
- }
- }
-
- @Override
- public void tabOpened() {
- if(null != gsv.getActiveDisplaySet().getActiveGraph()) {
- action.setEnabled(true);
- }
- }
-
- @Override
- public void tabChanged() {
- if(null == gsv.getActiveDisplaySet() || null == gsv.getActiveDisplaySet().getActiveGraph()) {
- action.setEnabled(false);
- } else {
- action.setEnabled(true);
- }
- }
- });
- }
-
- @Override
- public void tabChanged() {
- if(null == gsv.getActiveDisplaySet() || null == gsv.getActiveDisplaySet().getActiveGraph()) {
- action.setEnabled(false);
- } else {
- action.setEnabled(true);
- }
- }
- });
- }
- }
-
- /**
- * Removes all internal references in this class. Nothing should make any references
- * to anyting in this class after calling the dispose method.
- */
- @Override
- public void dispose() {
- fWindow = null;
- action = null;
- }
-
- private IWorkbenchWindow fWindow;
- private IAction action;
-}
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/handlers/SaveGraphImageHandler.java b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/handlers/SaveGraphImageHandler.java
new file mode 100644
index 0000000000..f22e750565
--- /dev/null
+++ b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/handlers/SaveGraphImageHandler.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Red Hat, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and Action implementation
+ * Red Hat - conversion to Handler implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.systemtap.graphing.ui.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.linuxtools.dataviewers.charts.actions.SaveChartAction;
+import org.eclipse.linuxtools.systemtap.graphing.ui.GraphDisplaySet;
+import org.eclipse.linuxtools.systemtap.graphing.ui.charts.AbstractChartBuilder;
+import org.eclipse.linuxtools.systemtap.graphing.ui.views.GraphSelectorEditor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.swtchart.Chart;
+
+/**
+ * This action is designed to allow for saving of the graph in the active window.
+ * It will let the user select the location to save the image, and then save it as
+ * a jpg image.
+ * @author Ryan Morse
+ * @since 3.0 Migrated from .ui.graphing package.
+ */
+public class SaveGraphImageHandler extends AbstractHandler {
+
+ private SaveChartAction saveChartAction = new SaveChartAction();
+
+ /**
+ * This is the main method of the action. It handles getting the active graph,
+ * prompting the user for a location to save the image to, and then actually doing
+ * the save.
+ */
+ @Override
+ public Object execute(ExecutionEvent event) {
+ saveChartAction.setChart(getActiveChart());
+ saveChartAction.run();
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return getActiveGraphEditor() != null;
+ }
+
+ private GraphSelectorEditor getActiveGraphEditor() {
+ IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().
+ getActivePage().getActiveEditor();
+ return editor instanceof GraphSelectorEditor ? (GraphSelectorEditor) editor : null;
+ }
+
+ private AbstractChartBuilder getActiveGraph() {
+ GraphSelectorEditor graphEditor = getActiveGraphEditor();
+ if (graphEditor == null) {
+ return null;
+ }
+ GraphDisplaySet gds = graphEditor.getActiveDisplaySet();
+ return gds == null ? null : gds.getActiveGraph();
+ }
+
+ private Chart getActiveChart() {
+ AbstractChartBuilder abs = getActiveGraph();
+ return abs == null ? null : abs.getChart();
+ }
+
+}
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/localization.properties b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/localization.properties
index 77bf967ce2..54f46d6448 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/localization.properties
+++ b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/localization.properties
@@ -170,12 +170,6 @@ OpenScriptOutputAction.OpenFile=Open File
OpenScriptOutputAction.Problem=Problem
OpenScriptOutputAction.UnableToOpenDialogTitle=Unable to change to the Graphing Perspective
-SaveGraphImageAction.CanNotGetGraph=Can't get active graph.
-SaveGraphImageAction.CanNotCreateImage=Can't create image
-SaveGraphImageAction.NewFile=New File
-SaveGraphImageAction.Problem=Problem
-SaveGraphImageAction.UnableToSaveGraph=Unable to Save Graph
-
GraphingPreferencePage.GraphDisplayPreferences=Basic preferences for graph display.
GraphingPreferencePage.RefreshDelay=&Refresh delay (ms):

Back to the top