ref #6596 Add new utility class WorkbenchUtility in workbench plugin
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 28 Jun 2017 07:04:13 +0000 (09:04 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 28 Jun 2017 08:28:59 +0000 (10:28 +0200)
 - move getE4WrappedPart() method to that class

eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphView.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptiveViewPart.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/MediaViewPart.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/supplementaldata/SupplementalDataViewPart.java
eu.etaxonomy.taxeditor.workbench/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/WorkbenchUtility.java [new file with mode: 0644]

index f10e87bf421fb1fbfcae1ff14edf63450862a144..3a08ee2b1230e0983ea30826fcbe1fe30b3aeb88 100644 (file)
@@ -25,6 +25,7 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.ui.forms,
  eu.etaxonomy.taxeditor.store,
  eu.etaxonomy.taxeditor.bulkeditor,
+ eu.etaxonomy.taxeditor.workbench,
  org.eclipse.zest.core,
  org.eclipse.zest.layouts,
  eu.etaxonomy.taxeditor.cdmlib,
index 14243a721db45a3f72f5f57f73f2e7606e11f039..c20dab5102b8a28c309e0e55cf661945cd9379e9 100644 (file)
@@ -61,7 +61,6 @@ public class ConceptGraphView extends AbstractCdmEditorViewPart {
                                IEditorInput input = ((IEditorPart) part).getEditorInput();
                                showViewer(part, new StructuredSelection(input));
                        }
-                       showViewer();
                }
 
        }
index c13bf546b0672bc252d17f02527a3dc713e8c12b..d915103d146437045bb5ef95979373f5e7bad1b3 100644 (file)
@@ -9,17 +9,9 @@
 
 package eu.etaxonomy.taxeditor.editor.view.descriptive;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.e4.ui.di.Persist;
-import org.eclipse.e4.ui.model.application.ui.MDirtyable;
-import org.eclipse.e4.ui.workbench.UIEvents.Dirtyable;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.GroupMarker;
 import org.eclipse.jface.action.IAction;
@@ -45,8 +37,6 @@ import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.internal.E4PartWrapper;
 
-import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
@@ -57,9 +47,7 @@ import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
-import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
 import eu.etaxonomy.taxeditor.editor.view.media.MediaViewPart;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
@@ -67,10 +55,10 @@ import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
 import eu.etaxonomy.taxeditor.model.ImageResources;
-import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
 import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
 import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 /**
  * @author n.hoffmann
@@ -97,8 +85,8 @@ public class DescriptiveViewPart extends AbstractCdmEditorViewPart implements IP
        protected int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
 
     private DescriptiveContentProvider provider;
-    
-    
+
+
        /** {@inheritDoc} */
        @Override
        public void createViewer(Composite parent) {
@@ -207,7 +195,7 @@ public class DescriptiveViewPart extends AbstractCdmEditorViewPart implements IP
                    showEmptyPage();
                }
        }
+
        @Override
        protected String getViewName(){
            return Messages.DescriptiveViewPart_FACTUAL_DATA;
@@ -286,18 +274,18 @@ public class DescriptiveViewPart extends AbstractCdmEditorViewPart implements IP
                    ((BulkEditor) part).forceDirty();
                    IStructuredSelection selection = (IStructuredSelection) ((BulkEditor) part).getSelectionProvider().getSelection();
                    ((BulkEditor) part).changed(selection.getFirstElement());
-                   
+
                }
-               
+
                if (part instanceof E4PartWrapper){
-               part = AbstractUtility.getE4WrappedPart(part);
+               part = WorkbenchUtility.getE4WrappedPart(part);
                if (part instanceof IDirtyMarkable){
                         StructuredSelection selection = new StructuredSelection(object);
                        ((IDirtyMarkable)part).changed(selection.getFirstElement());
                }
            }
 
-               
+
                super.changed(object);
        }
 
@@ -316,7 +304,7 @@ public class DescriptiveViewPart extends AbstractCdmEditorViewPart implements IP
            provider.toggleShowOnlyIndividualAssociations();
            viewer.refresh();
        }
-       
-       
+
+
 
 }
