Package factOrFiction.actions

Source Code of factOrFiction.actions.PrintDeckAction

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());
          }
    }
  }
}
TOP

Related Classes of factOrFiction.actions.PrintDeckAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.