ref #8475 Create FeatureState in wizard dialog
authorPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 16 Aug 2019 15:29:43 +0000 (17:29 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 16 Aug 2019 15:29:43 +0000 (17:29 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/AbstractEntityCollectionElementWizardPage.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/AbstractApplicableElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/FeatureStateWizard.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/FeatureStateWizardPage.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/InapplicableIfEntityCollectionSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/OnlyApplicableIfEntityCollectionSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameRelationshipWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameRelationshipWizardPage.java

index 77564264c1ff41f7bd8337d8818f3694d3088dcc..579dec5f6dc7bc0653d9766b7093ad6bf0912e6f 100644 (file)
@@ -13,30 +13,26 @@ import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.forms.widgets.TableWrapLayout;
 
-import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
-import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
-import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
 import eu.etaxonomy.taxeditor.ui.element.RootElement;
-import eu.etaxonomy.taxeditor.webapp.ICDMServerError;
 
 /**
  * @author pplitzner
  * @date Mar 30, 2016
  *
  */
-public abstract class AbstractEntityCollectionElementWizardPage extends WizardPage implements 
+public abstract class AbstractEntityCollectionElementWizardPage extends WizardPage implements
 IPropertyChangeListener {
 
     protected CdmFormFactory formFactory;
-    
+
 
     protected RootElement rootElement;
 
-    protected AbstractEntityCollectionElementWizardPage(String pageName) {
+    protected AbstractEntityCollectionElementWizardPage(String pageName, CdmFormFactory formFactory) {
         super(pageName);
-        
+        this.formFactory = formFactory;
     }
 
     /**
@@ -64,7 +60,7 @@ IPropertyChangeListener {
     public void dispose() {
         rootElement.removeElements();
         formFactory.removePropertyChangeListener(this);
-       
+
         super.dispose();
     }
 
index 77d0db17bb092792a3e8b4bcb51180f7f39bd1be..2a4cea9e49ef968191984c4a8e6eb172839615e0 100644 (file)
@@ -8,10 +8,7 @@
 */
 package eu.etaxonomy.taxeditor.ui.section.feature;
 
-import java.util.ArrayList;
 import java.util.Collections;
-import java.util.List;
-import java.util.Set;
 
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionListener;
@@ -20,8 +17,6 @@ import org.eclipse.swt.graphics.Color;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.FeatureState;
 import eu.etaxonomy.cdm.model.description.State;
-import eu.etaxonomy.cdm.model.term.TermNode;
-import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
@@ -50,6 +45,7 @@ public abstract class AbstractApplicableElement extends AbstractEntityCollection
         selectFeature = formFactory.createSelectionElement(Feature.class, element, "Feature", null, EntitySelectionElement.SELECTABLE, SWT.NONE);
         comboState = formFactory.createDefinedTermComboElement(Collections.EMPTY_LIST, element, getComboLabel(), null, style);
         comboState.setEnabled(false);
+        selectFeature.setEnabled(false);
     }
 
     protected abstract String getComboLabel();
@@ -57,44 +53,11 @@ public abstract class AbstractApplicableElement extends AbstractEntityCollection
     @Override
     public void setEntity(FeatureState entity) {
         this.entity = entity;
-        Feature feature = entity.getFeature();
-        selectFeature.setEntity(feature);
-        if(feature!=null){
-            updateCombo(feature);
-        }
-    }
-
-    private void updateCombo(Feature feature){
-        comboState.setEnabled(true);
-        List<State> stateTerms = new ArrayList<State>();
-        Set<TermVocabulary<State>> stateVocabularies = feature.getSupportedCategoricalEnumerations();
-        for (TermVocabulary<State> termVocabulary : stateVocabularies) {
-            stateTerms.addAll(termVocabulary.getTerms());
-        }
-        comboState.setTerms(stateTerms);
+        selectFeature.setEntity(entity.getFeature());
         comboState.setSelection(entity.getState());
-        if(getEntity().getId()>0){
-            comboState.removeEmptyElement();
-        }
     }
 
     @Override
     public void handleEvent(Object eventSource) {
-        if(eventSource==selectFeature){
-            Feature feature = selectFeature.getSelection();
-            entity.setFeature(feature);
-            updateCombo(feature);
-        }
-        else if(eventSource==comboState && comboState.getSelection()!=null){
-            if(getParentElement() instanceof OnlyApplicableIfEntityCollectionSection){
-                OnlyApplicableIfEntityCollectionSection parentElement = (OnlyApplicableIfEntityCollectionSection) getParentElement();
-                TermNode node = parentElement.getEntity();
-                node.removeApplicableState(entity);
-                State state = comboState.getSelection();
-                entity.setState(state);
-                node.addApplicableState(entity);
-                parentElement.removeElementAndUpdate(null);
-            }
-        }
     }
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/FeatureStateWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/FeatureStateWizard.java
new file mode 100644 (file)
index 0000000..9e13ea0
--- /dev/null
@@ -0,0 +1,49 @@
+/**
+* Copyright (C) 2019 EDIT
+* European Distributed Institute of Taxonomy
+* 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.
+*/
+package eu.etaxonomy.taxeditor.ui.section.feature;
+
+import org.eclipse.jface.wizard.Wizard;
+
+import eu.etaxonomy.cdm.model.description.FeatureState;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+
+/**
+ * @author pplitzner
+ * @since Aug 16, 2019
+ *
+ */
+public class FeatureStateWizard extends Wizard {
+
+    private FeatureStateWizardPage page;
+    private CdmFormFactory formFactory;
+    private String comboLabel;
+
+    public FeatureStateWizard(CdmFormFactory formFactory, String comboLabel) {
+        super();
+        this.formFactory = formFactory;
+        this.comboLabel = comboLabel;
+        setWindowTitle("Create Feature State");
+    }
+
+    @Override
+    public void addPages() {
+        page = new FeatureStateWizardPage("Create Feature State", comboLabel, formFactory);
+        addPage(page);
+    }
+
+    @Override
+    public boolean performFinish() {
+        return page.isPageComplete();
+    }
+
+    FeatureState getFeatureState(){
+        return page.getFeatureState();
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/FeatureStateWizardPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/FeatureStateWizardPage.java
new file mode 100644 (file)
index 0000000..1f85457
--- /dev/null
@@ -0,0 +1,86 @@
+/**
+* Copyright (C) 2019 EDIT
+* European Distributed Institute of Taxonomy
+* 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.
+*/
+package eu.etaxonomy.taxeditor.ui.section.feature;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.FeatureState;
+import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
+import eu.etaxonomy.taxeditor.ui.AbstractEntityCollectionElementWizardPage;
+import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
+
+/**
+ * @author pplitzner
+ * @since Aug 16, 2019
+ *
+ */
+public class FeatureStateWizardPage extends AbstractEntityCollectionElementWizardPage {
+
+    private TermComboElement<State> comboState;
+    private EntitySelectionElement<Feature> selectFeature;
+    private String comboLabel;
+
+    protected FeatureStateWizardPage(String pageName, String comboLabel, CdmFormFactory formFactory) {
+        super(pageName, formFactory);
+        this.comboLabel = comboLabel;
+        setTitle("Create Feature State");
+        setDescription("Select Feature and State");
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        super.createControl(parent);
+
+        selectFeature = formFactory.createSelectionElement(Feature.class, rootElement, "Feature", null, EntitySelectionElement.SELECTABLE, SWT.NONE);
+        comboState = formFactory.createDefinedTermComboElement(Collections.EMPTY_LIST, rootElement, comboLabel, null, SWT.NONE);
+        comboState.setEnabled(false);
+
+        formFactory.addPropertyChangeListener(this);
+    }
+
+    FeatureState getFeatureState(){
+        return FeatureState.NewInstance(selectFeature.getSelection(), comboState.getSelection());
+    }
+
+    private void updateCombo(Feature feature){
+        comboState.setEnabled(true);
+        List<State> stateTerms = new ArrayList<State>();
+        Set<TermVocabulary<State>> stateVocabularies = feature.getSupportedCategoricalEnumerations();
+        for (TermVocabulary<State> termVocabulary : stateVocabularies) {
+            stateTerms.addAll(termVocabulary.getTerms());
+        }
+        comboState.setTerms(stateTerms);
+    }
+
+    @Override
+    public boolean isPageComplete() {
+        return selectFeature.getSelection()!=null && comboState.getSelection()!=null;
+    }
+
+    @Override
+    public void propertyChange(PropertyChangeEvent event) {
+        if(event.getSource()==selectFeature){
+            Feature feature = selectFeature.getSelection();
+            updateCombo(feature);
+        }
+        getWizard().getContainer().updateButtons();
+    }
+
+}
index 4a37534824f84bfa3f1573e9cd1b0fdb9a84df22..6934439aea7caac3cd946edae7b02737c2d1a7c9 100644 (file)
@@ -12,6 +12,9 @@ package eu.etaxonomy.taxeditor.ui.section.feature;
 import java.util.Collection;
 import java.util.Comparator;
 
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.wizard.WizardDialog;
+
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.description.FeatureState;
 import eu.etaxonomy.cdm.model.term.TermNode;
@@ -54,7 +57,13 @@ public class InapplicableIfEntityCollectionSection extends AbstractEntityCollect
      */
     @Override
     public FeatureState createNewElement() {
-        return FeatureState.NewInstance();
+        FeatureStateWizard wizard = new FeatureStateWizard(formFactory, "Inapplicable If");
+        WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
+        int status = dialog.open();
+        if(status == IStatus.OK) {
+            return wizard.getFeatureState();
+        }
+        return null;
     }
 
     /**
index d4fa4b1f825218c6b6b87647da82b1afbd7c379e..3985a99edb77f9d61a70e3718618d03644b6e224 100644 (file)
@@ -12,6 +12,9 @@ package eu.etaxonomy.taxeditor.ui.section.feature;
 import java.util.Collection;
 import java.util.Comparator;
 
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.wizard.WizardDialog;
+
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.description.FeatureState;
 import eu.etaxonomy.cdm.model.term.TermNode;
@@ -53,7 +56,13 @@ public class OnlyApplicableIfEntityCollectionSection extends AbstractEntityColle
      */
     @Override
     public FeatureState createNewElement() {
-        return FeatureState.NewInstance();
+        FeatureStateWizard wizard = new FeatureStateWizard(formFactory, "Only applicable if");
+        WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
+        int status = dialog.open();
+        if(status == IStatus.OK) {
+            return wizard.getFeatureState();
+        }
+        return null;
     }
 
     /**
index 1e28b62af92ffbfa29d1b97847291e4ea9cfc07b..92e5786deb87c9a192e9965949c1d7ecdb184ebb 100644 (file)
@@ -48,7 +48,7 @@ public class NameRelationshipWizard extends Wizard implements IConversationEnabl
        /** {@inheritDoc} */
        @Override
        public void addPages() {
-               page = new NameRelationshipWizardPage(callingSection);
+               page = new NameRelationshipWizardPage(callingSection, callingSection.getFormFactory());
 
                addPage(page);
        }
index 899b835a6be0110735a5dddb59a891bf0305925c..7286359861359b0dbad019e43be61f59ed693feb 100644 (file)
@@ -20,6 +20,7 @@ import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.ui.AbstractEntityCollectionElementWizardPage;
 import eu.etaxonomy.taxeditor.ui.combo.NameRelationshipTypeCombo;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
 
 /**
@@ -56,13 +57,12 @@ public class NameRelationshipWizardPage extends AbstractEntityCollectionElementW
         *            object.
         */
        protected NameRelationshipWizardPage(
-                       NameRelationshipDetailSection callingSection) {
-               super("NameRelationshipWizardPage"); //$NON-NLS-1$
+                       NameRelationshipDetailSection callingSection, CdmFormFactory formFactory) {
+               super("NameRelationshipWizardPage", formFactory); //$NON-NLS-1$
                setTitle("New Name Relationship"); //$NON-NLS-1$
                //setDescription(callingSection.getEntity().getTitleCache());
                setDescription(Messages.NameRelationshipWizardPage_description);
                this.entity = callingSection.getEntity();
-               this.formFactory = callingSection.getFormFactory();
 
                formFactory.addPropertyChangeListener(this);
        }