Package org.eclipse.graphiti.ui.features

## Class DefaultPrintFeature

- java.lang.Object
- - org.eclipse.graphiti.features.impl.AbstractFeature
  - - org.eclipse.graphiti.features.impl.AbstractPrintFeature
    - - org.eclipse.graphiti.ui.features.DefaultPrintFeature

All Implemented Interfaces:
  `IFeature`, `IFeatureProviderHolder`, `IPrintFeature`, `IDescription`, `IName`

    public class DefaultPrintFeature
    extends AbstractPrintFeature
    implements IPrintFeature

The default feature implementation for printing a diagram. This feature is used to trigger printing from inside an open and initialized `DiagramEditor`. It relies on an existing `GraphicalViewer` showing the diagram to print.

Since:
  0.10 Has been moved from plug-in org.eclipse.graphiti package org.eclipse.graphiti.features

### Constructor Summary

Constructors
`DefaultPrintFeature​(IFeatureProvider fp)` Creates a new `DefaultPrintFeature`.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected org.eclipse.gef.GraphicalViewer` `getGraphicalViewer​(IPrintContext context)` Must return a `GraphicalViewer` that contains the diagram to be printed.
`protected IPrintConfiguration` `getPrintConfiguration​(org.eclipse.gef.GraphicalViewer viewer, org.eclipse.swt.printing.Printer printer)` Called to create a configuration object for the printing that defines what to print on which printer and how.
`protected org.eclipse.swt.printing.PrinterData` `getPrinterData​(IPrintContext context)` Creates the `PrinterData` information used for this print feature.
`protected org.eclipse.draw2d.PrintFigureOperation` `getPrintOperation​(IPrintConfiguration printConfiguration)` Called to create the operation that is actually used for printing a diagram.
`void` `print​(IPrintContext context)` Performs the print operation.

### Methods inherited from class org.eclipse.graphiti.features.impl.AbstractPrintFeature

`canExecute, canPrint, execute, getName, hasDoneChanges, postPrint, prePrint`

### Methods inherited from class org.eclipse.graphiti.features.impl.AbstractFeature

`addGraphicalRepresentation, canUndo, getAllBusinessObjectsForPictogramElement, getBusinessObjectForPictogramElement, getDescription, getDiagram, getDiagramBehavior, getFeatureProvider, getProgressCallback, getUserDecision, isAvailable, layoutPictogramElement, link, link, manageColor, manageColor, manageDefaultFont, manageFont, manageFont, setProgressCallback, toString, updatePictogramElement`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.eclipse.graphiti.IDescription

`getDescription`

### Methods inherited from interface org.eclipse.graphiti.features.IFeature

`canExecute, canUndo, execute, hasDoneChanges, isAvailable`

### Methods inherited from interface org.eclipse.graphiti.features.IFeatureProviderHolder

`getFeatureProvider`

### Methods inherited from interface org.eclipse.graphiti.IName

`getName`

### Methods inherited from interface org.eclipse.graphiti.features.IPrintFeature

`canPrint, postPrint, prePrint`

### Constructor Detail

#### DefaultPrintFeature

    public DefaultPrintFeature​(IFeatureProvider fp)

Creates a new `DefaultPrintFeature`.

Parameters:
  `fp` - The feature provider providing this feature

### Method Detail

#### print

    public void print​(IPrintContext context)

Performs the print operation. The default implementation delegates to `getGraphicalViewer(IPrintContext)` to retrieve the `GraphicalViewer` that already displays the diagram, queries for `PrinterData` to use by calling `getPrinterData(IPrintContext)` and finally uses `#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.

Specified by:
  `print` in interface `IPrintFeature`
Parameters:
  `context` - Context information for printing.

#### getGraphicalViewer

    protected org.eclipse.gef.GraphicalViewer getGraphicalViewer​(IPrintContext context)

Must return a `GraphicalViewer` that contains the diagram to be printed. The default implementation returns the viewer of the `DiagramEditor` that started this print feature; this is the one associated to the feature provider of the currently opened diagram, see `#getDiagramEditor()`.

Parameters:
  `context` - Context information for printing.
Returns:
  the viewer holding the diagram to print.

#### getPrinterData

    protected org.eclipse.swt.printing.PrinterData getPrinterData​(IPrintContext context)

Creates the `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.

Parameters:
  `context` - Context information for printing.
Returns:
  The printer data to use for this print feature.

#### getPrintConfiguration

    protected IPrintConfiguration getPrintConfiguration​(org.eclipse.gef.GraphicalViewer viewer,
                                                        org.eclipse.swt.printing.Printer printer)

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.

Parameters:
  `viewer` - The viewer displaying the diagram to print
  `printer` - The printer to use as default
Returns:
  A newly created dialog that implements the `IPrintConfiguration` interface used in the print job.

#### getPrintOperation

    protected org.eclipse.draw2d.PrintFigureOperation getPrintOperation​(IPrintConfiguration printConfiguration)

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.

Parameters:
  `printConfiguration` - The `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.
Returns:
  The operation that will be used to actually perform the printing.