index e1d981a3d9f76974098c31fb23c831c04300c10d..e233e0874324ef6af109d3d6eac7b769d548cdf6 100644 (file)
@@ -22,20 +22,15 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Tree;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.ISaveablePart;
 import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.internal.E4PartWrapper;
 
-import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
 import eu.etaxonomy.cdm.model.description.IDescribable;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
@@ -43,6 +38,7 @@ import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
 import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
 import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
 import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 /**
  * @author n.hoffmann
@@ -102,7 +98,7 @@ public class MediaViewPart extends AbstractCdmEditorViewPart implements IPartCon
 //                     showEmptyPage();
 //                     return;
 //             }
-               
+
 
         if (part instanceof DetailsViewPart || part instanceof SupplementalDataViewPart
                 || part instanceof DescriptiveViewPart) {
@@ -135,7 +131,7 @@ public class MediaViewPart extends AbstractCdmEditorViewPart implements IPartCon
                                }
                        }
                }
-               
+
                showEmptyPage();
        }
 
@@ -158,14 +154,14 @@ public class MediaViewPart extends AbstractCdmEditorViewPart implements IPartCon
 
            }
            if (part instanceof E4PartWrapper){
-               part = AbstractUtility.getE4WrappedPart(part);
+               part = WorkbenchUtility.getE4WrappedPart(part);
                if (part instanceof IDirtyMarkable){
                         StructuredSelection selection = new StructuredSelection(object);
                        ((IDirtyMarkable)part).changed(selection.getFirstElement());
                }
            }
-               
-           
+
+
            super.changed(object);
        }
 
index 3d394830b538ceec6c9dab2dce9a9b7d6dd58595..da95042cc0722a262c44401fb1527b6fdfd3db43 100644 (file)
@@ -9,7 +9,6 @@
 
 package eu.etaxonomy.taxeditor.model;
 
-import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -35,7 +34,6 @@ import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.core.runtime.jobs.ISchedulingRule;
 import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.resource.ColorRegistry;
@@ -57,7 +55,6 @@ import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
-import org.eclipse.ui.internal.E4PartWrapper;
 import org.eclipse.ui.part.EditorPart;
 import org.eclipse.ui.progress.IProgressConstants;
 import org.eclipse.ui.progress.IProgressService;
@@ -80,6 +77,7 @@ import eu.etaxonomy.taxeditor.ui.dialog.ReportTextDialog;
 import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
 import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
 import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 /**
  *
@@ -143,29 +141,12 @@ public abstract class AbstractUtility {
         IWorkbenchPage activePage = getActivePage();
         if(activePage!=null){
             IWorkbenchPart activePart = activePage.getActivePart();
-            Object e4WrappedPart = getE4WrappedPart(activePart);
+            Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
             return e4WrappedPart!=null?e4WrappedPart:activePart;
         }
         return null;
     }
 
-    public static Object getE4WrappedPart(Object activePart){
-        if(activePart instanceof E4PartWrapper){
-            //FIXME can be removed when E4 migration is complete
-            try {
-                Field field = activePart.getClass().getDeclaredField("wrappedPart");
-                field.setAccessible(true);
-                Object object = field.get(activePart);
-                if(object instanceof MPart){
-                    return ((MPart) object).getObject();
-                }
-            } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
-                e.printStackTrace();
-            }
-        }
-        return null;
-    }
-
     public static IWorkbench getWorkbench() {
         return TaxeditorStorePlugin.getDefault().getWorkbench();
     }
@@ -573,7 +554,7 @@ public abstract class AbstractUtility {
     public static Object getActiveE4Editor() {
         if(getActivePage()!=null){
             IEditorPart activeEditor = getActivePage().getActiveEditor();
-            Object wrappedPart = getE4WrappedPart(getActivePage().getActivePart());
+            Object wrappedPart = WorkbenchUtility.getE4WrappedPart(getActivePage().getActivePart());
             return wrappedPart!=null?wrappedPart:activeEditor;
         }
         return null;
index 85596906c9da220902941bc3d82b0dd01595ca9e..1a1974f340179d4f3cce30f38912efe69624fc7c 100644 (file)
@@ -42,6 +42,7 @@ import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 /**
  * <p>DetailsViewPart class.</p>
@@ -68,7 +69,7 @@ public class DetailsViewPart extends AbstractCdmEditorViewPart implements IPartC
        @Override
     protected void selectionChanged_internal(IWorkbenchPart workbenchPart, ISelection selection){
            Object part = workbenchPart;
-           Object wrappedPart = AbstractUtility.getE4WrappedPart(part);
+           Object wrappedPart = WorkbenchUtility.getE4WrappedPart(part);
            if(wrappedPart!=null){
                part = wrappedPart;
            }
@@ -250,7 +251,8 @@ public class DetailsViewPart extends AbstractCdmEditorViewPart implements IPartC
                                         TaxonRelationship rel = rels.iterator().next();
                                         if (rel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
                                                 getViewer().setInput(rel);
-                                                 showViewer();
+                                                showViewer();
+//                                               super.showViewer(part, selection);
                                                  return;
                                         }
                                 }
@@ -261,6 +263,7 @@ public class DetailsViewPart extends AbstractCdmEditorViewPart implements IPartC
         }
         getViewer().setInput(element);
         showViewer();
+//        super.showViewer(part, selection);
     }
 }
 
index b651e31bc5bcb04362b6c384c4ce99b5c561e123..4927a9684645d5128bc60010d57a62205fb5f020 100644 (file)
@@ -26,6 +26,7 @@ import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
 import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 
 /**
@@ -56,7 +57,7 @@ public class SupplementalDataViewPart extends AbstractCdmEditorViewPart {
        @Override
        protected void selectionChanged_internal(IWorkbenchPart workbenchPart, ISelection selection) {
            Object part = workbenchPart;
-        Object wrappedPart = AbstractUtility.getE4WrappedPart(part);
+        Object wrappedPart = WorkbenchUtility.getE4WrappedPart(part);
         if(wrappedPart!=null){
             part = wrappedPart;
         }
index 21fc49687e14d5737b0420c67cffc04021510ef5..03a0450dded6735e55882a9617e01e3cb905f192 100644 (file)
@@ -20,4 +20,5 @@ Require-Bundle: org.eclipse.ui,
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Import-Package: javax.inject;version="1.0.0"
 Bundle-ActivationPolicy: lazy
-Export-Package: eu.etaxonomy.taxeditor.workbench.part
+Export-Package: eu.etaxonomy.taxeditor.workbench,
+ eu.etaxonomy.taxeditor.workbench.part
diff --git a/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/WorkbenchUtility.java b/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/WorkbenchUtility.java
new file mode 100644 (file)
index 0000000..c5024bb
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+* Copyright (C) 2017 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.workbench;
+
+import java.lang.reflect.Field;
+
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.ui.internal.E4PartWrapper;
+import org.eclipse.ui.internal.e4.compatibility.CompatibilityView;
+
+/**
+ * Utility class for e4 workbench related operations
+ * @author pplitzner
+ * @since Jun 27, 2017
+ *
+ */
+public class WorkbenchUtility {
+
+    /**
+     * Checks if the activePart is an E4 wrapper for a legacy part and returns
+     * that part
+     *
+     * @param activePart the e4 wrapper
+     * @return the wrapped legacy part or <code>null</code>
+     */
+    public static Object getE4WrappedPart(Object activePart){
+        //FIXME can be removed when E4 migration is complete
+
+        Object object = null;
+        try {
+            if(activePart instanceof E4PartWrapper){
+                Field field = activePart.getClass().getDeclaredField("wrappedPart");
+                field.setAccessible(true);
+                object = field.get(activePart);
+            }
+            else if(activePart instanceof CompatibilityView){
+                Field field = activePart.getClass().getSuperclass().getDeclaredField("wrapped");
+                field.setAccessible(true);
+                object = field.get(activePart);
+            }
+        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
+            e.printStackTrace();
+        }
+        if(object instanceof MPart){
+            object =((MPart) object).getObject();
+        }
+        return object;
+    }
+}