Permalink
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...
mwenz committed Mar 8, 2013
1 parent 60d61d5 commit 2f256b6c7c4a0789703e05027c3244c571c60286
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 ...g.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 ...ins/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 ...org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/DoubleFieldWithDropDown.java
  15. +4 −3 ...graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/AbstractFigureSelectionDialog.java
  16. +5 −4 ...lipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/DefaultPrintPreferences.java
  17. +9 −2 ...g.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/ExportDiagramDialog.java
  18. +12 −5 ...org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/ui/print/PrintFigureDialog.java
  19. +9 −8 ...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 ...ns/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
@@ -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>
@@ -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
@@ -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());
}
@@ -1,14 +1,15 @@
/*******************************************************************************
* <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
* 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>
*
@@ -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;
@@ -129,6 +132,16 @@ public IPasteFeature getPasteFeature(IPasteContext context) {
return null;
}
+ @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);
@@ -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;
+ }
+}
Oops, something went wrong.

0 comments on commit 2f256b6

Please sign in to comment.