Project

General

Profile

« Previous | Next » 

Revision 6c610cc5

Added by Cherian Mathew almost 9 years ago

plugin.xml : updated plugin for new remoting handlers
RemotingCdmHandler, RemotingCdmOperation, RemotingCdmUpdateOperation : new handler / operation architecture
RemotingChangeAcceptedTaxonToSynonymHandler : using new remoting handler design
CdmStorePropertyTester : added isRemoting test

View differences:

eu.etaxonomy.taxeditor.navigation/plugin.xml
396 396
            name="%command.name.4">
397 397
      </command>
398 398
      <command
399
            defaultHandler="eu.etaxonomy.taxeditor.navigation.navigator.handler.ChangeAcceptedTaxonToSynonymHandler"
400 399
            id="eu.etaxonomy.taxeditor.navigator.command.update.changeAcceptedToSynonym"
401 400
            name="%command.name.5">
402 401
      </command>
......
472 471
            </with>
473 472
         </activeWhen>
474 473
      </handler>
474
      <handler
475
            class="eu.etaxonomy.taxeditor.navigation.navigator.handler.ChangeAcceptedTaxonToSynonymHandler"
476
            commandId="eu.etaxonomy.taxeditor.navigator.command.update.changeAcceptedToSynonym">
477
         <activeWhen>
478
            <test
479
                  property="eu.etaxonomy.taxeditor.preference.CdmStorePropertyTester.isRemoting">
480
            </test>
481
         </activeWhen>
482
      </handler>
475 483
   </extension>
476 484

  
477 485
      
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/NavigatorHandlerUtils.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.navigation.navigator.handler;
11

  
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.ui.IEditorInput;
14
import org.eclipse.ui.IEditorReference;
15
import org.eclipse.ui.IWorkbenchPage;
16
import org.eclipse.ui.PartInitException;
17
import org.eclipse.ui.handlers.HandlerUtil;
18

  
19
import eu.etaxonomy.cdm.model.common.ITreeNode;
20
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
22

  
23
/**
24
 * @author cmathew
25
 * @date 16 Jun 2015
26
 *
27
 */
