From: Patrick Plitzner Date: Wed, 28 Jun 2017 07:04:13 +0000 (+0200) Subject: ref #6596 Add new utility class WorkbenchUtility in workbench plugin X-Git-Tag: 4.8.0^2~47^2~3 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/ea1b3d4431db4e9f094f7d7a819a26c3b5090f95 ref #6596 Add new utility class WorkbenchUtility in workbench plugin - move getE4WrappedPart() method to that class --- diff --git a/eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF index f10e87bf4..3a08ee2b1 100644 --- a/eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF +++ b/eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF @@ -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, diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphView.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphView.java index 14243a721..c20dab510 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphView.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphView.java @@ -61,7 +61,6 @@ public class ConceptGraphView extends AbstractCdmEditorViewPart { IEditorInput input = ((IEditorPart) part).getEditorInput(); showViewer(part, new StructuredSelection(input)); } - showViewer(); } } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptiveViewPart.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptiveViewPart.java index c13bf546b..d915103d1 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptiveViewPart.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptiveViewPart.java @@ -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(); } - - + + } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/MediaViewPart.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/MediaViewPart.java index e1d981a3d..e233e0874 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/MediaViewPart.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/MediaViewPart.java @@ -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); } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java index 3d394830b..da95042cc 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java @@ -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; diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java index 85596906c..1a1974f34 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java @@ -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; /** *

DetailsViewPart class.

@@ -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); } } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/supplementaldata/SupplementalDataViewPart.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/supplementaldata/SupplementalDataViewPart.java index b651e31bc..4927a9684 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/supplementaldata/SupplementalDataViewPart.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/supplementaldata/SupplementalDataViewPart.java @@ -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; } diff --git a/eu.etaxonomy.taxeditor.workbench/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.workbench/META-INF/MANIFEST.MF index 21fc49687..03a0450dd 100644 --- a/eu.etaxonomy.taxeditor.workbench/META-INF/MANIFEST.MF +++ b/eu.etaxonomy.taxeditor.workbench/META-INF/MANIFEST.MF @@ -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 index 000000000..c5024bb2e --- /dev/null +++ b/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/WorkbenchUtility.java @@ -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 null + */ + 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; + } +}