Project

General

Profile

« Previous | Next » 

Revision 033aad78

Added by Katja Luther over 7 years ago

all polytomouskey related handler are now extended from RemotingCdmHandler

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyEditorLabels.java
19 19
    public static final String CREATE_CHILD_POLYTOMOUS_KEY_NODE_LABEL = "Create Child Polytomous Key Node";
20 20
    public static final String CREATE_SIBLING_POLYTOMOUS_KEY_NODE_LABEL = "Create Sibling Polytomous Key Node";
21 21
    public static final String INSERT_NODE_POLYTOMOUS_KEY_NODE_LABEL = "Insert Node Polytomous Key Node";
22
    public static final String DELETE_NODE_POLYTOMOUS_KEY_NODE_LABEL = "Insert Node Polytomous Key Node";
22 23

  
23 24
    public static final String NO_KEY_NODE_FOR_CHILD_SELECTED_MESSAGE = "No Key Node Selected.Please right-click on a specific key node to create a new child key node.";
24 25
    public static final String NO_KEY_NODE_FOR_SIBLING_SELECTED_MESSAGE = "No Key Node Selected.Please right-click on a specific key node to create a new sibling key node.";
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java
344 344
        }
345 345

  
346 346
        viewer.refresh();
347
        viewer.setSelection(new StructuredSelection(element));
347

  
348 348
	}
349 349

  
350 350
    /* (non-Javadoc)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/AbstractPolytomousKeyNodeHandler.java
1
/**
2
* Copyright (C) 2016 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.editor.key.polytomous.handler;
10

  
11
import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
12
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
13

  
14
/**
15
 * @author k.luther
16
 * @date 24.11.2016
17
 *
18
 */
