bulkeditor: merge of teams and persons and convert team to person and person to team
authorKatja Luther <k.luther@bgbm.org>
Mon, 18 May 2015 09:59:52 +0000 (09:59 +0000)
committerKatja Luther <k.luther@bgbm.org>
Mon, 18 May 2015 09:59:52 +0000 (09:59 +0000)
.gitattributes
eu.etaxonomy.taxeditor.bulkeditor/OSGI-INF/l10n/bundle.properties
eu.etaxonomy.taxeditor.bulkeditor/plugin.xml
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/BulkEditorMenuPropertyTester.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/BulkEditorPropertyTester.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/ConvertPerson2TeamHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/ConvertTeam2PersonHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/entitycreator/AgentCreator.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java

index 07c5c2fa84c47d8ba9dff23d36080b3541887d24..31cdf5895e01f2ee1bd06a6e6e5b224fad8bc685 100644 (file)
@@ -82,11 +82,14 @@ eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkedito
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorViewerConfiguration.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/IBulkEditorConstants.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/IBulkEditorSortProvider.java -text
+eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/BulkEditorMenuPropertyTester.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/BulkEditorPropertyTester.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/DeleteObjectContributionItem.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/DynamicMarkerTypeEditingMenu.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/DynamicNewObjectMenu.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/OpenBulkEditorContributionItem.java -text
+eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/ConvertPerson2TeamHandler.java -text
+eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/ConvertTeam2PersonHandler.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/MergeGroupHandler.java -text
 eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/OpenBulkEditorHandler.java -text
index 99cd6fa5b3dbced1e9b54d4dea4bd6b93d6439b5..8858bb121ccd79d440c8170cb27ea1905d011d0a 100644 (file)
@@ -14,4 +14,21 @@ command.label.0 = Set Current Line as Target for Duplicate Removal
 command.label.1 = Set as Candidate(s) for Duplicate Removal
 command.label.2 = Remove as Candidate(s) for Duplicate Removal
 command.label.3 = De-Duplicate Group
-command.label.4 = Delete
\ No newline at end of file
+command.label.4 = Delete
+command.label.5 = Convert Team to Person
+command.name = Merge Group
+command.name.0 = Set as Target for Group Merge
+command.name.1 = Dynamic Open Bulk Editor
+commandParameter.name = Bulk Editor Class
+command.name.2 = Dynamic New Object
+command.name.3 = Dynamic Delete Object
+command.name.4 = Set as Candidate for Group Merge
+command.name.5 = Remove as Candidate for Group Merge
+command.name.6 = Set Marker Flag
+command.name.7 = delete
+command.name.8 = convert Team to Person
+command.name.9 = convert Person to Team
+specification.label = Merge Candidate Annotation
+specification.label.0 = Merge Target Annotation
+command.label.6 = Convert Person to Team
+command.name.10 = convert Person to Team
\ No newline at end of file
index 0b1fdeab655ee2586575ab3dd96579e426945b04..f408f10ff1d902402c707fb61e42842a08b575df 100644 (file)
                </reference>\r
             </visibleWhen>\r
          </command>\r
+         \r
          <command\r
                commandId="bulkeditor.commands.setmergecandidate"\r
                label="%command.label.1"\r
                </reference>\r
             </visibleWhen>\r
          </command>\r
+         <command\r
+               commandId="eu.etaxonomy.taxeditor.bulkeditor.convertTeam2Person"\r
+               label="%command.label.5"\r
+               style="push">\r
+                  <visibleWhen\r
+                               checkEnabled="true">\r
+                               <and>\r
+                               <reference\r
+                       definitionId="isConvertEnabled">\r
+                               </reference>\r
+                               <reference \r
+                                               definitionId="isTeam">\r
+                               </reference>\r
+                       </and>\r
+                       </visibleWhen>\r
+         </command>\r
+         <command\r
+               commandId="eu.etaxonomy.taxeditor.bulkeditor.convertPerson2Team"\r
+               label="%command.label.6"\r
+               style="push">\r
+               <visibleWhen \r
+                       checkEnabled="true">>\r
+                               <and>\r
+                               <reference\r
+                       definitionId="isConvertEnabled">\r
+                               </reference>\r
+                               <reference \r
+                                       definitionId="isPerson">\r
+                               </reference>\r
+                       </and>\r
+                       </visibleWhen>\r
+         </command>\r
          <separator\r
                name="taxeditor-bulkeditor.separator2"\r
                visible="true">\r
       <command\r
             defaultHandler="eu.etaxonomy.taxeditor.bulkeditor.handler.MergeGroupHandler"\r
             id="bulkeditor.commands.mergegroup"\r
