#5301 Add merge call for saving new feature tree
authorCherian Mathew <c.mathew@bgbm.org>
Mon, 19 Oct 2015 14:02:06 +0000 (16:02 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Mon, 19 Oct 2015 14:02:06 +0000 (16:02 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/SelectFeatureTreeWizardPage.java

index 9457d0969e75f394043336e778a4d343786473f0..1a8b2a88922cd8dbc50e1b18e5daec245bbc10a0 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -12,7 +12,6 @@ package eu.etaxonomy.taxeditor.featuretree;
 
 import java.util.List;
 
 
 import java.util.List;
 
-import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ListViewer;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ListViewer;
@@ -33,10 +32,8 @@ import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.api.service.DeleteResult;
 import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
 
 import eu.etaxonomy.cdm.api.service.DeleteResult;
 import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
-import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
 import eu.etaxonomy.cdm.model.description.FeatureTree;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.cdm.model.description.FeatureTree;
 import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.store.StoreUtil;
 
 /**
  * <p>SelectFeatureTreeWizardPage class.</p>
 
 /**
  * <p>SelectFeatureTreeWizardPage class.</p>
@@ -61,7 +58,7 @@ public class SelectFeatureTreeWizardPage extends WizardPage implements ISelectio
                super(pageName);
                setMessage("Select a Feature Tree or create a new one.");
        }
                super(pageName);
                setMessage("Select a Feature Tree or create a new one.");
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
         */
        /* (non-Javadoc)
         * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
         */
@@ -69,48 +66,48 @@ public class SelectFeatureTreeWizardPage extends WizardPage implements ISelectio
        @Override
        public void createControl(Composite parent) {
                Composite composite = new Composite(parent, SWT.NULL);
        @Override
        public void createControl(Composite parent) {
                Composite composite = new Composite(parent, SWT.NULL);
-               
+
                composite.setLayout(new GridLayout());
                composite.setLayout(new GridLayout());
-               
+
                Composite composite_treeContent = new Composite(composite, SWT.NULL);
                composite_treeContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
                                true, true));
                composite_treeContent.setLayout(new GridLayout(2, false));
                Composite composite_treeContent = new Composite(composite, SWT.NULL);
                composite_treeContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
                                true, true));
                composite_treeContent.setLayout(new GridLayout(2, false));
-               
+
                viewer = new ListViewer(composite_treeContent);
                viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                viewer = new ListViewer(composite_treeContent);
                viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-       
+
                button_remove = new Button(composite_treeContent, SWT.PUSH);
                button_remove.setText("Remove");
                button_remove.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
                button_remove = new Button(composite_treeContent, SWT.PUSH);
                button_remove.setText("Remove");
                button_remove.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
-               
+
                Composite composite_treeTitle = new Composite(composite, SWT.NULL);
                composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
                                false));
                composite_treeTitle.setLayout(new GridLayout(3, false));
 
                Composite composite_treeTitle = new Composite(composite, SWT.NULL);
                composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
                                false));
                composite_treeTitle.setLayout(new GridLayout(3, false));
 
-               
-               
+
+
                Label label_title = new Label(composite_treeTitle, SWT.NULL);
                label_title.setText("New Feature Tree");
 
                text_title = new Text(composite_treeTitle, SWT.NULL);
                text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
                Label label_title = new Label(composite_treeTitle, SWT.NULL);
                label_title.setText("New Feature Tree");
 
                text_title = new Text(composite_treeTitle, SWT.NULL);
                text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-               
+
                button_add = new Button(composite_treeTitle, SWT.PUSH);
                button_add.setText("Add");
                button_add = new Button(composite_treeTitle, SWT.PUSH);
                button_add.setText("Add");
-                               
+
                viewer.setContentProvider(new FeatureTreeContentProvider());
                viewer.setLabelProvider(new FeatureTreeLabelProvider());
                viewer.setContentProvider(new FeatureTreeContentProvider());
                viewer.setLabelProvider(new FeatureTreeLabelProvider());
-               
+
                viewer.addSelectionChangedListener(this);
                viewer.addSelectionChangedListener(this);
