ref #8146 Adapt AvailableFeaturesWizard
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / featuretree / e4 / handler / CreateFeatureTreeHandler.java
index 1625e27ed51d02bd185cf41793a351f4d2fbb772..a520a32d80937043e9f48d1f4e0c17d86c056690 100644 (file)
@@ -8,22 +8,20 @@
 */
 package eu.etaxonomy.taxeditor.featuretree.e4.handler;
 
-import java.util.List;
-
 import javax.inject.Named;
 
-import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.e4.core.di.annotations.CanExecute;
 import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.di.UISynchronize;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
 
 import eu.etaxonomy.cdm.model.description.FeatureTree;
-import eu.etaxonomy.taxeditor.featuretree.e4.FeatureNodeDropAdapter;
-import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
+import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
 import eu.etaxonomy.taxeditor.featuretree.e4.operation.CreateFeatureTreeOperation;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 
 /**
  * @author pplitzner
@@ -33,28 +31,18 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
 public class CreateFeatureTreeHandler {
 
     @Execute
-    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
-        FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
+    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart, UISynchronize sync){
+        IFeatureTreeEditor editor = (IFeatureTreeEditor) thisPart.getObject();
 
-        if (editor.isDirty()) {
-            if (MessagingUtils.confirmDialog(FeatureNodeDropAdapter.SAVE_CHANGES_TITLE,
-                    FeatureNodeDropAdapter.SAVE_CHANGES_MESSAGE)){
-                editor.save(new NullProgressMonitor());
-            }
-            else{
-                return;
-            }
+        if (StoreUtil.promptCheckIsDirty(editor)) {
+            return;
         }
 
 
         FeatureTree tree = FeatureTree.NewInstance();
         tree.setTitleCache("New feature tree", true);
         CreateFeatureTreeOperation operation = new CreateFeatureTreeOperation(tree, editor, editor);
-        editor.addOperation(operation);
-        List<FeatureTree> trees = (List<FeatureTree>) editor.getViewer().getInput();
-        trees.add(tree);
-        editor.getViewer().setInput(trees);
-        editor.setDirty(true);
+        AbstractUtility.executeOperation(operation, sync);
     }
 
     @CanExecute
@@ -62,7 +50,7 @@ public class CreateFeatureTreeHandler {
             @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
             MHandledMenuItem menuItem) {
         boolean canExecute = false;
-        canExecute = thisPart.getObject() instanceof FeatureTreeEditor;
+        canExecute = thisPart.getObject() instanceof IFeatureTreeEditor;
         menuItem.setVisible(canExecute);
         return canExecute;
     }