]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.wiki.ui/src/org/simantics/wiki/ui/editor/WikiPrintAction.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.wiki.ui / src / org / simantics / wiki / ui / editor / WikiPrintAction.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.wiki.ui.editor;
13
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;
21
22 public class WikiPrintAction extends Action {
23
24         final IPrintable printable;
25
26         public WikiPrintAction(IPrintable printable) {
27                 this.printable = printable;
28         }
29
30         public void run() {
31                 if(!(printable instanceof EditorPart)) return;
32                 Shell shell = ((EditorPart)printable).getEditorSite().getShell();
33
34                 final PrintDialog dialog = new PrintDialog(shell, SWT.PRIMARY_MODAL);
35                 final PrinterData data = dialog.open();
36
37                 if (data != null) {
38                         final Printer printer = new Printer(data);
39
40                         Thread printingThread = new Thread("Printing") { //$NON-NLS-1$
41                                 public void run() {
42                                         printable.print(printer);
43                                 }
44                         };
45                         printingThread.start();
46                 }
47                 return;
48         }
49 }