28
public class NavigatorHandlerUtils {
29

  
30
    protected static boolean closeObsoleteEditor(ExecutionEvent event, TaxonNode taxonNode){
31
        IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
32
        boolean result = true;
33
        for (IEditorReference ref : activePage.getEditorReferences()) {
34
            try {
35
                String treeIndex = ((ITreeNode)taxonNode).treeIndex();
36

  
37

  
38
                IEditorInput input = ref.getEditorInput();
39
                if (input instanceof TaxonEditorInput) {
40
                    TaxonNode node = ((TaxonEditorInput) input).getTaxonNode();
41
                    //if node is a child of taxonNode then close the editor
42
                    if( ((ITreeNode) node).treeIndex().startsWith(treeIndex)){
43
                    //if (taxonNode.equals(node)) {
44
                        result &= activePage.closeEditor(ref.getEditor(false), true);
45

  
46
                    }
47
                }
48
            } catch (PartInitException e) {
49
                continue;
50
            }
51
        }
52
        return result;
53
    }
54

  
55
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingChangeAcceptedTaxonToSynonymHandler.java
1
/**
2
 *
3
 */
4
package eu.etaxonomy.taxeditor.navigation.navigator.handler;
5

  
6
import java.util.ArrayList;
7
import java.util.HashSet;
8
import java.util.Iterator;
9
import java.util.List;
10
import java.util.Set;
11
import java.util.UUID;
12

  
13
import org.apache.log4j.Logger;
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.Status;
17
import org.eclipse.jface.viewers.TreeSelection;
18
import org.eclipse.ui.handlers.HandlerUtil;
19

  
20
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
21
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
22
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
23
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
24
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
25

  
26
/**
27
 * <p>ChangeAcceptedTaxonToSynonymHandler class.</p>
28
 *
29
 * @author n.hoffmann
30
 * @created Jan 4, 2010
31
 * @version 1.0
32
 */
33
public class RemotingChangeAcceptedTaxonToSynonymHandler extends RemotingCdmHandler {
34

  
35
    private static final Logger logger = Logger
36
            .getLogger(RemotingChangeAcceptedTaxonToSynonymHandler.class);
37

  
38
    private static final String CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL = "Change Accepted Taxon to Synonym";
39
    private static final String SINGLE_TAXON_SELECTION_MESSAGE = "The operation move accepted taxon to synonymy is available only for a single taxon.";
40
    private static final String SOURCE_TAXON_HAS_CHILDREN_MESSAGE = "The accepted taxon must not have any childen. You need to move all childen to " +
41
            "another taxon node in the TaxonNavigator before attempting to turn the accepted " +
42
            "taxon into a synonym.";
43
    private static final String RELATED_EDITORS_NOT_CLOSED_MESSAGE = "Could not close related taxon anme editors. " +
44
            "Please close them manually.";
45

  
46
    private ITaxonTreeNode oldAcceptedTaxonNode;
47
	/**
48
     * @param label
49
     */
50
    public RemotingChangeAcceptedTaxonToSynonymHandler() {
51
        super(CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL);
52
    }
53
    /* (non-Javadoc)
54
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
55
     */
56
    @Override
57
    public IStatus allowOperations(ExecutionEvent event) {
58
        TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
59
        // check that only a single taxon has been selected
60
        if(selection.size() > 0) {
61
            return new Status(IStatus.ERROR,
62
                    "unknown",
63
                    SINGLE_TAXON_SELECTION_MESSAGE);
64
        }
65

  
66
        Iterator selectionIterator = selection.iterator();
67
        Set<ITaxonTreeNode> treeNodes = new HashSet<ITaxonTreeNode>();
68
        ITaxonTreeNode treeNode = treeNodes.iterator().next();
69
        oldAcceptedTaxonNode = treeNode;
70

  
71
        // check that the source taxon node does not have children
72
        if(((TaxonNode)oldAcceptedTaxonNode).getCountChildren() > 0) {
73
            return new Status(IStatus.ERROR,
74
                    "unknown",
75
                    SOURCE_TAXON_HAS_CHILDREN_MESSAGE);
76

  
77
        }
78

  
79
        // check all editors related to this taxon node are closed
80
        boolean allEditorsClosed = true;
81
        for (ITaxonTreeNode tn : treeNodes){
82
            if(treeNode instanceof TaxonNode) {
83
                allEditorsClosed &= NavigatorHandlerUtils.closeObsoleteEditor(event, (TaxonNode) tn);
84
            }
85
        }
86
        if(allEditorsClosed != true) {
87
            return new Status(IStatus.ERROR,
88
                    "unknown",
89
                    RELATED_EDITORS_NOT_CLOSED_MESSAGE);
90
        }
91

  
92
        return Status.OK_STATUS;
93
    }
94
    /* (non-Javadoc)
95
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#doOperations(org.eclipse.core.commands.ExecutionEvent)
96
     */
97
    @Override
98
    public IStatus doOperations(ExecutionEvent event) {
99
        List<UUID> excludeTaxa = new ArrayList<UUID>();
100
        excludeTaxa.add(oldAcceptedTaxonNode.getUuid());
101
        TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
102
                new ConversationHolderMock(),
103
                "Choose the accepted taxon",
104
                excludeTaxa,
105
                null,
106
                ((TaxonNode)oldAcceptedTaxonNode).getClassification());
107

  
108
        if (newAcceptedTaxonNode == null) {
109
            return null;
110
        }
111

  
112
        // run operation
113
        return Status.OK_STATUS;
114
    }
115
    /* (non-Javadoc)
116
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#postOperations(org.eclipse.core.commands.ExecutionEvent)
117
     */
118
    @Override
119
    public void postOperations(ExecutionEvent event) {
120
        // TODO Auto-generated method stub
121

  
122
    }
123

  
124

  
125
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmHandler.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.operation;
11

  
12
import org.eclipse.core.commands.AbstractHandler;
13
import org.eclipse.core.commands.ExecutionEvent;
14
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.jface.dialogs.ErrorDialog;
17

  
18
import eu.etaxonomy.taxeditor.model.MessagingUtils;
19

  
20
/**
21
 * @author cmathew
22
 * @date 16 Jun 2015
23
 *
24
 */
25
public abstract class RemotingCdmHandler extends AbstractHandler {
26

  
27
    private final String label;
28

  
29
    public RemotingCdmHandler(String label) {
30
        this.label = label;
31
    }
32

  
33
    /* (non-Javadoc)
34
     * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
35
     */
36
    @Override
37
    public Object execute(ExecutionEvent event) throws ExecutionException {
38
        IStatus allowStatus = allowOperations(event);
39
        if(allowStatus.isOK()) {
40
            IStatus opStatus = doOperations(event);
41
            onComplete(event, opStatus);
42
        } else {
43
            MessagingUtils.warningDialog("Can not perform " + label, event.getTrigger(), allowStatus);
44
        }
45
        return null;
46
    }
47

  
48
    public void onComplete(ExecutionEvent event, IStatus status) {
49
        if(!status.isOK() && status.getException() != null) {
50
            ErrorDialog.openError(null, "Error executing " + label, null, status);
51
        }
52
        postOperations(event);
53
    }
54

  
55
    public abstract IStatus allowOperations(ExecutionEvent event);
56

  
57
    public abstract IStatus doOperations(ExecutionEvent event);
58

  
59
    public abstract void postOperations(ExecutionEvent event);
60

  
61
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmOperation.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.operation;
11

  
12
import org.eclipse.core.commands.ExecutionException;
13
import org.eclipse.core.commands.operations.AbstractOperation;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17

  
18
/**
19
 * @author cmathew
20
 * @date 16 Jun 2015
21
 *
22
 */
23
public abstract class RemotingCdmOperation extends AbstractOperation {
24

  
25
    public RemotingCdmOperation(String label) {
26
        super(label);
27
    }
28

  
29
    /* (non-Javadoc)
30
     * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
31
     */
32
    @Override
33
    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
34

  
35
       boolean success = doExecute(monitor, info);
36
       postExecute(success);
37
       return onComplete(success);
38
    }
39

  
40
    public abstract boolean doExecute(IProgressMonitor monitor, IAdaptable info);
41

  
42
    public void postExecute(boolean success) {}
43

  
44
    public abstract IStatus onComplete(boolean success);
45

  
46
    /* (non-Javadoc)
47
     * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
48
     */
49
    @Override
50
    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
51
        // TODO Auto-generated method stub
52
        return null;
53
    }
54

  
55
    /* (non-Javadoc)
56
     * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
57
     */
58
    @Override
59
    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
60
        // TODO Auto-generated method stub
61
        return null;
62
    }
