Project

General

Profile

« Previous | Next » 

Revision 9bc47800

Added by Cherian Mathew over 8 years ago

Add remoting operation / handlers for key list editor

View differences:

eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/EntityCacherDebugResult.java
123 123
                sb.append(System.getProperty("line.separator"));
124 124
                CdmEntityInfo cei = entry.getKey();
125 125
                CdmBase cb = (CdmBase) cei.getObject();
126
                Object cbParent = cei.getParent().getObject();
127 126

  
127
                sb.append(" - " + cei.getField().getName() + ":" + cb.getUserFriendlyTypeName() + "/" + cb.getId());
128
                if(cei.getParent() != null) {
129
                    Object cbParent = cei.getParent().getObject();
130
                    sb.append("     in entity " + cbParent.getClass().getCanonicalName());
131
                    if(cbParent instanceof CdmBase) {
128 132

  
129
                sb.append(" - " + cei.getField().getName() + ":" + cb.getUserFriendlyTypeName() + "/" + cb.getId() +
130
                        " in entity " + cbParent.getClass().getCanonicalName());
131
                if(cbParent instanceof CdmBase) {
132
                    sb.append(" with id : " + ((CdmBase)cbParent).getId());
133
                        sb.append(" with id : " + ((CdmBase)cbParent).getId());
134
                    }
133 135
                }
134 136
                sb.append(System.getProperty("line.separator"));
135 137
                sb.append("  -- entity belongs to cache(s) : " + getCachesContainingEntity(cb));
......
138 140

  
139 141
                CdmEntityInfo dupCei = entry.getValue();
140 142
                CdmBase dupCb = (CdmBase) dupCei.getObject();
141
                Object dupCbParent = dupCei.getParent().getObject();
142 143

  
143
                sb.append(" - " + dupCei.getField().getName() + ":" + dupCb.getUserFriendlyTypeName() + "/" + dupCb.getId() +
144
                        " in entity " + dupCbParent.getClass().getCanonicalName());
145
                if(dupCbParent instanceof CdmBase) {
146
                    sb.append(" with id : " + ((CdmBase)dupCbParent).getId());
144
                String dupCeiFieldName = "";
145
                if(dupCei.getField() != null) {
146
                    dupCeiFieldName = dupCei.getField().getName();
147
                }
148
                sb.append(" - " + dupCeiFieldName + ":" + dupCb.getUserFriendlyTypeName() + "/" + dupCb.getId());
149
                if(dupCei.getParent() != null) {
150
                    Object dupCbParent = dupCei.getParent().getObject();
151
                    sb.append("      in entity " + dupCbParent.getClass().getCanonicalName());
152
                    if(dupCbParent instanceof CdmBase) {
153
                        sb.append(" with id : " + ((CdmBase)dupCbParent).getId());
154
                    }
147 155
                }
148 156
                sb.append(System.getProperty("line.separator"));
149 157
                sb.append("  -- entity belongs to cache(s) : " + getCachesContainingEntity(dupCb));
......
350 358
            childCei.setField(field);
351 359

  
352 360
            if(o != null) {
361
                boolean isProxy = ProxyUtils.isProxy(o);
353 362

  
354
                if(o instanceof HibernateProxy) {
355
                    isHibernateProxy = true;
356
                }
357

  
358
                if(o instanceof PersistentCollection) {
359
                    isPersistentCollection = true;
360
                }
361
                childCei.setObject(o);
362
                childCei.setProxy(isHibernateProxy || isPersistentCollection);
363
                if(!isHibernateProxy && !isPersistentCollection) {
364

  
363
                childCei.setProxy(isProxy);
364
                if(!isProxy) {
365
                    childCei.setObject(ProxyUtils.deproxy(o));
365 366
                    if(CdmBase.class.isAssignableFrom(o.getClass())) {
366 367
                        logger.info("found initialised cdm entity '" + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
367 368
                        cdmEntityInSubGraph  = (CdmBase)o;
eu.etaxonomy.taxeditor.editor/plugin.xml
1109 1109
            class="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.ToggleShowOnlyIndividualAssociationsHandler"
1110 1110
            commandId="eu.etaxonomy.taxeditor.editor.handler.showOnlyIndividualAssociations">
1111 1111
      </handler>
1112
      <handler
1113
            class="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.RemotingCreateChildPolytomousKeyNodeHandler"
1114
            commandId="eu.etaxonomy.taxeditor.key.polytomous.command.new.child">
1115
         <activeWhen>
1116
            <reference
1117
                  definitionId="isRemoting">
1118
            </reference>
1119
         </activeWhen>
1120
      </handler>
1121
      <handler
1122
            class="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.RemotingCreateSiblingPolytomousKeyNodeHandler"
1123
            commandId="eu.etaxonomy.taxeditor.key.polytomous.command.new.sibling">
1124
         <activeWhen>
1125
            <reference
1126
                  definitionId="isRemoting">
1127
            </reference>
1128
         </activeWhen>
1129
      </handler>
1112 1130
   </extension>
1113 1131
   <extension
1114 1132
         name="%extension.name"
......
1617 1635
            </test>
1618 1636
         </with>
1619 1637
      </definition>
1638
      <definition
1639
            id="isRemoting">
1640
         <test
1641
               property="eu.etaxonomy.taxeditor.preference.CdmStorePropertyTester.isRemoting">
1642
         </test>
1643
      </definition>
1620 1644
   </extension>
1621 1645
   <extension
1622 1646
         point="org.eclipse.core.expressions.propertyTesters">
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditor.java
17 17
import org.eclipse.ui.PartInitException;
18 18
import org.eclipse.ui.forms.editor.FormEditor;
19 19

  
20
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
21
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
22
import eu.etaxonomy.cdm.api.application.ICdmChangeListener;
20 23
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
21 24
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
25
import eu.etaxonomy.cdm.model.common.CdmBase;
22 26
import eu.etaxonomy.cdm.model.description.PolytomousKey;
23 27
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
24 28
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
......
35 39
 * @version 1.0
36 40
 */
37 41
public class KeyEditor extends FormEditor implements IConversationEnabled,
38
		IDirtyMarkable, IPartContentHasDetails {
42
		IDirtyMarkable, IPartContentHasDetails, ICdmChangeListener {
39 43

  
40 44
	public static final String ID = "eu.etaxonomy.taxeditor.editor.key";
41 45

  
......
57 61
    public void init(IEditorSite site, IEditorInput input)
58 62
            throws PartInitException {
59 63
        polytomousKeyEditorInput = (PolytomousKeyEditorInput)input;
64
        CdmApplicationState.getCurrentDataChangeService().register(this);
60 65
        super.init(site, input);
61 66
    }
62 67

  
......
201 206
		conversation.unregisterForDataStoreChanges(this);
202 207
		conversation.close();
203 208
		polytomousKeyEditorInput.dispose();
209
		CdmApplicationState.getCurrentDataChangeService().unregister(this);
204 210
		super.dispose();
205 211
	}
206 212

  
......
236 242
		PolytomousKey key = polytomousKeyEditorInput.getKey();
237 243
		setPartName(key.getTitleCache());
238 244
	}
245

  
246
    /* (non-Javadoc)
247
     * @see eu.etaxonomy.cdm.api.application.ICdmChangeListener#onChange(eu.etaxonomy.cdm.api.application.CdmChangeEvent)
248
     */
249
    @Override
250
    public void onChange(CdmChangeEvent event) {
251
        editorDirtyStateChanged();
252
        IEditorPart activeEditor = getActiveEditor();
253
        if (activeEditor instanceof IDirtyMarkable) {
254
            for(CdmBase cdmBase : event.getChangedObjects()) {
255
                ((IDirtyMarkable) activeEditor).changed(cdmBase);
256
            }
257
        }
258
    }
239 259
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyEditorLabels.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.editor.key.polytomous;
11

  
12
/**
13
 * @author cmathew
14
 * @date 21 Jul 2015
15
 *
16
 */
17
public interface PolytomousKeyEditorLabels {
18

  
19
    public static final String CREATE_CHILD_POLYTOMOUS_KEY_NODE_LABEL = "Create Child Polytomous Key Node";
20
    public static final String CREATE_SIBLING_POLYTOMOUS_KEY_NODE_LABEL = "Create Sibling Polytomous Key Node";
21

  
22
    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.";
23
    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.";
24
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java
262 262
	}
263 263

  
264 264
	public PolytomousKey getViewerInputKey() {
265
	    return (PolytomousKey) viewer.getInput();
265
	    return ((PolytomousKeyEditorInput) viewer.getInput()).getKey();
266 266
	}
267 267
	private void createMenu() {
268 268
		// register context menu
......
325 325
			for (PolytomousKeyNode child : children) {
326 326
				viewer.update(child, null);
327 327
			}
328
		}
329

  
330 328

  
329
		}
330
		viewer.refresh();
331 331
	}
332 332

  
333 333
    /* (non-Javadoc)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/RemotingCreateChildPolytomousKeyNodeHandler.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.editor.key.polytomous.handler;
11

  
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.operations.AbstractOperation;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Status;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.ui.IEditorPart;
18
import org.eclipse.ui.handlers.HandlerUtil;
19

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

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

  
36
    private PolytomousKeyNode parentNode;
37

  
38
    public RemotingCreateChildPolytomousKeyNodeHandler() {
39
        super(PolytomousKeyEditorLabels.CREATE_CHILD_POLYTOMOUS_KEY_NODE_LABEL);
40
    }
41
    /* (non-Javadoc)
42
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
43
     */
44
    @Override
45
    public IStatus allowOperations(ExecutionEvent event) {
46
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
47

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

  
52
            if (editorPage instanceof PolytomousKeyListEditor) {
53
                PolytomousKeyListEditor klEditor = (PolytomousKeyListEditor) editorPage;
54
                if(klEditor.getTableItemCount() == 0) {
55
                    PolytomousKey pk = klEditor.getViewerInputKey();
56
                    parentNode = pk.getRoot();
57

  
58
                } else {
59
                    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
60
                    if (selection.getFirstElement() instanceof PolytomousKeyNode) {
61
                        parentNode = (PolytomousKeyNode) selection.getFirstElement();
62
                    } else {
63
                        return new Status(IStatus.ERROR,
64
                                "unknown",
65
                                PolytomousKeyEditorLabels.NO_KEY_NODE_FOR_CHILD_SELECTED_MESSAGE);
66
                    }
67
                }
68
            }
69
        }
70
        return Status.OK_STATUS;
71
    }
72

  
73
    /* (non-Javadoc)
74
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
75
     */
76
    @Override
77
    public AbstractOperation prepareOperation(ExecutionEvent event) {
78
        return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode);
79
    }
80

  
81
    /* (non-Javadoc)
82
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
83
     */
84
    @Override
85
    public void onComplete() {
86
        // TODO Auto-generated method stub
87

  
88
    }
89

  
90
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/RemotingCreateSiblingPolytomousKeyNodeHandler.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.editor.key.polytomous.handler;
11

  
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.operations.AbstractOperation;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Status;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.ui.handlers.HandlerUtil;
18

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

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

  
31
    private PolytomousKeyNode parentNode;
32

  
33
    public RemotingCreateSiblingPolytomousKeyNodeHandler() {
34
        super(PolytomousKeyEditorLabels.CREATE_SIBLING_POLYTOMOUS_KEY_NODE_LABEL);
35
    }
36
    /* (non-Javadoc)
37
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
38
     */
39
    @Override
40
    public IStatus allowOperations(ExecutionEvent event) {
41

  
42
        IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
43

  
44
        if (selection.getFirstElement() instanceof PolytomousKeyNode) {
45
            parentNode = (PolytomousKeyNode) selection.getFirstElement();
46
        } else {
47
            return new Status(IStatus.ERROR,
48
                    "unknown",
49
                    PolytomousKeyEditorLabels.NO_KEY_NODE_FOR_SIBLING_SELECTED_MESSAGE);
50
        }
51

  
52
        return Status.OK_STATUS;
53
    }
54

  
55
    /* (non-Javadoc)
56
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
57
     */
58
    @Override
59
    public AbstractOperation prepareOperation(ExecutionEvent event) {
60
        return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode.getParent());
61
    }
62

  
63
    /* (non-Javadoc)
64
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
65
     */
66
    @Override
67
    public void onComplete() {
68
        // TODO Auto-generated method stub
69

  
70
    }
71

  
72
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/CreateNodeOperation.java
9 9
import org.eclipse.core.runtime.IProgressMonitor;
10 10
import org.eclipse.core.runtime.IStatus;
11 11

  
12
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
13 12
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
14 13
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
15 14
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
......
39 38
		childNode = PolytomousKeyNode.NewInstance();
40 39

  
41 40
		parentNode.addChild(childNode);
42
		childNode = CdmApplicationState.getCurrentAppConfig().getPolytomousKeyNodeService().merge(childNode);
41

  
43 42
		return postExecute(childNode);
44 43
	}
45 44

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/RemotingCreatePolytomousKeyNodeOperation.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.editor.key.polytomous.operation;
11

  
12
import org.eclipse.core.runtime.IAdaptable;
13
import org.eclipse.core.runtime.IProgressMonitor;
14

  
15
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
16
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
17
import eu.etaxonomy.cdm.model.common.CdmBase;
18
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
19
import eu.etaxonomy.taxeditor.operation.RemotingCdmMergeOperation;
20

  
21
/**
22
 * @author cmathew
23
 * @date 21 Jul 2015
24
 *
25
 */
26
public class RemotingCreatePolytomousKeyNodeOperation extends RemotingCdmMergeOperation {
27

  
28
    private final PolytomousKeyNode parentNode;
29

  
30
    private final static String LABEL = "Create new polytomous key node";
31

  
32
    public RemotingCreatePolytomousKeyNodeOperation(Object source,
33
            boolean async,
34
            PolytomousKeyNode parentNode){
35
        super(LABEL, Action.Create, source, async);
36
        this.parentNode = parentNode;
37
    }
38
    /* (non-Javadoc)
39
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmMergeOperation#doMergeExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
40
     */
41
    @Override
42
    protected CdmBase doMergeExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
43
        PolytomousKeyNode childNode = PolytomousKeyNode.NewInstance();
44
        parentNode.addChild(childNode);
45
        return CdmApplicationState.getCurrentAppConfig().getPolytomousKeyNodeService().merge(childNode);
46
    }
47

  
48
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmMergeOperation.java
12 12
import org.eclipse.core.runtime.IAdaptable;
13 13
import org.eclipse.core.runtime.IProgressMonitor;
14 14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Status;
15 16

  
16 17
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
17 18
import eu.etaxonomy.cdm.model.common.CdmBase;
......
55 56
     */
56 57
    @Override
57 58
    protected IStatus onComplete(boolean success) {
58
        // TODO Auto-generated method stub
59
        return null;
59
        return Status.OK_STATUS;
60 60
    }
61 61

  
62 62
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmOperation.java
71 71
        }
72 72
    }
73 73

  
74
    protected void fireDataChangeEvent(CdmBase cdmBase) {
75
        if(cdmBase != null) {
76
            CdmApplicationState.getCurrentDataChangeService().fireChangeEvent(new CdmChangeEvent(action, cdmBase, source.getClass()), async);
77
        }
78
    }
79

  
74 80
    /* (non-Javadoc)
75 81
     * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
76 82
     */

Also available in: Unified diff