Project

General

Profile

Download (2.65 KB) Statistics
| Branch: | Tag: | Revision:
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
	/** {@inheritDoc} */
43
	@Override
44
    public Object execute(ExecutionEvent event) throws ExecutionException {
45
		// make the editors taxon the selected taxon to export
46
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
47

    
48
		IEditorInput input = editor.getEditorInput();
49

    
50
		if(!(input instanceof TaxonEditorInputE4)){
51
			MessagingUtils.warningDialog("PDF generation not supported for selected input", this, "Generating PDF output is not supported for the current active editor");
52

    
53
			return null;
54
		}
55

    
56
		configurator = PublishConfigurator.NewLocalInstance(CdmStore.getCurrentApplicationConfiguration());
57

    
58
		Element taxonNodeElement = getTaxonNodeElement((TaxonEditorInputE4) input);
59
		configurator.addSelectedTaxonNodeElements(taxonNodeElement);
60

    
61
		configurator.setDoPublishEntireBranches(false);
62

    
63
		configurator.addOutputModule(new PdfOutputModule());
64
		configurator.addOutputModule(new XMLOutputModule());
65

    
66
		DirectPublishingWizard wizard = new DirectPublishingWizard(configurator);
67
		WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
68

    
69
		dialog.open();
70

    
71
		return null;
72
	}
73

    
74
	private Element getTaxonNodeElement(TaxonEditorInputE4 input){
75

    
76
		UUID taxonNodeUuid = input.getTaxonNode().getUuid();
77

    
78
		IXMLEntityFactory factory = configurator.getFactory();
79

    
80
		Element taxonNodeElement = factory.getTaxonNode(taxonNodeUuid);
81

    
82
		return taxonNodeElement;
83
	}
84
}
    (1-1/1)