ref #8475 Filter available feature to only parent features
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 19 Aug 2019 13:18:45 +0000 (15:18 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 19 Aug 2019 13:18:45 +0000 (15:18 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/FeatureStateWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/FeatureStateWizardPage.java
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

index 9e13ea0a7d55d97e208c747e25b5995d3d4b4cdb..0b2a350097a8be42286b174ca699a7c21e4332cd 100644 (file)
@@ -10,7 +10,9 @@ package eu.etaxonomy.taxeditor.ui.section.feature;
 
 import org.eclipse.jface.wizard.Wizard;
 
+import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.FeatureState;
+import eu.etaxonomy.cdm.model.term.TermNode;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 
 /**
@@ -23,17 +25,19 @@ public class FeatureStateWizard extends Wizard {
     private FeatureStateWizardPage page;
     private CdmFormFactory formFactory;
     private String comboLabel;
+    private TermNode<? extends Feature> termNode;
 
-    public FeatureStateWizard(CdmFormFactory formFactory, String comboLabel) {
+    public FeatureStateWizard(String comboLabel, TermNode<? extends Feature> termNode, CdmFormFactory formFactory) {
         super();
         this.formFactory = formFactory;
+        this.termNode = termNode;
         this.comboLabel = comboLabel;
         setWindowTitle("Create Feature State");
     }
 
     @Override
     public void addPages() {
-        page = new FeatureStateWizardPage("Create Feature State", comboLabel, formFactory);
+        page = new FeatureStateWizardPage("Create Feature State", comboLabel, termNode, formFactory);
         addPage(page);
     }
 
index 1f854577c07ac189c7cdfe985c04946e30f81bf8..1a889ba21fee8b542091c7c48e26d74f423351cb 100644 (file)
@@ -20,11 +20,11 @@ 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.TermNode;
 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
@@ -33,13 +33,15 @@ import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
  */
 public class FeatureStateWizardPage extends AbstractEntityCollectionElementWizardPage {
 
+    private TermComboElement<Feature> comboFeature;
     private TermComboElement<State> comboState;
-    private EntitySelectionElement<Feature> selectFeature;
     private String comboLabel;
+    private TermNode<? extends Feature> termNode;
 
-    protected FeatureStateWizardPage(String pageName, String comboLabel, CdmFormFactory formFactory) {
+    protected FeatureStateWizardPage(String pageName, String comboLabel, TermNode<? extends Feature> termNode, CdmFormFactory formFactory) {
         super(pageName, formFactory);
         this.comboLabel = comboLabel;
+        this.termNode = termNode;
         setTitle("Create Feature State");
         setDescription("Select Feature and State");
     }
@@ -48,7 +50,9 @@ public class FeatureStateWizardPage extends AbstractEntityCollectionElementWizar
     public void createControl(Composite parent) {
         super.createControl(parent);
 
-        selectFeature = formFactory.createSelectionElement(Feature.class, rootElement, "Feature", null, EntitySelectionElement.SELECTABLE, SWT.NONE);
+        comboFeature = formFactory.createDefinedTermComboElement(Collections.EMPTY_LIST, rootElement, "Parent Feature", null, SWT.NONE);
+        updateFeatureCombo();
+
         comboState = formFactory.createDefinedTermComboElement(Collections.EMPTY_LIST, rootElement, comboLabel, null, SWT.NONE);
         comboState.setEnabled(false);
 
@@ -56,12 +60,22 @@ public class FeatureStateWizardPage extends AbstractEntityCollectionElementWizar
     }
 
     FeatureState getFeatureState(){
-        return FeatureState.NewInstance(selectFeature.getSelection(), comboState.getSelection());
+        return FeatureState.NewInstance(comboFeature.getSelection(), comboState.getSelection());
+    }
+
+    private void updateFeatureCombo(){
+        List<Feature> features = new ArrayList<>();
+        TermNode<? extends Feature> parent = termNode.getParent();
+        while(parent!=null){
+            features.add(parent.getTerm());
+            parent = parent.getParent();
+        }
+        comboFeature.setTerms(features);
     }
 
-    private void updateCombo(Feature feature){
+    private void updateStateCombo(Feature feature){
         comboState.setEnabled(true);
-        List<State> stateTerms = new ArrayList<State>();
+        List<State> stateTerms = new ArrayList<>();
         Set<TermVocabulary<State>> stateVocabularies = feature.getSupportedCategoricalEnumerations();
         for (TermVocabulary<State> termVocabulary : stateVocabularies) {
             stateTerms.addAll(termVocabulary.getTerms());
@@ -71,14 +85,14 @@ public class FeatureStateWizardPage extends AbstractEntityCollectionElementWizar
 
     @Override
     public boolean isPageComplete() {
-        return selectFeature.getSelection()!=null && comboState.getSelection()!=null;
+        return comboFeature.getSelection()!=null && comboState.getSelection()!=null;
     }
 
     @Override
     public void propertyChange(PropertyChangeEvent event) {
-        if(event.getSource()==selectFeature){
-            Feature feature = selectFeature.getSelection();
-            updateCombo(feature);
+        if(event.getSource()==comboFeature){
+            Feature feature = comboFeature.getSelection();
+            updateStateCombo(feature);
         }
         getWizard().getContainer().updateButtons();
     }
index 6934439aea7caac3cd946edae7b02737c2d1a7c9..b21eca30c36be37c1e3d972be7699ba1b78ea00a 100644 (file)
@@ -16,6 +16,7 @@ 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.Feature;
 import eu.etaxonomy.cdm.model.description.FeatureState;
 import eu.etaxonomy.cdm.model.term.TermNode;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
@@ -28,7 +29,7 @@ import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
  * @date 06.03.2018
  *
  */
-public class InapplicableIfEntityCollectionSection extends AbstractEntityCollectionSection<TermNode, FeatureState>{
+public class InapplicableIfEntityCollectionSection extends AbstractEntityCollectionSection<TermNode<? extends Feature>, FeatureState>{
 
     public InapplicableIfEntityCollectionSection(CdmFormFactory formFactory, ConversationHolder conversation,
             ICdmFormElement parentElement, int style) {
@@ -39,7 +40,7 @@ public class InapplicableIfEntityCollectionSection extends AbstractEntityCollect
      * {@inheritDoc}
      */
     @Override
-    public Collection<FeatureState> getCollection(TermNode entity) {
+    public Collection<FeatureState> getCollection(TermNode <? extends Feature>entity) {
         return entity.getInapplicableIf();
     }
 
@@ -57,7 +58,7 @@ public class InapplicableIfEntityCollectionSection extends AbstractEntityCollect
      */
     @Override
     public FeatureState createNewElement() {
-        FeatureStateWizard wizard = new FeatureStateWizard(formFactory, "Inapplicable If");
+        FeatureStateWizard wizard = new FeatureStateWizard("Inapplicable If", getEntity(), formFactory);
         WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
         int status = dialog.open();
         if(status == IStatus.OK) {
index 3985a99edb77f9d61a70e3718618d03644b6e224..a1b2b02c0bdb188bc4c0b506bcb3f1329b236725 100644 (file)
@@ -16,6 +16,7 @@ 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.Feature;
 import eu.etaxonomy.cdm.model.description.FeatureState;
 import eu.etaxonomy.cdm.model.term.TermNode;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
@@ -28,7 +29,7 @@ import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
  * @date 06.03.2018
  *
  */
-public class OnlyApplicableIfEntityCollectionSection extends AbstractEntityCollectionSection<TermNode, FeatureState>{
+public class OnlyApplicableIfEntityCollectionSection extends AbstractEntityCollectionSection<TermNode<? extends Feature>, FeatureState>{
 
     public OnlyApplicableIfEntityCollectionSection(CdmFormFactory formFactory, ConversationHolder conversation,
             ICdmFormElement parentElement, int style) {
@@ -39,7 +40,7 @@ public class OnlyApplicableIfEntityCollectionSection extends AbstractEntityColle
      * {@inheritDoc}
      */
     @Override
-    public Collection<FeatureState> getCollection(TermNode entity) {
+    public Collection<FeatureState> getCollection(TermNode<? extends Feature> entity) {
         return entity.getOnlyApplicableIf();
     }
 
@@ -56,7 +57,7 @@ public class OnlyApplicableIfEntityCollectionSection extends AbstractEntityColle
      */
     @Override
     public FeatureState createNewElement() {
-        FeatureStateWizard wizard = new FeatureStateWizard(formFactory, "Only applicable if");
+        FeatureStateWizard wizard = new FeatureStateWizard("Only applicable if", getEntity(), formFactory);
         WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
         int status = dialog.open();
         if(status == IStatus.OK) {