Project

General

Profile

Download (3.3 KB) Statistics
| Branch: | Tag: | Revision:
1
// $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
package eu.etaxonomy.taxeditor.printpublisher.handler;
12

    
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.core.runtime.Status;
19
import org.eclipse.jface.wizard.WizardDialog;
20
import org.eclipse.ui.IEditorInput;
21
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.handlers.HandlerUtil;
23
import org.jdom.Element;
24

    
25
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
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
30
import eu.etaxonomy.taxeditor.printpublisher.wizard.DirectPublishingWizard;
31
import eu.etaxonomy.taxeditor.store.CdmStore;
32
import eu.etaxonomy.taxeditor.store.StoreUtil;
33

    
34
/**
35
 * <p>GeneratePdfHandler class.</p>
36
 *
37
 * @author n.hoffmann
38
 * @created Jul 20, 2010
39
 * @version 1.0
40
 */
41
public class GeneratePdfHandler extends AbstractHandler {
42
	
43
	private PublishConfigurator configurator;
44

    
45
	/** {@inheritDoc} */
46
	public Object execute(ExecutionEvent event) throws ExecutionException {
47
		// make the editors taxon the selected taxon to export
48
		IEditorPart editor = HandlerUtil.getActiveEditor(event);	
49

    
50
		IEditorInput input = editor.getEditorInput();
51
		
52
		if(!(input instanceof TaxonEditorInput)){
53
			StoreUtil.warningDialog("PDF generation not supported for selected input", this, "Generating PDF output is not supported for the current active editor");
54
			
55
			return null;
56
		}
57
		
58
		configurator = PublishConfigurator.NewLocalInstance(CdmStore.getCurrentApplicationController());
59
		
60
		Element taxonNodeElement = getTaxonNodeElement((TaxonEditorInput) input);
61
		configurator.addSelectedTaxonNodeElements(taxonNodeElement);
62
		
63
		configurator.setDoPublishEntireBranches(false);
64
		
65
		configurator.addOutputModule(new XMLOutputModule());
66
		configurator.addOutputModule(new PdfOutputModule());
67
	
68
	
69
	
70
	// while testing
71
//		configurator.setFeatureTree(UUID.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9"));
72
//		configurator.setExportFolder(new File("/Users/n.hoffmann/tmp/"));
73
//		
74
//		ConversationHolder conversation = CdmStore.createConversation();
75
//		conversation.close();
76
////		try{
77
//			Publisher.publish(configurator);
78
////			conversation.commit();
79
////		}finally{
80
////			conversation.close();
81
////		}
82
	
83
	
84
		// enable this when not testing
85
		DirectPublishingWizard wizard = new DirectPublishingWizard(configurator);
86
		WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
87
		
88
		int result = dialog.open();
89
		
90
		if(result == Status.OK || result == Status.CANCEL){
91
			return null;
92
		}else{
93
			throw new RuntimeException("An error occurred during print publishing.");
94
		}
95
	}
96
	
97
	private Element getTaxonNodeElement(TaxonEditorInput input){
98
		
99
		UUID taxonNodeUuid = input.getTaxonNode().getUuid();
100
		
101
		IXMLEntityFactory factory = configurator.getFactory();
102
		
103
		Element taxonNodeElement = factory.getTaxonNode(taxonNodeUuid);
104
		
105
		return taxonNodeElement;
106
	}
107
}
    (1-1/1)