Project

General

Profile

Download (5.6 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 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.navigation.navigator.e4.handler;
10

    
11
import java.util.ArrayList;
12
import java.util.List;
13
import java.util.UUID;
14

    
15
import org.eclipse.core.commands.operations.AbstractOperation;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
20
import org.eclipse.jface.viewers.TreeSelection;
21
import org.eclipse.swt.widgets.Display;
22
import org.eclipse.swt.widgets.Shell;
23

    
24
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
25
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
28
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
29
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
30
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
31
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
32
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
33

    
34
/**
35
 * @author cmathew
36
 * @date 19 Jun 2015
37
 *
38
 */
39
public class RemotingMoveFactualDataHandlerE4 extends RemotingCdmHandlerE4 {
40

    
41
    private TaxonNode sourceTaxonNode;
42
    private TaxonNode targetTaxonNode;
43

    
44
    public RemotingMoveFactualDataHandlerE4() {
45
        super(TaxonNavigatorLabels.MOVE_FACTUAL_DATA_LABEL);
46
    }
47

    
48
    @Override
49
    public IStatus allowOperations(TreeSelection selection,
50
            Shell shell,
51
            MPart activePart,
52
            MHandledMenuItem menuItem) {
53
        // check that only a single taxon tree node has been selected
54
        if(selection.size() > 1) {
55
            return new Status(IStatus.ERROR,
56
                    "unknown", //$NON-NLS-1$
57
                    TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
58
        }
59

    
60
        // check for no taxon tree node selected
61
        if(selection.size() == 0) {
62
            return new Status(IStatus.ERROR,
63
                    "unknown", //$NON-NLS-1$
64
                    TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
65
        }
66

    
67
        // check that selected object is a taxon node
68
        Object obj = selection.iterator().next();
69
        if(obj instanceof ITaxonTreeNode) {
70
            sourceTaxonNode = (TaxonNode)obj;
71
        } else {
72
            return new Status(IStatus.ERROR,
73
                    "unknown", //$NON-NLS-1$
74
                    TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
75
        }
76

    
77
        if(NavigationUtil.isDirty(sourceTaxonNode)) {
78
            return new Status(IStatus.ERROR,
79
                    "unknown", //$NON-NLS-1$
80
                    TaxonNavigatorLabels.UNSAVED_CHANGES_MESSAGE);
81
        }
82

    
83
        List<UUID> excludeTaxa = new ArrayList<UUID>();
84
        excludeTaxa.add(sourceTaxonNode.getTaxon().getUuid());
85

    
86
        targetTaxonNode = TaxonNodeSelectionDialog.select(shell,
87
                new ConversationHolderMock(),
88
                Messages.RemotingMoveFactualDataHandler_CHOOSE_TAXA,
89
                excludeTaxa,
90
                null,
91
                sourceTaxonNode.getClassification());
92

    
93
        if(targetTaxonNode == null) {
94
            return new Status(IStatus.CANCEL,
95
                    "unknown", //$NON-NLS-1$
96
                    ""); //$NON-NLS-1$
97
        }
98
        if(NavigationUtil.isDirty(targetTaxonNode)){
99
            return new Status(IStatus.ERROR,
100
                    "unknown", //$NON-NLS-1$
101
                    TaxonNavigatorLabels.UNSAVED_CHANGES_MESSAGE);
102
        }
103
        return Status.OK_STATUS;
104
    }
105

    
106
    @Override
107
    public AbstractOperation prepareOperation(TreeSelection selection,
108
            Shell shell,
109
            MPart activePart,
110
            MHandledMenuItem menuItem) {
111
        return new RemotingMoveFactualDataOperation(getTrigger(),
112
                false,
113
                sourceTaxonNode.getTaxon().getUuid(),
114
                targetTaxonNode.getTaxon().getUuid());
115
    }
116

    
117
    @Override
118
    public void onComplete() {
119
        Display.getDefault().asyncExec(new Runnable(){
120
            @Override
121
            public void run() {
122
                //FIXME E4 refresh factual view via events or similar
123
//                try {
124
//                    //close and re-open to refresh factual data view
125
//                    MultiPageTaxonEditor sourceEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(sourceTaxonNode.getUuid());
126
//                    MultiPageTaxonEditor targetEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(targetTaxonNode.getUuid());
127
//                    if(targetEditor != null){
128
//                        AbstractUtility.close(sourceEditor);
129
//                        AbstractUtility.close(targetEditor);
130
//                    }
131
//                    EditorUtil.openTaxonNodeE4(sourceTaxonNode.getUuid());
132
//                    EditorUtil.openTaxonNodeE4(targetTaxonNode.getUuid());
133
//                } catch (PartInitException e) {
134
//                    MessagingUtils.error(this.getClass(), e);
135
//                    throw new RuntimeException(e);
136
//                } catch (Exception e) {
137
//                    MessagingUtils.warningDialog(Messages.RemotingMoveFactualDataHandler_CREATE_FAILED, this, e.getMessage());
138
//                }
139
            }
140

    
141
        });
142
    }
143

    
144
    /**
145
     * {@inheritDoc}
146
     */
147
    @Override
148
    protected Object getTrigger() {
149
        return this;
150
    }
151
}
(13-13/15)