Project

General

Profile

Revision 5129bf4e

ID5129bf4e536d07caa735cd2f6d7c98416f906964
Parent 8f2a9479
Child ea7c58af

Added by Patrick Plitzner about 2 years ago

ref #7887 Prompt user if editor is dirty

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermEditorE4.java
25 25
import org.eclipse.e4.ui.services.EMenuService;
26 26
import org.eclipse.e4.ui.workbench.modeling.EPartService;
27 27
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
28
import org.eclipse.jface.dialogs.MessageDialog;
28 29
import org.eclipse.jface.util.LocalSelectionTransfer;
29 30
import org.eclipse.jface.viewers.ISelectionChangedListener;
30 31
import org.eclipse.jface.viewers.StructuredSelection;
......
153 154
        thisPart.setLabel(input.getName());
154 155
	}
155 156

  
157
    /**
158
     * Checks the dirty flag and, if set, prompts the user to optionally save
159
     * the editor
160
     *
161
     * @return <code>true</code> if the editor is not dirty anymore, either
162
     *         because it wasn't beforehand or because it has been saved.
163
     *         <code>false</code> otherwise
164
     */
165
	public boolean checkDirty(){
166
	    if (isDirty()){
167
	        boolean proceed = MessageDialog.openQuestion(null,
168
	                "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
169
	        if (proceed) {
170
	            save(null);
171
	            return true;
172
	        }
173
	        else{
174
	            return false;
175
	        }
176
	    }
177
	    else{
178
	        return true;
179
	    }
180
	}
181

  
156 182
	@Override
157 183
    @Persist
158 184
	public void save(IProgressMonitor monitor) {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/CreateDefinedTermHandlerE4.java
43 43
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
44 44
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MHandledMenuItem menuItem,
45 45
            UISynchronize sync) {
46

  
47 46
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
48

  
47
        if(!termEditor.checkDirty()){
48
            return;
49
        }
49 50
        boolean addTermAsKindOf =
50 51
                menuItem.getCommand().getElementId()
51 52
                .equals(AppModelId.COMMAND_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERMS_NEWKINDOFTERM)?true:false;
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/CreateTermVocabularyHandlerE4.java
35 35
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
36 36
            MMenuItem menuItem,
37 37
            UISynchronize sync) {
38

  
39 38
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
40

  
39
        if(!termEditor.checkDirty()){
40
            return;
41
        }
41 42
        String label = menuItem.getLocalizedLabel();
42 43
        IUndoContext undoContext = StoreUtil.getUndoContext();
43 44

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/DeleteTermBaseHandlerE4.java
20 20
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
21 21
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
22 22
import org.eclipse.e4.ui.services.IServiceConstants;
23
import org.eclipse.jface.dialogs.MessageDialog;
24 23
import org.eclipse.jface.viewers.IStructuredSelection;
25 24

  
26 25
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
......
44 43
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
45 44
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MMenuItem menuItem,
46 45
            UISynchronize sync) {
47

  
48 46
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
49

  
50
        if (termEditor.isDirty()){
51
            boolean proceed = MessageDialog.openQuestion(null,
52
                    "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
53
            if (proceed) {
54
                termEditor.save(null);
55
            } else {
56
                return;
57
            }
47
        if(!termEditor.checkDirty()){
48
            return;
58 49
        }
59 50
        String label = menuItem.getLocalizedLabel();
60 51
        IUndoContext undoContext = StoreUtil.getUndoContext();

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)