63

  
64
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmUpdateOperation.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.operation;
11

  
12
import java.util.Collection;
13

  
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.MultiStatus;
18
import org.eclipse.core.runtime.Status;
19

  
20
import eu.etaxonomy.cdm.api.service.UpdateResult;
21

  
22
/**
23
 * @author cmathew
24
 * @date 16 Jun 2015
25
 *
26
 */
27
public abstract class RemotingCdmUpdateOperation extends RemotingCdmOperation {
28

  
29
    private UpdateResult updateResult;
30

  
31
    /**
32
     * @param label
33
     */
34
    public RemotingCdmUpdateOperation(String label) {
35
        super(label);
36
    }
37

  
38
    /* (non-Javadoc)
39
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmOperation#doExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
40
     */
41
    @Override
42
    public boolean doExecute(IProgressMonitor monitor, IAdaptable info) {
43
        updateResult = doUpdateExecute(monitor, info);
44
        return updateResult.isOk();
45
    }
46

  
47
    public abstract UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info);
48

  
49
    /* (non-Javadoc)
50
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmOperation#onComplete(boolean)
51
     */
52
    @Override
53
    public IStatus onComplete(boolean success) {
54

  
55
        if(success) {
56
            return Status.OK_STATUS;
57
        }
58

  
59
        if(updateResult != null) {
60
            Collection<Exception> exceptions = updateResult.getExceptions();
61
            Status[] childStatus = new Status[exceptions.size()];
62

  
63
            for(Exception ex : exceptions) {
64
                Status status = new Status(IStatus.ERROR,
65
                        "unknown",
66
                        IStatus.ERROR,
67
                        ex.getLocalizedMessage(),
68
                        ex);
69
            }
70

  
71
            MultiStatus multiStatus = new MultiStatus("unknown",
72
                    IStatus.ERROR,
73
                    childStatus,
74
                    getLabel() + " is in error",
75
                    null);
76
            return multiStatus;
77
        }
78
        return null;
79
    }
80
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/CdmStorePropertyTester.java
1 1
// $Id$
2 2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10 10

  
11 11
package eu.etaxonomy.taxeditor.preference;
12 12

  
......
21 21
 */
22 22
public class CdmStorePropertyTester extends PropertyTester {
23 23

  
24
	private static final String EDITOR_IS_CONNECTED_TO_DB = "isCdmStoreConnected";
24
    private static final String EDITOR_IS_CONNECTED_TO_DB = "isCdmStoreConnected";
25
    private static final String IS_REMOTING = "isRemoting";
26

  
27
    @Override
28
    public boolean test(Object receiver, String property, Object[] args,
29
            Object expectedValue) {
30

  
31
        if(EDITOR_IS_CONNECTED_TO_DB.equals(property)){
32
            return isCdmStoreConnected();
33
        }
34

  
35
        if(IS_REMOTING.equals(property)){
36
            return isRemoting();
37
        }
38
        return false;
39
    }
40

  
41
    private boolean isCdmStoreConnected(){
42
        boolean active = CdmStore.isActive();
43
        return active;
44
    }
25 45

  
26
	@Override
27
	public boolean test(Object receiver, String property, Object[] args,
28
			Object expectedValue) {
46
    private boolean isRemoting() {
47
        return CdmStore.getCurrentSessionManager().isRemoting();
48
    }
29 49

  
30
	    if(EDITOR_IS_CONNECTED_TO_DB.equals(property)){
31
	        return isCdmStoreConnected();
32
	    }
33
		return false;
34
	}
35 50

  
36
	private boolean isCdmStoreConnected(){
37
	    boolean active = CdmStore.isActive();
38
	    return active;
39
	}
40 51
}

Also available in: Unified diff