1
|
package eu.etaxonomy.taxeditor.editor.view.checklist.e4.handler;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.UUID;
|
5
|
|
6
|
import javax.inject.Inject;
|
7
|
|
8
|
import org.eclipse.e4.core.services.log.Logger;
|
9
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
10
|
import org.eclipse.swt.widgets.Shell;
|
11
|
|
12
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
13
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
14
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
15
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
16
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
17
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
19
|
import eu.etaxonomy.taxeditor.editor.AppModelId;
|
20
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
21
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
22
|
import eu.etaxonomy.taxeditor.handler.defaultHandler.e4.DefaultOpenHandlerBaseE4;
|
23
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
24
|
import eu.etaxonomy.taxeditor.security.RequiredPermissions;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
|
27
|
public class OpenChecklistEditorHandlerE4 extends DefaultOpenHandlerBaseE4<ITaxonTreeNode> {
|
28
|
@Inject
|
29
|
private Logger logger;
|
30
|
private static final String COULD_NOT_OPEN_DISTRIBUTION_EDITOR_THE_HIERARCHY_IS_CORRUPTED = Messages.OpenChecklistEditorHandler_COULD_NOT_OPEN_MESSAGE;
|
31
|
private static final String COULD_NOT_OPEN_DISTRIBUTION_EDITOR = Messages.OpenChecklistEditorHandler_COULD_NOT_OPEN_TITLE;
|
32
|
|
33
|
@Override
|
34
|
protected ITaxonTreeNode getEntity(UUID uuid) {
|
35
|
ITaxonTreeNode taxonTreeNode = CdmStore.getService(ITaxonNodeService.class).load(uuid);
|
36
|
if(taxonTreeNode==null){
|
37
|
taxonTreeNode = CdmStore.getService(IClassificationService.class).load(uuid);
|
38
|
}
|
39
|
return taxonTreeNode;
|
40
|
}
|
41
|
|
42
|
@Override
|
43
|
protected void open(ITaxonTreeNode entity, Shell shell, EPartService partService) {
|
44
|
|
45
|
// if (PreferencesUtil.getBooleanValue(EditorPreferencePredicate.DistributionEditorActivated.getKey())) {
|
46
|
// if (StringUtils.isBlank(PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()) )){
|
47
|
//
|
48
|
// MessagingUtils.informationDialog(Messages.OpenChecklistEditorHandler_NO_AREAS, Messages.OpenChecklistEditorHandler_CHOOSE_AREA
|
49
|
// + Messages.OpenChecklistEditorHandler_GOTO_PREFERENCES);
|
50
|
// return;
|
51
|
// }
|
52
|
// if (entity instanceof Classification) {
|
53
|
// ChecklistEditorInput input = new ChecklistEditorInput(((Classification) entity));
|
54
|
// try {
|
55
|
// openChecklistEditor(input, partService);
|
56
|
// } catch (NullPointerException npe) {
|
57
|
// MessagingUtils.messageDialog(COULD_NOT_OPEN_DISTRIBUTION_EDITOR, OpenChecklistEditorHandlerE4.class,
|
58
|
// COULD_NOT_OPEN_DISTRIBUTION_EDITOR_THE_HIERARCHY_IS_CORRUPTED, npe);
|
59
|
// }
|
60
|
// } else if (entity instanceof TaxonNode) {
|
61
|
// ChecklistEditorInput input = new ChecklistEditorInput((TaxonNode) entity);
|
62
|
// try {
|
63
|
// openChecklistEditor(input, partService);
|
64
|
// } catch (NullPointerException npe) {
|
65
|
// MessagingUtils.messageDialog(COULD_NOT_OPEN_DISTRIBUTION_EDITOR, OpenChecklistEditorHandlerE4.class,
|
66
|
// COULD_NOT_OPEN_DISTRIBUTION_EDITOR_THE_HIERARCHY_IS_CORRUPTED, npe);
|
67
|
// }
|
68
|
// }
|
69
|
// }
|
70
|
|
71
|
EditorUtil.openDistributionEditor(entity.getUuid(), modelService, partService, application);
|
72
|
}
|
73
|
|
74
|
// private void openChecklistEditor(ChecklistEditorInput input, EPartService partService) {
|
75
|
// MPart part = partService.createPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_CHECKLISTEDITORE4);
|
76
|
// MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
|
77
|
// if(editorAreaPartStack!=null){
|
78
|
// editorAreaPartStack.getChildren().add(part);
|
79
|
// }
|
80
|
// part = partService.showPart(part, PartState.ACTIVATE);
|
81
|
// ChecklistEditorE4 checklistEditor = (ChecklistEditorE4) part.getObject();
|
82
|
// if (checklistEditor != null){
|
83
|
// checklistEditor.init(input);
|
84
|
// }else{
|
85
|
// logger.debug("Editor is null");
|
86
|
// }
|
87
|
// }
|
88
|
|
89
|
/**
|
90
|
* {@inheritDoc}
|
91
|
*/
|
92
|
@Override
|
93
|
protected boolean canExecute(ITaxonTreeNode entity) {
|
94
|
|
95
|
DescriptionBase instance = TaxonDescription.NewInstance();
|
96
|
boolean hasDescriptionPermission = CdmStore.currentAuthentiationHasPermission(instance, RequiredPermissions.DESCRIPTION_EDIT);
|
97
|
if (!hasDescriptionPermission){
|
98
|
return false;
|
99
|
}
|
100
|
boolean hasPermission = ((TaxonNode)entity).hasChildNodes() ? checkPermission(((TaxonNode)entity).getChildNodes(), false) || CdmStore.currentAuthentiationHasPermission(((TaxonNode) entity), RequiredPermissions.TAXONNODE_EDIT):CdmStore.currentAuthentiationHasPermission(((TaxonNode) entity), RequiredPermissions.TAXONNODE_EDIT);
|
101
|
return hasPermission && PreferencesUtil.getBooleanValue(PreferencePredicate.DistributionEditorActivated.getKey());
|
102
|
}
|
103
|
|
104
|
@Override
|
105
|
protected String getPartId() {
|
106
|
return AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART;
|
107
|
}
|
108
|
|
109
|
private boolean checkPermission(List<TaxonNode> nodes, boolean result){
|
110
|
|
111
|
for (TaxonNode node:nodes){
|
112
|
if (node.hasChildNodes() && !result){
|
113
|
result = result ||checkPermission(node.getChildNodes(), result);
|
114
|
|
115
|
}
|
116
|
result = result || CdmStore.currentAuthentiationHasPermission(node, RequiredPermissions.TAXONNODE_EDIT);
|
117
|
if (result){
|
118
|
return result;
|
119
|
}
|
120
|
}
|
121
|
return result;
|
122
|
}
|
123
|
}
|