Project

General

Profile

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