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
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
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.charts/icons/chart-save.pngbin0 -> 694 bytes
-rwxr-xr-xprofiling/org.eclipse.linuxtools.dataviewers.charts/icons/save_chart.gifbin583 -> 0 bytes
-rwxr-xr-xprofiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveChartAction.java226
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/Messages.java5
-rwxr-xr-xprofiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/actions/SaveChartAction.java195
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/messages.properties9
-rwxr-xr-xprofiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/view/ChartView.java4
-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
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif.tests/META-INF/MANIFEST.MF3
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/AbstractMassifTest.java23
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartExportTest.java46
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartTests.java31
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif/META-INF/MANIFEST.MF3
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/MassifViewPart.java46
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/charting/ChartEditorInput.java10
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/charting/ChartPNG.java42
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/messages.properties3
24 files changed, 411 insertions, 604 deletions
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.charts/icons/chart-save.png b/profiling/org.eclipse.linuxtools.dataviewers.charts/icons/chart-save.png
new file mode 100644
index 0000000000..358429abcc
--- /dev/null
+++ b/profiling/org.eclipse.linuxtools.dataviewers.charts/icons/chart-save.png
Binary files differ
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.charts/icons/save_chart.gif b/profiling/org.eclipse.linuxtools.dataviewers.charts/icons/save_chart.gif
deleted file mode 100755
index 466bfb1128..0000000000
--- a/profiling/org.eclipse.linuxtools.dataviewers.charts/icons/save_chart.gif
+++ /dev/null
Binary files differ
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveChartAction.java b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveChartAction.java
new file mode 100755
index 0000000000..ddd0ac7e2d
--- /dev/null
+++ b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveChartAction.java
@@ -0,0 +1,226 @@
+/*******************************************************************************
+ * 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:
+ * Marzia Maugeri <marzia.maugeri@st.com> - initial API and implementation
+ * Red Hat (various) - ongoing maintenance
+ *******************************************************************************/
+package org.eclipse.linuxtools.dataviewers.charts.actions;
+
+import java.io.File;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.linuxtools.internal.dataviewers.charts.Activator;
+import org.eclipse.linuxtools.internal.dataviewers.charts.Messages;
+import org.eclipse.swt.SWT;
+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.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.swtchart.Chart;
+
+/**
+ * An action to save any {@link Composite} (typically a {@link Chart}) as an image (jpeg/jpg, bmp, png).
+ *
+ * @since 6.0
+ */
+public class SaveChartAction extends Action {
+
+ private static final String[] saveAsImageExt =
+ { "*.png", "*.bmp", "*.jpg", "*.jpeg", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ private static final String DEFAULT_EXT = "png"; //$NON-NLS-1$
+ private static final String DEFAULT_TITLE = "newChart"; //$NON-NLS-1$
+ private static final Map<String, Integer> EXTENSION_MAP = new HashMap<>();
+
+ private Composite contents = null;
+ private String title = null;
+
+ static {
+ EXTENSION_MAP.put("png", SWT.IMAGE_PNG); //$NON-NLS-1$
+ EXTENSION_MAP.put("bmp", SWT.IMAGE_BMP); //$NON-NLS-1$
+ EXTENSION_MAP.put("jpeg", SWT.IMAGE_JPEG); //$NON-NLS-1$
+ EXTENSION_MAP.put("jpg", SWT.IMAGE_JPEG); //$NON-NLS-1$
+ }
+
+ public SaveChartAction() {
+ super(Messages.ChartConstants_SAVE_CHART_AS, Activator.getImageDescriptor("icons/chart-save.png")); //$NON-NLS-1$
+ this.setEnabled(false);
+ }
+
+ /**
+ * Sets the image plugin on the contents and enables the action if contents are not null.
+ * Also, a default title for the file to be saved is generated.
+ * @param contents The image contents to be saved.
+ */
+ public void setChart(Composite contents) {
+ setChart(contents, null);
+ }
+
+ /**
+ * The same as {@link #setChart(Composite)}, but allows specification of a custom default
+ * title for the image file to be saved.
+ * @param contents The image contents to be saved.
+ * @param title The default title of the image file when it is saved. Set this to <code>null</code>
+ * if a title should be generated from the {@link #contents}.
+ */
+ public void setChart(Composite contents, String title) {
+ this.contents = contents;
+ if (contents != null) {
+ this.title = title != null ? title : getDefaultName();
+ setEnabled(true);
+ } else {
+ setEnabled(false);
+ }
+ }
+
+ private String getDefaultName() {
+ if (contents instanceof Chart) {
+ return ((Chart) contents).getTitle().getText().replaceAll(" ", "_"); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ return DEFAULT_TITLE;
+ }
+ }
+
+ /**
+ * Open a dialog with which to save the contents at a user-specified path.
+ */
+ @Override
+ public void run() {
+ if (problemExists()) {
+ return;
+ }
+ File file = askForAndPrepareFile();
+ if (file == null) {
+ return; // Cancelled
+ }
+ generateImageFile(file);
+ }
+
+ /**
+ * Save the previously-set contents as an image without the need for user input.
+ * @param path The path to save the image to.
+ */
+ public void run(String path) {
+ if (problemExists()) {
+ return;
+ }
+ File file = new File(makePathWithVerifiedExt(path));
+ if (shouldOverwrite(file, null)) {
+ generateImageFile(new File(path));
+ }
+ }
+
+ private boolean problemExists() {
+ IStatus status = null;
+ if (!isEnabled()) {
+ status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ Messages.ChartConstants_ERROR_CHART_CLOSED);
+ } else if (contents.isDisposed()) {
+ status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ Messages.ChartConstants_ERROR_CHART_DISPOSED);
+ }
+
+ if (status != null) {
+ ErrorDialog.openError(getWorkbenchShell(),
+ Messages.ChartConstants_ERROR_SAVING_CHART,
+ Messages.ChartConstants_ERROR_SAVING_CHART_MESSAGE, status);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Ask the user for the path to save the file at, and check if this path overwrites any existing file.
+ * (Note that using dialog.setOverwrite(true) is insufficient, as the path name may be appended with a
+ * file extension after the standard overwrite checks occur.)
+ * @return A file with the specified pathname, appended with an appropriate extension.
+ */
+ private File askForAndPrepareFile() {
+ final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ final FileDialog dialog = new FileDialog(shell, SWT.SAVE);
+ dialog.setFilterExtensions(saveAsImageExt);
+ dialog.setText(Messages.ChartConstants_SAVE_CHART_DIALOG_TEXT);
+ dialog.setFileName(title);
+
+ do {
+ String path = dialog.open();
+ if (path == null) {
+ return null; // Cancelled
+ }
+
+ path = makePathWithVerifiedExt(path);
+
+ File file = new File(path);
+ if (shouldOverwrite(file, shell)) {
+ return file;
+ }
+ // If not overwriting, bring up dialog again (loop)
+ dialog.setFileName(file.getName());
+ } while (true);
+ }
+
+ private boolean shouldOverwrite(File file, Shell shell) {
+ if (!file.exists()) {
+ return true;
+ }
+ if (MessageDialog.openQuestion(shell != null ? shell :
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ Messages.ChartConstants_CONFIRM_OVERWRITE_TITLE,
+ MessageFormat.format(Messages.ChartConstants_CONFIRM_OVERWRITE_MSG, file))) {
+ file.delete();
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Checks if the provided path has a valid file extension supported by {@link ImageLoader#save(String, int)}.
+ * If not, a copy of the path is returned, with its extension replaced with a default one.
+ */
+ private String makePathWithVerifiedExt(String path) {
+ String pathExt = Path.fromOSString(path).getFileExtension();
+ if (pathExt == null) {
+ return path.concat('.' + DEFAULT_EXT);
+ }
+ if (EXTENSION_MAP.containsKey(pathExt)) {
+ return path;
+ }
+ return path.replaceAll(pathExt.concat("$"), DEFAULT_EXT); //$NON-NLS-1$
+ }
+
+ private void generateImageFile(File file) {
+ // Extension is chosen based on the file name, not the dialog filter selection.
+ int extension = EXTENSION_MAP.get(Path.fromOSString(file.getName()).getFileExtension());
+
+ Display dsp = Display.getCurrent();
+ GC gc = new GC(contents);
+ Image img = new Image(dsp, contents.getSize().x, contents.getSize().y);
+ gc.copyArea(img, 0, 0);
+ gc.dispose();
+ ImageLoader imageLoader = new ImageLoader();
+ imageLoader.data = new ImageData[] { img.getImageData() };
+ imageLoader.save(file.getAbsolutePath(), extension);
+ }
+
+ private Shell getWorkbenchShell() {
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ }
+
+}
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/Messages.java b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/Messages.java
index 03fb1fdc56..8e32673909 100644
--- a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/Messages.java
+++ b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/Messages.java
@@ -13,7 +13,7 @@ package org.eclipse.linuxtools.internal.dataviewers.charts;
import org.eclipse.osgi.util.NLS;
/**
- *
+ *
* @author Xavier Raynaud <xavier.raynaud@kalray.eu>
*/
public class Messages extends NLS {
@@ -28,6 +28,7 @@ public class Messages extends NLS {
public static String ChartConstants_CREATE_NEW_CHART_FROM_SELECTION;
public static String ChartConstants_DESELECT_ALL;
public static String ChartConstants_ERROR_SAVING_CHART;
+ public static String ChartConstants_ERROR_SAVING_CHART_MESSAGE;
public static String ChartConstants_NO_COLUMN_SELECTED;
public static String ChartConstants_PIE_CHART;
public static String ChartConstants_SAVE_CHART_AS;
@@ -36,6 +37,8 @@ public class Messages extends NLS {
public static String ChartConstants_SELECT_COLUMNS_TO_SHOW;
public static String ChartConstants_SELECT_YOUR_CHART_TYPE;
public static String ChartConstants_VERTICAL_BARS;
+ public static String ChartConstants_ERROR_CHART_DISPOSED;
+ public static String ChartConstants_ERROR_CHART_CLOSED;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/actions/SaveChartAction.java b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/actions/SaveChartAction.java
deleted file mode 100755
index 356a45f487..0000000000
--- a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/actions/SaveChartAction.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 STMicroelectronics.
- * 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:
- * Marzia Maugeri <marzia.maugeri@st.com> - initial API and implementation
- *******************************************************************************/
-package org.eclipse.linuxtools.internal.dataviewers.charts.actions;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.linuxtools.internal.dataviewers.charts.Activator;
-import org.eclipse.linuxtools.internal.dataviewers.charts.Messages;
-import org.eclipse.swt.SWT;
-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.Display;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.progress.UIJob;
-import org.swtchart.Chart;
-
-/**
- * An action to save a chart as an image (jpeg, gif, png)
- *
- * @author Marzia Maugeri <marzia.maugeri@st.com>
- */
-public class SaveChartAction extends Action {
-
- /** The section name of the "save chart as image" action dialog settings */
- private static final String TAG_SECTION_CHARTS_SAVEACTION_STATE = "charts_saveasimg_section"; //$NON-NLS-1$
- /** The key used by the file dialog to save its file name */
- private static final String TAG_IMG_FILE_NAME = "IMG_FILE_NAME"; //$NON-NLS-1$
- /** The key used by the file dialog to save its filter path */
- private static final String TAG_IMG_FILTER_PATH = "IMG_FILTER_PATH"; //$NON-NLS-1$
-
- /** Image extension for jpg format */
- private static final String EXT_JPG = "*.jpg"; //$NON-NLS-1$
- /** Image extension for jpeg format */
- private static final String EXT_JPEG = "*.jpeg"; //$NON-NLS-1$
- /** Image extension for png format */
- private static final String EXT_PNG = "*.png"; //$NON-NLS-1$
- /** Image extension for gif format */
- private static final String EXT_GIF = "*.gif"; //$NON-NLS-1$
- /** The file extensions provided by the "save chart as image" file dialog */
- private static final String[] saveAsImageExt = { EXT_PNG, EXT_GIF, EXT_JPG, EXT_JPEG, "*.*" }; //$NON-NLS-1$
- /** The names associated to the files extensions provided by the "save chart as image" file dialog */
- private static final String[] saveAsImageExtNames = new String[] {
- "PNG (*.png)", "GIF (*.gif)", "JPEG (*.jpg)", "JPEG (*.jpeg)", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- Messages.ChartConstants_ALL_FILES };
-
- private final FileDialog dialog;
- private final Shell shell;
- private Chart cm;
-
- /**
- * Constructor
- *
- * @param shell
- * the shell used by the dialogs
- */
- public SaveChartAction(Shell shell) {
- super(Messages.ChartConstants_SAVE_CHART_AS + "...", Activator.getImageDescriptor("icons/save_chart.gif")); //$NON-NLS-1$ //$NON-NLS-2$
- this.setEnabled(false);
- this.shell = shell;
- this.dialog = new FileDialog(shell, SWT.SAVE);
- dialog.setFilterExtensions(saveAsImageExt);
- dialog.setFilterNames(saveAsImageExtNames);
- dialog.setText(Messages.ChartConstants_SAVE_CHART_DIALOG_TEXT);
- // restore state if there is one saved
- restoreState();
- }
-
- /**
- * Sets the image plugins on the chart and enables the action if chart is not null.
- *
- * @param chart
- */
- public void setChart(Chart chart) {
- if (chart != null) {
- setEnabled(true);
- } else {
- setEnabled(false);
- }
- cm = chart;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.action.Action#run()
- */
- @Override
- public void run() {
- String path = dialog.open();
- if (path == null) {
- // cancel pressed
- return;
- }
- final File file = new File(path);
- if (file.exists()) {
- boolean overwrite = MessageDialog.openQuestion(shell, Messages.ChartConstants_CONFIRM_OVERWRITE_TITLE,
- Messages.ChartConstants_CONFIRM_OVERWRITE_MSG);
- if (overwrite) {
- file.delete();
- } else {
- return;
- }
- }
-
- final String ext = dialog.getFilterNames()[dialog.getFilterIndex()];
-
- UIJob saveAsImage = new UIJob(Messages.ChartConstants_SAVE_CHART_AS + " " + file.getName()) { //$NON-NLS-1$
- @Override
- public IStatus runInUIThread(IProgressMonitor monitor) {
- int extention;
- if (EXT_GIF.equals(ext)) {
- extention = SWT.IMAGE_GIF;
- } else if (EXT_JPEG.equals(ext) || EXT_JPG.equals(ext)) {
- extention = SWT.IMAGE_JPEG;
- } else {
- extention = SWT.IMAGE_PNG;
- }
-
- try {
- monitor.beginTask(Messages.ChartConstants_SAVE_CHART_AS + " " + file.getName() + "...", //$NON-NLS-1$//$NON-NLS-2$
- IProgressMonitor.UNKNOWN);
- file.createNewFile();
- generateImageFile(file, extention);
- return Status.OK_STATUS;
- } catch (IOException e) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ChartConstants_ERROR_SAVING_CHART
- + " (" + file.getAbsolutePath() + "):\n" + e.getMessage(), e); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- };
- saveAsImage.setUser(true);
- saveAsImage.schedule();
-
- // save the state of the dialog
- saveState();
- }
-
- /**
- * Restores the state of this action (file dialog)
- */
- private void restoreState() {
- IDialogSettings settings = Activator.getDefault().getDialogSettings()
- .getSection(TAG_SECTION_CHARTS_SAVEACTION_STATE);
- if (settings == null) {
- settings = Activator.getDefault().getDialogSettings().addNewSection(TAG_SECTION_CHARTS_SAVEACTION_STATE);
- return;
- }
-
- dialog.setFileName(settings.get(TAG_IMG_FILE_NAME));
- dialog.setFilterPath(settings.get(TAG_IMG_FILTER_PATH));
- }
-
- /**
- * Saves the state of this action (file dialog)
- */
- private void saveState() {
- IDialogSettings settings = Activator.getDefault().getDialogSettings()
- .getSection(TAG_SECTION_CHARTS_SAVEACTION_STATE);
- if (settings == null) {
- settings = Activator.getDefault().getDialogSettings().addNewSection(TAG_SECTION_CHARTS_SAVEACTION_STATE);
- }
- settings.put(TAG_IMG_FILE_NAME, dialog.getFileName());
- settings.put(TAG_IMG_FILTER_PATH, dialog.getFilterPath());
- }
-
- private void generateImageFile(File file, int extention) {
- Display dsp = Display.getCurrent();
- GC gc = new GC(cm);
- Image img = new Image(dsp, cm.getSize().x, cm.getSize().y);
- gc.copyArea(img, 0, 0);
- gc.dispose();
- ImageLoader imageLoader = new ImageLoader();
- imageLoader.data = new ImageData[] { img.getImageData() };
- imageLoader.save(file.getAbsolutePath(), extention);
- }
-
-}
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/messages.properties b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/messages.properties
index d37052d6af..62f496d61b 100644
--- a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/messages.properties
+++ b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/messages.properties
@@ -11,17 +11,20 @@
ChartConstants_ALL_FILES=All Files (*.*)
ChartConstants_BAR_GRAPH=Bar graph
ChartConstants_CHART_BUILDER=Chart builder
-ChartConstants_CONFIRM_OVERWRITE_MSG=File already exists. Overwrite?
+ChartConstants_CONFIRM_OVERWRITE_MSG=File {0} already exists. Overwrite?
ChartConstants_CONFIRM_OVERWRITE_TITLE=Confirm overwrite
ChartConstants_CREATE_CHART=Create chart...
ChartConstants_CREATE_NEW_CHART_FROM_SELECTION=Create chart from selection...
ChartConstants_DESELECT_ALL=Deselect all
ChartConstants_ERROR_SAVING_CHART=Error saving chart
+ChartConstants_ERROR_SAVING_CHART_MESSAGE=An error occurred while attempting to save the chart.
ChartConstants_NO_COLUMN_SELECTED=No column selected
ChartConstants_PIE_CHART=Pie chart
-ChartConstants_SAVE_CHART_AS=Save chart as
-ChartConstants_SAVE_CHART_DIALOG_TEXT=Select an image file (extension will be set to ".png" if not recognized).
+ChartConstants_SAVE_CHART_AS=Save chart as...
+ChartConstants_SAVE_CHART_DIALOG_TEXT=Save Chart As Image (extension will be set to ".png" if not recognized)
ChartConstants_SELECT_ALL=Select all
ChartConstants_SELECT_COLUMNS_TO_SHOW=Select the columns(s) to show
ChartConstants_SELECT_YOUR_CHART_TYPE=Select your chart type
ChartConstants_VERTICAL_BARS=Vertical bars
+ChartConstants_ERROR_CHART_DISPOSED=The selected chart is disposed and cannot be saved.
+ChartConstants_ERROR_CHART_CLOSED=A chart must be open for it to be saved. \ No newline at end of file
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/view/ChartView.java b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/view/ChartView.java
index 8df700d6cf..c1b11dd94f 100755
--- a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/view/ChartView.java
+++ b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/view/ChartView.java
@@ -13,8 +13,8 @@ package org.eclipse.linuxtools.internal.dataviewers.charts.view;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.linuxtools.dataviewers.charts.actions.SaveChartAction;
import org.eclipse.linuxtools.internal.dataviewers.charts.Activator;
-import org.eclipse.linuxtools.internal.dataviewers.charts.actions.SaveChartAction;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchPage;
@@ -89,7 +89,7 @@ public class ChartView extends ViewPart {
}
private void createActions() {
- saveChartAction = new SaveChartAction(getViewSite().getShell());
+ saveChartAction = new SaveChartAction();
}
protected void initToolBar(IToolBarManager manager) {
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):
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/META-INF/MANIFEST.MF b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/META-INF/MANIFEST.MF
index 7665909067..b3bf16512b 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/META-INF/MANIFEST.MF
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/META-INF/MANIFEST.MF
@@ -4,7 +4,8 @@ Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.eclipse.linuxtools.valgrind.massif.tests
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: %Bundle-Vendor.0
-Require-Bundle: org.junit;bundle-version="4.7.0"
+Require-Bundle: org.junit;bundle-version="4.7.0",
+ org.eclipse.linuxtools.dataviewers.charts
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/AbstractMassifTest.java b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/AbstractMassifTest.java
index 28973605da..7f61f3572b 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/AbstractMassifTest.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/AbstractMassifTest.java
@@ -18,6 +18,10 @@ import java.io.File;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifHeapTreeNode;
@@ -25,6 +29,8 @@ import org.eclipse.linuxtools.internal.valgrind.massif.MassifPlugin;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot.SnapshotType;
import org.eclipse.linuxtools.internal.valgrind.tests.AbstractValgrindTest;
+import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin;
+import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
@@ -99,4 +105,21 @@ public abstract class AbstractMassifTest extends AbstractValgrindTest {
}
}
+ protected IAction getToolbarAction(String actionId) {
+ IAction result = null;
+ ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
+ IToolBarManager manager = view.getViewSite().getActionBars()
+ .getToolBarManager();
+ for (IContributionItem item : manager.getItems()) {
+ if (item instanceof ActionContributionItem) {
+ ActionContributionItem actionItem = (ActionContributionItem) item;
+ if (actionItem.getAction().getId()
+ .equals(actionId)) {
+ result = actionItem.getAction();
+ }
+ }
+ }
+ return result;
+ }
+
}
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartExportTest.java b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartExportTest.java
index 2c97646527..5536926dc2 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartExportTest.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartExportTest.java
@@ -14,14 +14,16 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.util.ArrayList;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.linuxtools.dataviewers.charts.actions.SaveChartAction;
+import org.eclipse.linuxtools.internal.valgrind.massif.MassifViewPart;
import org.eclipse.linuxtools.internal.valgrind.massif.charting.ChartEditorInput;
-import org.eclipse.linuxtools.internal.valgrind.massif.charting.ChartPNG;
-import org.eclipse.linuxtools.internal.valgrind.massif.charting.HeapChart;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.PlatformUI;
import org.junit.After;
@@ -29,23 +31,29 @@ import org.junit.Before;
import org.junit.Test;
public class ChartExportTest extends AbstractMassifTest {
- private IPath pngPath;
+ private String[] pathNames = new String[]{"chart.png", "chart.jpg", "chart.jpeg", "chart.bmp"};
+ private ArrayList<IPath> paths = new ArrayList<>();
@Before
public void prep() throws Exception {
proj = createProjectAndBuild("alloctest"); //$NON-NLS-1$
- pngPath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
- assertNotNull(pngPath);
- pngPath = pngPath.append("alloctest").append("chart.png"); //$NON-NLS-1$ //$NON-NLS-2$
+ IPath basePath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
+ assertNotNull(basePath);
+ basePath = basePath.append("alloctest");
+ for (String pathName : pathNames) {
+ paths.add(basePath.append(pathName));
+ }
}
@Override
@After
public void tearDown() throws CoreException {
- File chartFile = pngPath.toFile();
- if (chartFile.exists()) {
- chartFile.delete();
+ for (IPath path : paths) {
+ File chartFile = path.toFile();
+ if (chartFile.exists()) {
+ chartFile.delete();
+ }
}
deleteProject(proj);
@@ -62,12 +70,24 @@ public class ChartExportTest extends AbstractMassifTest {
.getEditorInput();
assertTrue("input must be ChartEditorInput",
input instanceof ChartEditorInput);
- HeapChart chart = ((ChartEditorInput) input).getChart();
- ChartPNG png = new ChartPNG(chart);
- png.renderPNG(pngPath);
+ Composite control = ((ChartEditorInput) input).getChart().getChartControl();
+ if (control.getSize().x == 0 || control.getSize().y == 0) {
+ // Manually resize the composite to non-zero width/height so it can be saved
+ control.setSize(10, 10);
+ }
+
+ SaveChartAction saveChartAction = (SaveChartAction) getToolbarAction(MassifViewPart.SAVE_CHART_ACTION);
+ assertNotNull(saveChartAction);
+
+ for (IPath path : paths) {
+ saveAsPath(saveChartAction, path);
+ }
+ }
- File chartFile = pngPath.toFile();
+ private void saveAsPath(SaveChartAction saveChartAction, IPath path) {
+ saveChartAction.run(path.toString());
+ File chartFile = path.toFile();
assertTrue(chartFile.exists());
assertTrue(chartFile.length() > 0);
}
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartTests.java b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartTests.java
index 5c11e23330..caa3d1564e 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartTests.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartTests.java
@@ -18,10 +18,7 @@ import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IContributionItem;
-import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifHeapTreeNode;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifLaunchConstants;
@@ -33,12 +30,10 @@ import org.eclipse.linuxtools.internal.valgrind.massif.charting.ChartLocationsDi
import org.eclipse.linuxtools.internal.valgrind.massif.charting.HeapChart;
import org.eclipse.linuxtools.internal.valgrind.massif.charting.Messages;
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin;
-import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
import org.junit.After;
import org.junit.Before;
@@ -64,8 +59,7 @@ public class ChartTests extends AbstractMassifTest {
ILaunchConfiguration config = createConfiguration(proj.getProject());
doLaunch(config, "testEditorName"); //$NON-NLS-1$
- ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
- IAction chartAction = getChartAction(view);
+ IAction chartAction = getChartAction();
assertNotNull(chartAction);
chartAction.run();
@@ -100,8 +94,7 @@ public class ChartTests extends AbstractMassifTest {
ILaunchConfiguration config = createConfiguration(proj.getProject());
doLaunch(config, "testChartCallback"); //$NON-NLS-1$
- ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
- IAction chartAction = getChartAction(view);
+ IAction chartAction = getChartAction();
assertNotNull(chartAction);
chartAction.run();
@@ -163,8 +156,7 @@ public class ChartTests extends AbstractMassifTest {
doLaunch(config, testName);
- ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
- IAction chartAction = getChartAction(view);
+ IAction chartAction = getChartAction();
assertNotNull(chartAction);
chartAction.run();
@@ -176,19 +168,8 @@ public class ChartTests extends AbstractMassifTest {
assertEquals(HeapChart.getByteUnits()[ix], chart.getXUnits());
}
- private IAction getChartAction(IViewPart view) {
- IAction result = null;
- IToolBarManager manager = view.getViewSite().getActionBars()
- .getToolBarManager();
- for (IContributionItem item : manager.getItems()) {
- if (item instanceof ActionContributionItem) {
- ActionContributionItem actionItem = (ActionContributionItem) item;
- if (actionItem.getAction().getId()
- .equals(MassifViewPart.CHART_ACTION)) {
- result = actionItem.getAction();
- }
- }
- }
- return result;
+ private IAction getChartAction() {
+ return getToolbarAction(MassifViewPart.CHART_ACTION);
}
+
}
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif/META-INF/MANIFEST.MF b/valgrind/org.eclipse.linuxtools.valgrind.massif/META-INF/MANIFEST.MF
index 0c96eddd51..1d320fc967 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif/META-INF/MANIFEST.MF
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif/META-INF/MANIFEST.MF
@@ -6,7 +6,8 @@ Bundle-Version: 1.1.0.qualifier
Bundle-Activator: org.eclipse.linuxtools.internal.valgrind.massif.MassifPlugin
Bundle-Vendor: %Bundle-Vendor.0
Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime
+ org.eclipse.core.runtime,
+ org.eclipse.linuxtools.dataviewers.charts
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/MassifViewPart.java b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/MassifViewPart.java
index 10379b3f34..79b92eb51a 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/MassifViewPart.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/MassifViewPart.java
@@ -14,12 +14,8 @@ import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -34,9 +30,9 @@ import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.linuxtools.dataviewers.charts.actions.SaveChartAction;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot.SnapshotType;
import org.eclipse.linuxtools.internal.valgrind.massif.charting.ChartEditorInput;
-import org.eclipse.linuxtools.internal.valgrind.massif.charting.ChartPNG;
import org.eclipse.linuxtools.internal.valgrind.massif.charting.HeapChart;
import org.eclipse.linuxtools.valgrind.ui.IValgrindToolView;
import org.eclipse.swt.SWT;
@@ -50,8 +46,6 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.IEditorInput;
@@ -99,6 +93,7 @@ public class MassifViewPart extends ViewPart implements IValgrindToolView {
private Action treeAction;
private MassifPidMenuAction pidAction;
+ private SaveChartAction saveChartAction;
private List<ChartEditorInput> chartInputs;
@@ -248,30 +243,8 @@ public class MassifViewPart extends ViewPart implements IValgrindToolView {
chartAction.setToolTipText(Messages
.getString("MassifViewPart.Display_Heap_Allocation")); //$NON-NLS-1$
- Action saveChartAction = new Action(Messages.getString("MassifViewPart.Save_Chart"), IAction.AS_PUSH_BUTTON) { //$NON-NLS-1$
- @Override
- public void run() {
- ChartEditorInput currentInput = getChartInput(pid);
- if (currentInput.getChart().getChartControl().isDisposed()) {
- IStatus status = new Status(IStatus.ERROR, MassifPlugin.PLUGIN_ID,
- Messages.getString("MassifViewPart.disposed_chart_reason")); //$NON-NLS-1$
- ErrorDialog.openError(Display.getDefault().getActiveShell(),
- Messages.getString("MassifViewPart.Error"), //$NON-NLS-1$
- Messages.getString("MassifViewPart.disposed_chart_title"), status); //$NON-NLS-1$
- return;
- }
-
- String path = getChartSavePath(currentInput.getName() + ".png"); //$NON-NLS-1$
- if (path != null) {
- ChartPNG renderer = new ChartPNG(currentInput.getChart());
- renderer.renderPNG(Path.fromOSString(path));
- }
- }
- };
+ saveChartAction = new SaveChartAction();
saveChartAction.setId(SAVE_CHART_ACTION);
- saveChartAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
- MassifPlugin.PLUGIN_ID, "icons/chart-save.png")); //$NON-NLS-1$
- saveChartAction.setToolTipText(Messages.getString("MassifViewPart.Save_Chart")); //$NON-NLS-1$
treeAction = new Action(
Messages.getString("MassifViewPart.Show_Heap_Tree"), IAction.AS_CHECK_BOX) { //$NON-NLS-1$
@@ -295,17 +268,6 @@ public class MassifViewPart extends ViewPart implements IValgrindToolView {
return new IAction[] { pidAction, chartAction, saveChartAction, treeAction };
}
- private String getChartSavePath(String defaultName) {
- Shell parent = new Shell(Display.getDefault());
- FileDialog dialog = new FileDialog(parent, SWT.SAVE);
- dialog.setText(Messages.getString("MassifViewPart.Save_chart_dialog_title")); //$NON-NLS-1$
- dialog.setOverwrite(true);
- dialog.setFilterExtensions(new String[] { ".png" }); //$NON-NLS-1$
- dialog.setFileName(defaultName);
-
- return dialog.open();
- }
-
private void createChart(MassifSnapshot[] snapshots) {
String title = chartName + " [PID: " + pid + "]"; //$NON-NLS-1$//$NON-NLS-2$
HeapChart chart = new HeapChart(snapshots, title);
@@ -331,6 +293,7 @@ public class MassifViewPart extends ViewPart implements IValgrindToolView {
}
}
});
+ saveChartAction.setChart(chartInput.getChart().getChartControl(), chartInput.getName());
}
private String getInputName(String description) {
@@ -353,6 +316,7 @@ public class MassifViewPart extends ViewPart implements IValgrindToolView {
@Override
public void refreshView() {
if (output != null && pid != null) {
+ saveChartAction.setChart(null);
MassifSnapshot[] snapshots = output.getSnapshots(pid);
pidAction.setPids(output.getPids());
if (snapshots != null) {
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/charting/ChartEditorInput.java b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/charting/ChartEditorInput.java
index 7dfa54a0ad..8b8700c941 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/charting/ChartEditorInput.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/charting/ChartEditorInput.java
@@ -19,7 +19,7 @@ import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.plugin.AbstractUIPlugin;
public class ChartEditorInput implements IEditorInput {
-
+
private HeapChart chart;
private MassifViewPart view;
private String name;
@@ -43,10 +43,10 @@ public class ChartEditorInput implements IEditorInput {
}
@Override
- public String getName() {
+ public String getName() {
return name;
}
-
+
public Integer getPid() {
return pid;
}
@@ -66,11 +66,11 @@ public class ChartEditorInput implements IEditorInput {
public Object getAdapter(Class adapter) {
return null;
}
-
+
public HeapChart getChart() {
return chart;
}
-
+
public MassifViewPart getView() {
return view;
}
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/charting/ChartPNG.java b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/charting/ChartPNG.java
deleted file mode 100644
index 9cd7d802e1..0000000000
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/charting/ChartPNG.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2004, 2005 Actuate 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:
- * Actuate Corporation - initial API and implementation
- * Elliott Baron <ebaron@redhat.com> - Modified implementation
- ***********************************************************************/
-package org.eclipse.linuxtools.internal.valgrind.massif.charting;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.swt.SWT;
-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.Composite;
-import org.eclipse.swt.widgets.Display;
-
-public class ChartPNG {
-
- private HeapChart cm = null;
-
- public ChartPNG(HeapChart chart) {
- cm = chart;
- }
-
- public void renderPNG(IPath pngPath) {
- Composite comp = cm.getChartControl();
- Display dsp = Display.getCurrent();
- GC gc = new GC(comp);
- Image img = new Image(dsp, comp.getSize().x + 1, comp.getSize().y + 1);
- gc.copyArea(img, 0, 0);
- gc.dispose();
- ImageLoader imageLoader = new ImageLoader();
- imageLoader.data = new ImageData[] {img.getImageData()};
- imageLoader.save(pngPath.toOSString(), SWT.IMAGE_PNG);
- }
-}
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/messages.properties b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/messages.properties
index b222091e3e..49e10e3136 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/messages.properties
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/messages.properties
@@ -30,9 +30,6 @@ MassifToolPage.profile_stack=Profile stack
MassifToolPage.Remove=Rem&ove
MassifToolPage.time_unit=Time unit:
MassifViewPart.Display_Heap_Allocation=Display Heap Allocation Graph
-MassifViewPart.disposed_chart_reason=The chart to be saved must be open.
-MassifViewPart.disposed_chart_title=Cannot save a disposed chart.
-MassifViewPart.Error=Error
MassifViewPart.Extra_Heap=Extra Heap (B)
MassifViewPart.Save_Chart=Save Chart As PNG
MassifViewPart.Save_chart_dialog_title=Save Chart

Back to the top