Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug 370888 - API Access to export and print

*Moved print and save image functionality from action to feature
*Moved default features for print and save to graphiti.ui plugin
*Added abstract base features for print and save in graphiti bundle
*Extracted interfaces to enable clients to provide custom
implementations for configuring printing and saving
*Modified Graphiti default printing and saving implementations to
support the new configuration interfaces
*Moved functionality for save as image from internal Graphiti service to
save as image feature
*Adapted save as image UI test

Change-Id: Ifeed1b65d33a04e7ba0b5c031802c7348ee6de67
  • Loading branch information...
commit 2f256b6c7c4a0789703e05027c3244c571c60286 1 parent 60d61d5
@mwenz mwenz authored
Showing with 1,403 additions and 700 deletions.
  1. +16 −0 plugins/org.eclipse.graphiti.ui/.settings/.api_filters
  2. +2 −0  plugins/org.eclipse.graphiti.ui/META-INF/MANIFEST.MF
  3. +2 −2 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramBehavior.java
  4. +14 −1 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/features/DefaultFeatureProvider.java
  5. +166 −0 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/features/DefaultPrintFeature.java
  6. +427 −0 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/features/DefaultSaveImageFeature.java
  7. +46 −39 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/action/PrintGraphicalViewerAction.java
  8. +54 −19 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/action/SaveImageAction.java
  9. +2 −7 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/GraphitiUiInternal.java
  10. +0 −77 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/IUiService.java
  11. +0 −254 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/impl/UiService.java
  12. +0 −37 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/DefaultPreferences.java
  13. +7 −5 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/DoubleField.java
  14. +7 −5 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/DoubleFieldWithDropDown.java
  15. +4 −3 ...g.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/AbstractFigureSelectionDialog.java
  16. +5 −4 ...ins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/DefaultPrintPreferences.java
  17. +9 −2 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/ExportDiagramDialog.java
  18. +12 −5 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/PrintFigureDialog.java
  19. +9 −8 ...g.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/PrintFigureScaleableOperation.java
  20. +81 −0 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/print/IPrintConfiguration.java
  21. +74 −0 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/print/IPrintPreferences.java
  22. +101 −0 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/saveasimage/ISaveAsImageConfiguration.java
  23. +17 −42 plugins/org.eclipse.graphiti/.settings/.api_filters
  24. +2 −3 plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/IFeatureProvider.java
  25. +20 −6 plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/IPrintFeature.java
  26. +25 −10 plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/ISaveImageFeature.java
  27. +4 −7 plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/AbstractFeatureProvider.java
  28. +132 −0 plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/AbstractPrintFeature.java
  29. +130 −0 plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/AbstractSaveImageFeature.java
  30. +0 −70 plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/DefaultPrintFeature.java
  31. +0 −70 plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/DefaultSaveImageFeature.java
  32. +3 −0  plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/util/PredefinedColoredAreas.java
  33. +15 −11 tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/GFDialogTests.java
  34. +2 −11 tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/GFPackageTests.java
  35. +15 −2 tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/FeatureParametersTest.java
