Project

General

Profile

Revision d1dd048b

IDd1dd048b5919f0ca9cc6acc70a7ef33bca463d1f
Parent 8315bf09
Child c872869c

Added by Patrick Plitzner almost 2 years ago

ref #6774 Rename export handler

View differences:

eu.etaxonomy.taxeditor.store/fragment.e4xmi
11 11
      <tags>nonRestore</tags>
12 12
      <handlers xmi:id="_DYhGACHXEeiP8eNo0PEm1g" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.CreateFeatureTreeHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.CreateFeatureTreeHandler" command="_AJtnsCHXEeiP8eNo0PEm1g"/>
13 13
      <handlers xmi:id="_Bb0TwCFeEeiVXriJfxPIuA" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureTreeHandlers" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureTreeHandler" command="_3mqzkCFdEeiVXriJfxPIuA"/>
14
      <handlers xmi:id="_VSc2UGcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportHandler" command="_I_yx4GcqEee0qLTtA2ZpVQ"/>
14
      <handlers xmi:id="_VSc2UGcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportWordHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportWordHandler" command="_I_yx4GcqEee0qLTtA2ZpVQ"/>
15 15
      <handlers xmi:id="_3wq0cGceEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.AddFeatureHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.AddFeatureHandler" command="_oftL0GceEee0qLTtA2ZpVQ"/>
16 16
      <handlers xmi:id="_DcmpgPhnEei8uPv-H2wqnw" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportOntologyHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportOntologyHandler" command="_xyZ4oPhmEei8uPv-H2wqnw"/>
17 17
      <menus xsi:type="menu:PopupMenu" xmi:id="__Jwh4GceEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.popupmenu.featureTreeEditor">
......
98 98
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_mPdAcGceEee0qLTtA2ZpVQ" featurename="commands" parentElementId="xpath:/">
99 99
    <elements xsi:type="commands:Command" xmi:id="_oftL0GceEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.addFeature" commandName="%command.commandname.1" description="%command.description.1"/>
100 100
    <elements xsi:type="commands:Command" xmi:id="_fNBtQGcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.removeFeature" commandName="%command.commandname.2" description="%command.description.2"/>
101
    <elements xsi:type="commands:Command" xmi:id="_I_yx4GcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.exportTree" commandName="%command.commandname.3"/>
101
    <elements xsi:type="commands:Command" xmi:id="_I_yx4GcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.exportTreeWord" commandName="%command.commandname.3"/>
102 102
    <elements xsi:type="commands:Command" xmi:id="_efb88IcsEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.change" commandName="%command.name"/>
103 103
    <elements xsi:type="commands:Command" xmi:id="_cs5L0IctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.edit" commandName="%command.name.0"/>
104 104
    <elements xsi:type="commands:Command" xmi:id="_o0HcUIctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.clone" commandName="%command.name.8"/>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/FeatureTreeExportHandler.java
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.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.description.FeatureTree;
29
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
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

  
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
        IFeatureTreeEditor editor = (IFeatureTreeEditor) thisPart.getObject();
47

  
48
        if(StoreUtil.checkDirty(editor)){
49
            return;
50
        }
51

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

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

  
79
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/FeatureTreeExportWordHandler.java
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.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.description.FeatureTree;
29
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
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

  
35
/**
36
 * @author pplitzner
37
 * @since Jul 12, 2017
38
 *
39
 */
40
public class FeatureTreeExportWordHandler {
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
        IFeatureTreeEditor editor = (IFeatureTreeEditor) thisPart.getObject();
47

  
48
        if(StoreUtil.checkDirty(editor)){
49
            return;
50
        }
51

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

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

  
79
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)