-            name="Merge Group">\r
+            name="%command.name">\r
       </command>\r
       <command\r
             defaultHandler="eu.etaxonomy.taxeditor.bulkeditor.handler.SetMergeTargetHandler"\r
             id="bulkeditor.commands.setmergetarget"\r
-            name="Set as Target for Group Merge">\r
+            name="%command.name.0">\r
       </command>\r
       <command\r
             defaultHandler="eu.etaxonomy.taxeditor.bulkeditor.handler.OpenBulkEditorHandler"\r
             id="taxeditor-bulkeditor.dynamicopenmenu"\r
-            name="Dynamic Open Bulk Editor">\r
+            name="%command.name.1">\r
          <commandParameter\r
                id="taxeditor-bulkeditor.commandParameter.inputType"\r
-               name="Bulk Editor Class"\r
+               name="%commandParameter.name"\r
                values="eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputTypeValues">\r
          </commandParameter>\r
       </command>\r
       <command\r
             defaultHandler="eu.etaxonomy.taxeditor.annotatedlineeditor.handler.NewObjectHandler"\r
             id="taxeditor-bulkeditor.dynamicnewobjectcommand"\r
-            name="Dynamic New Object">\r
+            name="%command.name.2">\r
       </command>\r
       <command\r
             defaultHandler="eu.etaxonomy.taxeditor.annotatedlineeditor.handler.DeleteObjectHandler"\r
             id="taxeditor-bulkeditor.dynamicdeleteobjectcommand"\r
-            name="Dynamic Delete Object">\r
+            name="%command.name.3">\r
       </command>\r
       <command\r
             defaultHandler="eu.etaxonomy.taxeditor.bulkeditor.handler.SetMergeCandidateHandler"\r
             id="bulkeditor.commands.setmergecandidate"\r
-            name="Set as Candidate for Group Merge">\r
+            name="%command.name.4">\r
       </command>\r
       <command\r
             defaultHandler="eu.etaxonomy.taxeditor.bulkeditor.handler.RemoveMergeCandidateHandler"\r
             id="bulkeditor.commands.removemergecandidate"\r
-            name="Remove as Candidate for Group Merge">\r
+            name="%command.name.5">\r
       </command>\r
       <command\r
             defaultHandler="eu.etaxonomy.taxeditor.bulkeditor.handler.SetMarkerFlagHandler"\r
             id="taxeditor-bulkeditor.command.setMarkerFlag"\r
-            name="Set Marker Flag">\r
+            name="%command.name.6">\r
       </command>\r
       <command\r
             id="eu.etaxonomy.taxeditor.bulkeditor.delete"\r
-            name="delete">\r
+            name="%command.name.7">\r
+      </command>\r
+      <command\r
+            id="eu.etaxonomy.taxeditor.bulkeditor.convertTeam2Person"\r
+            name="%command.name.8">\r
+      </command>\r
+      <command\r
+            id="eu.etaxonomy.taxeditor.bulkeditor.convertPerson2Team"\r
+            name="%command.name.10">\r
       </command>\r
       <!--command\r
             defaultHandler="eu.etaxonomy.taxeditor.bulkeditor.handler.NewEntityHandler"\r
             highlightPreferenceValue="true"\r
             icon="icons/merge_candidate.gif"\r
             includeOnPreferencePage="true"\r
-            label="Merge Candidate Annotation"\r
+            label="%specification.label"\r
             overviewRulerPreferenceKey="merge_candidate_annotation_overview"\r
             overviewRulerPreferenceValue="true"\r
             presentationLayer="0"\r
             highlightPreferenceValue="true"\r
             icon="icons/merge_target.gif"\r
             includeOnPreferencePage="true"\r
-            label="Merge Target Annotation"\r
+            label="%specification.label.0"\r
             overviewRulerPreferenceKey="merge_target_annotation_overview"\r
             overviewRulerPreferenceValue="true"\r
             presentationLayer="1"\r
             </test>\r
          </with>\r
       </definition>\r
