2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.printpublisher
.handler
;
12 import java
.util
.UUID
;
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
;
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
;
33 * <p>GeneratePdfHandler class.</p>
36 * @created Jul 20, 2010
38 public class GeneratePdfHandler
extends AbstractHandler
{
40 private PublishConfigurator configurator
;
43 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
44 // make the editors taxon the selected taxon to export
45 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
47 IEditorInput input
= editor
.getEditorInput();
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");
55 configurator
= PublishConfigurator
.NewLocalInstance(CdmStore
.getCurrentApplicationConfiguration());
57 Element taxonNodeElement
= getTaxonNodeElement((TaxonEditorInputE4
) input
);
58 configurator
.addSelectedTaxonNodeElements(taxonNodeElement
);
60 configurator
.setDoPublishEntireBranches(false);
62 configurator
.addOutputModule(new PdfOutputModule());
63 configurator
.addOutputModule(new XMLOutputModule());
65 DirectPublishingWizard wizard
= new DirectPublishingWizard(configurator
);
66 WizardDialog dialog
= new WizardDialog(HandlerUtil
.getActiveShell(event
), wizard
);
73 private Element
getTaxonNodeElement(TaxonEditorInputE4 input
){
75 UUID taxonNodeUuid
= input
.getTaxonNode().getUuid();
77 IXMLEntityFactory factory
= configurator
.getFactory();
79 Element taxonNodeElement
= factory
.getTaxonNode(taxonNodeUuid
);
81 return taxonNodeElement
;