commit 6d75492c66af2716e737af2153b1a65352efbadf
Author: a.theys <a.theys@localhost>
Date:   Wed Jan 25 17:55:28 2012 +0000

    AT: commiting latest changes to the Palm Use data extension

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesLabelProvider.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesLabelProvider.java
index 37968d9a7..c6b9e4aaa 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesLabelProvider.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesLabelProvider.java
@@ -17,6 +17,8 @@ import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.description.CategoricalData;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.cdm.model.description.StateData;
 import eu.etaxonomy.cdm.model.description.TextData;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
@@ -43,8 +45,30 @@ public class UsesLabelProvider extends ColumnLabelProvider implements
 			}
 		}
 		else if (element instanceof CategoricalData) {
-			TextData textData = categoricalDescriptionBuilder.build((CategoricalData) element, getLanguageList());
-			text = textData.getText(CdmStore.getDefaultLanguage());
+			//String text = "";
+			//TextData textData = categoricalDescriptionBuilder.build((CategoricalData) element, getLanguageList());
+			if (((CategoricalData) element).getStates() != null) {
+				for (StateData statedata : ((CategoricalData) element).getStates()) {
+					if(statedata.getState() != null) {
+						text = text + statedata.getState().getTitleCache();
+					}
+					else {
+						text = "No data provided";
+					}
+				}
+			}
+			if (((CategoricalData) element).getStatesOnly() != null) {
+				for (State state : ((CategoricalData) element).getStatesOnly()) {
+					if (state != null) {
+						text = text + state.getTitleCache();
+					}
+					else {
+						text = "No data provided";
+					}
+				}
+			}
+			
+			//text = textData.getText(CdmStore.getDefaultLanguage());
 			if (text == null || text.length() == 0) {
 				text = "No data provided";
 			}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
index 7a6a2d8db..1b93de00c 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
@@ -250,6 +250,8 @@ import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.user.UserDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.user.UserDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.userecords.UseRecordDetailElement;
+import eu.etaxonomy.taxeditor.ui.section.userecords.UseRecordDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailSection;
@@ -1526,7 +1528,8 @@ public class CdmFormFactory extends FormToolkit {
 		REFERENCED_ENTITY, 
 		TERM_VOCABULARY,
 		NAMED_AREA, 
-		NAMED_AREA_LEVEL
+		NAMED_AREA_LEVEL, 
+		USE_RECORD
 	}
 	
 	public AbstractFormSection createDefinedTermDetailSection(Class definedTermClass,
@@ -1724,7 +1727,12 @@ public class CdmFormFactory extends FormToolkit {
 			section = new NamedAreaDetailSection(this, conversation, parentElement, 
 					selectionProvider, style);
 			break;
+		case USE_RECORD:
+			section = new UseRecordDetailSection(this, conversation, parentElement,
+					selectionProvider, style);
+			break;
 		}
+		
 
 		if (section == null) {
 			throw new RuntimeException(
@@ -1859,6 +1867,10 @@ public class CdmFormFactory extends FormToolkit {
 		case NAMED_AREA_LEVEL:
 			element = new DefinedTermDetailElement<NamedAreaLevel>(this, parentElement);
 			break;
+		case USE_RECORD:
+			//element = new UseRecordDetailElement(this, parentElement, style);
+			element = new UseRecordDetailElement(this, parentElement);
+			break;
 		}
 
 		if (element == null) {
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java
index bd7862777..4906b1138 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java
@@ -1,31 +1,46 @@
 package eu.etaxonomy.taxeditor.ui.section.userecords;
 
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
 import org.apache.log4j.Logger;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.ui.forms.widgets.Section;
 
+import eu.etaxonomy.cdm.api.service.IVocabularyService;
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.LanguageString;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.cdm.model.description.CategoricalData;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.TermStore;
 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.forms.CheckboxElement;
-import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EntityDetailType;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EntityDetailType;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.description.StateDataSection;
 import eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement;
 
 //public class UseRecordDetailElement extends AbstractDetailedDescriptionDetailElement<CategoricalData> {
-public class UseRecordDetailElement extends AbstractCdmDetailElement<CategoricalData> {
+public class UseRecordDetailElement extends AbstractCdmDetailElement<CategoricalData> implements SelectionListener {
 
 	
 	private static final Logger logger = Logger
 			.getLogger(DescriptionElementDetailElement.class);
 	
-	private CheckboxElement checkbox_orderRelevant;
-	private TermComboElement UseCategory_stateData;
-	private UseSubCategorySection UseSubCategory_stateData;
+	//private CheckboxElement checkbox_orderRelevant;
+	private TermComboElement<State> combo_UseCategory;
+	private TermComboElement<State> combo_UseSubCategory;
 	//private AbstractDetailedDescriptionDetailElement detailElement;
 	
 	/*public UseRecordDetailElement(CdmFormFactory formFactory,
@@ -45,25 +60,104 @@ public class UseRecordDetailElement extends AbstractCdmDetailElement<Categorical
 			CategoricalData entity, int style) {
 		
 		
-		State state = State.NewInstance("Tato", "Toto", "Titi");
+		//State state = State.NewInstance("Tato", "Toto", "Titi");
 		//checkbox_orderRelevant = formFactory.createCheckbox(formElement, "Order Relevant", entity.getOrderRelevant(), style);
-		UseCategory_stateData = formFactory.createTermComboElement(State.class, this, "Use Category", state , style);
+		combo_UseCategory = formFactory.createTermComboElement(State.class, this, "Use Category", null , style);
+		combo_UseCategory.addSelectionListener(this);
+		combo_UseSubCategory = formFactory.createTermComboElement(State.class, this, "Use Sub Category", null , style);
+		//List<State> listOfTerms = TermStore.getTerms(State.class,null , false);
+		
+		
+		//UUID uuidUseCategory = UUID.fromString("2bb365af-ce6c-4196-a30b-e69b05099ed0"); 
+		//TermVocabulary termVoc = CdmStore.getService(IVocabularyService.class).find(uuidUseCategory);
+		List<State> termsToAdd = setUseCategoryComboTerms(TermStore.getTerms(State.class,null , false));
+		//combo_UseCategory.setTerms(setUseCategoryComboTerms(listOfTerms));
+		combo_UseCategory.setTerms(termsToAdd);
+		
+				//getPreferredTerms(State.class));
+		//UseSubCategory_stateData = formFactory.createTermComboElement(State.class, this, "Use Sub Category", null , style);
 		//createEntityDetailSection(EntityDetailType.USE_CAT, getConversationHolder(), formElement, Section.EXPANDED);
-		UseSubCategory_stateData = (UseSubCategorySection) formFactory.createEntityDetailSection(EntityDetailType.USE_SUBCAT, getConversationHolder(), formElement,Section.EXPANDED);
+		//UseSubCategory_stateData = (UseSubCategorySection) formFactory.createEntityDetailSection(EntityDetailType.USE_SUBCAT, getConversationHolder(), formElement,Section.EXPANDED);
 		//UseCategory_stateData.setEntity(entity);
-		UseSubCategory_stateData.setEntity(entity);
+		//UseSubCategory_stateData.setEntity(entity);
 		//UseCategory_stateData.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY(2, 1));
-		UseSubCategory_stateData.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY(2, 1));
+		//UseSubCategory_stateData.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY(2, 1));
 		
 	}
 	
 	
+	private List<State> setUseCategoryComboTerms(List<State> listOfTerms) {
+		List<State> termsToAdd = new ArrayList<State>();
+		for(State term : listOfTerms) {
+			
+			if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals("Use Category"))) {
+				termsToAdd.add(term);
+			}
+		}
+		return termsToAdd;
+		
+	}
+	
+	private List<State> setUseCategoryComboTerms(List<State> listOfTerms,
+			State selectedUseCategory) {
+		List<State> termsToAdd = new ArrayList<State>();
+		for(State term : listOfTerms) {
+			if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedUseCategory.getTitleCache()))) {
+				termsToAdd.add(term);
+			}
+				
+		}
+		
+		// TODO Auto-generated method stub
+		return termsToAdd;
+	}
+
 	/** {@inheritDoc} */
 	@Override
 	public void handleEvent(Object eventSource) {
-		if(eventSource == checkbox_orderRelevant){
+		/*if(eventSource == checkbox_orderRelevant){
 			getEntity().setOrderRelevant(checkbox_orderRelevant.getSelection());
+		}*/
+		if(eventSource == combo_UseCategory){
+			TermVocabulary<State> useCategoryVocabulary = TermVocabulary.NewInstance("Use category vocabulary", "use categories", null, null); 
+			State useCategory1 = State.NewInstance("My first use category", "use category 1", null);
+			useCategoryVocabulary.addTerm(useCategory1);
+			getEntity().addState(useCategory1);
+			List<State> currentStates = new ArrayList<State>();
+			currentStates.add(combo_UseCategory.getSelection());
+			getEntity().setStatesOnly(currentStates);
+			//getEntity().addState(combo_UseCategory.getSelection());
+			//.setOrderRelevant(combo_UseCategory.getSelection());
 		}
 	}
+	
+	/** {@inheritDoc} */
+	@Override
+	public void setEntity(CategoricalData entity) {
+//		section_stateData.setEntity(entity);
+		super.setEntity(entity);
+	}
+
+	@Override
+	public void widgetSelected(SelectionEvent e) {
+		State selectedUseCategory = combo_UseCategory.getSelection();
+		if (selectedUseCategory != null) {
+			combo_UseSubCategory.setTerms(setUseCategoryComboTerms(TermStore.getTerms(State.class,null , false), selectedUseCategory));
+			/*selectedLanguageString = getMultilanguageText().get(
+					selectedLanguage);
+
+			element_languageString.setLanguageString(selectedLanguageString);*/
+		}
+		
+	}
+
+	
+
+	@Override
+	public void widgetDefaultSelected(SelectionEvent e) {
+		// TODO Auto-generated method stub
+		
+	}
+	
 
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailSection.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailSection.java
index 38f0fd34c..31891b7e7 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailSection.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailSection.java
@@ -5,9 +5,9 @@ import org.eclipse.jface.viewers.ISelectionProvider;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType;
-import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
 
 public class UseRecordDetailSection extends AbstractCdmDetailSection<DescriptionElementBase> {
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/userecords/UseRecordsViewer.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/userecords/UseRecordsViewer.java
index 047a4a052..d587b3fc2 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/userecords/UseRecordsViewer.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/userecords/UseRecordsViewer.java
@@ -10,9 +10,9 @@ import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
-import eu.etaxonomy.taxeditor.ui.forms.RootElement;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EntityDetailType;
+import eu.etaxonomy.taxeditor.ui.element.RootElement;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EntityDetailType;
 import eu.etaxonomy.taxeditor.ui.section.description.DescribedSpecimenSection;
 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailSection;
