import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.core.expressions.EvaluationContext;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
import org.eclipse.jface.dialogs.MessageDialog;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.widgets.FileDialog;\r
import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.IWorkbenchPart;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
import org.jfree.chart.ChartUtilities;\r
import org.jfree.chart.JFreeChart;\r
+import org.simantics.sysdyn.ui.Activator;\r
\r
/**\r
* Exports the current chart in TrendView\r
\r
@Override\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
- EvaluationContext c = (EvaluationContext)event.getApplicationContext();\r
- Object o = c.getParent().getVariable("activePart");\r
- if(o != null && o instanceof TrendView) {\r
- TrendView trendView = (TrendView) o;\r
+ IWorkbenchPart part = HandlerUtil.getActivePart(event);\r
+ if (part instanceof TrendView) {\r
+ TrendView trendView = (TrendView) part;\r
int width = trendView.getPanel().getSize().width;\r
int height = trendView.getPanel().getSize().height;\r
int compressionLevel = 0;\r
\r
while(true) {\r
FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
- fd.setText("Export trend to PNG");\r
+ fd.setText("Export Trend to PNG");\r
String[] ext = {"*.png"};\r
fd.setFilterExtensions(ext);\r
String selected = fd.open();\r
try {\r
ChartUtilities.saveChartAsPNG(file, chart, width, height, null, true, compressionLevel);\r
} catch (IOException e) {\r
- e.printStackTrace();\r
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Save as PNG failed.", e));\r
}\r
return null;\r
}\r
package org.simantics.sysdyn.ui.trend;\r
\r
-//import java.awt.geom.Rectangle2D;\r
-//import java.io.File;\r
-//import java.io.FileNotFoundException;\r
-//import java.io.FileOutputStream;\r
-//import java.io.OutputStreamWriter;\r
-//import java.io.UnsupportedEncodingException;\r
-//import java.io.Writer;\r
-\r
import java.awt.geom.Rectangle2D;\r
import java.io.File;\r
import java.io.IOException;\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.core.expressions.EvaluationContext;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
import org.eclipse.jface.dialogs.MessageDialog;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.widgets.FileDialog;\r
import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.IWorkbenchPart;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
import org.simantics.jfreechart.chart.ChartUtils;\r
+import org.simantics.sysdyn.ui.Activator;\r
\r
public class TrendToSvg extends AbstractHandler {\r
\r
@Override\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
- EvaluationContext c = (EvaluationContext)event.getApplicationContext();\r
- Object o = c.getParent().getVariable("activePart");\r
- if(o != null && o instanceof TrendView) {\r
- TrendView trendView = (TrendView) o;\r
+ IWorkbenchPart part = HandlerUtil.getActivePart(event);\r
+ if (part instanceof TrendView) {\r
+ TrendView trendView = (TrendView) part;\r
\r
Shell shell = HandlerUtil.getActiveShellChecked(event);\r
\r
while(true) {\r
FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
- fd.setText("Export trend to SVG");\r
+ fd.setText("Export Trend to SVG");\r
String[] ext = {"*.svg"};\r
fd.setFilterExtensions(ext);\r
String selected = fd.open();\r
new Rectangle2D.Double(0, 0, trendView.getPanel().getWidth(), trendView.getPanel().getHeight()),\r
file);\r
} catch (IOException e) {\r
- e.printStackTrace();\r
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Save as SVG failed.", e));\r
} \r
- \r
+\r
return null;\r
}\r
}\r