Project

General

Profile

Download (5.06 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 javax.inject.Named;
12

    
13
import org.eclipse.e4.core.di.annotations.CanExecute;
14
import org.eclipse.e4.core.di.annotations.Execute;
15
import org.eclipse.e4.core.di.annotations.Optional;
16
import org.eclipse.e4.ui.di.UISynchronize;
17
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.swt.widgets.Shell;
22

    
23
import eu.etaxonomy.cdm.persistence.dto.TermNodeDto;
24
import eu.etaxonomy.cdm.persistence.dto.TermTreeDto;
25
import eu.etaxonomy.taxeditor.termtree.e4.ITermTreeEditor;
26

    
27
/**
28
 * @author pplitzner
29
 * @since Jul 12, 2017
30
 *
31
 */
32
public class AddTermHandler extends AbstractAddTermHandler{
33

    
34
    @Execute
35
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
36
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
37
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart, UISynchronize sync) {
38
        super.execute(shell, thisPart, selection, sync);
39
    }
40
//        IFeatureTreeEditor editor = ((IFeatureTreeEditor) thisPart.getObject());
41
//        if (StoreUtil.promptCheckIsDirty(editor)) {
42
//            return;
43
//        }
44
//        TermTreeDto tree = (TermTreeDto) selection.getFirstElement();
45
////
46
////        TermChooseWizard wizard = new TermChooseWizard(tree.getTermType());
47
////        WizardDialog dialog = new WizardDialog(shell, wizard);
48
////
49
////        if (dialog.open() == IStatus.OK) {
50
////            List<TermDto> selectedTerms = wizard.getSelectedTerms();
51
////            for (TermDto termDto: selectedTerms) {
52
////                AddFeatureOperation operation = new AddFeatureOperation(termDto.getUuid(), tree.getRoot(), editor, editor);
53
////                AbstractUtility.executeOperation(operation, sync);
54
////            }
55
////        }
56
//
57
//        AvailableFeaturesWizard wizard = new AvailableFeaturesWizard(tree.getTermType());
58
//        WizardDialog dialog = new WizardDialog(shell, wizard);
59
//
60
//        if (dialog.open() == IStatus.OK) {
61
//            Collection<DefinedTermBase> additionalTerms = wizard.getAdditionalFeatures();
62
//            for (DefinedTermBase term : additionalTerms) {
63
////                if (tree.getRoot().getUuid()== null){
64
////                    TermTree termTree = CdmStore.getService(ITermTreeService.class).load(tree.getUuid());
65
////                    tree = TermTreeDto.fromTree(termTree);
66
////                }
67
//                if (!tree.isAllowDuplicate()){
68
//                    boolean isDuplicate = editor.checkDuplicates(term.getUuid(), tree.getUuid());
69
//                    if (isDuplicate){
70
//                        MessagingUtils.informationDialog("No duplicates allowed", "This term tree does not allow duplicates.");
71
//                        return;
72
//                    }
73
//                }
74
//
75
//                AddFeatureOperation operation = new AddFeatureOperation(term.getUuid(), tree.getRoot(), editor, editor);
76
//                editor.addOperation(operation);
77
//                editor.setDirty();
78
//                if (editor instanceof ICharacterEditor){
79
//                    CharacterNodeDto newDto = new CharacterNodeDto(CharacterDto.fromCharacter((Character)term), tree.getRoot(), 0, tree, null, null, null);
80
//                }else{
81
//                    TermNodeDto newDto = new TermNodeDto(TermDto.fromTerm(term), tree.getRoot(), 0, tree, null, null, null);
82
//                }
83
//
84
////                ((AbstractTermTreeEditor)editor).getViewer().refresh();
85
//                if (editor instanceof ICharacterEditor){
86
//                    editor.refresh();
87
//                }else{
88
//                    Object[] expandedElements = ((AbstractTermTreeEditor)editor).getViewer().getExpandedElements();
89
//                    ((AbstractTermTreeEditor)editor).getViewer().setInput(((AbstractTermTreeEditor)editor).getTrees());
90
//                    ((AbstractTermTreeEditor)editor).getViewer().setExpandedElements(expandedElements);
91
//                }
92
//            }
93
//        }
94
//    }
95

    
96
    @CanExecute
97
    public boolean canExecute(
98
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
99
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
100
            MHandledMenuItem menuItem) {
101
        boolean canExecute = false;
102
        canExecute = thisPart.getObject() instanceof ITermTreeEditor
103
                && selection!=null
104
                && selection.size()==1
105
                && selection.getFirstElement() instanceof TermTreeDto;
106
        menuItem.setVisible(canExecute);
107
        return canExecute;
108
    }
109

    
110
    @Override
111
    protected TermNodeDto getParent(IStructuredSelection selection) {
112
        return ((TermTreeDto) selection.getFirstElement()).getRoot();
113
    }
114
}
(3-3/11)