+      <definition\r
+            id="isConvertEnabled">\r
+         <with\r
+               variable="activeEditor">\r
+            <test\r
+                  property="taxeditor-bulkeditor.propertyTester.isConvertingEnabled">\r
+            </test>\r
+         </with>\r
+      </definition>\r
       <definition\r
             id="isTaxonBulkEditorInput">\r
          <with\r
             </test>\r
          </with>\r
       </definition>\r
+       <definition\r
+            id="isTeam">\r
+         <with\r
+               variable="selection">\r
+            <test\r
+                  property="eu.etaxonomy.taxeditor.bulkeditor.command.isTeam">\r
+            </test>\r
+         </with>\r
+      </definition>\r
+      <definition\r
+            id="isPerson">\r
+         <with\r
+               variable="selection">\r
+            <test\r
+                  property="eu.etaxonomy.taxeditor.bulkeditor.command.isPerson">\r
+            </test>\r
+         </with>\r
+      </definition>\r
    </extension>\r
    <extension\r
          point="org.eclipse.core.expressions.propertyTesters">\r
             class="eu.etaxonomy.taxeditor.bulkeditor.command.BulkEditorPropertyTester"\r
             id="taxeditor-bulkeditor.PropertyTester"\r
             namespace="taxeditor-bulkeditor.propertyTester"\r
-            properties="isMergingEnabled, isDerivedUnitEditor, isTaxonEditor, isGroupEditor"\r
+            properties="isMergingEnabled, isDerivedUnitEditor, isTaxonEditor, isGroupEditor, isConvertingEnabled"\r
             type="eu.etaxonomy.taxeditor.bulkeditor.BulkEditor">\r
       </propertyTester>\r
+      <propertyTester\r
+            class="eu.etaxonomy.taxeditor.bulkeditor.command.BulkEditorMenuPropertyTester"\r
+            id="eu.etaxonomy.taxeditor.bulkeditor.command.BulkEditorMenuPropertyTester"\r
+            namespace="eu.etaxonomy.taxeditor.bulkeditor.command"\r
+            properties="isTeam, isPerson"\r
+            type="java.lang.Object">\r
+      </propertyTester>\r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.handlers">\r
             </with>\r
          </activeWhen>\r
       </handler>\r
+      <handler\r
+            class="eu.etaxonomy.taxeditor.bulkeditor.handler.ConvertTeam2PersonHandler"\r
+            commandId="eu.etaxonomy.taxeditor.bulkeditor.convertTeam2Person">\r
+      </handler>\r
+      <handler\r
+            class="eu.etaxonomy.taxeditor.bulkeditor.handler.ConvertPerson2TeamHandler"\r
+            commandId="eu.etaxonomy.taxeditor.bulkeditor.convertPerson2Team">\r
+      </handler>\r
+      \r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.preferencePages">\r
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/BulkEditorMenuPropertyTester.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/BulkEditorMenuPropertyTester.java
new file mode 100644 (file)
index 0000000..529b304
--- /dev/null
@@ -0,0 +1,53 @@
+// $Id$\r
+/**\r
+* Copyright (C) 2015 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.taxeditor.bulkeditor.command;\r
+\r
+import org.eclipse.core.expressions.PropertyTester;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+\r
+import eu.etaxonomy.cdm.model.agent.Person;\r
+import eu.etaxonomy.cdm.model.agent.Team;\r
+\r
+/**\r
+ * @author k.luther\r
+ * @date 13.05.2015\r
+ *\r
+ */\r
+public class BulkEditorMenuPropertyTester extends PropertyTester {\r
+\r
+\r
+       private static final String IS_TEAM = "isTeam";\r
+       private static final String IS_PERSON = "isPerson";\r
+       \r
+       public BulkEditorMenuPropertyTester(){\r
+       }\r
+       /**\r
+        * {@inheritDoc}\r
+        */\r
+       @Override\r
+       public boolean test(Object receiver, String property, Object[] args,\r
+                       Object expectedValue) {\r
+               System.out.println("TEST!!");\r
+               if(receiver instanceof IStructuredSelection){\r
+                       IStructuredSelection selection = (IStructuredSelection) receiver;\r
+                       Object selectedElement = selection.getFirstElement();\r
+                       if (property.equals(IS_PERSON) && selectedElement instanceof Person){\r
+                               return true;\r
+                       } \r
+                       if (property.equals(IS_TEAM) && selectedElement instanceof Team){\r
+                               return true;\r
+                       }\r
+                       return false;\r
+               \r
+               }\r
+               return false;\r
+       }\r
+\r
+}\r
index 0d3efd55b2c4d688f58a0658f2f1b43516352116..7368adc1d835f5dbfda890534210eee434e8af07 100644 (file)
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.bulkeditor.command;
 
 import org.apache.log4j.Logger;
 import org.eclipse.core.expressions.PropertyTester;
