X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/a6d63028cb38503408bf1db09391888ae32492d7..12addc56e71b065b36ba5ca00f449243e3a44cda:/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java index 47b1bc79b..cf8d57439 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java @@ -9,89 +9,101 @@ */ package eu.etaxonomy.taxeditor.view.e4.details; +import javax.annotation.PostConstruct; import javax.inject.Inject; -import javax.inject.Named; -import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.log.Logger; import org.eclipse.e4.ui.model.application.ui.basic.MPart; -import org.eclipse.e4.ui.services.IServiceConstants; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWTException; import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IEditorPart; import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; import eu.etaxonomy.cdm.model.description.Feature; import eu.etaxonomy.taxeditor.l10n.Messages; +import eu.etaxonomy.taxeditor.model.AbstractUtility; import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; import eu.etaxonomy.taxeditor.model.IPartContentHasDetails; -import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewerE4; +import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData; +import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData; +import eu.etaxonomy.taxeditor.model.MessagingUtils; +import eu.etaxonomy.taxeditor.preference.PreferencesUtil; import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4; -import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility; +import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4; +import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart; /** * @author pplitzner * @date 18.07.2017 * */ -public class DetailsPartE4 extends AbstractCdmEditorPartE4{ +public class DetailsPartE4 extends AbstractCdmEditorPartE4 implements IPartContentHasSupplementalData, IPartContentHasFactualData { + @Inject + private Logger logger; - @Inject + @Inject public DetailsPartE4() { } - /** - * {@inheritDoc} - */ - @Override - protected AbstractCdmDataViewerE4 createViewer(Composite parent) { - return new DetailsViewerE4(parent, this); + @PostConstruct + public void create(Composite parent, MPart thisPart, IEclipseContext context) { + + this.thisPart = thisPart; + + viewer = ContextInjectionFactory.make(DetailsViewerE4.class, context); + ((DetailsViewerE4)viewer).init(parent, this); + + // Propagate selection from viewer + selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event))); + viewer.addSelectionChangedListener(selectionChangedListener); } - @Inject - @Optional - public void selectionChanged( - @Named(IServiceConstants.ACTIVE_SELECTION)Object selection, - @Named(IServiceConstants.ACTIVE_PART)MPart activePart, - MPart thisPart){ - if(activePart==thisPart){ - return; - } - if(selection==null){ - showEmptyPage(); + @Override + public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) { + if (activePart==thisPart){ return; } - Object partObject = activePart; - Object wrappedPart = WorkbenchUtility.getE4WrappedPart(activePart); - if(wrappedPart!=null){ - partObject = wrappedPart; - } - - IStructuredSelection structuredSelection; - if(!(selection instanceof IStructuredSelection)){ - structuredSelection = new StructuredSelection(selection); - } - else{ - structuredSelection = (IStructuredSelection) selection; - } - if(structuredSelection.isEmpty()){ - showEmptyPage(); + Object partObject = createPartObject(activePart); + if (partObject instanceof SupplementalDataPartE4 ) { + // do not show empty page return; } - if((partObject instanceof IEditorPart) || (partObject instanceof IPartContentHasDetails) - && partObject instanceof IConversationEnabled) { + + if(partObject instanceof IPartContentHasDetails){ + IStructuredSelection structuredSelection = createSelection(selection); + if(structuredSelection==null || structuredSelection.isEmpty()){ + showEmptyPage(); + return; + } + if(!(partObject instanceof ISelectionElementEditingPart) && + partObject instanceof IConversationEnabled && ((IConversationEnabled) partObject).getConversationHolder()==null) { + //TODO show specific message (refactor EmptyElement to allow specific messages) + showEmptyPage(); + return; + } // do not show details for feature nodes TODO strange check to avoid having shown the distribution map for every FeatureNodeContainer if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){ // do show the map for distributions - Feature feature = ((FeatureNodeContainer) ((IStructuredSelection) selection).getFirstElement()).getFeature(); + Feature feature = ((FeatureNodeContainer) structuredSelection.getFirstElement()).getFeature(); if(!feature.equals(Feature.DISTRIBUTION())){ showEmptyPage(); return; } } - showViewer(structuredSelection); - selectionProvidingPart = activePart; + + //FIXME this is a temporary workaround to fix selection handling for supplemental data view + // Now the supp data view gets double selection from details view and name editor (see #7126) + + viewer.setSelection(structuredSelection, false); + + showViewer(structuredSelection, activePart, viewer); + + + return; } else{ @@ -100,6 +112,29 @@ public class DetailsPartE4 extends AbstractCdmEditorPartE4{ } } + public void refreshSelection(){ + selectionChanged_internal(new StructuredSelection(this.viewer.getInput()), selectionProvidingPart, thisPart); + } + + @Override + protected void showEmptyPage() { + super.showEmptyPage(); + if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed() ){ + try{ + ((DetailsViewerE4)viewer).destroySections(); + }catch(SWTException e){ + if (PreferencesUtil.isShowUpWidgetIsDisposedMessages() && e.getMessage().equals("Widget is disposed")){ + MessagingUtils.errorDialog("Widget is disposed", + null, + MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE, + null, + e, + true); + + } + } + } + } @Override protected String getViewName(){