--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.wiki.ui.editor;\r
+\r
+import org.eclipse.jface.action.Action;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.printing.PrintDialog;\r
+import org.eclipse.swt.printing.Printer;\r
+import org.eclipse.swt.printing.PrinterData;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.part.EditorPart;\r
+\r
+public class WikiPrintAction extends Action {\r
+\r
+ final IPrintable printable;\r
+\r
+ public WikiPrintAction(IPrintable printable) {\r
+ this.printable = printable;\r
+ }\r
+\r
+ public void run() {\r
+ if(!(printable instanceof EditorPart)) return;\r
+ Shell shell = ((EditorPart)printable).getEditorSite().getShell();\r
+\r
+ final PrintDialog dialog = new PrintDialog(shell, SWT.PRIMARY_MODAL);\r
+ final PrinterData data = dialog.open();\r
+\r
+ if (data != null) {\r
+ final Printer printer = new Printer(data);\r
+\r
+ Thread printingThread = new Thread("Printing") { //$NON-NLS-1$\r
+ public void run() {\r
+ printable.print(printer);\r
+ }\r
+ };\r
+ printingThread.start();\r
+ }\r
+ return;\r
+ }\r
+}\r