Project

General

Profile

« Previous | Next » 

Revision 61100aa0

Added by Patrick Plitzner about 3 years ago

ref #7865 Change method signature for checking for dirty taxa editors

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
54 54
import eu.etaxonomy.taxeditor.model.AbstractUtility;
55 55
import eu.etaxonomy.taxeditor.model.MessagingUtils;
56 56
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
57
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
57 58

  
58 59
/**
59 60
 * Utility for the editor package
......
237 238
        return dirtyParts;
238 239
    }
239 240

  
240
    public static Collection<MPart> checkForTaxonChanges(UUID taxonUUID, EPartService partService ){
241
    public static Collection<IE4SavablePart> checkForTaxonChanges(UUID taxonUUID, EPartService partService ){
241 242
        Collection<MPart> parts = partService.getParts();
242
        Collection<MPart> dirtyParts = new HashSet();
243
        Collection<IE4SavablePart> dirtyParts = new HashSet<>();
243 244
        //check if part is already opened
244
        boolean isDirty = false;
245 245
        for (MPart part : parts) {
246 246
            if(part.getObject() instanceof TaxonNameEditorE4
247 247
                    && ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
248 248
                    && ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(taxonUUID)){
249 249
                if (part.isDirty()){
250
                    dirtyParts.add(part);
250
                    dirtyParts.add((IE4SavablePart) part);
251 251
                }
252 252

  
253 253
                break;
254 254
            }else if (taxonUUID == null){
255 255
                if (part.isDirty() && (part.getObject() instanceof TaxonNameEditorE4 || (part.getObject() instanceof BulkEditorE4 && ((BulkEditorE4)part.getObject()).getEditorInput() instanceof TaxonEditorInput))){
256
                    dirtyParts.add(part);
256
                    dirtyParts.add((IE4SavablePart) part);
257 257
                }
258 258
            }
259 259
        }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionElementsHandlerE4.java
19 19

  
20 20
import javax.inject.Named;
21 21

  
22
import org.eclipse.core.runtime.NullProgressMonitor;
22 23
import org.eclipse.e4.core.di.annotations.CanExecute;
23 24
import org.eclipse.e4.core.di.annotations.Execute;
24 25
import org.eclipse.e4.core.di.annotations.Optional;
......
50 51
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
51 52
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
52 53
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionElementsOperation;
53
import eu.etaxonomy.taxeditor.model.AbstractUtility;
54 54
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
55 55
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
56 56
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
57 57
import eu.etaxonomy.taxeditor.store.CdmStore;
58 58
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
59 59
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
60
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
60 61

  
61 62

  
62 63
/**
......
158 159
            }
159 160
            newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid();
160 161

  
161
            Collection<MPart> targetEditors = EditorUtil.checkForChanges(targetTaxon.getUuid(), partService);
162

  
163
            if (targetEditors != null || this.editor.isDirty()){
164
                boolean proceed = MessageDialog.openQuestion(null,
165
                        Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE);
166
                if( targetEditors.iterator().hasNext() ){
167
                    MPart part = targetEditors.iterator().next();
168
                    if (proceed) {
169
                        if (part != null){
170
                            if (part.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")){
171
                                TaxonNameEditorE4 targetEditor = (TaxonNameEditorE4) WorkbenchUtility.getE4WrappedPart(part);
172

  
173
                                targetEditor.save(AbstractUtility.getMonitor());
174
                            }
175
                            if (editor.isDirty()){
176
                                editor.save(AbstractUtility.getMonitor());
177
                            }
178
                        } else {
179
                            return;
180
                        }
181
                    }
162
            Collection<IE4SavablePart> targetEditors = EditorUtil.checkForTaxonChanges(targetTaxon.getUuid(), partService);
163

  
164
            if (!targetEditors.isEmpty() || this.editor.isDirty()){
165
                if(MessageDialog.openQuestion(null,Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE)){
166
                    this.editor.save(new NullProgressMonitor());
167
                    targetEditors.forEach(editor->editor.save(new NullProgressMonitor()));
168
                    return;
169
                }
170
                else{
171
                    return;
182 172
                }
183 173
            }
184 174

  
185
//            if ((targetEditor != null && targetEditor.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")) || this.editor.isDirty()){
186
//                boolean proceed = MessageDialog.openQuestion(null,
187
//                        Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE);
188
//                if (proceed) {
189
//                    if (targetEditor != null){
190
//                        e4WrappedPart = WorkbenchUtility.getE4WrappedPart(targetEditor);
191
//                        ((TaxonNameEditorE4)e4WrappedPart).save(AbstractUtility.getMonitor());
192
//                    }
193
//                    if (editor.isDirty()){
194
//                        editor.save(AbstractUtility.getMonitor());
195
//                    }
196
//                } else {
197
//                    return;
198
//                }
199
//            }
200

  
201 175
            String moveMessage = String.format(Messages.MoveDescriptionElementsHandler_ELEMENTS_MOVED, editor.getTaxon());
202 176

  
203 177
            AbstractPostTaxonOperation operation = new MoveDescriptionElementsOperation(
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionToOtherTaxonHandlerE4.java
12 12

  
13 13
import javax.inject.Named;
14 14

  
15
import org.eclipse.core.runtime.NullProgressMonitor;
15 16
import org.eclipse.e4.core.di.annotations.CanExecute;
16 17
import org.eclipse.e4.core.di.annotations.Execute;
17 18
import org.eclipse.e4.core.di.annotations.Optional;
......
45 46
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
46 47
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
47 48
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
49
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
48 50

  
49 51
/**
50 52
 *
......
122 124
        newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid();
123 125
        newAcceptedTaxonUuid = newAcceptedTaxonNode.getTaxon().getUuid();
124 126

  
125
        Collection<MPart> targetEditors = EditorUtil.checkForChanges(newAcceptedTaxonUuid, partService);
126

  
127
        if (targetEditors != null || this.editor.isDirty()){
128
            boolean proceed = MessageDialog.openQuestion(null,
129
                    Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE);
130
            if( targetEditors.iterator().hasNext() ){
131
                MPart part = targetEditors.iterator().next();
132
                if (proceed) {
133
                    if (part != null){
134
                        if (part.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")){
135
                            TaxonNameEditorE4 targetEditor = (TaxonNameEditorE4) WorkbenchUtility.getE4WrappedPart(part);
136
                            targetEditor.save(AbstractUtility.getMonitor());
137
                        }
138
                        if (editor.isDirty()){
139
                            editor.save(AbstractUtility.getMonitor());
140
                        }
141
                    } else {
142
                        return;
143
                    }
144
                }
127
        Collection<IE4SavablePart> targetEditors = EditorUtil.checkForTaxonChanges(newAcceptedTaxonUuid, partService);
128

  
129
        if (!targetEditors.isEmpty() || this.editor.isDirty()){
130
            if(MessageDialog.openQuestion(null,Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE)) {
131
                this.editor.save(new NullProgressMonitor());
132
                targetEditors.forEach(editor->editor.save(new NullProgressMonitor()));
133
                return;
134
            }
135
            else{
136
                return;
145 137
            }
146 138
        }
147 139

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionToOtherTaxonOperation.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.editor.view.descriptive.operation;
11 11

  
12
import org.apache.commons.lang.StringUtils;
13 12
import org.eclipse.core.commands.ExecutionException;
14 13
import org.eclipse.core.commands.operations.IUndoContext;
15 14
import org.eclipse.core.runtime.IAdaptable;
......
18 17

  
19 18
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
20 19
import eu.etaxonomy.cdm.api.service.IDescriptionService;
21
import eu.etaxonomy.cdm.model.common.Annotation;
22
import eu.etaxonomy.cdm.model.common.AnnotationType;
23
import eu.etaxonomy.cdm.model.common.Language;
24 20
import eu.etaxonomy.cdm.model.description.TaxonDescription;
25 21
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
27 22
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
28 23
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29 24
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
......
72 67
	@Override
73 68
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
74 69
			throws ExecutionException {
75

  
76 70
		monitor.worked(20);
77 71
		bind();
78

  
79
		String moveMessage = String.format(Messages.MoveDescriptionToOtherTaxonOperation_MOVED_FROM, description.getTaxon());
80
		if(description.isProtectedTitleCache()){
81
			String separator = ""; //$NON-NLS-1$
82
			if(!StringUtils.isBlank(description.getTitleCache())){
83
				separator = " - "; //$NON-NLS-1$
84
			}
85
			description.setTitleCache(description.getTitleCache() + separator + moveMessage, true);
86
		}
87
		Annotation annotation = Annotation.NewInstance(moveMessage, Language.getDefaultLanguage());
88
		annotation.setAnnotationType(AnnotationType.TECHNICAL());
89
		description.addAnnotation(annotation);
90 72
		CdmStore.getService(IDescriptionService.class).moveTaxonDescription(description.getUuid(), newAcceptedTaxonNode.getTaxon().getUuid());
91 73
		monitor.worked(40);
92 74

  
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/SetPublishFlagForSubtreeHandlerE4.java
32 32
import eu.etaxonomy.cdm.api.service.config.PublishForSubtreeConfigurator;
33 33
import eu.etaxonomy.cdm.model.taxon.Classification;
34 34
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
35
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
36 35
import eu.etaxonomy.taxeditor.editor.EditorUtil;
37
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
38 36
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
39 37
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
40 38
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetPublishForSubtreeOperation;
41 39
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
42 40
import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetPublishForSubtreeWizard;
43
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
41
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
44 42

  
45 43
/**
46 44
 * @author k.luther
......
89 87
                    "unknown", //$NON-NLS-1$
90 88
                    TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
91 89
        }
92
        Collection<MPart> dirtyParts = EditorUtil.checkForTaxonChanges(null, partService);
90
        Collection<IE4SavablePart> dirtyParts = EditorUtil.checkForTaxonChanges(null, partService);
93 91

  
94 92
        if (dirtyParts != null && !dirtyParts.isEmpty()){
95 93
            String[] buttonLables = {YES, NO,CANCEL};
......
103 101
                return Status.CANCEL_STATUS;
104 102
            }
105 103

  
106
            Iterator<MPart> partIterator = dirtyParts.iterator();
104
            Iterator<IE4SavablePart> partIterator = dirtyParts.iterator();
107 105
            while( partIterator.hasNext() ){
108
                MPart part = partIterator.next();
106
                IE4SavablePart part = partIterator.next();
109 107
                if (proceed) {
110 108
                    if (part != null){
111
                        if (part.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")){ //$NON-NLS-1$
112
                            TaxonNameEditorE4 targetEditor = (TaxonNameEditorE4) WorkbenchUtility.getE4WrappedPart(part);
113
                            targetEditor.save(new NullProgressMonitor());
114
                        }else if (part.getElementId().equals("bulkeditor.editor")){ //$NON-NLS-1$
115
                            BulkEditorE4 targetEditor = (BulkEditorE4) WorkbenchUtility.getE4WrappedPart(part);
116
                            targetEditor.save(new NullProgressMonitor());
117
                        }
118

  
109
                        part.save(new NullProgressMonitor());
119 110
                    }
120

  
121 111
                }
122 112
            }
123 113
        }
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/SetSecReferenceForSubtreeHandlerE4.java
31 31
import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
32 32
import eu.etaxonomy.cdm.model.taxon.Classification;
33 33
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
34
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
35 34
import eu.etaxonomy.taxeditor.editor.EditorUtil;
36
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
37 35
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
38 36
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
39 37
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetSecundumForSubtreeOperation;
40 38
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
41 39
import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetSecundumForSubtreeConfigurationWizard;
42
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
40
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
43 41

  
44 42
/**
45 43
 * @author k.luther
......
84 82
                    "unknown", //$NON-NLS-1$
85 83
                    TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
86 84
        }
87
        Collection<MPart> dirtyParts = EditorUtil.checkForTaxonChanges(null, partService);
85
        Collection<IE4SavablePart> dirtyParts = EditorUtil.checkForTaxonChanges(null, partService);
88 86

  
89 87
        if (dirtyParts != null && !dirtyParts.isEmpty()){
90 88
            String[] buttonLables = {Messages.YES, Messages.NO,Messages.TreeNodeDropAdapter_CANCEL};
......
98 96
                return Status.CANCEL_STATUS;
99 97
            }
100 98

  
101
            Iterator<MPart> partIterator = dirtyParts.iterator();
99
            Iterator<IE4SavablePart> partIterator = dirtyParts.iterator();
102 100
            while( partIterator.hasNext() ){
103
                MPart part = partIterator.next();
101
                IE4SavablePart part = partIterator.next();
104 102
                if (proceed) {
105 103
                    if (part != null){
106
                        if (part.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")){ //$NON-NLS-1$
107
                            TaxonNameEditorE4 targetEditor = (TaxonNameEditorE4) WorkbenchUtility.getE4WrappedPart(part);
108
                            targetEditor.save(new NullProgressMonitor());
109
                        }else if (part.getElementId().equals("bulkeditor.editor")){ //$NON-NLS-1$
110
                            BulkEditorE4 targetEditor = (BulkEditorE4) WorkbenchUtility.getE4WrappedPart(part);
111
                            targetEditor.save(new NullProgressMonitor());
112
                        }
113

  
104
                        part.save(new NullProgressMonitor());
114 105
                    }
115

  
116 106
                }
117 107
            }
118 108
        }

Also available in: Unified diff