View
16 plugins/org.eclipse.graphiti.ui/.settings/.api_filters
@@ -400,6 +400,22 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/graphiti/ui/features/DefaultPrintFeature.java" type="org.eclipse.graphiti.ui.features.DefaultPrintFeature">
+ <filter id="574619656">
+ <message_arguments>
+ <message_argument value="IPrintFeature"/>
+ <message_argument value="DefaultPrintFeature"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/features/DefaultSaveImageFeature.java" type="org.eclipse.graphiti.ui.features.DefaultSaveImageFeature">
+ <filter id="574619656">
+ <message_arguments>
+ <message_argument value="ISaveImageFeature"/>
+ <message_argument value="DefaultSaveImageFeature"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/graphiti/ui/internal/command/EclipseProgress.java" type="org.eclipse.graphiti.ui.internal.command.EclipseProgress">
<filter id="574619656">
<message_arguments>
View
2  plugins/org.eclipse.graphiti.ui/META-INF/MANIFEST.MF
@@ -44,5 +44,7 @@ Export-Package: org.eclipse.graphiti.ui.editor;version="0.10.0",
org.eclipse.graphiti.ui.internal.util.ui.print;version="0.10.0";x-friends:="org.eclipse.graphiti.export.batik",
org.eclipse.graphiti.ui.internal.util.ui.sfx;version="0.10.0";x-internal:=true,
org.eclipse.graphiti.ui.platform;version="0.10.0",
+ org.eclipse.graphiti.ui.print;version="0.10.0",
+ org.eclipse.graphiti.ui.saveasimage;version="0.10.0",
org.eclipse.graphiti.ui.services;version="0.10.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
View
4 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramBehavior.java
@@ -526,7 +526,7 @@ protected void initializeGraphicalViewer() {
if (featureProvider != null) {
IPrintFeature pf = featureProvider.getPrintFeature();
if (pf != null && parentPart != null) {
- registerAction(new PrintGraphicalViewerAction(parentPart, pf));
+ registerAction(new PrintGraphicalViewerAction(this, getConfigurationProvider()));
}
}
@@ -1447,7 +1447,7 @@ protected void initActionRegistry(ZoomManager zoomManager) {
if (sf != null) {
ISaveImageContext context = new SaveImageContext();
- action = new SaveImageAction(sf, context, this);
+ action = new SaveImageAction(this, getConfigurationProvider());
actionRegistry.registerAction(action);
selectionActions.add(action.getId());
}
View
15 .../org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/features/DefaultFeatureProvider.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -9,6 +9,7 @@
*
* Contributors:
* SAP AG - initial API, implementation and documentation
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
@@ -27,9 +28,11 @@
import org.eclipse.graphiti.features.IMoveConnectionDecoratorFeature;
import org.eclipse.graphiti.features.IMoveShapeFeature;
import org.eclipse.graphiti.features.IPasteFeature;
+import org.eclipse.graphiti.features.IPrintFeature;
import org.eclipse.graphiti.features.IRemoveBendpointFeature;
import org.eclipse.graphiti.features.IRemoveFeature;
import org.eclipse.graphiti.features.IResizeShapeFeature;
+import org.eclipse.graphiti.features.ISaveImageFeature;
import org.eclipse.graphiti.features.IUpdateFeature;
import org.eclipse.graphiti.features.context.IAddBendpointContext;
import org.eclipse.graphiti.features.context.ICopyContext;
@@ -130,6 +133,16 @@ public IPasteFeature getPasteFeature(IPasteContext context) {
}
@Override
+ public IPrintFeature getPrintFeature() {
+ return new DefaultPrintFeature(this);
+ }
+
+ @Override
+ public ISaveImageFeature getSaveImageFeature() {
+ return new DefaultSaveImageFeature(this);
+ }
+
+ @Override
public IRemoveBendpointFeature getRemoveBendpointFeature(IRemoveBendpointContext context) {
IRemoveBendpointFeature ret = new DefaultRemoveBendpointFeature(this);
return ret;
View
166 ...ins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/features/DefaultPrintFeature.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2013 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ * mwenz - Bug 323155 - Check usage scenarios for DefaultPrintFeature and
+ * DefaultSaveImageFeature
+ * mwenz - Bug 370888 - API Access to export and print
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.ui.features;
+
+import org.eclipse.draw2d.PrintFigureOperation;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IPrintFeature;
+import org.eclipse.graphiti.features.context.IPrintContext;
+import org.eclipse.graphiti.features.impl.AbstractPrintFeature;
+import org.eclipse.graphiti.ui.editor.DiagramEditor;
+import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal;
+import org.eclipse.graphiti.ui.internal.util.ui.print.PrintFigureDialog;
+import org.eclipse.graphiti.ui.internal.util.ui.print.PrintFigureScaleableOperation;
+import org.eclipse.graphiti.ui.print.IPrintConfiguration;
+import org.eclipse.swt.printing.Printer;
+import org.eclipse.swt.printing.PrinterData;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * The default feature implementation for printing a diagram. This feature is
+ * used to trigger printing from inside an open and initialized
+ * {@link DiagramEditor}. It relies on an existing {@link GraphicalViewer}
+ * showing the diagram to print.
+ *
+ * @since 0.10 Has been moved from plug-in org.eclipse.graphiti package
+ * org.eclipse.graphiti.features
+ */
+public class DefaultPrintFeature extends AbstractPrintFeature implements IPrintFeature {
+
+ /**
+ * Creates a new {@link DefaultPrintFeature}.
+ *
+ * @param fp
+ * The feature provider providing this feature
+ */
+ public DefaultPrintFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ /**
+ * Performs the print operation. The default implementation delegates to
+ * {@link #getGraphicalViewer(IPrintContext)} to retrieve the
+ * {@link GraphicalViewer} that already displays the diagram, queries for
+ * {@link PrinterData} to use by calling
+ * {@link #getPrinterData(IPrintContext)} and finally uses
+ * {@link #getPrintOperation(Printer, IPrintConfiguration)} to create an
+ * operation to perform the printing. All those methods may be overridden to
+ * change the default behavior, so normally one would not need to override
+ * this method unless the complete sequence needs to changed or the printing
+ * is performed in a completely different scenario.
+ *
+ * @param context
+ * Context information for printing.
+ */
+ public void print(IPrintContext context) {
+
+ // Get viewer containing the diagram to print (by default the one
+ // contained in the diagram editor that starts this feature
+ GraphicalViewer viewer = getGraphicalViewer(context);
+
+ // Create PrinterData and Printer
+ PrinterData printerData = getPrinterData(context);
+ Printer printer = new Printer(printerData);
+
+ // Create the PrintFigureDialog and open it
+ IPrintConfiguration printConfiguration = getPrintConfiguration(viewer, printer);
+ if (printConfiguration.configure() == IPrintConfiguration.OK) {
+ // Create the print operation ...
+ PrintFigureOperation op = getPrintOperation(printConfiguration);
+ // ... and start the printing
+ op.run(getName());
+ printConfiguration.cleanUp();
+ }
+ }
+
+ /**
+ * Must return a {@link GraphicalViewer} that contains the diagram to be
+ * printed. The default implementation returns the viewer of the
+ * {@link DiagramEditor} that started this print feature; this is the one
+ * associated to the feature provider of the currently opened diagram, see
+ * {@link #getDiagramEditor()}.
+ *
+ * @param context
+ * Context information for printing.
+ * @return the viewer holding the diagram to print.
+ */
+ protected GraphicalViewer getGraphicalViewer(IPrintContext context) {
+ DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
+ return (GraphicalViewer) diagramEditor.getAdapter(GraphicalViewer.class);
+ }
+
+ /**
+ * Creates the {@link PrinterData} information used for this print feature.
+ * The default implementation simply gets the info for the default printer
+ * of the system or the first printer in the list of available printers in
+ * case no default is defined.
+ *
+ * @param context
+ * Context information for printing.
+ * @return The printer data to use for this print feature.
+ */
+ protected PrinterData getPrinterData(IPrintContext context) {
+ PrinterData printerData = Printer.getDefaultPrinterData();
+ if (printerData == null || (printerData.name == null && printerData.driver == null)) {
+ PrinterData[] printerDatas = Printer.getPrinterList();
+ if (printerDatas != null && printerDatas.length > 0) {
+ printerData = printerDatas[0];
+ }
+ }
+ return printerData;
+ }
+
+ /**
+ * Called to create a configuration object for the printing that defines
+ * what to print on which printer and how. The default implementation
+ * returns the standard Graphiti dialog used for printing that allows the
+ * user to define which printer to use, which figure to print and various
+ * other print settings.
+ *
+ * @param viewer
+ * The viewer displaying the diagram to print
+ * @param printer
+ * The printer to use as default
+ * @return A newly created dialog that implements the
+ * {@link IPrintConfiguration} interface used in the print job.
+ */
+ protected IPrintConfiguration getPrintConfiguration(GraphicalViewer viewer, Printer printer) {
+ Shell shell = GraphitiUiInternal.getWorkbenchService().getShell();
+ IPrintConfiguration printImageDialog = new PrintFigureDialog(shell, viewer, printer);
+ return printImageDialog;
+ }
+
+ /**
+ * Called to create the operation that is actually used for printing a
+ * diagram. The default implementation returns the Graphiti default print
+ * operation that should be sufficient for almost all use cases.
+ *
+ * @param printConfiguration
+ * The {@link IPrintConfiguration} instance that was used to
+ * configure this print operation. In the default implementation
+ * this is the dialog to use for selecting the printer and other
+ * settings.
+ * @return The operation that will be used to actually perform the printing.
+ */
+ protected PrintFigureOperation getPrintOperation(IPrintConfiguration printConfiguration) {
+ PrintFigureOperation op = new PrintFigureScaleableOperation(printConfiguration);
+ return op;
+ }
+}
View
427 ...org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/features/DefaultSaveImageFeature.java
@@ -0,0 +1,427 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2013 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ * mwenz - Bug 323155 - Check usage scenarios for DefaultPrintFeature and
+ * DefaultSaveImageFeature
+ * mwenz - Bug 370888 - API Access to export and print
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.ui.features;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.ISaveImageFeature;
+import org.eclipse.graphiti.features.context.IPrintContext;
+import org.eclipse.graphiti.features.context.ISaveImageContext;
+import org.eclipse.graphiti.features.impl.AbstractSaveImageFeature;
+import org.eclipse.graphiti.internal.util.T;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.ui.editor.DiagramEditor;
+import org.eclipse.graphiti.ui.internal.platform.ExtensionManager;
+import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal;
+import org.eclipse.graphiti.ui.internal.util.ui.print.ExportDiagramDialog;
+import org.eclipse.graphiti.ui.internal.util.ui.print.IDiagramsExporter;
+import org.eclipse.graphiti.ui.saveasimage.ISaveAsImageConfiguration;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.ImageLoader;
+import org.eclipse.swt.graphics.PaletteData;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * The default feature implementation for saving a diagram as an image. This
+ * feature is used to trigger saving from inside an open and initialized
+ * {@link DiagramEditor}. It relies on an existing {@link GraphicalViewer}
+ * showing the diagram to save.
+ *
+ * @since 0.10 Has been moved from plug-in org.eclipse.graphiti package
+ * org.eclipse.graphiti.features
+ */
+public class DefaultSaveImageFeature extends AbstractSaveImageFeature implements ISaveImageFeature {
+
+ /**
+ * Creates a new {@link DefaultSaveImageFeature}.
+ *
+ * @param fp
+ * The feature provider providing this feature
+ */
+ public DefaultSaveImageFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ /**
+ * Performs the save as image operation. The default implementation
+ * delegates to {@link #getGraphicalViewer(IPrintContext)} to retrieve the
+ * {@link GraphicalViewer} that already displays the diagram, queries for
+ * {@link ISaveAsImageConfiguration} to use by calling
+ * {@link #getSaveAsImageConfiguration(GraphicalViewer)}, queries for the
+ * filename by delegating to
+ * {@link #getFilename(GraphicalViewer, ISaveAsImageConfiguration)} and
+ * finally uses
+ * {@link #getSaveAsImageOperation(ISaveAsImageConfiguration, String)} to
+ * create an operation to perform the save as image operation. All those
+ * methods may be overridden to change the default behavior, so normally one
+ * would not need to override this method unless the complete sequence needs
+ * to changed or the save as image is performed in a completely different
+ * scenario.
+ *
+ * @param context
+ * Context information for saving as an image.
+ */
+ public void save(ISaveImageContext context) {
+
+ // Get viewer containing the diagram to print (by default the one
+ // contained in the diagram editor that starts this feature
+ GraphicalViewer viewer = getGraphicalViewer(context);
+
+ // Configure and open dialog
+ ISaveAsImageConfiguration saveAsImageConfiguration = getSaveAsImageConfiguration(viewer);
+ if (saveAsImageConfiguration.configure() == Window.OK) {
+
+ // Select filename with file-dialog
+ String filename = getFilename(viewer, saveAsImageConfiguration);
+ if (filename != null) {
+ Shell shell = GraphitiUiInternal.getWorkbenchService().getShell();
+ try {
+ // Add extension to filename (if none exists)
+ filename = addFileExtension(saveAsImageConfiguration.getFormattedFileExtension(), filename);
+
+ // Create the save as image operation ...
+ IRunnableWithProgress operation = getSaveAsImageOperation(saveAsImageConfiguration, filename);
+
+ // ... and start save as image
+ new ProgressMonitorDialog(shell).run(false, false, operation);
+ } catch (InterruptedException e) {
+ T.racer().warning("Save as image operation was cancelled by user"); //$NON-NLS-1$
+ } catch (Exception e) {
+ String message = "Cannot save image: "; //$NON-NLS-1$
+ MessageDialog.openError(shell, "Cannot save image", message + e.getMessage()); //$NON-NLS-1$
+ T.racer().error(message, e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Must return a {@link GraphicalViewer} that contains the diagram to be
+ * saved as an image. The default implementation returns the viewer of the
+ * {@link DiagramEditor} that started this save as image feature; this is
+ * the one associated to the feature provider of the currently opened
+ * diagram, see {@link #getDiagramEditor()}.
+ *
+ * @param context
+ * Context information for saving.
+ * @return the viewer holding the diagram to save.
+ */
+ protected GraphicalViewer getGraphicalViewer(ISaveImageContext context) {
+ DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
+ return (GraphicalViewer) diagramEditor.getAdapter(GraphicalViewer.class);
+ }
+
+ /**
+ * Called to create a configuration object for the save as image operation
+ * that defines what to save and in which format, zoom level etc.. The
+ * default implementation returns the standard Graphiti dialog used for save
+ * as image that allows the user to define the standard Graphiti settings.
+ *
+ * @param viewer
+ * The {@link GraphicalViewer} displaying the diagram to print
+ * @return A newly created dialog that implements the
+ * {@link ISaveAsImageConfiguration} interface used in the save as
+ * image job.
+ */
+ protected ISaveAsImageConfiguration getSaveAsImageConfiguration(GraphicalViewer viewer) {
+ Shell shell = GraphitiUiInternal.getWorkbenchService().getShell();
+ ISaveAsImageConfiguration saveAsImageDialog = new ExportDiagramDialog(shell, viewer);
+
+ // Add exporters
+ saveAsImageDialog.addExporters(getDiagramExporters());
+ return saveAsImageDialog;
+ }
+
+ /**
+ * Must return the filename under which the image will be saved. The
+ * filename can (and shall be) without an extension as this will be added by
+ * a separate (outside) call to {@link #addFileExtension(String, String)}.
+ * The default implementation brings up a standard Eclipse file selection
+ * dialog in save mode. The dialog is configured to select between the
+ * allowed extensions for images (standard one plus the ones the registered
+ * Graphiti image exporters allow).
+ *
+ * @param viewer
+ * The {@link GraphicalViewer} displaying the diagram to print
+ * @param saveAsImageDialog
+ * The save as image configurations as defined by
+ * {@link #getSaveAsImageConfiguration(GraphicalViewer)}.
+ * @return A string containg the absolute path of the selected file, or null
+ * if the dialog was cancelled or an error occurred.
+ */
+ protected String getFilename(GraphicalViewer viewer, ISaveAsImageConfiguration saveAsImageConfiguration) {
+ Shell shell = GraphitiUiInternal.getWorkbenchService().getShell();
+ FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
+ String fileExtensions[] = new String[] { "*." + saveAsImageConfiguration.getFormattedFileExtension() }; //$NON-NLS-1$
+ fileDialog.setFilterExtensions(fileExtensions);
+ String name = ((Diagram) viewer.getContents().getModel()).getName();
+ fileDialog.setFileName(name);
+ String filename = fileDialog.open();
+ return filename;
+ }
+
+ /**
+ * Adds the given file extension to the given filename.
+ *
+ * @param extension
+ * A string holding the extension.
+ * @param filename
+ * A string holding the filename.
+ * @return A string holding the filename plus the extension.
+ */
+ protected String addFileExtension(String extension, String filename) {
+ IPath path = new Path(filename);
+ if (path.getFileExtension() == null) {
+ filename = filename + "." + extension; //$NON-NLS-1$
+ }
+ return filename;
+ }
+
+ /**
+ * Called to create the operation that is actually used for executing the
+ * save as image functionality. The default implementation returns the
+ * Graphiti default save as image operation that should be sufficient for
+ * almost all use cases.
+ * <p>
+ * This method delegates to
+ * {@link #getSaveAsImageOperationForStandardExporter(ISaveAsImageConfiguration, String)}
+ * to perform the save as image for the standard formats like GIF, JPG, BMP
+ * etc. and to
+ * {@link #getSaveAsImageOperationForNonStandardExporter(ISaveAsImageConfiguration, String)}
+ * for the non standard exporters (registered via the Graphiti export image
+ * extension point) like SVG.
+ *
+ * @param saveAsImageConfiguration
+ * The {@link ISaveAsImageConfiguration} instance that was used
+ * to configure this save as image operation. In the default
+ * implementation this is the dialog to use for selecting the
+ * image format, zoom level etc.
+ * @param filename
+ * The filename to use for saving the image
+ * @return The operation that will be used to actually perform the save as
+ * image.
+ */
+ protected IRunnableWithProgress getSaveAsImageOperation(final ISaveAsImageConfiguration saveAsImageConfiguration,
+ final String filename) {
+ IRunnableWithProgress operation = null;
+
+ String imageExtension = saveAsImageConfiguration.getFileExtension();
+ if (getDiagramExporters().containsKey(imageExtension)) {
+ // If the exporter is non-standard, i.e. registered via
+ // extension point, we need to call the registered
+ // exporter
+ operation = getSaveAsImageOperationForNonStandardExporter(saveAsImageConfiguration, filename);
+ } else {
+ // Handle internal image format
+ operation = getSaveAsImageOperationForStandardExporter(saveAsImageConfiguration, filename);
+ }
+ return operation;
+ }
+
+ /**
+ * Called to create the operation that is actually used for executing the
+ * save as image functionality for standard formats. The default
+ * implementation returns the Graphiti default save as image operation that
+ * should be sufficient for almost all use cases.
+ *
+ * @param saveAsImageConfiguration
+ * The {@link ISaveAsImageConfiguration} instance that was used
+ * to configure this save as image operation. In the default
+ * implementation this is the dialog to use for selecting the
+ * image format, zoom level etc.
+ * @param filename
+ * The filename to use for saving the image
+ * @return The operation that will be used to actually perform the save as
+ * image.
+ */
+ protected IRunnableWithProgress getSaveAsImageOperationForNonStandardExporter(
+ final ISaveAsImageConfiguration saveAsImageConfiguration, final String filename) {
+
+ String imageExtension = saveAsImageConfiguration.getFileExtension();
+ final IDiagramsExporter exporter = ExtensionManager.getSingleton().getDiagramExporterForType(imageExtension);
+ Assert.isNotNull(exporter);
+ IRunnableWithProgress operation = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ try {
+ exporter.export(saveAsImageConfiguration.getScaledImage(), saveAsImageConfiguration.getFigure(),
+ filename, saveAsImageConfiguration.getImageScaleFactor());
+ } catch (Exception e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ };
+ return operation;
+ }
+
+ /**
+ * Called to create the operation that is actually used for executing the
+ * save as image functionality for non-standard formats. The default
+ * implementation returns the Graphiti default save as image operation that
+ * should be sufficient for almost all use cases.
+ *
+ * @param saveAsImageConfiguration
+ * The {@link ISaveAsImageConfiguration} instance that was used
+ * to configure this save as image operation. In the default
+ * implementation this is the dialog to use for selecting the
+ * image format, zoom level etc.
+ * @param filename
+ * The filename to use for saving the image
+ * @return The operation that will be used to actually perform the save as
+ * image.
+ */
+ protected IRunnableWithProgress getSaveAsImageOperationForStandardExporter(
+ final ISaveAsImageConfiguration saveAsImageConfiguration, final String filename) {
+
+ int imageFormat = saveAsImageConfiguration.getImageFormat();
+ final byte imageBytes[] = convertImageToBytes(saveAsImageConfiguration.getScaledImage(), imageFormat);
+ IRunnableWithProgress operation = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ FileOutputStream outputStream = null;
+ try {
+ outputStream = new FileOutputStream(filename);
+ outputStream.write(imageBytes);
+ } catch (Exception e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ try {
+ outputStream.close();
+ } catch (Exception x) {
+ T.racer().error("close output stream failed", x); //$NON-NLS-1$
+ }
+ }
+ }
+ };
+ return operation;
+ }
+
+ /**
+ * Returns all available Graphiti diagram exporters that are registered at
+ * the according Graphiti extension point. Note that the standard exporters
+ * like GIF, JPG, BMP are not part of the returned ones.
+ *
+ * @return A {@link Map} holding all exporters.
+ */
+ protected Map<String, Boolean> getDiagramExporters() {
+ Map<String, Boolean> diagramExporterTypes = ExtensionManager.getSingleton().getDiagramExporterTypes();
+ return diagramExporterTypes;
+ }
+
+ private byte[] convertImageToBytes(Image image, int format) {
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+
+ try {
+ ImageData imDat = null;
+ // Save as GIF is only working if not more than 256 colors are used
+ // in the image
+ if (format == SWT.IMAGE_GIF) {
+ imDat = create8BitIndexedPaletteImage(image);
+ }
+
+ if (imDat == null) {
+ imDat = image.getImageData();
+ }
+
+ ImageLoader imageLoader = new ImageLoader();
+ imageLoader.data = new ImageData[] { imDat };
+ try {
+ imageLoader.save(result, format);
+ } catch (SWTException e) {
+ String error = "Depth: " + Integer.toString(image.getImageData().depth) + "\n" + "X: " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + Integer.toString(image.getImageData().x)
+ + "\n" + "Y: " + Integer.toString(image.getImageData().y); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new IllegalStateException(error, e);
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ } finally {
+ image.dispose();
+ }
+
+ return result.toByteArray();
+ }
+
+ private ImageData create8BitIndexedPaletteImage(Image image) {
+ int upperboundWidth = image.getBounds().width;
+ int upperboundHeight = image.getBounds().height;
+ ImageData imageData = image.getImageData();
+
+ // determine number of used colors
+ ArrayList<Integer> colors = new ArrayList<Integer>();
+ for (int x = 0; x < upperboundWidth; x++) {
+ for (int y = 0; y < upperboundHeight; y++) {
+ int color = imageData.getPixel(x, y);
+ Integer colorInteger = new Integer(color);
+ if (!colors.contains(colorInteger))
+ colors.add(colorInteger);
+ }
+ }
+
+ // at the moment this is only working if not more than 256 colors are
+ // used in the image
+ if (colors.size() > 256) {
+ throw new IllegalStateException(
+ "Image contains more than 256 colors. \n Automated color reduction is currently not supported."); //$NON-NLS-1$
+ }
+
+ // create an indexed palette
+ RGB[] rgbs = new RGB[256];
+ for (int i = 0; i < 256; i++)
+ rgbs[i] = new RGB(255, 255, 255);
+ for (int i = 0; i < colors.size(); i++) {
+ int pixelValue = ((colors.get(i))).intValue();
+ int red = (pixelValue & imageData.palette.redMask) >>> Math.abs(imageData.palette.redShift);
+ int green = (pixelValue & imageData.palette.greenMask) >>> Math.abs(imageData.palette.greenShift);
+ int blue = (pixelValue & imageData.palette.blueMask) >>> Math.abs(imageData.palette.blueShift);
+ rgbs[i] = new RGB(red, green, blue);
+ }
+
+ // create new imageData
+ PaletteData palette = new PaletteData(rgbs);
+ ImageData newImageData = new ImageData(imageData.width, imageData.height, 8, palette);
+
+ // adjust imageData with regard to the palette
+ for (int x = 0; x < upperboundWidth; x++) {
+ for (int y = 0; y < upperboundHeight; y++) {
+ int color = imageData.getPixel(x, y);
+ newImageData.setPixel(x, y, colors.indexOf(new Integer(color)));
+ }
+ }
+
+ return newImageData;
+ }
+}
View
85 ...e.graphiti.ui/src/org/eclipse/graphiti/ui/internal/action/PrintGraphicalViewerAction.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2012 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -10,6 +10,7 @@
* Contributors:
* SAP AG - initial API, implementation and documentation
* mwenz - Bug 371527 - Recursive attempt to activate part while in the middle of activating part
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
@@ -17,20 +18,21 @@
package org.eclipse.graphiti.ui.internal.action;
import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.ui.actions.PrintAction;
+import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.IPrintFeature;
import org.eclipse.graphiti.features.context.IPrintContext;
import org.eclipse.graphiti.features.context.impl.PrintContext;
-import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal;
-import org.eclipse.graphiti.ui.internal.util.ui.print.PrintFigureDialog;
-import org.eclipse.graphiti.ui.internal.util.ui.print.PrintFigureScaleableOperation;
+import org.eclipse.graphiti.internal.command.FeatureCommandWithContext;
+import org.eclipse.graphiti.internal.command.GenericFeatureCommandWithContext;
+import org.eclipse.graphiti.internal.command.ICommand;
+import org.eclipse.graphiti.platform.IDiagramBehavior;
+import org.eclipse.graphiti.ui.editor.DiagramEditor;
+import org.eclipse.graphiti.ui.internal.command.GefCommandWrapper;
+import org.eclipse.graphiti.ui.platform.IConfigurationProvider;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.printing.Printer;
-import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
@@ -53,7 +55,7 @@
private static IAction TEMPLATE_ACTION = ActionFactory.PRINT.create(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow());
- private IPrintFeature printFeature;
+ private IConfigurationProvider configurationProvider;
// last time when we checked whether a printer is available with
// super.calculateEnabled()
@@ -72,10 +74,9 @@
* belongs. From the WorkbenchPart the GraphicalViewer will be
* determined.
*/
- public PrintGraphicalViewerAction(IWorkbenchPart part,
- IPrintFeature printFeature) {
- super(part);
- this.printFeature = printFeature;
+ public PrintGraphicalViewerAction(IDiagramBehavior diagramBehavior, IConfigurationProvider configurationProvider) {
+ super(((DiagramEditor) diagramBehavior.getDiagramContainer()).getWorkbenchPart());
+ this.configurationProvider = configurationProvider;
// set all values of the TEMPLATE_ACTION for this Action.
setId(TEMPLATE_ACTION.getId());
@@ -95,8 +96,19 @@ public PrintGraphicalViewerAction(IWorkbenchPart part,
*/
@Override
protected boolean calculateEnabled() {
- if (getWorkbenchPart().getAdapter(GraphicalViewer.class) == null)
+ IFeatureProvider featureProvider = getFeatureProvider();
+ if (featureProvider == null) {
return false;
+ }
+ IPrintFeature feature = featureProvider.getPrintFeature();
+ IPrintContext context = createPrintContext();
+ if (feature == null || !feature.canPrint(context)) {
+ return false;
+ }
+
+ if (getWorkbenchPart().getAdapter(GraphicalViewer.class) == null) {
+ return false;
+ }
long currentTime = System.currentTimeMillis();
long diffTime = (currentTime - lastPrinterCheckTime) / 1000;
@@ -126,7 +138,6 @@ public void run() {
});
}
return cachedEnabled;
- // TODO ask also feature for canPrint() ?
}
/**
@@ -137,32 +148,28 @@ public void run() {
*/
@Override
public void run() {
- IPrintContext printContext = new PrintContext();
- printFeature.prePrint(printContext);
-
- Shell shell = GraphitiUiInternal.getWorkbenchService().getShell();
-
- // get viewer
- GraphicalViewer viewer = (GraphicalViewer) getWorkbenchPart().getAdapter(GraphicalViewer.class);
-
- // create default PrinterData
- PrinterData printerData = Printer.getDefaultPrinterData();
- if (printerData == null || (printerData.name == null && printerData.driver == null)) {
- printerData = Printer.getPrinterList()[0];
+ IPrintContext context = createPrintContext();
+ final IFeatureProvider featureProvider = getFeatureProvider();
+ IPrintFeature feature = featureProvider.getPrintFeature();
+ if (feature != null) {
+ final FeatureCommandWithContext command = new GenericFeatureCommandWithContext(feature, context);
+ executeOnCommandStack(command);
}
+ }
- // open PrintFigureDialog
- PrintFigureDialog printImageDialog = new PrintFigureDialog(shell, viewer, new Printer(printerData));
- printImageDialog.open();
- if (printImageDialog.getReturnCode() != Window.CANCEL) {
+ private IPrintContext createPrintContext() {
+ PrintContext context = new PrintContext();
+ return context;
+ }
- // start the printing
- PrintFigureScaleableOperation op = new PrintFigureScaleableOperation(printImageDialog.getPrinter(),
- printImageDialog.getFigure(), printImageDialog.getScaledImage(), printImageDialog.getPreferences());
- op.run(getWorkbenchPart().getTitle());
- printImageDialog.cleanUp();
- }
+ private IFeatureProvider getFeatureProvider() {
+ return configurationProvider.getDiagramTypeProvider().getFeatureProvider();
+ }
- printFeature.postPrint(printContext);
+ private void executeOnCommandStack(ICommand command) {
+ CommandStack commandStack = configurationProvider.getDiagramEditor().getEditDomain().getCommandStack();
+ GefCommandWrapper wrapperCommand = new GefCommandWrapper(command, configurationProvider.getDiagramBehavior()
+ .getEditingDomain());
+ commandStack.execute(wrapperCommand);
}
}
View
73 .../org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/action/SaveImageAction.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -12,18 +12,27 @@
* jpasch - Bug 323025 ActionBarContributor cleanup
* Bug 336488 - DiagramEditor API
* pjpaulin - Bug 352120 - Now uses IDiagramContainerUI interface
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
*******************************************************************************/
package org.eclipse.graphiti.ui.internal.action;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.ISaveImageFeature;
import org.eclipse.graphiti.features.context.ISaveImageContext;
-import org.eclipse.graphiti.ui.editor.DiagramBehavior;
+import org.eclipse.graphiti.features.context.impl.SaveImageContext;
+import org.eclipse.graphiti.internal.command.FeatureCommandWithContext;
+import org.eclipse.graphiti.internal.command.GenericFeatureCommandWithContext;
+import org.eclipse.graphiti.internal.command.ICommand;
+import org.eclipse.graphiti.platform.IDiagramBehavior;
import org.eclipse.graphiti.ui.internal.Messages;
-import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal;
+import org.eclipse.graphiti.ui.internal.command.GefCommandWrapper;
+import org.eclipse.graphiti.ui.platform.IConfigurationProvider;
import org.eclipse.jface.action.Action;
/**
@@ -32,11 +41,8 @@
*/
public class SaveImageAction extends Action {
- private ISaveImageFeature saveImageFeature;
-
- private ISaveImageContext context;
-
- private DiagramBehavior diagramBehavior;
+ private IDiagramBehavior diagramBehavior;
+ private IConfigurationProvider configurationProvider;
public static final String TOOL_TIP = Messages.SaveImageAction_1_xmsg;
@@ -46,12 +52,11 @@
public static final String ACTION_DEFINITION_ID = "org.eclipse.graphiti.ui.internal.action.SaveImageAction"; //$NON-NLS-1$
- public SaveImageAction(ISaveImageFeature saveImageFeature, ISaveImageContext context,
- DiagramBehavior diagramBehavior) {
+ public SaveImageAction(IDiagramBehavior diagramBehavior, IConfigurationProvider configurationProvider) {
super();
- this.saveImageFeature = saveImageFeature;
- this.context = context;
this.diagramBehavior = diagramBehavior;
+ this.configurationProvider = configurationProvider;
+
setText(TEXT);
setToolTipText(TOOL_TIP);
setId(ACTION_ID);
@@ -60,17 +65,47 @@ public SaveImageAction(ISaveImageFeature saveImageFeature, ISaveImageContext con
@Override
public boolean isEnabled() {
- return saveImageFeature.canSave(context);
+ IFeatureProvider featureProvider = getFeatureProvider();
+ if (featureProvider == null) {
+ return false;
+ }
+ ISaveImageFeature feature = featureProvider.getSaveImageFeature();
+ ISaveImageContext context = createSaveImageContext();
+ if (feature == null || !feature.canSave(context)) {
+ return false;
+ }
+
+ if (((IAdaptable) diagramBehavior.getDiagramContainer()).getAdapter(GraphicalViewer.class) == null) {
+ return false;
+ }
+
+ return true;
}
@Override
public void run() {
- saveImageFeature.preSave(context);
+ ISaveImageContext context = createSaveImageContext();
+ IFeatureProvider featureProvider = getFeatureProvider();
+ ISaveImageFeature feature = featureProvider.getSaveImageFeature();
+ if (feature != null) {
+ FeatureCommandWithContext command = new GenericFeatureCommandWithContext(feature, context);
+ executeOnCommandStack(command);
+ }
+ }
+
+ private ISaveImageContext createSaveImageContext() {
+ SaveImageContext context = new SaveImageContext();
+ return context;
+ }
- // get viewer and start save-image-dialog
- GraphicalViewer viewer = (GraphicalViewer) diagramBehavior.getDiagramContainer().getGraphicalViewer();
- GraphitiUiInternal.getUiService().startSaveAsImageDialog(viewer);
+ private IFeatureProvider getFeatureProvider() {
+ return configurationProvider.getDiagramTypeProvider().getFeatureProvider();
+ }
- saveImageFeature.postSave(context);
+ private void executeOnCommandStack(ICommand command) {
+ CommandStack commandStack = configurationProvider.getDiagramBehavior().getEditDomain().getCommandStack();
+ GefCommandWrapper wrapperCommand = new GefCommandWrapper(command, configurationProvider.getDiagramBehavior()
+ .getEditingDomain());
+ commandStack.execute(wrapperCommand);
}
-}
+}
View
9 ...eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/GraphitiUiInternal.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2011 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -10,6 +10,7 @@
* Contributors:
* SAP AG - initial API, implementation and documentation
* mwenz - Bug 324859 - Need Undo/Redo support for Non-EMF based domain objects
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
@@ -20,7 +21,6 @@
import org.eclipse.graphiti.ui.internal.services.impl.EmfService;
import org.eclipse.graphiti.ui.internal.services.impl.GefService;
import org.eclipse.graphiti.ui.internal.services.impl.TraceService;
-import org.eclipse.graphiti.ui.internal.services.impl.UiService;
import org.eclipse.graphiti.ui.internal.services.impl.WorkbenchService;
/**
@@ -30,7 +30,6 @@
public class GraphitiUiInternal {
final private static IEmfService emfService = new EmfService();
- final private static IUiService uiService = new UiService();
final private static ITraceService traceService = new TraceService();
final private static IGefService gefService = new GefService();
final private static IWorkbenchService workbenchService = new WorkbenchService();
@@ -40,10 +39,6 @@ public static IEmfService getEmfService() {
return emfService;
}
- public static IUiService getUiService() {
- return uiService;
- }
-
public static ITraceService getTraceService() {
return traceService;
}
View
77 ...ins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/IUiService.java
@@ -1,77 +0,0 @@
-/*******************************************************************************
- * <copyright>
- *
- * Copyright (c) 2005, 2010 SAP AG.
- * 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:
- * SAP AG - initial API, implementation and documentation
- *
- * </copyright>
- *
- *******************************************************************************/
-package org.eclipse.graphiti.ui.internal.services;
-
-import org.eclipse.gef.GraphicalViewer;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-
-/**
- * @noimplement This interface is not intended to be implemented by clients.
- * @noextend This class is not intended to be subclassed by clients.
- */
-public interface IUiService {
-
- /**
- * Returns the bytes of an encoded image for the specified IFigure in the
- * specified format.
- *
- * @param image
- * The Figure to create an image for.
- * @param format
- * One of SWT.IMAGE_BMP, SWT.IMAGE_BMP_RLE, SWT.IMAGE_GIF
- * SWT.IMAGE_ICO, SWT.IMAGE_JPEG, or SWT.IMAGE_PNG
- * @param scaleFactor
- * The scale factor, which is applied to the created the image.
- *
- * @return The bytes of an encoded image for the specified Figure
- * @throws Exception
- * if GIF is th format and the image contains more than 256
- * colors
- */
- public abstract byte[] createImage(Image image, int format) throws Exception;
-
- /**
- * Creates an image with 8 bit color depth and an indexed palette from the
- * given image. This is the format required for GIF images.
- *
- * @param image
- * The image, from which to create the new image.
- *
- * @return The new image with 8 bit color depth and an indexed palette.
- *
- * @throws Exception
- * If the image has more than 256 colors (not supported yet).
- */
- public abstract ImageData create8BitIndexedPaletteImage(Image image) throws Exception;
-
- /**
- * Start the procedure to save the given GraphicalViewer as an image:
- * <ul>
- * <li>opens a dialog to select the figure, image-format and the
- * scale-factor</li>
- * <li>opens a dialog to select the filename</li>
- * <li>saves the image to the file</li>
- * </ul>
- *
- * @param graphicalViewer
- * The GraphicalViewer, which to save as an image.
- */
- public abstract void startSaveAsImageDialog(GraphicalViewer graphicalViewer);
-
-
-
-}
View
254 ...org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/impl/UiService.java
@@ -1,254 +0,0 @@
-/*******************************************************************************
- * <copyright>
- *
- * Copyright (c) 2005, 2010 SAP AG.
- * 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:
- * SAP AG - initial API, implementation and documentation
- *
- * </copyright>
- *
- *******************************************************************************/
-package org.eclipse.graphiti.ui.internal.services.impl;
-
-import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
-import java.util.ArrayList;
-import java.util.Map;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.gef.GraphicalViewer;
-import org.eclipse.graphiti.internal.util.T;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.ui.internal.platform.ExtensionManager;
-import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal;
-import org.eclipse.graphiti.ui.internal.services.IUiService;
-import org.eclipse.graphiti.ui.internal.util.ui.print.ExportDiagramDialog;
-import org.eclipse.graphiti.ui.internal.util.ui.print.IDiagramsExporter;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.ImageLoader;
-import org.eclipse.swt.graphics.PaletteData;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * A collection of static helper methods regarding Draw2d.
- *
- * @noinstantiate This class is not intended to be instantiated by clients.
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class UiService implements IUiService {
-
- public byte[] createImage(Image image, int format) throws Exception {
- ByteArrayOutputStream result = new ByteArrayOutputStream();
-
- try {
- ImageData imDat = null;
- // at the moment saving as GIF is only working if not more than 256
- // colors are used in the figure
- if (format == SWT.IMAGE_GIF) {
- imDat = create8BitIndexedPaletteImage(image);
- }
-
- if (imDat == null)
- imDat = image.getImageData();
-
- ImageLoader imageLoader = new ImageLoader();
- imageLoader.data = new ImageData[] { imDat };
- try {
- imageLoader.save(result, format);
- } catch (SWTException e) {
- String error = "Depth: " + Integer.toString(image.getImageData().depth) + "\n" + "X: " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + Integer.toString(image.getImageData().x)
- + "\n" + "Y: " + Integer.toString(image.getImageData().y); //$NON-NLS-1$ //$NON-NLS-2$
- throw new IllegalStateException(error, e);
- }
-
- } finally {
- image.dispose();
- }
-
- return result.toByteArray();
- }
-
- public ImageData create8BitIndexedPaletteImage(Image image) throws Exception {
- int upperboundWidth = image.getBounds().width;
- int upperboundHeight = image.getBounds().height;
- ImageData imageData = image.getImageData();
-
- // determine number of used colors
- ArrayList<Integer> colors = new ArrayList<Integer>();
- for (int x = 0; x < upperboundWidth; x++) {
- for (int y = 0; y < upperboundHeight; y++) {
- int color = imageData.getPixel(x, y);
- Integer colorInteger = new Integer(color);
- if (!colors.contains(colorInteger))
- colors.add(colorInteger);
- }
- }
-
- // at the moment this is only working if not more than 256 colors are
- // used in the image
- if (colors.size() > 256)
- throw new Exception(
- "Image contains more than 256 colors. \n Automated color reduction is currently not supported."); //$NON-NLS-1$
-
- // create an indexed palette
- RGB[] rgbs = new RGB[256];
- for (int i = 0; i < 256; i++)
- rgbs[i] = new RGB(255, 255, 255);
- for (int i = 0; i < colors.size(); i++) {
- int pixelValue = ((colors.get(i))).intValue();
- int red = (pixelValue & imageData.palette.redMask) >>> Math.abs(imageData.palette.redShift);
- int green = (pixelValue & imageData.palette.greenMask) >>> Math.abs(imageData.palette.greenShift);
- int blue = (pixelValue & imageData.palette.blueMask) >>> Math.abs(imageData.palette.blueShift);
- rgbs[i] = new RGB(red, green, blue);
- }
-
- // create new imageData
- PaletteData palette = new PaletteData(rgbs);
- ImageData newImageData = new ImageData(imageData.width, imageData.height, 8, palette);
-
- // adjust imageData with regard to the palette
- for (int x = 0; x < upperboundWidth; x++) {
- for (int y = 0; y < upperboundHeight; y++) {
- int color = imageData.getPixel(x, y);
- newImageData.setPixel(x, y, colors.indexOf(new Integer(color)));
- }
- }
-
- return newImageData;
- }
-
- public void startSaveAsImageDialog(GraphicalViewer graphicalViewer) {
- final String METHOD = "startSaveAsImageDialog(graphicalViewer)"; //$NON-NLS-1$
-
- // check extension point for exporters
- Map<String, Boolean> diagramExporterTypes = ExtensionManager.getSingleton().getDiagramExporterTypes();
-
- // configure dialog with exporters and open dialog
- final Shell shell = GraphitiUiInternal.getWorkbenchService().getShell();
- final ExportDiagramDialog saveAsImageDialog = new ExportDiagramDialog(shell, graphicalViewer);
- saveAsImageDialog.addExporters(diagramExporterTypes);
- saveAsImageDialog.open();
- if (saveAsImageDialog.getReturnCode() == Window.CANCEL)
- return;
-
- // select filename with file-dialog
- FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
- String fileExtensions[] = new String[] { "*." + saveAsImageDialog.getFormattedFileExtension() }; //$NON-NLS-1$
- fileDialog.setFilterExtensions(fileExtensions);
- String name = ((Diagram) graphicalViewer.getContents().getModel()).getName();
- fileDialog.setFileName(name);
- String filename = fileDialog.open();
- if (filename != null) {
- try {
- // add extension to filename (if none exists)
- IPath path = new Path(filename);
- if (path.getFileExtension() == null)
- filename = filename + "." + saveAsImageDialog.getFormattedFileExtension(); //$NON-NLS-1$
-
- final String file = filename;
- final Image im = saveAsImageDialog.getScaledImage();
- String imageExtension = saveAsImageDialog.getFileExtension();
- IRunnableWithProgress operation;
- // if the exporter is non-standard, i.e. registered via
- // extension point, we need to call the registered exporter.
- if (diagramExporterTypes.containsKey(imageExtension)) {
- final IDiagramsExporter exporter = ExtensionManager.getSingleton().getDiagramExporterForType(
- imageExtension);
- Assert.isNotNull(exporter);
- operation = getExportOp(METHOD, shell, saveAsImageDialog, file, im, exporter);
- new ProgressMonitorDialog(shell).run(false, false, operation);
-
- } else {
- int imageFormat = saveAsImageDialog.getImageFormat();
- byte image[] = createImage(im, imageFormat);
- operation = getSaveToFileOp(shell, file, image);
- }
- new ProgressMonitorDialog(shell).run(false, false, operation);
- } catch (Exception e) {
- String message = "Cannot save image: "; //$NON-NLS-1$
- MessageDialog.openError(shell, "Cannot save image", message + e.getMessage()); //$NON-NLS-1$
- T.racer()
- .error(METHOD, message + "\nDetails: " + GraphitiUiInternal.getTraceService().getStacktrace(e)); //$NON-NLS-1$
- e.printStackTrace();
- }
- }
- }
-
- private IRunnableWithProgress getExportOp(final String METHOD, final Shell shell,
- final ExportDiagramDialog saveAsImageDialog, final String file, final Image im,
- final IDiagramsExporter exporter) {
- IRunnableWithProgress operation;
- operation = new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) {
- try {
- exporter.export(im, saveAsImageDialog.getFigure(), file, saveAsImageDialog.getImageScaleFactor());
- } catch (Exception e) {
- handleException(shell, e);
- }
- }
-
- };
- return operation;
- }
-
- private void handleException(final Shell shell, Exception e) {
- String message = "Can not export diagram: "; //$NON-NLS-1$
- MessageDialog.openError(shell, "Can not export diagram", message + e.getMessage()); //$NON-NLS-1$
- e.printStackTrace();
- }
-
- /**
- * Returns an IRunnableWithProgress, which saves the given contents to a
- * File with the given filename.
- *
- * @param shell
- *
- * @param filename
- * The name of the file, where to save the contents.
- * @param contents
- * The contents to save into the file.
- * @throws Exception
- * On any errors that occur.
- */
- private IRunnableWithProgress getSaveToFileOp(final Shell shell, final String filename, final byte contents[])
- throws Exception {
- IRunnableWithProgress operation = new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) {
- FileOutputStream outputStream = null;
- try {
- outputStream = new FileOutputStream(filename);
- outputStream.write(contents);
- } catch (Exception e) {
- handleException(shell, e);
- } finally {
- try {
- outputStream.close();
- } catch (Exception x) {
- T.racer().error("close output stream failed", x); //$NON-NLS-1$
- }
- }
- }
- };
-
- return operation;
- }
-
-}
View
37 ....eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/DefaultPreferences.java
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * <copyright>
- *
- * Copyright (c) 2005, 2010 SAP AG.
- * 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:
- * SAP AG - initial API, implementation and documentation
- *
- * </copyright>
- *
- *******************************************************************************/
-package org.eclipse.graphiti.ui.internal.util.ui;
-
-/**
- * A generic interface for preference containers (e.g. print, saveas, ...),
- * which serves as abstraction for generic edit fields which store their values
- * in a preference object
- *
- * @noinstantiate This class is not intended to be instantiated by clients.
- * @noextend This class is not intended to be subclassed by clients.
- */
-public interface DefaultPreferences {
-
- public void setDefaults();
-
- public void setIntPreference(int atIndex, int value);
-
- public void setDoublePreference(int atIndex, double value);
-
- public int getIntPreference(int atIndex);
-
- public double getDoublePreference(int atIndex);
-}
View
12 ...ins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/DoubleField.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -10,12 +10,14 @@
* Contributors:
* SAP AG - initial API, implementation and documentation
* mwenz - Bug 323359 Avoid usage of java.lang.text, ICU4J etc.
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
*******************************************************************************/
package org.eclipse.graphiti.ui.internal.util.ui;
+import org.eclipse.graphiti.ui.print.IPrintPreferences;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
@@ -28,7 +30,7 @@
/**
* A Text control allowing only non-negative decimal input. Writes its state to
- * a DefaultPreferences object passed in the constructor.
+ * a IPrintPreferences object passed in the constructor.
*
* @noinstantiate This class is not intended to be instantiated by clients.
* @noextend This class is not intended to be subclassed by clients.
@@ -37,7 +39,7 @@
public static final String decimalNumberFormat = "###0.00"; //$NON-NLS-1$
- private DefaultPreferences _preferences;
+ private IPrintPreferences _preferences;
private int _index;
Text _text;
private boolean _internalModify = false;
@@ -46,7 +48,7 @@
/**
* Creates a new DoubleField.
*/
- public DoubleField(Composite parent, int style, DefaultPreferences prefs, int index) {
+ public DoubleField(Composite parent, int style, IPrintPreferences prefs, int index) {
super(parent, style);
_preferences = prefs;
_index = index;
@@ -81,7 +83,7 @@ public void setEnabled(boolean en) {
}
/**
- * Updates control according to value in the DefaultPreferences. If it is
+ * Updates control according to value in the IPrintPreferences. If it is
* the first update with an empty textfield, the preference value is set. If
* it is not the first time an empty text field occurs, nothing happens
* avoiding the confusing behaviour of updating to 0.00 when the user
View
12 ...pse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/DoubleFieldWithDropDown.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -10,6 +10,7 @@
* Contributors:
* SAP AG - initial API, implementation and documentation
* mwenz - Bug 323359 Avoid usage of java.lang.text, ICU4J etc.
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
@@ -17,6 +18,7 @@
package org.eclipse.graphiti.ui.internal.util.ui;
import org.eclipse.graphiti.ui.internal.Messages;
+import org.eclipse.graphiti.ui.print.IPrintPreferences;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
@@ -29,7 +31,7 @@
/**
* A Combo control allowing only non-negative decimal input. Writes its state to
- * a DefaultPreferences object passed in the constructor.
+ * a IPrintPreferences object passed in the constructor.
*
* @noinstantiate This class is not intended to be instantiated by clients.
* @noextend This class is not intended to be subclassed by clients.
@@ -38,7 +40,7 @@
public static final String decimalNumberFormat = "###0.00"; //$NON-NLS-1$
- private DefaultPreferences _preferences;
+ private IPrintPreferences _preferences;
private int _index;
private Combo _text;
private boolean _internalModify = false;
@@ -47,7 +49,7 @@
/**
* Creates a new DoubleFieldWithDropDown.
*/
- public DoubleFieldWithDropDown(Composite parent, int style, DefaultPreferences prefs, int index, double[] defaults) {
+ public DoubleFieldWithDropDown(Composite parent, int style, IPrintPreferences prefs, int index, double[] defaults) {
super(parent, style);
_preferences = prefs;
_index = index;
@@ -74,7 +76,7 @@ public void setEnabled(boolean en) {
}
/**
- * Updates control according to value in the DefaultPreferences. If it is
+ * Updates control according to value in the IPrintPreferences. If it is
* the first update with an empty textfield, the preference value is set. If
* it is not the first time an empty text field occurs, nothing happens
* avoiding the confusing behaviour of updating to 0.00 when the user
View
7 ....ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/AbstractFigureSelectionDialog.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2012 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -11,6 +11,7 @@
* SAP AG - initial API, implementation and documentation
* mwenz - Bug 323034 - Aligned vertical gaps between groups
* mgorning - Bug 352874 - Exports of Diagrams > 3000x3000 px
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
@@ -33,7 +34,7 @@
import org.eclipse.graphiti.ui.internal.editor.GFFigureCanvas;
import org.eclipse.graphiti.ui.internal.fixed.FixedScaledGraphics;
import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal;
-import org.eclipse.graphiti.ui.internal.util.ui.DefaultPreferences;
+import org.eclipse.graphiti.ui.print.IPrintPreferences;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
@@ -107,7 +108,7 @@
*/
private Image _scaledImage;
- protected DefaultPreferences _preferences;
+ protected IPrintPreferences _preferences;
private GraphicalEditPart _selectedEditPart;
View
9 ...aphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/DefaultPrintPreferences.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -9,13 +9,14 @@
*
* Contributors:
* SAP AG - initial API, implementation and documentation
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
*******************************************************************************/
package org.eclipse.graphiti.ui.internal.util.ui.print;
-import org.eclipse.graphiti.ui.internal.util.ui.DefaultPreferences;
+import org.eclipse.graphiti.ui.print.IPrintPreferences;
/**
* This class is a simple container for the preferences for the print dialog.
@@ -23,7 +24,7 @@
* @noinstantiate This class is not intended to be instantiated by clients.
* @noextend This class is not intended to be subclassed by clients.
*/
-public class DefaultPrintPreferences implements DefaultPreferences {
+public class DefaultPrintPreferences implements IPrintPreferences {
// double preferences
public static final int SCALE_FACTOR_X = 0;
@@ -78,7 +79,7 @@ public DefaultPrintPreferences() {
setDefaults();
}
- // =================== interface DefaultPreferences =======================
+ // =================== interface IPrintPreferences =======================
public void setDefaults() {
for (int i = 0; i < NUM_OF_INT_PREFERENCES; i++)
View
11 ...e.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/ExportDiagramDialog.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2012 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -12,6 +12,7 @@
* jpasch - Bug 345315 Missing units for "Choose scale-factor
* mgorning - Bug 352874 - Exports of Diagrams > 3000x3000 px
* mwenz - Bug 375037 - ArrayIndexOutOfBoundsException when exporting diagram to SVG
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
@@ -27,6 +28,7 @@
import org.eclipse.graphiti.internal.util.T;
import org.eclipse.graphiti.ui.internal.Messages;
import org.eclipse.graphiti.ui.internal.util.ui.DoubleFieldWithDropDown;
+import org.eclipse.graphiti.ui.saveasimage.ISaveAsImageConfiguration;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
@@ -46,7 +48,8 @@
* @noinstantiate This class is not intended to be instantiated by clients.
* @noextend This class is not intended to be subclassed by clients.
*/
-public class ExportDiagramDialog extends AbstractFigureSelectionDialog implements ModifyListener {
+public class ExportDiagramDialog extends AbstractFigureSelectionDialog implements ModifyListener,
+ ISaveAsImageConfiguration {
private String[] IMAGE_FILE_EXTENSIONS = new String[] { "BMP", "GIF", "JPG", "PNG", "RLE" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
@@ -85,6 +88,10 @@ public ExportDiagramDialog(Shell shell, GraphicalViewer graphicalViewer) {
super(shell, graphicalViewer);
}
+ public int configure() {
+ return open();
+ }
+
public void addExporters(Map<String, Boolean> diagramExporterTypes) {
additionalExporterTypes = diagramExporterTypes;
List<String> asList = new ArrayList<String>();
View
17 ...pse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/PrintFigureDialog.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2011 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -11,6 +11,7 @@
* SAP AG - initial API, implementation and documentation
* mwenz - Bug 323359 Avoid usage of java.lang.text, ICU4J etc.
* mwenz - Bug 323034 - Aligned vertical gaps between groups
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
@@ -22,9 +23,10 @@
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.graphiti.ui.internal.Messages;
-import org.eclipse.graphiti.ui.internal.util.ui.DefaultPreferences;
import org.eclipse.graphiti.ui.internal.util.ui.DoubleField;
import org.eclipse.graphiti.ui.internal.util.ui.DoubleFieldWithDropDown;
+import org.eclipse.graphiti.ui.print.IPrintConfiguration;
+import org.eclipse.graphiti.ui.print.IPrintPreferences;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
@@ -54,7 +56,8 @@
* @noinstantiate This class is not intended to be instantiated by clients.
* @noextend This class is not intended to be subclassed by clients.
*/
-public class PrintFigureDialog extends AbstractFigureSelectionDialog implements ModifyListener, PaintListener {
+public class PrintFigureDialog extends AbstractFigureSelectionDialog implements IPrintConfiguration, ModifyListener,
+ PaintListener {
private static final String COLON = ":"; //$NON-NLS-1$
@@ -548,7 +551,7 @@ public double getPrinterScaleFactor() {
*
* @return The printer preferences as given through this dialog.
*/
- public DefaultPreferences getPreferences() {
+ public IPrintPreferences getPreferences() {
return _preferences;
}
@@ -662,7 +665,7 @@ private Point determineMargins(Rectangle printRegion, org.eclipse.swt.graphics.R
/**
* Transforms preview values into printer values and stores them in the
- * DefaultPreferences.
+ * IPrintPreferences.
*/
private void adjustPrinterValuesUsingPreview(int leftMargin, int topMargin, int imageWidthScaled, int imageHeightScaled,
Rectangle printRegion, org.eclipse.swt.graphics.Rectangle previewRegion) {
@@ -730,4 +733,8 @@ private void aspectRatioOnChanged() {
_preferences.setDoublePreference(DefaultPrintPreferences.SCALE_FACTOR_Y, _preferences
.getDoublePreference(DefaultPrintPreferences.SCALE_FACTOR_X));
}
+
+ public int configure() {
+ return open();
+ }
}
View
17 ....ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/PrintFigureScaleableOperation.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -9,6 +9,7 @@
*
* Contributors:
* SAP AG - initial API, implementation and documentation
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
@@ -19,9 +20,9 @@
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PrintFigureOperation;
import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.graphiti.ui.internal.util.ui.DefaultPreferences;
+import org.eclipse.graphiti.ui.print.IPrintConfiguration;
+import org.eclipse.graphiti.ui.print.IPrintPreferences;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.printing.Printer;
/**
* A PrintFigureOperation, which allows to print with fully configurable size
@@ -42,7 +43,7 @@
*
* @see DefaultPrintPreferences
*/
- private DefaultPreferences _preferences;
+ private IPrintPreferences _preferences;
private Image _image;
/**
@@ -56,10 +57,10 @@
* The image to print, this is currently used for printing since
* Figures do not allow for flexible xy-scaling.
*/
- public PrintFigureScaleableOperation(Printer p, IFigure figure, Image image, DefaultPreferences prefs) {
- super(p, figure);
- _preferences = prefs;
- _image = image;
+ public PrintFigureScaleableOperation(IPrintConfiguration printConfiguration) {
+ super(printConfiguration.getPrinter(), printConfiguration.getFigure());
+ _preferences = printConfiguration.getPreferences();
+ _image = printConfiguration.getScaledImage();
}
/**
View
81 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/print/IPrintConfiguration.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012, 2013 SAP AG.
+ * 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:
+ * mwenz - Bug 370888 - API Access to export and print
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.ui.print;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.printing.Printer;
+
+/**
+ * This interface defines a print configuration container, that is used for
+ * printing a diagram. The container itself is also capable of providing an
+ * image for the figure to print.
+ *
+ * @since 0.10
+ */
+public interface IPrintConfiguration {
+
+ /**
+ * The return code for {@link #configure()} that indicates a successful
+ * configuration process.
+ */
+ public static final int OK = Window.OK;
+
+ /**
+ * Configures this container. May e.g. mean that a popup is presented to the
+ * user, but also simply some default values are set.
+ *
+ * @return The return code of this operation. Anything else than 0 will be
+ * interpreted as a cancellation request.
+ */
+ public int configure();
+
+ /**
+ * Returns the figure to be printed.
+ *
+ * @return The figure to be printed
+ */
+ public IFigure getFigure();
+
+ /**
+ * Calculates an image with the applied scale factors.
+ *
+ * @return A scaled image
+ */
+ public Image getScaledImage();
+
+ /**
+ * The defined preferences for printing
+ *
+ * @return A filled {@link IPrintPreferences} instance holding the
+ * current configuration
+ */
+ public IPrintPreferences getPreferences();
+
+ /**
+ * Cleans up all stored data.
+ */
+ public void cleanUp();
+
+ /**
+ * Returns the {@link Printer} to be used.
+ *
+ * @return The printer.
+ */
+ public Printer getPrinter();
+
+}
View
74 plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/print/IPrintPreferences.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2013 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ * mwenz - Bug 370888 - API Access to export and print
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.ui.print;
+
+/**
+ * A generic interface for preference containers for printing a diagram, which
+ * serves as abstraction for generic edit fields which store their values in a
+ * preference object
+ *
+ * @noinstantiate This class is not intended to be instantiated by clients.
+ * @noextend This class is not intended to be subclassed by clients.
+ * @since 0.10
+ */
+public interface IPrintPreferences {
+
+ /**
+ * Resets all preferences to their default values.
+ */
+ public void setDefaults();
+
+ /**
+ * Sets the integer preference value of the preference at position atIndex
+ * to the given value.
+ *
+ * @param atIndex
+ * The index of the preference to set
+ * @param value
+ * The new value to set
+ */
+ public void setIntPreference(int atIndex, int value);
+
+ /**
+ * Returns the integer value of the preference with the given index.
+ *
+ * @param atIndex
+ * The index of the preference to return
+ * @return The value of the preference with the given index as an integer
+ */
+ public int getIntPreference(int atIndex);
+
+ /**
+ * Sets the double preference value of the preference at position atIndex to
+ * the given value.
+ *
+ * @param atIndex
+ * The index of the preference to set
+ * @param value
+ * The new value to set
+ */
+ public void setDoublePreference(int atIndex, double value);
+
+ /**
+ * Returns the double value of the preference with the given index.
+ *
+ * @param atIndex
+ * The index of the preference to return
+ * @return The value of the preference with the given index as a double
+ */
+ public double getDoublePreference(int atIndex);
+}
View
101 ...clipse.graphiti.ui/src/org/eclipse/graphiti/ui/saveasimage/ISaveAsImageConfiguration.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2013, 2013 SAP AG.
+ * 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:
+ * mwenz - Bug 370888 - API Access to export and print
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.ui.saveasimage;
+
+import java.util.Map;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * This interface defines a save as image configuration container, that is used
+ * for saving a diagram as an image. The container itself is also capable of
+ * providing an image for the figure to save as an image.
+ *
+ * @since 0.10
+ */
+public interface ISaveAsImageConfiguration {
+
+ /**
+ * The return code for {@link #configure()} that indicates a successful
+ * configuration process.
+ */
+ public static final int OK = Window.OK;
+
+ /**
+ * Should add the given exporters to an internal list. Clients may use this
+ * list to let users select in an UI from the exporters or programmatically
+ * decide which one to use.
+ *
+ * @param diagramExporterTypes
+ * A {@link Map} holding all exporters.
+ */
+ public void addExporters(Map<String, Boolean> diagramExporterTypes);
+
+ /**
+ * Does the actual configuration. May bring up a UI.
+ *
+ * @return
+ */
+ public int configure();
+
+ /**
+ * Returns the selected file extension formatted in a standard way, e.g.
+ * converted to lower case.
+ *
+ * @return A string holding the file extension
+ */
+ public String getFormattedFileExtension();
+
+ /**
+ * Returns the image in the final scaled version that fits the zooom factor
+ * etc. the user (or the configure coding) defined.
+ *
+ * @return An {@link Image} containing what shall be saved.
+ */
+ public Image getScaledImage();
+
+ /**
+ * Returns the file extension to use.
+ *
+ * @return A string holding the file extension
+ */
+ public String getFileExtension();
+
+ /**
+ * Returns the image format as defined by the SWT.IMAGE_* constants like
+ * {@link SWT#IMAGE_BMP}.
+ *
+ * @return An integer defining the format
+ */
+ public int getImageFormat();
+
+ /**
+ * Returns the figure to be saved as an image.
+ *
+ * @return The figure to be saved as an image
+ */
+ public IFigure getFigure();
+
+ /**
+ * Retunrs the scale factor to be used in the saved image.
+ *
+ * @return A double value defining the scale factor.
+ */
+ public double getImageScaleFactor();
+}
View
59 plugins/org.eclipse.graphiti/.settings/.api_filters
@@ -1,50 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.graphiti" version="2">
- <resource path="META-INF/MANIFEST.MF">
- <filter id="923795461">
+ <resource path="META-INF/MANIFEST.MF" type="org.eclipse.graphiti.features.impl.DefaultPrintFeature">
+ <filter id="305324134">
<message_arguments>
- <message_argument value="0.10.0"/>
- <message_argument value="0.9.0"/>
+ <message_argument value="org.eclipse.graphiti.features.impl.DefaultPrintFeature"/>
+ <message_argument value="org.eclipse.graphiti_0.10.0"/>
</message_arguments>
</filter>
</resource>
- <resource path="src/org/eclipse/graphiti/features/context/impl/DeleteContext.java" type="org.eclipse.graphiti.features.context.impl.DeleteContext">
- <filter id="576720909">
+ <resource path="META-INF/MANIFEST.MF" type="org.eclipse.graphiti.features.impl.DefaultSaveImageFeature">
+ <filter id="305324134">
<message_arguments>
- <message_argument value="PictogramElementContext"/>
- <message_argument value="DeleteContext"/>
+ <message_argument value="org.eclipse.graphiti.features.impl.DefaultSaveImageFeature"/>
+ <message_argument value="org.eclipse.graphiti_0.10.0"/>
</message_arguments>
</filter>
</resource>
- <resource path="src/org/eclipse/graphiti/features/context/impl/DirectEditingContext.java" type="org.eclipse.graphiti.features.context.impl.DirectEditingContext">
- <filter id="576720909">
+ <resource path="src/org/eclipse/graphiti/features/impl/AbstractFeatureProvider.java" type="org.eclipse.graphiti.features.impl.AbstractFeatureProvider">
+ <filter id="421650549">
<message_arguments>
- <message_argument value="DetailedPictogramElementContext"/>
- <message_argument value="DirectEditingContext"/>
+ <message_argument value="org.eclipse.graphiti.features.impl.AbstractFeatureProvider"/>
+ <message_argument value="getPrintFeature()"/>
</message_arguments>
</filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/features/context/impl/LayoutContext.java" type="org.eclipse.graphiti.features.context.impl.LayoutContext">
- <filter id="576720909">
- <message_arguments>
- <message_argument value="PictogramElementContext"/>
- <message_argument value="LayoutContext"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/features/context/impl/RemoveContext.java" type="org.eclipse.graphiti.features.context.impl.RemoveContext">
- <filter id="576720909">
+ <filter id="421650549">
<message_arguments>
- <message_argument value="PictogramElementContext"/>
- <message_argument value="RemoveContext"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/features/context/impl/UpdateContext.java" type="org.eclipse.graphiti.features.context.impl.UpdateContext">
- <filter id="576720909">
- <message_arguments>
- <message_argument value="PictogramElementContext"/>
- <message_argument value="UpdateContext"/>
+ <message_argument value="org.eclipse.graphiti.features.impl.AbstractFeatureProvider"/>
+ <message_argument value="getSaveImageFeature()"/>
</message_arguments>
</filter>
</resource>
@@ -127,7 +109,7 @@
<message_argument value="getSelectionInfoForShape(Shape)"/>
</message_arguments>
</filter>
- <filter comment="getToolTip changes its return type to Object" id="338792546">
+ <filter id="338792546">
<message_arguments>
<message_argument value="org.eclipse.graphiti.tb.DefaultToolBehaviorProvider"/>
<message_argument value="getToolTip(GraphicsAlgorithm)"/>
@@ -209,7 +191,7 @@
<message_argument value="getSelectionInfoForShape(Shape)"/>
</message_arguments>
</filter>
- <filter comment="getToolTip changes its return type to Object" id="405901410">
+ <filter id="405901410">
<message_arguments>
<message_argument value="org.eclipse.graphiti.tb.IToolBehaviorProvider"/>
<message_argument value="getToolTip(GraphicsAlgorithm)"/>
@@ -289,11 +271,4 @@
</message_arguments>
</filter>
</resource>
- <resource path="src/org/eclipse/graphiti/util/PredefinedColoredAreas.java" type="org.eclipse.graphiti.util.PredefinedColoredAreas">
- <filter id="1143996420">
- <message_arguments>
- <message_argument value="createGradientColoredArea(String, int, LocationType, String, int, LocationType)"/>
- </message_arguments>
- </filter>
- </resource>
</component>
View
5 plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/IFeatureProvider.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2011 SAP AG.
+ * Copyright (c) 2005, 2013 SAP AG.
* 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
@@ -13,6 +13,7 @@
* DefaultSaveImageFeature
* mwenz - Bug 356218 - Added hasDoneChanges updates to update diagram feature
* and called features via editor command stack to check it
+ * mwenz - Bug 370888 - API Access to export and print
*
* </copyright>
*
@@ -40,8 +41,6 @@
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.features.impl.AbstractFeatureProvider;
-import org.eclipse.graphiti.features.impl.DefaultPrintFeature;
-import org.eclipse.graphiti.features.impl.DefaultSaveImageFeature;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;