*/
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.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.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.IPartContentHasSupplementalData;
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
-import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
+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 {
@Inject
public DetailsPartE4() {
}
- /**
- * {@inheritDoc}
- */
- @Override
- protected AbstractCdmDataViewerE4 createViewer(Composite parent) {
- return new DetailsViewerE4(parent, this);
+ @PostConstruct
+ public void create(Composite parent, MPart thisPart) {
+
+ this.thisPart = thisPart;
+
+ viewer = new DetailsViewerE4(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;
- }
+ Object partObject = createPartObject(activePart);
- IStructuredSelection structuredSelection;
- if(!(selection instanceof IStructuredSelection)){
- structuredSelection = new StructuredSelection(selection);
- }
- else{
- structuredSelection = (IStructuredSelection) selection;
- }
- if(structuredSelection.isEmpty()){
- showEmptyPage();
- 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;
+ showViewer(structuredSelection, activePart, viewer);
return;
}
else{
}
}
+ @Override
+ protected void showEmptyPage() {
+ super.showEmptyPage();
+ if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()){
+ ((DetailsViewerE4)viewer).destroySections();
+ }
+ }
@Override
protected String getViewName(){