Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.printpublisher / src / main / java / eu / etaxonomy / taxeditor / printpublisher / handler / GeneratePdfHandler.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.printpublisher.handler;
11
12 import java.util.UUID;
13
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.jface.wizard.WizardDialog;
18 import org.eclipse.ui.IEditorInput;
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.handlers.HandlerUtil;
21 import org.jdom.Element;
22
23 import eu.etaxonomy.cdm.print.IXMLEntityFactory;
24 import eu.etaxonomy.cdm.print.PublishConfigurator;
25 import eu.etaxonomy.cdm.print.out.pdf.PdfOutputModule;
26 import eu.etaxonomy.cdm.print.out.xml.XMLOutputModule;
27 import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
28 import eu.etaxonomy.taxeditor.model.MessagingUtils;
29 import eu.etaxonomy.taxeditor.printpublisher.wizard.DirectPublishingWizard;
30 import eu.etaxonomy.taxeditor.store.CdmStore;
31
32 /**
33 * <p>GeneratePdfHandler class.</p>
34 *
35 * @author n.hoffmann
36 * @created Jul 20, 2010
37 */
38 public class GeneratePdfHandler extends AbstractHandler {
39
40 private PublishConfigurator configurator;
41
42 @Override
43 public Object execute(ExecutionEvent event) throws ExecutionException {
44 // make the editors taxon the selected taxon to export
45 IEditorPart editor = HandlerUtil.getActiveEditor(event);
46
47 IEditorInput input = editor.getEditorInput();
48
49 if(!(input instanceof TaxonEditorInputE4)){
50 MessagingUtils.warningDialog("PDF generation not supported for selected input", this, "Generating PDF output is not supported for the current active editor");
51
52 return null;
53 }
54
55 configurator = PublishConfigurator.NewLocalInstance(CdmStore.getCurrentApplicationConfiguration());
56
57 Element taxonNodeElement = getTaxonNodeElement((TaxonEditorInputE4) input);
58 configurator.addSelectedTaxonNodeElements(taxonNodeElement);
59
60 configurator.setDoPublishEntireBranches(false);
61
62 configurator.addOutputModule(new PdfOutputModule());
63 configurator.addOutputModule(new XMLOutputModule());
64
65 DirectPublishingWizard wizard = new DirectPublishingWizard(configurator);
66 WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
67
68 dialog.open();
69
70 return null;
71 }
72
73 private Element getTaxonNodeElement(TaxonEditorInputE4 input){
74
75 UUID taxonNodeUuid = input.getTaxonNode().getUuid();
76
77 IXMLEntityFactory factory = configurator.getFactory();
78
79 Element taxonNodeElement = factory.getTaxonNode(taxonNodeUuid);
80
81 return taxonNodeElement;
82 }
83 }