*/
package eu.etaxonomy.taxeditor.view.e4;
+import java.util.Collection;
import java.util.Set;
import javax.annotation.PreDestroy;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWTException;
+import org.springframework.security.core.GrantedAuthority;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.ITermNodeService;
import eu.etaxonomy.cdm.api.service.ITermService;
import eu.etaxonomy.cdm.api.service.IVocabularyService;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.name.TaxonName;
import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
import eu.etaxonomy.cdm.persistence.dto.TermDto;
+import eu.etaxonomy.cdm.persistence.dto.TermNodeDto;
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.editor.IBulkEditor;
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.security.RequiredPermissions;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
import eu.etaxonomy.taxeditor.view.e4.details.DetailsViewerE4;
/**
* @author pplitzner
* @since Aug 10, 2017
- *
*/
public abstract class AbstractCdmEditorPartE4
implements IConversationEnabled, IDirtyMarkable, ISelectionElementEditingPart, IPostOperationEnabled{
- private DelaySelection delaySelection = null;
+ private static final Logger logger = Logger.getLogger(AbstractCdmEditorPartE4.class);
+
+ private DelaySelection delaySelection = null;
/**
* This is the monitor for the DelaySelection runnable.
* If it is <code>true</code> then it is currently delaying a selection.
*/
private boolean isInDelay;
- private boolean isEnabled;
- private static final Logger logger = Logger.getLogger(AbstractCdmEditorPartE4.class);
+ private boolean isEnabled = true;
/**
* This class invokes internal_selectionChanged() in a separate thread.
public synchronized void setThisPart(MPart thisPart) {
this.thisPart = thisPart;
}
-
}
protected Viewer viewer;
protected abstract void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart);
+ protected boolean showEmptyIfNoActiveEditor(){
+ return true;
+ }
+
@Inject
public void selectionChanged(
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
return;
}
// no active editor found
- if(activePart==thisPart && WorkbenchUtility.getActiveEditorPart(partService)==null){
+ if(activePart==thisPart && WorkbenchUtility.getActiveEditorPart(partService)==null && showEmptyIfNoActiveEditor()){
showEmptyPage();
return;
}
if (viewer != null && viewer.getControl()!= null && viewer.getInput() != null && !viewer.getControl().isDisposed()){
try{
- viewer.getControl().setEnabled(true);
+ viewer.getControl().setEnabled(isEnabled);
}catch(SWTException e){
logger.debug("Something went wrong for viewer.getControl().setEnabled(true) in " + this.getClass().getSimpleName(), e);
}
-
}
- if((previousSelection!=null && selection!=null) && (activePart != null && selectionProvidingPart != null && activePart.equals(selectionProvidingPart)) &&
- (previousSelection==selection
- || previousSelection.equals(selection)
- || new StructuredSelection(selection).equals(previousSelection))
+ if((previousSelection!=null && selection!=null)
+ && (activePart != null && selectionProvidingPart != null && activePart.equals(selectionProvidingPart))
+ && (previousSelection==selection
+ || previousSelection.equals(selection)
+ || new StructuredSelection(selection).equals(previousSelection))
) {
return;
}
if(delaySelection==null){
delaySelection = new DelaySelection(selection, activePart, thisPart);
+ }else{
+ delaySelection.setSelection(selection);
+ delaySelection.setActivePart(activePart);
+ delaySelection.setThisPart(thisPart);
}
- delaySelection.setSelection(selection);
- delaySelection.setActivePart(activePart);
- delaySelection.setThisPart(thisPart);
if(!isInDelay){
isInDelay = true;
sync.asyncExec(delaySelection);
}
}
- /** {@inheritDoc} */
@Override
public void changed(Object object) {
if(selectionProvidingPart!=null){
if(part instanceof IDirtyMarkable){
((IDirtyMarkable) part).changed(object);
}
+ if (part instanceof IBulkEditor){
+ ((IBulkEditor)part).setSelection(createSelection(object));
+ }
}
}
return viewer;
}
+ public boolean isEnabled() {
+ return isEnabled;
+ }
+
+ public void setEnabled(boolean isEnabled) {
+ this.isEnabled = isEnabled;
+ }
+
protected void showViewer(IStructuredSelection selection, MPart activePart, Viewer viewer){
+ if(CdmStore.getCurrentSessionManager().getActiveSession()==null){
+ return;
+ }
if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()){
Object element = selection.getFirstElement();
Object part = createPartObject(activePart);
+ if (viewer.getControl().isDisposed()){
+ return;
+ }
viewer.getControl().setEnabled(true);
- if(selection.getFirstElement()!=null){
+ if(element != null){
if (element instanceof Taxon){
+
Taxon taxon = HibernateProxyHelper.deproxy(element, Taxon.class);
- if (taxon.isMisapplication() || taxon.isProparteSynonym() || taxon.isInvalidDesignation()){
+ if (part instanceof ITaxonEditor){
+ TaxonNode node = ((ITaxonEditor) part).getTaxonNode();
+ if (node != null){
+ boolean doEnable = CdmStore.currentAuthentiationHasPermission(node,
+ RequiredPermissions.TAXON_EDIT);
+ if (!doEnable){
+ //check whether there are explicit TaxonNode rights
+ boolean taxonnodePermissionExists = false;
+ Collection<? extends GrantedAuthority> authorities = CdmStore.getCurrentAuthentiation().getAuthorities();
+ for (GrantedAuthority grantedAuthority: authorities){
+ if (grantedAuthority.getAuthority().startsWith("TAXONNODE")){
+ taxonnodePermissionExists = true;
+ }
+ }
+ if (!taxonnodePermissionExists){
+ doEnable = true;
+ }
+ }
+
+ //TODO: differ between the views
+ this.isEnabled = doEnable;
+ }
+ }
+ if (taxon.isMisapplication() || taxon.isProparteSynonym() ){
if(part instanceof ITaxonEditor){
Taxon accepted = ((ITaxonEditor) part).getTaxon();
+
Set<TaxonRelationship> rels = taxon.getTaxonRelations(accepted);
if (rels != null && rels.iterator().hasNext() && !taxon.equals(accepted)){
TaxonRelationship rel = rels.iterator().next();
- if ((rel.getType().isMisappliedNameOrInvalidDesignation() || rel.getType().isAnySynonym()) && !rel.getFromTaxon().equals(((ITaxonEditor) part).getTaxon())){
+ if ((rel.getType().isMisappliedName() || rel.getType().isAnySynonym()) && !rel.getFromTaxon().equals(((ITaxonEditor) part).getTaxon())){
viewer.setInput(rel);
selectionProvidingPart = activePart;
return;
}
}
}
-
-
}
}
+
//unwrap term DTOs
if(element instanceof TermDto){
element = CdmStore.getService(ITermService.class).load(((TermDto) element).getUuid());
element = CdmStore.getService(IVocabularyService.class).load(((TermVocabularyDto) element).getUuid());
}
+
selectionProvidingPart = activePart;
if (viewer instanceof DetailsViewerE4){
- ((DetailsViewerE4)viewer).setInput(element, part);
- if (!selectionProvidingPart.getElementId().equals("eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart")){
- ((DetailsViewerE4)viewer).setDetailsEnabled(true);
- }
+ if (selectionProvidingPart.getElementId().equals("eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart")){
+ ((DetailsViewerE4)viewer).setDetailsEnabled(false);
+ }else{
+ ((DetailsViewerE4)viewer).setDetailsEnabled(isEnabled);
+ }
+ ((DetailsViewerE4)viewer).setInput(element, part);
+
}
else{
+ if(element instanceof TermNodeDto){
+ element = CdmStore.getService(ITermNodeService.class).load(((TermNodeDto) element).getUuid());
+ }
if (activePart.getObject() instanceof DetailsPartE4 && element instanceof TaxonName){
selectionProvidingPart = ((DetailsPartE4)activePart.getObject()).getSelectionProvidingPart();
}
+
viewer.setInput(element);
+ viewer.getControl().setEnabled(isEnabled);
}
}
}
+
}
protected Object createPartObject(MPart activePart) {
null,
e,
true);
-
}
}
-
}
+
reset();
if(thisPart!=null){
thisPart.setLabel(getViewName());
return structuredSelection;
}
- /**
- * {@inheritDoc}
- */
@Override
public ConversationHolder getConversationHolder() {
if(selectionProvidingPart != null && selectionProvidingPart instanceof IConversationEnabled) {
return null;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean postOperation(Object objectAffectedByOperation) {
changed(objectAffectedByOperation);
+// Object part = selectionProvidingPart.getObject();
+// if (part instanceof IBulkEditor){
+// ((IBulkEditor)part).setSelection(createSelection(objectAffectedByOperation));
+// }
return true;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean onComplete() {
viewer.refresh();
return true;
}
- /**
- * {@inheritDoc}
- */
@Override
public MPart getSelectionProvidingPart() {
return selectionProvidingPart;
}
- /**
- * {@inheritDoc}
- */
@Override
public void update(CdmDataChangeMap arg0) {
}
- /**
- * {@inheritDoc}
- */
@Override
public void forceDirty() {
}