+
 import org.eclipse.ui.IEditorInput;
 
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
@@ -38,7 +39,9 @@ public class BulkEditorPropertyTester extends PropertyTester {
        private static final String IS_GROUP_EDITOR = "isGroupEditor";
     public static final String IS_DERIVED_UNIT_EDITOR = "isDerivedUnitEditor";
     public static final String IS_TAXON_EDITOR = "isTaxonEditor";
-
+    public static final String IS_CONVERT_ENABLED = "isConvertingEnabled";
+    public static final String IS_PERSON = "isPerson";
+    public static final String IS_TEAM = "isTeam";
        /* (non-Javadoc)
         * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
         */
@@ -46,14 +49,22 @@ public class BulkEditorPropertyTester extends PropertyTester {
        @Override
     public boolean test(Object receiver, String property, Object[] args,
                        Object expectedValue) {
-               BulkEditor bulkEditor = (BulkEditor) receiver;
-
+               BulkEditor bulkEditor = null;
+               
+               
+               bulkEditor = (BulkEditor) receiver;
                if (IS_MERGING_ENABLED.equals(property)) {
                        IEditorInput input = bulkEditor.getEditorInput();
                        if (input instanceof AbstractBulkEditorInput) {
                                return ((AbstractBulkEditorInput<?>) input).isMergingEnabled();
                        }
                }
+               if (IS_CONVERT_ENABLED.equals(property)) {
+                       IEditorInput input = bulkEditor.getEditorInput();
+                       if (input instanceof AbstractBulkEditorInput) {
+                               return ((AbstractBulkEditorInput<?>) input).isConvertingEnabled();
+                       }
+               }
                else if(IS_GROUP_EDITOR.equals(property)){
                        return bulkEditor.getEditorInput() instanceof GroupEditorInput;
                }
@@ -63,6 +74,7 @@ public class BulkEditorPropertyTester extends PropertyTester {
         else if(IS_TAXON_EDITOR.equals(property)){
             return bulkEditor.getEditorInput() instanceof TaxonEditorInput;
         }
+               
 //             if (("isPublishFlagEditingEnabled").equals(property)) {
 //                     IEditorInput input = bulkEditor.getEditorInput();
 //                     if (input instanceof NameEditorInput) {
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/ConvertPerson2TeamHandler.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/ConvertPerson2TeamHandler.java
new file mode 100644 (file)
index 0000000..2191fa9
--- /dev/null
@@ -0,0 +1,99 @@
+// $Id$\r
+/**\r
+* Copyright (C) 2015 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.taxeditor.bulkeditor.handler;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.ui.IEditorInput;\r
+import org.eclipse.ui.IEditorPart;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.eclipse.ui.texteditor.IDocumentProvider;\r
+\r
+import eu.etaxonomy.cdm.api.service.IAgentService;\r
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;\r
+import eu.etaxonomy.cdm.model.agent.Person;\r
+import eu.etaxonomy.cdm.model.agent.Team;\r
+import eu.etaxonomy.cdm.strategy.merge.MergeException;\r
+import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService;\r
+import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;\r
+import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;\r
+import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;\r
+import eu.etaxonomy.taxeditor.model.MessagingUtils;\r
+import eu.etaxonomy.taxeditor.store.CdmStore;\r
+\r
+/**\r
+ * @author k.luther\r
+ * @date 12.05.2015\r
+ *\r
+ */\r
+public class ConvertPerson2TeamHandler extends AbstractHandler {\r
+\r
+       /**\r
+        * {@inheritDoc}\r
+        */\r
+       @Override\r
+       public Object execute(ExecutionEvent event) throws ExecutionException {\r
+               ISelection selection = HandlerUtil.getCurrentSelection(event);\r
+               \r
+               IEditorPart editor = HandlerUtil.getActiveEditor(event);\r
+               \r
+               IEditorInput input = editor.getEditorInput();\r
+               if (editor.isDirty()){\r
+                       boolean proceed = MessageDialog.openQuestion(null,\r
+                                       "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");\r
+                       if (proceed) {\r
+                               editor.doSave(null);\r
+                       } else {\r
+                               return null;\r
+                       }\r
+               }\r
+               if((input instanceof IEntityPersistenceService) && (selection instanceof IStructuredSelection)){\r
+                       \r
+                       \r
+                       IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider();\r
+                       LineAnnotationModel model = \r
+                                       (LineAnnotationModel) provider.getAnnotationModel(input);\r
+                       \r
+                       \r
+                       IStructuredSelection structuredSelection = (IStructuredSelection) selection;\r
+                       \r
+                       IEntityPersistenceService persistenceService = (IEntityPersistenceService) input;\r
+               \r
+                       Team team ;\r
+                       for(Object object : structuredSelection.toList()){\r
+                               LineAnnotation annotation = (LineAnnotation) model.getAnnotation(object);\r
+                               team = null;\r
+                               if (object instanceof Person){\r
+                                       Person person = HibernateProxyHelper.deproxy(object, Person.class);\r
+                                       try {\r
+                                               team = CdmStore.getService(IAgentService.class).convertPerson2Team(person);\r
+                                       } catch (IllegalArgumentException e) {\r
+                                               MessagingUtils.informationDialog("Can not convert Team to Person", e.getMessage());\r
+                                       } catch (MergeException e) {\r
+                                               MessagingUtils.informationDialog("Can not convert Team to Person", e.getMessage());\r
+                                       }\r
+                               }else{\r
+                                       MessagingUtils.informationDialog("Can not convert Team to Person", "convertTeam2Person can only be called on a team.");\r
+                               }\r
+                               \r
+                               if (team != null){\r
+                                       ((BulkEditor) editor).removeAnnotatedLine(annotation);\r
+                                       ((BulkEditor) editor).createAnnotatedLine(team);\r
+                               }\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+\r
+}\r
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/ConvertTeam2PersonHandler.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/ConvertTeam2PersonHandler.java
new file mode 100644 (file)
index 0000000..846ada1
--- /dev/null
@@ -0,0 +1,101 @@
+// $Id$\r
+/**\r
+* Copyright (C) 2015 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.taxeditor.bulkeditor.handler;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.ui.IEditorInput;\r
+import org.eclipse.ui.IEditorPart;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.eclipse.ui.texteditor.IDocumentProvider;\r
+\r
+import eu.etaxonomy.cdm.api.service.AgentServiceImpl;\r
+import eu.etaxonomy.cdm.api.service.IAgentService;\r
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;\r
+import eu.etaxonomy.cdm.model.agent.AgentBase;\r
+import eu.etaxonomy.cdm.model.agent.Person;\r
+import eu.etaxonomy.cdm.model.agent.Team;\r
+import eu.etaxonomy.cdm.strategy.merge.MergeException;\r
+import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService;\r
+import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;\r
+import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;\r
+import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;\r
+import eu.etaxonomy.taxeditor.model.MessagingUtils;\r
+import eu.etaxonomy.taxeditor.store.CdmStore;\r
+\r
+/**\r
+ * @author k.luther\r
+ * @date 12.05.2015\r
+ *\r
+ */\r
+public class ConvertTeam2PersonHandler extends AbstractHandler {\r
+\r
+       /**\r
+        * {@inheritDoc}\r
+        */\r
+       @Override\r
+       public Person execute(ExecutionEvent event) throws ExecutionException {\r
+               ISelection selection = HandlerUtil.getCurrentSelection(event);\r
+               \r
+               IEditorPart editor = HandlerUtil.getActiveEditor(event);\r
+               \r
+               IEditorInput input = editor.getEditorInput();\r
+               if (editor.isDirty()){\r
+                       boolean proceed = MessageDialog.openQuestion(null,\r
+                                       "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");\r
+                       if (proceed) {\r
+                               editor.doSave(null);\r
+                       } else {\r
+                               return null;\r
+                       }\r
+               }\r
+               if((input instanceof IEntityPersistenceService) && (selection instanceof IStructuredSelection)){\r
+                       \r
+                       \r
+                       IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider();\r
+                       LineAnnotationModel model = \r
+                                       (LineAnnotationModel) provider.getAnnotationModel(input);\r
+                       \r
+                       \r
+                       IStructuredSelection structuredSelection = (IStructuredSelection) selection;\r
+                       \r
+                       IEntityPersistenceService persistenceService = (IEntityPersistenceService) input;\r
+               \r
+                       Person person ;\r
+                       for(Object object : structuredSelection.toList()){\r
+                               LineAnnotation annotation = (LineAnnotation) model.getAnnotation(object);\r
+                               person = null;\r
+                               if (object instanceof Team){\r
+                                       Team team = HibernateProxyHelper.deproxy(object, Team.class);\r
+                                       try {\r
+                                               person = CdmStore.getService(IAgentService.class).convertTeam2Person(team);\r
+                                       } catch (IllegalArgumentException e) {\r
+                                               MessagingUtils.informationDialog("Can not convert Team to Person", e.getMessage());\r
+                                       } catch (MergeException e) {\r
+                                               MessagingUtils.informationDialog("Can not convert Team to Person", e.getMessage());\r
+                                       }\r
+                               }else{\r
+                                       MessagingUtils.informationDialog("Can not convert Team to Person", "convertTeam2Person can only be called on a team.");\r
+                               }\r
+                               \r
+                               if (person != null){\r
+                                       ((BulkEditor) editor).removeAnnotatedLine(annotation);\r
+                                       ((BulkEditor) editor).createAnnotatedLine(person);\r
+                               }\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+\r
+}\r
index 5a7cccc119a7ae8ca03599d85595af7a614f2c8a..e5b852b5ab76e79dc3e8abf0862f5ef0cd935e35 100644 (file)
@@ -207,6 +207,14 @@ public abstract class AbstractBulkEditorInput<T extends ICdmBase> implements IEd
                return false;
        }
 
+       /**
+        * <p>isMergingEnabled</p>
+        *
+        * @return a boolean.
+        */
+       public boolean isConvertingEnabled() {
+               return false;
+       }
        /**
         * <p>isMarkerTypeEditingEnabled</p>
         *
@@ -217,10 +225,7 @@ public abstract class AbstractBulkEditorInput<T extends ICdmBase> implements IEd
                return false;
        }
 
-       /*
-        * (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#merge(eu.etaxonomy.cdm.model.common.IdentifiableEntity, eu.etaxonomy.cdm.model.common.IdentifiableEntity)
-        */
+
        /** {@inheritDoc} */
        @Override
     public boolean merge(T entity, T mergeTarget) {
@@ -239,10 +244,7 @@ public abstract class AbstractBulkEditorInput<T extends ICdmBase> implements IEd
                return true;
        }
 
-       /*
-        * (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#create(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
-        */
+
        /** {@inheritDoc} */
        @Override
     public boolean create(T entity) {
index 923d532c08bfaf6b62246a04cbc82e6b82b9bee0..5cc1e2925509da08a27a6bb05fa4f654879341af 100644 (file)
@@ -20,10 +20,20 @@ import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurato
 import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
+import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
+import eu.etaxonomy.cdm.strategy.merge.DefaultMergeStrategy;
+import eu.etaxonomy.cdm.strategy.merge.IMergable;
+import eu.etaxonomy.cdm.strategy.merge.IMergeStrategy;
+import eu.etaxonomy.cdm.strategy.merge.MergeException;
+import eu.etaxonomy.cdm.strategy.merge.MergeMode;
 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
+import eu.etaxonomy.taxeditor.bulkeditor.handler.MergeGroupHandler;
 import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.AgentCreator;
 import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
+import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 
@@ -34,7 +44,7 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @created 25.06.2009
  * @version 1.0
  */
-public class AgentEditorInput extends AbstractBulkEditorInput<AgentBase> {
+public class AgentEditorInput extends AbstractBulkEditorInput<TeamOrPersonBase> {
 
        /**
         * 
@@ -99,10 +109,39 @@ public class AgentEditorInput extends AbstractBulkEditorInput<AgentBase> {
        public boolean isMergingEnabled() {
                return true;
        }
+       
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
+        */
+       /** {@inheritDoc} */
+       @Override
+       public boolean isConvertingEnabled() {
+               return true;
+       }
+       
+       /** {@inheritDoc} */
+       @Override
+    public boolean merge(TeamOrPersonBase entity, TeamOrPersonBase mergeTarget) {
+               if (entity instanceof IMergable) {
+                       try {
+                               IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(Person.class);
+                               strategy.setMergeMode("institutionalMemberships", MergeMode.FIRST);
+                               CdmStore.getCommonService().merge((IMergable)mergeTarget, (IMergable)entity, strategy);                         
+                       } catch (MergeException e) {
+                               MessagingUtils.errorDialog("Bulk Editor Merge Error",
+                                               this,
+                                               "Could not merge chosen objects of type " + entity.getClass().getName(),
+                                               TaxeditorBulkeditorPlugin.PLUGIN_ID,
+                                               e,
+                                               true);
+                       }
+               }
+               return true;
+       }
 
        /** {@inheritDoc} */
        @Override
-       public List<AgentBase> listEntities(IIdentifiableEntityServiceConfigurator configurator) {
+       public List<TeamOrPersonBase> listEntities(IIdentifiableEntityServiceConfigurator configurator) {
                return CdmStore.getSearchManager().findTeamOrPersons(configurator);
        }
        
@@ -130,10 +169,10 @@ public class AgentEditorInput extends AbstractBulkEditorInput<AgentBase> {
         * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getSortProviders()
         */
        @Override
-       public List<IBulkEditorSortProvider<AgentBase>> getSortProviders() {
-               List<IBulkEditorSortProvider<AgentBase>> sortProviders = super.getSortProviders();
+       public List<IBulkEditorSortProvider<TeamOrPersonBase>> getSortProviders() {
+               List<IBulkEditorSortProvider<TeamOrPersonBase>> sortProviders = super.getSortProviders();
                
-               sortProviders.add(0, new IdentifiableEntitySortProvider<AgentBase>());
+               sortProviders.add(0, new IdentifiableEntitySortProvider<TeamOrPersonBase>());
                
                return sortProviders;
        }
@@ -142,8 +181,21 @@ public class AgentEditorInput extends AbstractBulkEditorInput<AgentBase> {
         * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#createEntityCreator()
         */
        @Override
-       protected IEntityCreator<AgentBase> createEntityCreator() {
+       protected IEntityCreator<TeamOrPersonBase> createEntityCreator() {
                return new AgentCreator();
        }
 
+       @Override
+       public boolean save(TeamOrPersonBase entity) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean delete(TeamOrPersonBase entity)
+                       throws ReferencedObjectUndeletableException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
 }
index 015b24a287550061d5c71dc282a414b3c2d7ca47..efb0bdc10b977a0771474284eee127449662b0f2 100644 (file)
@@ -28,15 +28,14 @@ import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
  * @created 18.09.2009
  * @version 1.0
  */
-public class AgentCreator implements IEntityCreator<AgentBase> {
-       private static final Logger logger = Logger
-                       .getLogger(AgentCreator.class);
+public class AgentCreator implements IEntityCreator<TeamOrPersonBase> {
+       private static final Logger logger = Logger.getLogger(AgentCreator.class);
 
        /* (non-Javadoc)
         * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.String)
         */
        /** {@inheritDoc} */
-       public AgentBase createEntity(String text) {
+       public TeamOrPersonBase createEntity(String text) {
                // FIXME
                logger.error("FIXMEFIXMEFIXMEFIXMEFIXMEFIXMEFIXMEFIXMEFIXMEFIXMEFIXME");
                logger.error("We can only create Persons at the moment. See #1820");
@@ -48,7 +47,7 @@ public class AgentCreator implements IEntityCreator<AgentBase> {
         * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.Class, java.lang.String)
         */
        /** {@inheritDoc} */
-       public AgentBase createEntity(Object key, String text) {
+       public TeamOrPersonBase createEntity(Object key, String text) {
                TeamOrPersonBase teamOrPerson = null;
                if (Team.class.equals((key))) {
                        teamOrPerson = Team.NewInstance();
index 1f24d45216a4716abd36730fb223f1d79b71a5f2..e9968f0b3ee523c90524ae351f704bb4e600557d 100644 (file)
@@ -138,9 +138,10 @@ public class SearchManager {
         * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
         * @return a {@link java.util.List} object.
         */
-       public List<AgentBase> findTeamOrPersons(IIdentifiableEntityServiceConfigurator configurator){
+       @SuppressWarnings("unchecked")
+       public List<TeamOrPersonBase> findTeamOrPersons(IIdentifiableEntityServiceConfigurator configurator){
                configurator.setClazz(TeamOrPersonBase.class);
-               return findAgents(configurator);
+               return (List)findAgents(configurator);
        }
 
        /**