--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.printpublisher.handler;
+
+import java.util.UUID;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.jdom.Element;
+
+import eu.etaxonomy.cdm.print.IXMLEntityFactory;
+import eu.etaxonomy.cdm.print.PublishConfigurator;
+import eu.etaxonomy.cdm.print.out.pdf.PdfOutputModule;
+import eu.etaxonomy.cdm.print.out.xml.XMLOutputModule;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.printpublisher.wizard.DirectPublishingWizard;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
+
+/**
+ * <p>GeneratePdfHandler class.</p>
+ *
+ * @author n.hoffmann
+ * @created Jul 20, 2010
+ * @version 1.0
+ */
+public class GeneratePdfHandler extends AbstractHandler {
+
+ private PublishConfigurator configurator;
+
+ /** {@inheritDoc} */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ // make the editors taxon the selected taxon to export
+ IEditorPart editor = HandlerUtil.getActiveEditor(event);
+
+ IEditorInput input = editor.getEditorInput();
+
+ if(!(input instanceof TaxonEditorInput)){
+ StoreUtil.warningDialog("PDF generation not supported for selected input", this, "Generating PDF output is not supported for the current active editor");
+
+ return null;
+ }
+
+ configurator = PublishConfigurator.NewLocalInstance(CdmStore.getCurrentApplicationController());
+
+ Element taxonNodeElement = getTaxonNodeElement((TaxonEditorInput) input);
+ configurator.addSelectedTaxonNodeElements(taxonNodeElement);
+
+ configurator.setDoPublishEntireBranches(false);
+
+ configurator.addOutputModule(new XMLOutputModule());
+ configurator.addOutputModule(new PdfOutputModule());
+
+
+
+ // while testing
+// configurator.setFeatureTree(UUID.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9"));
+// configurator.setExportFolder(new File("/Users/n.hoffmann/tmp/"));
+//
+// ConversationHolder conversation = CdmStore.createConversation();
+// conversation.close();
+//// try{
+// Publisher.publish(configurator);
+//// conversation.commit();
+//// }finally{
+//// conversation.close();
+//// }
+
+
+ // enable this when not testing
+ DirectPublishingWizard wizard = new DirectPublishingWizard(configurator);
+ WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
+
+ int result = dialog.open();
+
+ if(result == Status.OK || result == Status.CANCEL){
+ return null;
+ }else{
+ throw new RuntimeException("An error occurred during print publishing.");
+ }
+ }
+
+ private Element getTaxonNodeElement(TaxonEditorInput input){
+
+ UUID taxonNodeUuid = input.getTaxonNode().getUuid();
+
+ IXMLEntityFactory factory = configurator.getFactory();
+
+ Element taxonNodeElement = factory.getTaxonNode(taxonNodeUuid);
+
+ return taxonNodeElement;
+ }
+}