CdmAuthorityEditor : Editor for updating Cdm authorities
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 9 Apr 2013 12:50:57 +0000 (12:50 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 9 Apr 2013 12:50:57 +0000 (12:50 +0000)
CdmAuthorityEditorInput : Input for the CdmAuthorityEditor
EditCdmAuthoritiesHandler : Handler to open CdmAuthorityEditor
EditorUtil : added method to open CdmAuthorityEditor
plugin.xml : added extensions to the BulkEditor menu to open the CdmAuthorityEditor checking if the selected object is Group

.gitattributes
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditor.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditorInput.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/handler/EditCdmAuthoritiesHandler.java [new file with mode: 0644]

index 81d8ea17a0002c62e33217ec2bab91d54dfd389f..beba8398d519837059517effdd664132385cee6b 100644 (file)
@@ -350,6 +350,9 @@ eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonE
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInputFactory.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/UseObjectManager.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/ViewerConfiguration.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditor.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditorInput.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/handler/EditCdmAuthoritiesHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/EditNewTaxonHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenParentHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/SaveAllHandler.java -text
index 9961cb68a39b53e967c7f767fb3ec238414533ba..dece78af052770ff988dbacbeac255f72a3ed6ec 100644 (file)
             id="eu.etaxonomy.taxeditor.editor.key.polytomous.list"
             name="Polytomous Key List Editor">
       </editor>
+      <editor
+            class="eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditor"
+            default="false"
+            id="eu.etaxonomy.taxeditor.editor.group.authority"
+            name="Cdm Authority Editor">
+      </editor>
    </extension>
       <extension
             point="org.eclipse.ui.views">
                style="push">
          </command>
       </menuContribution>
+      <menuContribution
+            allPopups="false"
+            locationURI="popup:#BulkEditorContext?before=taxeditor-bulkeditor.separator1">
+         <command
+               commandId="eu.etaxonomy.taxeditor.group.cdmauthorities.edit"
+               label="Edit Authorities"
+               style="push">
+            <visibleWhen>
+               <reference
+                     definitionId="isGroup">
+               </reference>
+            </visibleWhen>
+         </command>
+      </menuContribution>
    </extension>
    <extension
          point="org.eclipse.ui.handlers">
             id="eu.etaxonomy.taxeditor.editor.view.concept.command.open"
             name="Open Related Concept">
       </command>
+      <category
+            id="eu.etaxonomy.taxeditor.bulkeditor.group.category"
+            name="-- Group">
+      </category>
+      <command
+            categoryId="eu.etaxonomy.taxeditor.bulkeditor.group.category"
+            defaultHandler="eu.etaxonomy.taxeditor.editor.group.authority.handler.EditCdmAuthoritiesHandler"
+            id="eu.etaxonomy.taxeditor.group.cdmauthorities.edit"
+            name="Edit CDM Authorities">
+      </command>
    </extension>
    <extension
          point="org.eclipse.core.expressions.definitions">
             </test>
          </with>
       </definition>
+      <definition
+            id="isGroup">
+         <with
+               variable="activeEditor">
+            <test
+                  property="taxeditor-bulkeditor.propertyTester.isGroup">
+            </test>
+         </with>
+      </definition>
    </extension>
    <extension
          point="org.eclipse.core.expressions.propertyTesters">
             properties="isMedia,isDescription,isDescriptionElement,isDeletable,isFeatureNodeContainer,isImageGallery"
             type="org.eclipse.jface.viewers.TreeSelection">
       </propertyTester>
+      <propertyTester
+            class="eu.etaxonomy.taxeditor.bulkeditor.command.BulkEditorPropertyTester"
+            id="taxeditor-bulkeditor.PropertyTester"
+            namespace="taxeditor-bulkeditor.propertyTester"
+            properties="isGroup"
+            type="eu.etaxonomy.taxeditor.bulkeditor.BulkEditor">
+      </propertyTester>
    </extension>
    <extension
          point="org.eclipse.ui.bindings">   
index 222bf2c60890352ea1fd390835eceeafa3645e9a..df7875ca6d99b8a571f90d0ba61dd54934d3e66a 100644 (file)
@@ -26,6 +26,8 @@ import org.eclipse.ui.IEditorReference;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.handlers.HandlerUtil;
 
+import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditorInput;
+import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditor;
 import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
 import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
 import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
@@ -73,6 +75,11 @@ public class EditorUtil extends AbstractUtility {
                        throws PartInitException {
                open(input, KeyEditor.ID);
        }
+       
+       public static void open(CdmAuthorityEditorInput input)
+                       throws PartInitException {
+               open(input, CdmAuthorityEditor.ID);
+       }
 
        /**
         * Taxon Editors may be opened by supplying a taxon node uuid. Session gets
@@ -317,4 +324,10 @@ public class EditorUtil extends AbstractUtility {
                                .NewInstance(polytomousKeyUuid);
                open(input);
        }
+       
+       public static void openCdmAuthorities(UUID groupUuid)
+                       throws Exception {
+               CdmAuthorityEditorInput input = CdmAuthorityEditorInput.NewInstance(groupUuid);
+               open(input);
+       }
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditor.java
new file mode 100644 (file)
index 0000000..0d95276
--- /dev/null
@@ -0,0 +1,168 @@
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.group.authority;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorPart;
+import org.eclipse.swt.layout.FillLayout;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.model.common.Group;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
+import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityCompositeViewer;
+
+/**
+ * Editor responsible for editing authorities related to a particular {@link Group} entity.
+ * 
+ * @author cmathew
+ * @created Mar 28, 2013
+ *
+ */
+public class CdmAuthorityEditor extends EditorPart implements IConversationEnabled, IDirtyMarkableSelectionProvider {
+
+       public static final String ID = "eu.etaxonomy.taxeditor.editor.group.authority"; //$NON-NLS-1$
+
+       private boolean dirty;
+       private ConversationHolder conversation;
+       private CdmAuthorityCompositeViewer viewer;
+       
+       public CdmAuthorityEditor() {                   
+               
+       }
+
+       /**
+        * Create contents of the editor part.
+        * @param parent
+        */
+       @Override
+       public void createPartControl(Composite parent) {
+               Composite container = new Composite(parent, SWT.NONE);
+               container.setLayout(new FillLayout(SWT.HORIZONTAL));
+               
+               this.viewer = new CdmAuthorityCompositeViewer(container, this,((CdmAuthorityEditorInput) getEditorInput()).getGroup());
+
+               conversation = ((CdmAuthorityEditorInput) getEditorInput()).getConversationHolder();
+               setPartName(getEditorInput().getName());                        
+
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+        */
+       @Override
+       public void setFocus() {
+       
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+        */
+       @Override
+       public void doSave(IProgressMonitor monitor) {
+               try {
+                       monitor.beginTask("Saving CDM Authority Editor", 1);
+                       getConversationHolder().commit(true);                   
+                       dirty = false;
+                       firePropertyChange(PROP_DIRTY);
+                       monitor.worked(1);
+               } finally {
+                       monitor.done();
+                       viewer.save();
+               }
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.part.EditorPart#doSaveAs()
+        */
+       @Override
+       public void doSaveAs() {
+               // Do the Save As operation
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
+        */
+       @Override
+       public void init(IEditorSite site, IEditorInput input)
+                       throws PartInitException {
+               setSite(site);
+               setInput(input);
+       }       
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.part.EditorPart#isDirty()
+        */
+       @Override
+       public boolean isDirty() {
+               return dirty;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
+        */
+       @Override
+       public boolean isSaveAsAllowed() {
+               return false;
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
+        */
+       @Override
+       public void update(CdmDataChangeMap changeEvents) {
+               // TODO Auto-generated method stub
+               
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
+        */
+       @Override
+       public void changed(Object element) {
+               //FIXME : should be optimised to split changes into adding / removing authorities 
+               //        vs updating authorites
+               dirty=true;
+               firePropertyChange(PROP_DIRTY);
+               // if the change has happened on the group then refresh the table
+               if(element instanceof Group) {
+                       
+                       //FIXME: activating (setting focus) on the editor happens on every change
+                       //       This should be changed to only when the drop is successful
+                       getSite().getPage().activate(this);
+               }
+               
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
+        */
+       @Override
+       public ConversationHolder getConversationHolder() {
+               return conversation;
+       }
+       
+       /*
+        * (non-Javadoc)
+        * 
+        * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
+        */
+       @Override
+       public void dispose() {
+               conversation.unregisterForDataStoreChanges(this);
+               conversation.close();
+               super.dispose();
+       }
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditorInput.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditorInput.java
new file mode 100644 (file)
index 0000000..0e2553a
--- /dev/null
@@ -0,0 +1,141 @@
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.group.authority;
+
+import java.util.UUID;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.IGroupService;
+import eu.etaxonomy.cdm.model.common.Group;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * Editor input for the {@link CdmAuthorityEditor}.
+ * 
+ * @author cmathew
+ * @created Mar 28, 2013
+ *
+ */
+
+public class CdmAuthorityEditorInput implements IEditorInput, IConversationEnabled {
+       private ConversationHolder conversation;
+       private Group group;
+       
+       protected CdmAuthorityEditorInput(ConversationHolder conversation, Group group) {
+               this.conversation = conversation;
+               this.group = group;
+               
+       }
+       
+       /**
+        * Creates a new instance of the input for a given group.
+        * 
+        * @param groupUuid
+        * @return
+        * @throws Exception
+        */
+       public static CdmAuthorityEditorInput NewInstance(UUID groupUuid) throws Exception{
+               ConversationHolder conversation = CdmStore.createConversation();
+               Group group = CdmStore.getService(IGroupService.class).load(groupUuid, null);                   
+               return new CdmAuthorityEditorInput(conversation, group);
+       }
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+        */
+       @Override
+       public Object getAdapter(Class adapter) {
+               if (adapter == Group.class) {
+                       return this.group;
+               }               
+               
+               return null;
+       }
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
+        */
+       @Override
+       public void update(CdmDataChangeMap changeEvents) {
+               // TODO Auto-generated method stub
+               
+       }
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
+        */
+       @Override
+       public ConversationHolder getConversationHolder() {
+               return this.conversation;
+       }
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IEditorInput#exists()
+        */
+       @Override
+       public boolean exists() {
+               return group != null;
+       }
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
+        */
+       @Override
+       public ImageDescriptor getImageDescriptor() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IEditorInput#getName()
+        */
+       @Override
+       public String getName() {
+               return group.getName();
+       }
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IEditorInput#getPersistable()
+        */
+       @Override
+       public IPersistableElement getPersistable() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IEditorInput#getToolTipText()
+        */
+       @Override
+       public String getToolTipText() {
+               return getName();
+       }       
+       
+       /* (non-Javadoc)
+        * @see java.lang.Object#equals(java.lang.Object)
+        */
+       @Override
+       public boolean equals(Object object) {
+               if (object instanceof CdmAuthorityEditorInput
+                               && getGroup() != null
+                               && getGroup().equals(((CdmAuthorityEditorInput) object).getGroup())
+               ){
+                       return true;
+               }
+               return super.equals(object);
+       }
+       
+       /**
+        * Getter method for group member.
+        * 
+        * @return
+        */
+       public Group getGroup() {
+               return this.group;
+       }
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/handler/EditCdmAuthoritiesHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/handler/EditCdmAuthoritiesHandler.java
new file mode 100644 (file)
index 0000000..3d1940a
--- /dev/null
@@ -0,0 +1,88 @@
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.group.authority.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Display;
+
+import eu.etaxonomy.cdm.model.common.Group;
+import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditor;
+import eu.etaxonomy.taxeditor.model.LineSelection;
+
+
+/**
+ * Handler which opens an instance of the {@link CdmAuthorityEditor} for a particluar group.
+ * 
+ * @author cmathew
+ * @created Mar 28, 2013
+ *
+ */
+
+public class EditCdmAuthoritiesHandler  extends AbstractHandler {
+
+       /* (non-Javadoc)
+        * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+        */
+       @Override
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               BulkEditor editor = (BulkEditor) EditorUtil.getActiveEditor();
+               
+               ISelection selection = editor.getSite().getSelectionProvider().getSelection(); 
+               if(selection instanceof LineSelection){
+                  
+                       final LineSelection lineSelection = (LineSelection) selection;
+                       
+                       Job job = new Job("Opening Cdm Authorities"){
+
+                               @Override
+                               protected IStatus run(IProgressMonitor monitor) {
+                                       monitor.beginTask("Opening Cdm Authorities", lineSelection.size());
+                                       
+                                       for(final Object selectedObject : lineSelection.toArray()){
+                                               if(selectedObject instanceof Group){
+                                                       
+                                                       Display.getDefault().asyncExec(new Runnable(){
+
+                                                               @Override
+                                                               public void run() {                                                                 
+                                                                       try {
+                                                                               EditorUtil.openCdmAuthorities(((Group)selectedObject).getUuid());
+                                                                       } catch (Exception e) {
+                                                                               EditorUtil.warningDialog("Could not open CDM Authority Editor", EditorUtil.class, e.getMessage());
+                                                                       }
+                                                               }
+                                                               
+                                                       });
+                                                       monitor.worked(1);
+                                               }
+                                       }
+                                       monitor.done();
+                                       return Status.OK_STATUS;
+                               }
+                               
+                       };
+                       
+                       job.setPriority(Job.SHORT);
+                       job.schedule();                 
+                       
+               }
+               return null;
+       }
+
+}
+