Project

General

Profile

Revision cf349935

IDcf3499355498af8ab4a78ceaa2e875cebb0d406a
Parent 54571b82
Child 288109a7

Added by Patrick Plitzner almost 2 years ago

Ask for saving before executing operations

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureNodeDropAdapter.java
13 13
import java.util.Collection;
14 14
import java.util.Collections;
15 15

  
16
import org.eclipse.core.runtime.NullProgressMonitor;
16 17
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
17 18
import org.eclipse.jface.util.LocalSelectionTransfer;
18 19
import org.eclipse.jface.viewers.IStructuredSelection;
......
35 36
import eu.etaxonomy.taxeditor.store.CdmStore;
36 37
import eu.etaxonomy.taxeditor.ui.dialog.selection.TermVocabularySelectionDialog;
37 38
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
39
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
38 40

  
39 41
public class FeatureNodeDropAdapter extends ViewerDropAdapter {
40 42

  
43
    public static final String SAVE_CHANGES_TITLE = "Unsaved changes";
44
    public static final String SAVE_CHANGES_MESSAGE = "The editor has unsaved changes. You need to save before performind this operation. Save now?";
45

  
41 46
    private MDirtyable dirtyable;
42 47
    private IE4SavablePart savablePart;
43 48

  
......
49 54

  
50 55
	@Override
51 56
	public boolean performDrop(Object data) {
57
        if(dirtyable.isDirty()){
58
            if(MessagingUtils.confirmDialog(SAVE_CHANGES_TITLE, SAVE_CHANGES_MESSAGE)){
59
                savablePart.save(new NullProgressMonitor());
60
            }
61
            else{
62
                return false;
63
            }
64
        }
52 65
		Object currentTarget = getCurrentTarget();
53 66
		FeatureNode target = null;
54 67
		if(currentTarget instanceof FeatureTree){
......
140 153
		        }
141 154
		    }
142 155
		}
143
		dirtyable.setDirty(true);
144 156
		viewer.refresh();
145 157
		return true;
146 158
	}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddChildFeatureHandler.java
