Revision a776559e
Added by Katja Luther over 4 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DeleteHandlerE4.java | ||
---|---|---|
28 | 28 |
import org.eclipse.jface.viewers.IStructuredSelection; |
29 | 29 |
import org.eclipse.swt.widgets.Shell; |
30 | 30 |
|
31 |
import eu.etaxonomy.cdm.api.service.DeleteResult; |
|
32 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
|
33 |
import eu.etaxonomy.cdm.api.service.UpdateResult.Status; |
|
34 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
31 | 35 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
32 | 36 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
33 | 37 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
34 | 38 |
import eu.etaxonomy.cdm.model.description.TaxonNameDescription; |
39 |
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4; |
|
35 | 40 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
36 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
|
37 | 41 |
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4; |
42 |
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView; |
|
38 | 43 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4; |
39 | 44 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteDescriptionElementOperation; |
40 | 45 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteSpecimenDescriptionOperation; |
41 | 46 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteTaxonDescriptionOperation; |
42 | 47 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteTaxonNameDescriptionOperation; |
43 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
44 | 48 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
45 | 49 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
46 | 50 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
47 | 51 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
52 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
48 | 53 |
|
49 | 54 |
/** |
50 | 55 |
* |
... | ... | |
73 | 78 |
IUndoContext undoContext = EditorUtil.getUndoContext(); |
74 | 79 |
|
75 | 80 |
List<AbstractPostOperation> operations = new ArrayList(); |
76 |
|
|
81 |
AbstractPostOperation operation = null; |
|
77 | 82 |
for(Iterator iter = selection.iterator();iter.hasNext();){ |
78 | 83 |
Object object = iter.next(); |
79 |
|
|
80 |
// TaxonDescription |
|
81 |
if(object instanceof TaxonDescription ){ |
|
82 |
DeleteTaxonDescriptionOperation operation = new DeleteTaxonDescriptionOperation(label, undoContext, (TaxonDescription) object, factualDataPart, cdmEntitySessionEnabled); |
|
83 |
|
|
84 |
operations.add(operation); |
|
85 |
((TaxonDescription) object).getTaxon().removeDescription((TaxonDescription) object); |
|
86 |
operation.getPostOperationEnabled().postOperation(object); |
|
84 |
if (object == null){ |
|
85 |
continue; |
|
87 | 86 |
} |
88 |
if(object instanceof TaxonNameDescription ){ |
|
89 |
DeleteTaxonNameDescriptionOperation operation = new DeleteTaxonNameDescriptionOperation(label, undoContext, (TaxonNameDescription) object, factualDataPart, cdmEntitySessionEnabled); |
|
90 |
operations.add(operation); |
|
91 |
((TaxonNameDescription) object).getTaxonName().removeDescription((TaxonNameDescription) object); |
|
92 |
operation.getPostOperationEnabled().postOperation(object); |
|
87 |
DescriptionBase description = null; |
|
88 |
DeleteResult result = new DeleteResult(); |
|
89 |
if (object instanceof DescriptionBase){ |
|
90 |
result = CdmStore.getService(IDescriptionService.class).isDeletable(((DescriptionBase) object).getUuid()); |
|
91 |
description = (DescriptionBase) object; |
|
92 |
} else if (object instanceof DescriptionElementBase){ |
|
93 |
description = ((DescriptionElementBase)object).getInDescription(); |
|
93 | 94 |
} |
94 |
else if(object instanceof SpecimenDescription){ |
|
95 |
DeleteSpecimenDescriptionOperation operation = new DeleteSpecimenDescriptionOperation(label, undoContext, (SpecimenDescription) object, factualDataPart, cdmEntitySessionEnabled); |
|
96 |
operations.add(operation) ; |
|
97 |
((SpecimenDescription) object).getDescribedSpecimenOrObservation().removeDescription((SpecimenDescription) object); |
|
95 |
if (result.getStatus().equals(Status.OK)){ |
|
96 |
// TaxonDescription |
|
97 |
if(object instanceof TaxonDescription ){ |
|
98 | 98 |
|
99 |
} |
|
100 |
// DescriptionElementBase |
|
101 |
else if(object instanceof DescriptionElementBase){ |
|
102 |
DeleteDescriptionElementOperation operation = new DeleteDescriptionElementOperation(label, undoContext, (DescriptionElementBase) object, factualDataPart, cdmEntitySessionEnabled); |
|
103 |
AbstractUtility.executeOperation(operation, sync); |
|
104 |
} |
|
105 |
else if(object instanceof FeatureNodeContainer){ |
|
106 |
List<DescriptionElementBase> descriptions = ((FeatureNodeContainer) object).getDescriptionElementsForEntireBranch(); |
|
99 |
operation = new DeleteTaxonDescriptionOperation(label, undoContext, (TaxonDescription) object, factualDataPart, cdmEntitySessionEnabled); |
|
100 |
|
|
101 |
((TaxonDescription) object).getTaxon().removeDescription((TaxonDescription) object); |
|
102 |
|
|
103 |
} else if(object instanceof TaxonNameDescription ){ |
|
104 |
operation = new DeleteTaxonNameDescriptionOperation(label, undoContext, (TaxonNameDescription) object, factualDataPart, cdmEntitySessionEnabled); |
|
105 |
|
|
106 |
((TaxonNameDescription) object).getTaxonName().removeDescription((TaxonNameDescription) object); |
|
107 |
|
|
108 |
} else if(object instanceof SpecimenDescription){ |
|
109 |
operation = new DeleteSpecimenDescriptionOperation(label, undoContext, (SpecimenDescription) object, factualDataPart, cdmEntitySessionEnabled); |
|
110 |
|
|
111 |
((SpecimenDescription) object).getDescribedSpecimenOrObservation().removeDescription((SpecimenDescription) object); |
|
107 | 112 |
|
108 |
for(DescriptionElementBase description : descriptions){ |
|
109 |
DeleteDescriptionElementOperation operation = new DeleteDescriptionElementOperation(label, undoContext, description, factualDataPart, cdmEntitySessionEnabled); |
|
113 |
} else if(object instanceof DescriptionElementBase){ |
|
114 |
// DescriptionElementBase |
|
115 |
operation = new DeleteDescriptionElementOperation(label, undoContext, (DescriptionElementBase) object, factualDataPart, cdmEntitySessionEnabled); |
|
116 |
((DescriptionElementBase) object).getInDescription().removeElement((DescriptionElementBase) object); |
|
117 |
} else if(object instanceof FeatureNodeContainer){ |
|
118 |
List<DescriptionElementBase> descriptions = ((FeatureNodeContainer) object).getDescriptionElementsForEntireBranch(); |
|
110 | 119 |
|
111 |
AbstractUtility.executeOperation(operation, sync); |
|
120 |
for(DescriptionElementBase descriptionElement : descriptions){ |
|
121 |
operation = new DeleteDescriptionElementOperation(label, undoContext, descriptionElement, factualDataPart, cdmEntitySessionEnabled); |
|
122 |
|
|
123 |
} |
|
124 |
} |
|
125 |
// if (operation != null){ |
|
126 |
// operation.getPostOperationEnabled().postOperation(object); |
|
127 |
// } |
|
128 |
if (factualDataPart.getSelectionProvidingPart().getObject() instanceof TaxonNameEditorE4){ |
|
129 |
((TaxonNameEditorE4)factualDataPart.getSelectionProvidingPart().getObject()).getEditorInput().addOperation(operation); |
|
130 |
((TaxonNameEditorE4)factualDataPart.getSelectionProvidingPart().getObject()).setDirty(); |
|
131 |
((TaxonNameEditorE4)factualDataPart.getSelectionProvidingPart().getObject()).redraw(); |
|
132 |
} |
|
133 |
if (factualDataPart.getSelectionProvidingPart().getObject() instanceof DerivateView){ |
|
134 |
((DerivateView)factualDataPart.getSelectionProvidingPart().getObject()).addOperation(operation); |
|
135 |
((DerivateView)factualDataPart.getSelectionProvidingPart().getObject()).setDirty(true); |
|
136 |
if (object instanceof DescriptionBase){ |
|
137 |
((DerivateView)factualDataPart.getSelectionProvidingPart().getObject()).changed(((SpecimenDescription)object).getDescribedSpecimenOrObservation()); |
|
138 |
} else if (object instanceof DescriptionElementBase){ |
|
139 |
if (description != null){ |
|
140 |
factualDataPart.changed(description); |
|
141 |
} |
|
142 |
} |
|
143 |
} |
|
144 |
if (factualDataPart.getSelectionProvidingPart().getObject() instanceof BulkEditorE4){ |
|
145 |
((BulkEditorE4)factualDataPart.getSelectionProvidingPart().getObject()).addOperation(operation); |
|
146 |
((BulkEditorE4)factualDataPart.getSelectionProvidingPart().getObject()).setDirty(true); |
|
147 |
((BulkEditorE4)factualDataPart.getSelectionProvidingPart().getObject()).changed(((SpecimenDescription)object).getDescribedSpecimenOrObservation()); |
|
112 | 148 |
} |
113 | 149 |
} |
114 |
|
|
115 | 150 |
else{ |
116 |
MessagingUtils.error(getClass(), Messages.DeleteHandler_INVALID_SELECTION, null); |
|
117 |
} |
|
118 |
} |
|
151 |
Exception e = result.getExceptions() != null && !result.getExceptions().isEmpty()? result.getExceptions().iterator().next() : null; |
|
152 |
|
|
153 |
MessagingUtils.informationDialog("Delete not possible", e.getMessage()); |
|
154 |
break; |
|
119 | 155 |
|
120 |
// execute all cumulated operations |
|
121 |
for(AbstractPostOperation operation : operations){ |
|
122 |
if (factualDataPart.getSelectionProvidingPart().getObject() instanceof TaxonNameEditorE4){ |
|
123 |
((TaxonNameEditorE4)factualDataPart.getSelectionProvidingPart().getObject()).getEditorInput().addOperation(operation); |
|
124 |
((TaxonNameEditorE4)factualDataPart.getSelectionProvidingPart().getObject()).setDirty(); |
|
125 |
((TaxonNameEditorE4)factualDataPart.getSelectionProvidingPart().getObject()).redraw(); |
|
126 | 156 |
} |
127 | 157 |
|
128 |
// AbstractUtility.executeOperation(operation, sync); |
|
129 | 158 |
} |
130 | 159 |
|
160 |
|
|
161 |
|
|
131 | 162 |
} |
132 | 163 |
|
133 | 164 |
|
Also available in: Unified diff
ref #8784: fix deleteHandler for factual data