Revision 41e1666a
Added by Patrick Plitzner over 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.featuretree.e4; |
11 | 11 |
|
12 |
import java.util.ArrayList; |
|
13 | 12 |
import java.util.Arrays; |
14 | 13 |
import java.util.HashMap; |
15 | 14 |
import java.util.List; |
... | ... | |
32 | 31 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
33 | 32 |
import org.eclipse.jface.viewers.IStructuredSelection; |
34 | 33 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
34 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
35 | 35 |
import org.eclipse.jface.viewers.TreeViewer; |
36 | 36 |
import org.eclipse.swt.dnd.DND; |
37 | 37 |
import org.eclipse.swt.dnd.Transfer; |
... | ... | |
49 | 49 |
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer; |
50 | 50 |
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider; |
51 | 51 |
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider; |
52 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
53 | 52 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
54 | 53 |
import eu.etaxonomy.taxeditor.model.IDirtyMarkable; |
55 | 54 |
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails; |
56 | 55 |
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData; |
57 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
58 | 56 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
59 | 57 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
60 | 58 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
... | ... | |
90 | 88 |
|
91 | 89 |
private TreeViewer viewer; |
92 | 90 |
|
93 |
private List<AbstractPostOperation> operations = new ArrayList<>(); |
|
94 |
|
|
95 | 91 |
@Inject |
96 | 92 |
public FeatureTreeEditor() { |
97 | 93 |
CdmStore.getContextManager().addContextListener(this); |
... | ... | |
156 | 152 |
return dirty.isDirty(); |
157 | 153 |
} |
158 | 154 |
|
159 |
public void addOperation(AbstractPostOperation operation){ |
|
160 |
operations.add(operation); |
|
161 |
} |
|
162 |
|
|
163 | 155 |
/** {@inheritDoc} */ |
164 | 156 |
@Override |
165 | 157 |
public void selectionChanged(SelectionChangedEvent event) { |
... | ... | |
214 | 206 |
|
215 | 207 |
// commit the conversation and start a new transaction immediately |
216 | 208 |
conversation.commit(true); |
217 |
operations.forEach(operation->AbstractUtility.executeOperation(operation, sync)); |
|
218 |
operations.clear(); |
|
219 | 209 |
|
220 | 210 |
CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(getRootEntities()); |
221 | 211 |
|
222 |
/* |
|
223 |
* reload feature trees is needed to update i.e. |
|
224 |
* temporarily created feature nodes by adding features. |
|
225 |
* This is related to the current saving strategy which |
|
226 |
* emulates all changes on the visible feature tree but |
|
227 |
* the actual change is done when saving via executeOperation() |
|
228 |
*/ |
|
229 | 212 |
Object[] expandedElements = viewer.getExpandedElements(); |
230 |
viewer.getTree().removeAll(); |
|
231 |
List<FeatureTree> trees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null); |
|
232 |
viewer.setInput(trees); |
|
213 |
initialiseRootEntities(); |
|
233 | 214 |
viewer.setExpandedElements(expandedElements); |
234 | 215 |
|
235 | 216 |
this.setDirty(false); |
236 | 217 |
} |
237 | 218 |
|
219 |
private void initialiseRootEntities() { |
|
220 |
viewer.getTree().removeAll(); |
|
221 |
List<FeatureTree> trees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null); |
|
222 |
viewer.setInput(trees); |
|
223 |
} |
|
224 |
|
|
238 | 225 |
@PreDestroy |
239 | 226 |
public void dispose(){ |
240 | 227 |
selService.setSelection(null); |
... | ... | |
311 | 298 |
*/ |
312 | 299 |
@Override |
313 | 300 |
public boolean postOperation(Object objectAffectedByOperation) { |
314 |
return false; |
|
301 |
initialiseRootEntities(); |
|
302 |
viewer.refresh(); |
|
303 |
if(objectAffectedByOperation != null){ |
|
304 |
StructuredSelection selection = new StructuredSelection(objectAffectedByOperation); |
|
305 |
viewer.setSelection(selection); |
|
306 |
viewer.expandToLevel(objectAffectedByOperation, 1); |
|
307 |
} |
|
308 |
return true; |
|
315 | 309 |
} |
316 | 310 |
|
317 | 311 |
/** |
Also available in: Unified diff
ref #6806 Fix dirty state handling and saving in feature tree editor