Project

General

Profile

Download (3 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.termtree.e4.handler;
10

    
11
import java.io.File;
12

    
13
import javax.inject.Named;
14

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

    
27
import eu.etaxonomy.cdm.io.descriptive.word.out.WordExportConfigurator;
28
import eu.etaxonomy.cdm.model.term.TermTree;
29
import eu.etaxonomy.cdm.persistence.dto.TermTreeDto;
30
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
31
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
32
import eu.etaxonomy.taxeditor.store.CdmStore;
33
import eu.etaxonomy.taxeditor.store.StoreUtil;
34
import eu.etaxonomy.taxeditor.termtree.e4.ITermTreeEditor;
35

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

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

    
49
        if(StoreUtil.promptCheckIsDirty(editor)){
50
            return;
51
        }
52

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

    
67
    @CanExecute
68
    public boolean canExecute(
69
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
70
            MHandledMenuItem menuItem) {
71
        boolean canExecute = false;
72
        canExecute = PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES)
73
                && selection!=null
74
                && selection.size()==1
75
                && selection.getFirstElement() instanceof TermTreeDto;
76
        menuItem.setVisible(canExecute);
77
        return canExecute;
78
    }
79

    
80
}
(11-11/11)