19
public abstract class AbstractPolytomousKeyNodeHandler extends RemotingCdmHandler {
20

  
21

  
22
    IPolytomousKeyEditorPage editorPage;
23

  
24
    /**
25
     * @param label
26
     */
27
    public AbstractPolytomousKeyNodeHandler(String label) {
28
        super(label);
29
        // TODO Auto-generated constructor stub
30
    }
31

  
32

  
33

  
34

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

  
11 11
package eu.etaxonomy.taxeditor.editor.key.polytomous.handler;
12 12

  
13
import org.eclipse.core.commands.AbstractHandler;
14 13
import org.eclipse.core.commands.ExecutionEvent;
15 14
import org.eclipse.core.commands.ExecutionException;
16 15
import org.eclipse.core.commands.common.NotDefinedException;
16
import org.eclipse.core.commands.operations.AbstractOperation;
17 17
import org.eclipse.core.commands.operations.IUndoContext;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Status;
18 20
import org.eclipse.jface.dialogs.MessageDialog;
19 21
import org.eclipse.jface.viewers.IStructuredSelection;
20 22
import org.eclipse.ui.IEditorPart;
21 23
import org.eclipse.ui.handlers.HandlerUtil;
22 24

  
23
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
24
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
25 25
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
26 26
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
27 27
import eu.etaxonomy.taxeditor.editor.EditorUtil;
28 28
import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
29 29
import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
30
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
31
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
30 32
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.DeleteNodeOperation;
31 33
import eu.etaxonomy.taxeditor.model.MessagingUtils;
32 34
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
33
import eu.etaxonomy.taxeditor.store.CdmStore;
34 35

  
35 36
/**
36 37
 * @author n.hoffmann
37 38
 * @created Dec 6, 2010
38 39
 * @version 1.0
39 40
 */
40
public class DeleteNodeHandler extends AbstractHandler {
41
public class DeleteNodeHandler extends AbstractPolytomousKeyNodeHandler {
42

  
43

  
44
    PolytomousKeyNode nodeToBeDeleted;
45
    /**
46
     * @param label
47
     */
48
    public DeleteNodeHandler(String label) {
49
        super(label);
50

  
51
    }
52

  
53

  
54

  
55
    public DeleteNodeHandler() {
56
        super(PolytomousKeyEditorLabels.DELETE_NODE_POLYTOMOUS_KEY_NODE_LABEL);
57
    }
41 58

  
42 59
	/*
43 60
	 * (non-Javadoc)
44
	 * 
61
	 *
45 62
	 * @see
46 63
	 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
47 64
	 * ExecutionEvent)
......
73 90

  
74 91
					for (Object element : selection.toArray()) {
75 92
						PolytomousKeyNode keyNode = HibernateProxyHelper.deproxy(element, PolytomousKeyNode.class);
76
						
93

  
77 94
						AbstractPostOperation operation = new DeleteNodeOperation(
78 95
								label, undoContext, keyNode, editorPage);
79 96
						EditorUtil.executeOperation(operation);
......
86 103
	                MessageDialog.openInformation(
87 104
	                        EditorUtil.getShell(),
88 105
	                        "No Key Node Selected",
89
	                        "Please right-click on a specific key node to delete a key node.");	            
90
			}			
106
	                        "Please right-click on a specific key node to delete a key node.");
107
			}
91 108
		}
92 109

  
93 110
		return null;
94 111
	}
95 112

  
113
    /**
114
     * {@inheritDoc}
115
     */
116
    @Override
117
    public IStatus allowOperations(ExecutionEvent event) {
118
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
119

  
120
        if (editor instanceof KeyEditor) {
121
            editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
122
                    .getActiveEditor();
123

  
124
            if (editorPage instanceof PolytomousKeyListEditor) {
125
                PolytomousKeyListEditor klEditor = (PolytomousKeyListEditor) editorPage;
126
                IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
127
                    if (selection.getFirstElement() instanceof PolytomousKeyNode) {
128
                        nodeToBeDeleted = (PolytomousKeyNode) selection.getFirstElement();
129
                    } else {
130
                        return new Status(IStatus.ERROR,
131
                                "unknown",
132
                                PolytomousKeyEditorLabels.NO_KEY_NODE_FOR_CHILD_SELECTED_MESSAGE);
133
                    }
134
                }
135

  
136
        }
137
        return Status.OK_STATUS;
138
    }
139

  
140
    /**
141
     * {@inheritDoc}
142
     */
143
    @Override
144
    public AbstractOperation prepareOperation(ExecutionEvent event) {
145
        IUndoContext undoContext = EditorUtil.getUndoContext();
146
        String label = "";
147
        try {
148
            label = event.getCommand().getName();
149
        } catch (NotDefinedException e) {
150
            MessagingUtils.warn(getClass(), "Command name not set.");
151
        }
152
        return new DeleteNodeOperation(label, undoContext, nodeToBeDeleted, editorPage);
153
    }
154

  
155
    /**
156
     * {@inheritDoc}
157
     */
158
    @Override
159
    public void onComplete() {
160
        // TODO Auto-generated method stub
161

  
162
    }
163

  
96 164
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/InsertNewNodeHandler.java
23 23
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
24 24
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
25 25
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.InsertPolytomousKeyNodeOperation;
26
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
27 26

  
28 27
/**
29 28
 * @author k.luther
30 29
 * @date 17.11.2016
31 30
 *
32 31
 */
33
public class InsertNewNodeHandler extends RemotingCdmHandler{
32
public class InsertNewNodeHandler extends AbstractPolytomousKeyNodeHandler{
34 33

  
35 34
    private PolytomousKeyNode parentNode ;
36 35

  
36

  
37 37
    public InsertNewNodeHandler() {
38 38
        super(PolytomousKeyEditorLabels.INSERT_NODE_POLYTOMOUS_KEY_NODE_LABEL);
39 39
    }
......
47 47
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
48 48

  
49 49
        if (editor instanceof KeyEditor) {
50
            IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
50
            editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
51 51
                    .getActiveEditor();
52 52

  
53 53
            if (editorPage instanceof PolytomousKeyListEditor) {
......
76 76
     */
77 77
    @Override
78 78
    public AbstractOperation prepareOperation(ExecutionEvent event) {
79
        return new InsertPolytomousKeyNodeOperation(event.getTrigger(), false, parentNode);
79
        return new InsertPolytomousKeyNodeOperation(event.getTrigger(), false, parentNode, editorPage);
80 80
    }
81 81

  
82 82
    /**
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/RemotingCreateChildPolytomousKeyNodeHandler.java
24 24
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
25 25
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
26 26
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.RemotingCreatePolytomousKeyNodeOperation;
27
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
28 27

  
29 28
/**
30 29
 * @author cmathew
31 30
 * @date 21 Jul 2015
32 31
 *
33 32
 */
34
public class RemotingCreateChildPolytomousKeyNodeHandler extends RemotingCdmHandler {
33
public class RemotingCreateChildPolytomousKeyNodeHandler extends AbstractPolytomousKeyNodeHandler {
35 34

  
36 35
    private PolytomousKeyNode parentNode;
36
    IPolytomousKeyEditorPage editorPage;
37

  
37 38

  
38 39
    public RemotingCreateChildPolytomousKeyNodeHandler() {
39 40
        super(PolytomousKeyEditorLabels.CREATE_CHILD_POLYTOMOUS_KEY_NODE_LABEL);
......
46 47
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
47 48

  
48 49
        if (editor instanceof KeyEditor) {
49
            IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
50
            editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
50 51
                    .getActiveEditor();
51 52

  
52 53
            if (editorPage instanceof PolytomousKeyListEditor) {
......
75 76
     */
76 77
    @Override
77 78
    public AbstractOperation prepareOperation(ExecutionEvent event) {
78
        return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode);
79
        return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode, editorPage);
79 80
    }
80 81

  
81 82
    /* (non-Javadoc)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/RemotingCreateSiblingPolytomousKeyNodeHandler.java
14 14
import org.eclipse.core.runtime.IStatus;
15 15
import org.eclipse.core.runtime.Status;
16 16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.ui.IEditorPart;
17 18
import org.eclipse.ui.handlers.HandlerUtil;
18 19

  
19 20
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
21
import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
22
import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
20 23
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
21 24
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.RemotingCreatePolytomousKeyNodeOperation;
22
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
23 25

  
24 26
/**
25 27
 * @author cmathew
26 28
 * @date 21 Jul 2015
27 29
 *
28 30
 */
29
public class RemotingCreateSiblingPolytomousKeyNodeHandler extends RemotingCdmHandler {
31
public class RemotingCreateSiblingPolytomousKeyNodeHandler extends AbstractPolytomousKeyNodeHandler {
30 32

  
31 33
    private PolytomousKeyNode parentNode;
32 34

  
35

  
33 36
    public RemotingCreateSiblingPolytomousKeyNodeHandler() {
34 37
        super(PolytomousKeyEditorLabels.CREATE_SIBLING_POLYTOMOUS_KEY_NODE_LABEL);
35 38
    }
......
38 41
     */
39 42
    @Override
40 43
    public IStatus allowOperations(ExecutionEvent event) {
41

  
44
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
42 45
        IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
43

  
46
        editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
47
                .getActiveEditor();
44 48
        if (selection.getFirstElement() instanceof PolytomousKeyNode) {
45 49
            parentNode = (PolytomousKeyNode) selection.getFirstElement();
46 50
        } else {
......
57 61
     */
58 62
    @Override
59 63
    public AbstractOperation prepareOperation(ExecutionEvent event) {
60
        return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode.getParent());
64
        return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode.getParent(), editorPage);
61 65
    }
62 66

  
63 67
    /* (non-Javadoc)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/DeleteNodeOperation.java
16 16
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
17 17
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
18 18
import eu.etaxonomy.taxeditor.model.MessagingUtils;
19
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
19
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
20 20
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
21 21
import eu.etaxonomy.taxeditor.store.CdmStore;
22 22

  
......
24 24
 * @author n.hoffmann
25 25
 *
26 26
 */
27
public class DeleteNodeOperation extends AbstractPostTaxonOperation {
27
public class DeleteNodeOperation extends AbstractPostOperation<PolytomousKeyNode> {
28 28

  
29 29
	private final PolytomousKeyNode parent;
30 30
	private final PolytomousKeyNode node;
31 31

  
32

  
32 33
	public DeleteNodeOperation(String label, IUndoContext undoContext,
33 34
			PolytomousKeyNode node, IPostOperationEnabled postOperationEnabled) {
34
		super(label, undoContext, postOperationEnabled);
35
	    super(label, undoContext, node, postOperationEnabled);
35 36
		this.node = node;
36 37
		this.parent = node.getParent();
37 38
	}
......
63 64
		} else{
64 65
			result = service.delete(node.getUuid(), true);
65 66
		}
66
		
67

  
67 68
		if (!result.isOk() || result.getExceptions().size() > 0){
68 69
			Exception t = new Exception();
69 70
			if (result.getExceptions().size() >1){
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/InsertPolytomousKeyNodeOperation.java
17 17
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
18 18
import eu.etaxonomy.cdm.model.common.CdmBase;
19 19
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
20
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
20 21
import eu.etaxonomy.taxeditor.operation.RemotingCdmDefaultOperation;
21 22

  
22 23
/**
......
30 31

  
31 32
    private final static String LABEL = "Insert new polytomous key node";
32 33

  
34
    /**
35
    *
36
    */
37
   protected IPostOperationEnabled postOperationEnabled;
38

  
33 39
    /**
34 40
     * @param label
35 41
     * @param action
......
38 44
     */
39 45
    public InsertPolytomousKeyNodeOperation(Object source,
40 46
            boolean async,
41
            PolytomousKeyNode parentNode) {
47
            PolytomousKeyNode parentNode, IPostOperationEnabled postOperationEnabled) {
42 48
        super(LABEL, Action.Create, source, async);
43 49
        this.parentNode = parentNode;
50
        this.postOperationEnabled = postOperationEnabled;
44 51
    }
45 52

  
46 53
    /**
......
58 65
        for (PolytomousKeyNode node: copy){
59 66
           childNode.addChild(node);
60 67
        }
61

  
68
        this.postOperationEnabled.postOperation(childNode);
62 69
        return childNode;
63 70
    }
64 71

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/RemotingCreatePolytomousKeyNodeOperation.java
15 15
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
16 16
import eu.etaxonomy.cdm.model.common.CdmBase;
17 17
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
18
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
18 19
import eu.etaxonomy.taxeditor.operation.RemotingCdmDefaultOperation;
19 20

  
20 21
/**
......
26 27

  
27 28
    private final PolytomousKeyNode parentNode;
28 29
    private PolytomousKeyNode childNode;
30
    /**
31
    *
32
    */
33
   protected IPostOperationEnabled postOperationEnabled;
29 34

  
30 35
    public PolytomousKeyNode getChildNode() {
31 36
        return childNode;
......
35 40

  
36 41
    public RemotingCreatePolytomousKeyNodeOperation(Object source,
37 42
            boolean async,
38
            PolytomousKeyNode parentNode){
43
            PolytomousKeyNode parentNode, IPostOperationEnabled postOperationEnabled){
39 44
        super(LABEL, Action.Create, source, async);
40 45
        this.parentNode = parentNode;
46
        this.postOperationEnabled = postOperationEnabled;
41 47
    }
42 48

  
43 49
    /* (non-Javadoc)
......
47 53
    protected CdmBase doSimpleExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
48 54
      childNode = PolytomousKeyNode.NewInstance();
49 55
      parentNode.addChild(childNode);
50
      return childNode;
56
      if (postOperationEnabled.postOperation(childNode)){
57
          return childNode;
58
      }else {
59
          return null;
60
      }
51 61
    }
52 62

  
63

  
64

  
65

  
66

  
67

  
53 68
}

Also available in: Unified diff