13 13
import javax.inject.Named;
14 14

  
15 15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.NullProgressMonitor;
16 17
import org.eclipse.e4.core.di.annotations.CanExecute;
17 18
import org.eclipse.e4.core.di.annotations.Execute;
18 19
import org.eclipse.e4.core.di.annotations.Optional;
......
26 27
import eu.etaxonomy.cdm.model.description.Feature;
27 28
import eu.etaxonomy.cdm.model.description.FeatureNode;
28 29
import eu.etaxonomy.taxeditor.featuretree.AvailableFeaturesWizard;
30
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureNodeDropAdapter;
29 31
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
30 32
import eu.etaxonomy.taxeditor.featuretree.e4.operation.AddFeatureOperation;
33
import eu.etaxonomy.taxeditor.model.MessagingUtils;
31 34

  
32 35
/**
33 36
 * @author pplitzner
......
41 44
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
42 45
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection) {
43 46
        FeatureTreeEditor editor = ((FeatureTreeEditor) thisPart.getObject());
47
        if (editor.isDirty()) {
48
            if (MessagingUtils.confirmDialog(FeatureNodeDropAdapter.SAVE_CHANGES_TITLE,
49
                    FeatureNodeDropAdapter.SAVE_CHANGES_MESSAGE)){
50
                editor.save(new NullProgressMonitor());
51
            }
52
            else{
53
                return;
54
            }
55
        }
56

  
44 57
        AvailableFeaturesWizard wizard = new AvailableFeaturesWizard();
45 58
        WizardDialog dialog = new WizardDialog(shell, wizard);
46 59

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddFeatureHandler.java
13 13
import javax.inject.Named;
14 14

  
15 15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.NullProgressMonitor;
16 17
import org.eclipse.e4.core.di.annotations.CanExecute;
17 18
import org.eclipse.e4.core.di.annotations.Execute;
18 19
import org.eclipse.e4.core.di.annotations.Optional;
......
27 28
import eu.etaxonomy.cdm.model.description.FeatureNode;
28 29
import eu.etaxonomy.cdm.model.description.FeatureTree;
29 30
import eu.etaxonomy.taxeditor.featuretree.AvailableFeaturesWizard;
31
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureNodeDropAdapter;
30 32
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
31 33
import eu.etaxonomy.taxeditor.featuretree.e4.operation.AddFeatureOperation;
34
import eu.etaxonomy.taxeditor.model.MessagingUtils;
32 35

  
33 36
/**
34 37
 * @author pplitzner
......
42 45
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
43 46
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart) {
44 47
        FeatureTreeEditor editor = ((FeatureTreeEditor) thisPart.getObject());
48

  
49
        if (editor.isDirty()) {
50
            if (MessagingUtils.confirmDialog(FeatureNodeDropAdapter.SAVE_CHANGES_TITLE,
51
                    FeatureNodeDropAdapter.SAVE_CHANGES_MESSAGE)){
52
                editor.save(new NullProgressMonitor());
53
            }
54
            else{
55
                return;
56
            }
57
        }
58

  
59

  
45 60
        AvailableFeaturesWizard wizard = new AvailableFeaturesWizard();
46 61
        WizardDialog dialog = new WizardDialog(shell, wizard);
47 62

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/CreateFeatureTreeHandler.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.ui.model.application.ui.basic.MPart;
......
19 20
import org.eclipse.e4.ui.services.IServiceConstants;
20 21

  
21 22
import eu.etaxonomy.cdm.model.description.FeatureTree;
23
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureNodeDropAdapter;
22 24
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
23 25
import eu.etaxonomy.taxeditor.featuretree.e4.operation.CreateFeatureTreeOperation;
26
import eu.etaxonomy.taxeditor.model.MessagingUtils;
24 27

  
25 28
/**
26 29
 * @author pplitzner
......
31 34

  
32 35
    @Execute
33 36
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
37
        FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
38

  
39
        if (editor.isDirty()) {
40
            if (MessagingUtils.confirmDialog(FeatureNodeDropAdapter.SAVE_CHANGES_TITLE,
41
                    FeatureNodeDropAdapter.SAVE_CHANGES_MESSAGE)){
42
                editor.save(new NullProgressMonitor());
43
            }
44
            else{
45
                return;
46
            }
47
        }
48

  
49

  
34 50
        FeatureTree tree = FeatureTree.NewInstance();
35 51
        tree.setTitleCache("New feature tree", true);
36
        FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
37 52
        CreateFeatureTreeOperation operation = new CreateFeatureTreeOperation(tree, editor, editor);
38 53
        editor.addOperation(operation);
39 54
        List<FeatureTree> trees = (List<FeatureTree>) editor.getViewer().getInput();
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/FeatureTreeExportHandler.java
12 12

  
13 13
import javax.inject.Named;
14 14

  
15
import org.eclipse.core.runtime.NullProgressMonitor;
15 16
import org.eclipse.core.runtime.jobs.Job;
16 17
import org.eclipse.e4.core.di.annotations.CanExecute;
17 18
import org.eclipse.e4.core.di.annotations.Execute;
18 19
import org.eclipse.e4.core.di.annotations.Optional;
20
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19 21
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
20 22
import org.eclipse.e4.ui.services.IServiceConstants;
21 23
import org.eclipse.jface.viewers.IStructuredSelection;
......
25 27

  
26 28
import eu.etaxonomy.cdm.io.descriptive.owl.out.OwlExportConfigurator;
27 29
import eu.etaxonomy.cdm.model.description.FeatureTree;
30
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureNodeDropAdapter;
31
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
32
import eu.etaxonomy.taxeditor.model.MessagingUtils;
28 33
import eu.etaxonomy.taxeditor.store.CdmStore;
29 34

  
30 35
/**
......
36 41

  
37 42
    @Execute
38 43
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
39
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection){
44
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
45
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
46
        FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
47

  
48
        if (editor.isDirty()) {
49
            if (MessagingUtils.confirmDialog(FeatureNodeDropAdapter.SAVE_CHANGES_TITLE,
50
                    FeatureNodeDropAdapter.SAVE_CHANGES_MESSAGE)){
51
                editor.save(new NullProgressMonitor());
52
            }
53
            else{
54
                return;
55
            }
56
        }
57

  
40 58
        FeatureTree selectedFeatureTree = (FeatureTree) selection.getFirstElement();
41 59
        DirectoryDialog dialog = new DirectoryDialog(shell);
42 60
        String directoryString = dialog.open();
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/PasteFeatureHandler.java
3 3

  
4 4
import javax.inject.Named;
5 5

  
6
import org.eclipse.core.runtime.NullProgressMonitor;
6 7
import org.eclipse.e4.core.di.annotations.CanExecute;
7 8
import org.eclipse.e4.core.di.annotations.Execute;
8 9
import org.eclipse.e4.core.di.annotations.Optional;
......
15 16

  
16 17
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
17 18
import eu.etaxonomy.cdm.model.description.FeatureNode;
19
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureNodeDropAdapter;
18 20
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
21
import eu.etaxonomy.taxeditor.model.MessagingUtils;
19 22
import eu.etaxonomy.taxeditor.store.CdmStore;
20 23

  
21 24
public class PasteFeatureHandler {
......
23 26
    @Execute
24 27
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
25 28
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){
26
        ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
27 29
        FeatureTreeEditor editor = (FeatureTreeEditor)part.getObject();
30

  
31
        if (editor.isDirty()) {
32
            if (MessagingUtils.confirmDialog(FeatureNodeDropAdapter.SAVE_CHANGES_TITLE,
33
                    FeatureNodeDropAdapter.SAVE_CHANGES_MESSAGE)){
34
                editor.save(new NullProgressMonitor());
35
            }
36
            else{
37
                return;
38
            }
39
        }
40

  
41
        ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
28 42
        FeatureNode parentNode = (FeatureNode) selection.getFirstElement();
29 43
        FeatureNode copiedNode = (FeatureNode) ((IStructuredSelection)clipBoardSelection).getFirstElement();
30 44

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/RemoveFeatureHandler.java
10 10

  
11 11
import javax.inject.Named;
12 12

  
13
import org.eclipse.core.runtime.NullProgressMonitor;
13 14
import org.eclipse.e4.core.di.annotations.CanExecute;
14 15
import org.eclipse.e4.core.di.annotations.Execute;
15 16
import org.eclipse.e4.core.di.annotations.Optional;
......
19 20
import org.eclipse.jface.viewers.IStructuredSelection;
20 21

  
21 22
import eu.etaxonomy.cdm.model.description.FeatureNode;
23
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureNodeDropAdapter;
22 24
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
23 25
import eu.etaxonomy.taxeditor.featuretree.e4.operation.RemoveFeatureOperation;
26
import eu.etaxonomy.taxeditor.model.MessagingUtils;
24 27
import eu.etaxonomy.taxeditor.workbench.part.IE4ViewerPart;
25 28

  
26 29
/**
......
34 37
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
35 38
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection){
36 39
        FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
40

  
41
        if (editor.isDirty()) {
42
            if (MessagingUtils.confirmDialog(FeatureNodeDropAdapter.SAVE_CHANGES_TITLE,
43
                    FeatureNodeDropAdapter.SAVE_CHANGES_MESSAGE)){
44
                editor.save(new NullProgressMonitor());
45
            }
46
            else{
47
                return;
48
            }
49
        }
50

  
37 51
        for (Object selectedObject : selection.toArray()) {
38 52
            FeatureNode featureNode = (FeatureNode) selectedObject;
39 53
            RemoveFeatureOperation operation = new RemoveFeatureOperation(featureNode, editor, editor);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/RemoveFeatureTreeHandler.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;
......
21 22
import org.eclipse.jface.viewers.IStructuredSelection;
22 23

  
23 24
import eu.etaxonomy.cdm.model.description.FeatureTree;
25
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureNodeDropAdapter;
24 26
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
25 27
import eu.etaxonomy.taxeditor.featuretree.e4.operation.RemoveFeatureTreeOperation;
28
import eu.etaxonomy.taxeditor.model.MessagingUtils;
26 29

  
27 30
/**
28 31
 * @author pplitzner
......
35 38
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
36 39
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection){
37 40
        FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
41

  
42
        if (editor.isDirty()) {
43
            if (MessagingUtils.confirmDialog(FeatureNodeDropAdapter.SAVE_CHANGES_TITLE,
44
                    FeatureNodeDropAdapter.SAVE_CHANGES_MESSAGE)){
45
                editor.save(new NullProgressMonitor());
46
            }
47
            else{
48
                return;
49
            }
50
        }
51

  
38 52
        List<FeatureTree> trees = (List<FeatureTree>) editor.getViewer().getInput();
39 53
        for (Object selectedObject : selection.toArray()) {
40 54
            FeatureTree featureTree = (FeatureTree) selectedObject;

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)