Project

General

Profile

Revision a776559e

IDa776559e41e607d2659c2dca6fff1f16cfb15f25
Parent 01e26d23
Child b0947131

Added by Katja Luther 6 months ago

ref #8784: fix deleteHandler for factual data

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
16 16
import javax.inject.Inject;
17 17
import javax.inject.Named;
18 18

  
19
import org.eclipse.core.commands.ExecutionException;
20
import org.eclipse.core.commands.operations.IOperationHistory;
21
import org.eclipse.core.runtime.IAdaptable;
19 22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.NullProgressMonitor;
25
import org.eclipse.core.runtime.Status;
20 26
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
21 27
import org.eclipse.e4.core.contexts.IEclipseContext;
22 28
import org.eclipse.e4.core.di.annotations.Optional;
......
45 51
import org.eclipse.swt.widgets.Composite;
46 52
import org.eclipse.swt.widgets.Tree;
47 53
import org.eclipse.ui.IMemento;
54
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
48 55

  
49 56
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
50 57
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
51 58
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
52 59
import eu.etaxonomy.cdm.api.service.ITaxonService;
53 60
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
54
import eu.etaxonomy.cdm.model.molecular.Sequence;
55 61
import eu.etaxonomy.cdm.model.molecular.SingleRead;
56 62
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
57 63
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
......
64 70
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
65 71
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
66 72
import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController;
73
import eu.etaxonomy.taxeditor.model.AbstractUtility;
67 74
import eu.etaxonomy.taxeditor.model.IContextListener;
68 75
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
69 76
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
......
71 78
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
72 79
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
73 80
import eu.etaxonomy.taxeditor.model.MessagingUtils;
81
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
74 82
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
75 83
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
76 84
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
77 85
import eu.etaxonomy.taxeditor.store.CdmStore;
86
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
78 87
import eu.etaxonomy.taxeditor.view.search.derivative.DerivateContentProvider;
79 88
import eu.etaxonomy.taxeditor.view.search.derivative.DerivateLabelProvider;
80 89
import eu.etaxonomy.taxeditor.workbench.part.ICollapsableExpandable;
......
155 164

  
156 165
    private ISelectionChangedListener selectionChangedListener;
157 166

  
167
    private Set<AbstractPostOperation> operations = new HashSet<>();
168

  
158 169
    @Inject
159 170
    private MPart thisPart;
160 171

  
......
358 369
        // commit the conversation and start a new transaction immediately
359 370
        conversation.commit(true);
360 371

  
372
        for(AbstractPostOperation entry:operations){
373
            IStatus status = Status.CANCEL_STATUS;
374
            final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
375
                    .getUIInfoAdapter(AbstractUtility.getShell());
376
            String operationlabel = entry.getLabel();
377
            try {
378
                entry.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
379
                status = entry.execute(new NullProgressMonitor(), uiInfoAdapter);
380
            } catch (ExecutionException e) {
381

  
382
                MessagingUtils.operationDialog(AbstractUtility.class, e, TaxeditorStorePlugin.PLUGIN_ID, operationlabel, null);
383

  
384
            }
385

  
386
            String statusString = status.equals(Status.OK_STATUS) ? "completed"
387
                    : "cancelled";
388

  
389
            IPostOperationEnabled postOperationEnabled = entry
390
                    .getPostOperationEnabled();
391
            if (postOperationEnabled != null) {
392
                postOperationEnabled.onComplete();
393
            }
394

  
395

  
396
            //AbstractUtility.executeOperation(entry,sync);
397
        }
398

  
399
        operations.clear();
361 400
        CdmStore.getService(IOccurrenceService.class).merge(new ArrayList<>(rootElements), true);
362 401

  
363 402
        monitor.worked(1);
......
376 415
        dirty.setDirty(isDirty);
377 416
    }
378 417

  
418
    public Set<AbstractPostOperation> getOperations() {
419
        return operations;
420
    }
421

  
422
    public void addOperation(AbstractPostOperation operation) {
423
        this.operations.add(operation);
424
    }
425

  
379 426
    @Focus
380 427
    public void setFocus() {
381 428
        //make sure to bind again if maybe in another view the conversation was unbound
......
648 695
    }
649 696

  
650 697

  
698
    @Override
651 699
    public boolean isDirty() {
652 700
        return dirty.isDirty();
653 701
    }
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

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/DeleteSpecimenDescriptionOperation.java
51 51
			throws ExecutionException {
52 52

  
53 53
		monitor.worked(40);
54
		CdmStore.getService(IDescriptionService.class).deleteDescription(description);
54
		CdmStore.getService(IDescriptionService.class).deleteDescription(description.getUuid());
55 55

  
56 56
		return postExecute(description);
57 57
	}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)