-               
+
                text_title.addModifyListener(this);
                button_add.addSelectionListener(new AddButtonSelectionListener());
                button_remove.addSelectionListener(new RemoveButtonSelectionListener());
                text_title.addModifyListener(this);
                button_add.addSelectionListener(new AddButtonSelectionListener());
                button_remove.addSelectionListener(new RemoveButtonSelectionListener());
-               
+
                List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
                List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
-               
+
                viewer.setInput(input);
                modifyText(null);
                setControl(composite);
                viewer.setInput(input);
                modifyText(null);
                setControl(composite);
@@ -120,15 +117,15 @@ public class SelectFeatureTreeWizardPage extends WizardPage implements ISelectio
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
-                       
+
                if(selection.size() == 1){
                        FeatureTree selectedFeatureTree = (FeatureTree) selection.getFirstElement();
                        ((FeatureTreeEditorWizard) getWizard()).setSelectedFeatureTree(selectedFeatureTree);
                if(selection.size() == 1){
                        FeatureTree selectedFeatureTree = (FeatureTree) selection.getFirstElement();
                        ((FeatureTreeEditorWizard) getWizard()).setSelectedFeatureTree(selectedFeatureTree);
-                       
+
                }
                }
-               
+
                setPageComplete(true);
                setPageComplete(true);
-               
+
                button_remove.setEnabled(selection.size() >= 1);
        }
 
                button_remove.setEnabled(selection.size() >= 1);
        }
 
@@ -137,36 +134,42 @@ public class SelectFeatureTreeWizardPage extends WizardPage implements ISelectio
        public boolean canFlipToNextPage() {
                return ((IStructuredSelection) viewer.getSelection()).size() == 1;
        }
        public boolean canFlipToNextPage() {
                return ((IStructuredSelection) viewer.getSelection()).size() == 1;
        }
-       
+
        /** {@inheritDoc} */
        @Override
        public void modifyText(ModifyEvent e) {
                button_add.setEnabled(! text_title.getText().isEmpty());
        }
        /** {@inheritDoc} */
        @Override
        public void modifyText(ModifyEvent e) {
                button_add.setEnabled(! text_title.getText().isEmpty());
        }
-       
+
        private class AddButtonSelectionListener extends SelectionAdapter {
        private class AddButtonSelectionListener extends SelectionAdapter {
-               public void widgetSelected(SelectionEvent e) {
+               @Override
+        public void widgetSelected(SelectionEvent e) {
                        FeatureTree featureTree = FeatureTree.NewInstance();
                        featureTree.setTitleCache(text_title.getText(), true);
                        FeatureTree featureTree = FeatureTree.NewInstance();
                        featureTree.setTitleCache(text_title.getText(), true);
-                       
+
                        viewer.add(featureTree);
                        viewer.add(featureTree);
-                       CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(featureTree);
+                       if(CdmStore.getCurrentSessionManager().isRemoting()) {
+                CdmStore.getService(IFeatureTreeService.class).merge(featureTree);
+                       } else {
+                           CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(featureTree);
+                       }
                        text_title.setText("");
                        viewer.setSelection(new StructuredSelection(featureTree));
                        text_title.setText("");
                        viewer.setSelection(new StructuredSelection(featureTree));
-                       
+
                }
        }
                }
        }
-       
+
        private class RemoveButtonSelectionListener extends SelectionAdapter {
        private class RemoveButtonSelectionListener extends SelectionAdapter {
-               public void widgetSelected(SelectionEvent e) {
+               @Override
+        public void widgetSelected(SelectionEvent e) {
                        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                        for(Object element : selection.toArray()){
                                viewer.remove(element);
                        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                        for(Object element : selection.toArray()){
                                viewer.remove(element);
-                               
-                               DeleteResult result =   CdmStore.getService(IFeatureTreeService.class).delete((FeatureTree) element);
-                               
+
+                               DeleteResult result =   CdmStore.getService(IFeatureTreeService.class).delete(((FeatureTree) element).getUuid());
+
                                if (result.isError()){
                                if (result.isError()){
-                                       
+
                                }
                                viewer.setSelection(new StructuredSelection(new Object[0]));
                        }
                                }
                                viewer.setSelection(new StructuredSelection(new Object[0]));
                        }