package factOrFiction.actions;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.ui.IEditorPart;
import factOrFiction.model.Deck;
import factOrFiction.print.IPrintDeck;
import factOrFiction.print.PageFrame;
import factOrFiction.print.PrintManager;
import factOrFiction.print.ui.PrintPreviewDialog;
public class PrintDeckAction extends ExtensionCallAction {
public PrintDeckAction(IConfigurationElement element, IEditorPart targetEditor) {
super(element, targetEditor);
}
@Override
public void run() {
if(editor == null)
return;
Object clazz = createExecutable();
if (clazz != null && clazz instanceof IPrintDeck) {
IPrintDeck print = (IPrintDeck)clazz;
Deck deck = (Deck)editor.getEditorInput().getAdapter(Deck.class);
if( deck == null)
return;
try {
PageFrame page = print.getPrintable(deck);
PrintPreviewDialog dlg = new PrintPreviewDialog(editor.getSite().getShell(), page);
if( dlg.open() == Window.OK ) {
PrinterData printerData = dlg.getPrinterData();
PrintManager.print(printerData, page);
}
} catch(Exception e) {
e.printStackTrace();
MessageDialog.openError(editor.getSite().getShell(), "Print execution", "Internal error while printing " + configElement.getName());
}
}
}
}