1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.wiki.ui.editor;
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.printing.PrintDialog;
17 import org.eclipse.swt.printing.Printer;
18 import org.eclipse.swt.printing.PrinterData;
19 import org.eclipse.swt.widgets.Shell;
20 import org.eclipse.ui.part.EditorPart;
22 public class WikiPrintAction extends Action {
24 final IPrintable printable;
26 public WikiPrintAction(IPrintable printable) {
27 this.printable = printable;
31 if(!(printable instanceof EditorPart)) return;
32 Shell shell = ((EditorPart)printable).getEditorSite().getShell();
34 final PrintDialog dialog = new PrintDialog(shell, SWT.PRIMARY_MODAL);
35 final PrinterData data = dialog.open();
38 final Printer printer = new Printer(data);
40 Thread printingThread = new Thread("Printing") { //$NON-NLS-1$
42 printable.print(printer);
45 printingThread.start();