Project

General

Profile

Download (3.13 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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
package eu.etaxonomy.taxeditor.featuretree.e4.handler;
10

    
11
import java.io.File;
12

    
13
import javax.inject.Named;
14

    
15
import org.eclipse.core.runtime.NullProgressMonitor;
16
import org.eclipse.core.runtime.jobs.Job;
17
import org.eclipse.e4.core.di.annotations.CanExecute;
18
import org.eclipse.e4.core.di.annotations.Execute;
19
import org.eclipse.e4.core.di.annotations.Optional;
20
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
21
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
22
import org.eclipse.e4.ui.services.IServiceConstants;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.swt.widgets.DirectoryDialog;
25
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.ui.progress.IProgressConstants;
27

    
28
import eu.etaxonomy.cdm.io.descriptive.word.out.WordExportConfigurator;
29
import eu.etaxonomy.cdm.model.description.FeatureTree;
30
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureNodeDropAdapter;
31
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
32
import eu.etaxonomy.taxeditor.model.MessagingUtils;
33
import eu.etaxonomy.taxeditor.store.CdmStore;
34

    
35
/**
36
 * @author pplitzner
37
 * @since Jul 12, 2017
38
 *
39
 */
40
public class FeatureTreeExportHandler {
41

    
42
    @Execute
43
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
44
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
45
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
46
        FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
47

    
48
        if (editor.isDirty()) {
49
            if (MessagingUtils.confirmDialog(FeatureNodeDropAdapter.SAVE_CHANGES_TITLE,
50
                    FeatureNodeDropAdapter.SAVE_CHANGES_MESSAGE)){
51
                editor.save(new NullProgressMonitor());
52
            }
53
            else{
54
                return;
55
            }
56
        }
57

    
58
        FeatureTree selectedFeatureTree = (FeatureTree) selection.getFirstElement();
59
        DirectoryDialog dialog = new DirectoryDialog(shell);
60
        String directoryString = dialog.open();
61
        if(directoryString!=null){
62
            // create job
63
            Job job = CdmStore.getExportManager().createIOServiceJob(WordExportConfigurator.NewInstance(null, null, selectedFeatureTree), new File(directoryString+"/"+selectedFeatureTree.getTitleCache()+".docx"));
64
            // configure the job
65
            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
66
            job.setUser(true);
67
            // schedule job
68
            job.schedule();
69
        }
70
    }
71

    
72
    @CanExecute
73
    public boolean canExecute(
74
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
75
            MHandledMenuItem menuItem) {
76
        boolean canExecute = false;
77
        canExecute = selection!=null
78
                && selection.size()==1
79
                && selection.getFirstElement() instanceof FeatureTree;
80
        menuItem.setVisible(canExecute);
81
        return canExecute;
82
    }
83

    
84
}
(5-5/8)