+/**\r
+* Copyright (C) 2011 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
package eu.etaxonomy.taxeditor.editor.view.uses;\r
\r
import java.util.Arrays;\r
import java.util.List;\r
-import java.util.Map;\r
-\r
-import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;\r
\r
import org.eclipse.jface.viewers.ColumnLabelProvider;\r
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;\r
import org.eclipse.jface.viewers.StyledString;\r
\r
-import eu.etaxonomy.cdm.api.service.DefaultCategoricalDescriptionBuilder;\r
-import eu.etaxonomy.cdm.api.service.DescriptionBuilder;\r
+import eu.etaxonomy.cdm.model.common.DefinedTerm;\r
import eu.etaxonomy.cdm.model.common.Language;\r
import eu.etaxonomy.cdm.model.common.LanguageString;\r
import eu.etaxonomy.cdm.model.description.CategoricalData;\r
import eu.etaxonomy.cdm.model.description.DescriptionBase;\r
-import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
-import eu.etaxonomy.cdm.model.description.Modifier;\r
-import eu.etaxonomy.cdm.model.description.State;\r
import eu.etaxonomy.cdm.model.description.StateData;\r
import eu.etaxonomy.cdm.model.description.TextData;\r
+import eu.etaxonomy.taxeditor.editor.l10n.Messages;\r
+import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;\r
import eu.etaxonomy.taxeditor.store.CdmStore;\r
+import eu.etaxonomy.taxeditor.store.UsageTermCollection;\r
\r
+/**\r
+ * UsesLabelProvider Class\r
+ * @author a.theys\r
+ * @created mar 13, 2012\r
+ * @version 1.0\r
+ */\r
public class UsesLabelProvider extends ColumnLabelProvider implements\r
IStyledLabelProvider {\r
- \r
- private static DescriptionBuilder<CategoricalData> categoricalDescriptionBuilder = new DefaultCategoricalDescriptionBuilder();\r
- public String getText(Object element) {\r
- String text = "";\r
- /*\r
- * return DescriptionHelper.getLabel(element);\r
- * \r
- * for (Marker marker : element.getMarkers()) { if\r
- * (marker.getMarkerType().getTitleCache().equals("use")) { return\r
- * "Use: " + text; } }\r
- */\r
+\r
+ private static final String USE = Messages.UsesLabelProvider_USE;\r
+ private static final String NO_DATA_PROVIDED = Messages.UsesLabelProvider_NO_DATA;\r
+ private static final String SEMICOLON = ";"; //$NON-NLS-1$\r
+\r
+ /** {@inheritDoc} */\r
+ @Override\r
+ public String getText(Object element) {\r
+ String text = ""; //$NON-NLS-1$\r
+\r
if (element instanceof DescriptionBase) {\r
text = ((DescriptionBase) element).getTitleCache();\r
if (text == null || text.length() == 0) {\r
- text = "Use: No label provided";\r
+ text = USE+Messages.UsesLabelProvider_NO_LABEL;\r
}\r
else {\r
- text = "Use: " + text;\r
+ text = USE + text;\r
}\r
}\r
else if (element instanceof CategoricalData) {\r
- //String text = "";\r
- //TextData textData = categoricalDescriptionBuilder.build((CategoricalData) element, getLanguageList());\r
- if (!((CategoricalData) element).getStates().isEmpty()) {\r
- for (StateData statedata : ((CategoricalData) element).getStates()) {\r
- if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals("Use Category")) {\r
- text = text + statedata.getState().getTitleCache() + "; ";\r
+ if (!((CategoricalData) element).getStateData().isEmpty()) {\r
+ boolean isUseCategoryAbsent = true;\r
+ for (StateData statedata : ((CategoricalData) element).getStateData()) {\r
+ if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useCategoryVocabularyLabel)) {\r
+ text = text + statedata.getState().getTitleCache() + SEMICOLON;\r
+ isUseCategoryAbsent = false;\r
}\r
}\r
- for (StateData statedata : ((CategoricalData) element).getStates()) {\r
- if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals("Use SubCategory")) {\r
- text = text + statedata.getState().getTitleCache() + "; ";\r
+ if(isUseCategoryAbsent) {\r
+ text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;\r
+ }\r
+\r
+ boolean isUseSubCategoryAbsent = true;\r
+ for (StateData statedata : ((CategoricalData) element).getStateData()) {\r
+ if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel)) {\r
+ text = text + statedata.getState().getTitleCache() + SEMICOLON;\r
+ isUseSubCategoryAbsent = false;\r
}\r
}\r
+ if(isUseSubCategoryAbsent) {\r
+ text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;\r
+ }\r
+ }\r
+ else {\r
+ text = text + UsageTermCollection.notAvailableLabel + SEMICOLON + UsageTermCollection.notAvailableLabel + SEMICOLON;\r
}\r
if (!((CategoricalData) element).getModifiers().isEmpty()) {\r
- for (Modifier modifier: ((CategoricalData) element).getModifiers()){\r
- if(GetVocabularyType(modifier, "Country")) {\r
- text = text + modifier.getTitleCache()+ "; ";\r
+ for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){\r
+ modifier.getPartOf();\r
+ modifier.getVocabulary();\r
+ }\r
+\r
+ boolean isPlantPartAbsent = true;\r
+ for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){\r
+ if(GetVocabularyType(modifier, UsageTermCollection.plantPartLabel)) {\r
+ text = text + modifier.getTitleCache()+ SEMICOLON;\r
+ isPlantPartAbsent = false;\r
}\r
- \r
+\r
+ }\r
+ if (isPlantPartAbsent) {\r
+ text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;\r
}\r
- for (Modifier modifier: ((CategoricalData) element).getModifiers()){\r
- if(GetVocabularyType(modifier, "Plant Part")) {\r
- text = text + modifier.getTitleCache()+ "; ";\r
+\r
+ boolean isHumanGroupAbsent = true;\r
+ for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){\r
+ if(GetVocabularyType(modifier, UsageTermCollection.humanGroupLabel)) {\r
+ text = text + modifier.getTitleCache()+ SEMICOLON;\r
+ isHumanGroupAbsent = false;\r
}\r
- \r
}\r
- for (Modifier modifier: ((CategoricalData) element).getModifiers()){\r
- if(GetVocabularyType(modifier, "Human Group")) {\r
- text = text + modifier.getTitleCache()+ "; ";\r
+ if (isHumanGroupAbsent) {\r
+ text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;\r
+ }\r
+\r
+ boolean isEthnicGroupAbsent = true;\r
+ for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){\r
+ if(GetVocabularyType(modifier, UsageTermCollection.ethnicGroupLabel)) {\r
+ text = text + modifier.getTitleCache()+ SEMICOLON;\r
+ isEthnicGroupAbsent = false;\r
}\r
- \r
}\r
- for (Modifier modifier: ((CategoricalData) element).getModifiers()){\r
- if(GetVocabularyType(modifier, "Ethnic Group")) {\r
- text = text + modifier.getTitleCache()+ "; ";\r
+ if (isEthnicGroupAbsent) {\r
+ text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;\r
+ }\r
+\r
+ boolean isCountryAbsent = true;\r
+ for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){\r
+ if(GetVocabularyType(modifier, UsageTermCollection.countryLabel)) {\r
+ text = text + modifier.getTitleCache()+ SEMICOLON;\r
+ isCountryAbsent = false;\r
}\r
- \r
+ }\r
+ if (isCountryAbsent) {\r
+ text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;\r
}\r
}\r
- \r
+ else {\r
+ text = text + UsageTermCollection.notAvailableLabel + SEMICOLON + UsageTermCollection.notAvailableLabel + SEMICOLON + UsageTermCollection.notAvailableLabel + SEMICOLON + UsageTermCollection.notAvailableLabel + SEMICOLON;\r
+ }\r
+\r
if (text == null || text.length() == 0) {\r
- text = "No data provided";\r
+ text = NO_DATA_PROVIDED;\r
+ }\r
+ else {\r
+ String[] textElements = text.split(SEMICOLON);\r
+ String dataportalString = textElements[0] + SEMICOLON + textElements[1] + SEMICOLON + textElements[5] + SEMICOLON + textElements[2] + SEMICOLON + textElements[3] + SEMICOLON + textElements[4] + SEMICOLON ;\r
+\r
+ ((CategoricalData)element).putModifyingText(CdmStore.getDefaultLanguage(), dataportalString);\r
}\r
return text;\r
}\r
\r
- else{\r
- text = "Use Record";\r
+ else if (element instanceof TextData) {\r
+ List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});\r
+ LanguageString languageString = ((TextData) element).getPreferredLanguageString(languages);\r
+ text = languageString != null ? languageString.getText() : null;\r
+ if (text == null || text.length() == 0) {\r
+ text = NO_DATA_PROVIDED;\r
+ }\r
+ }\r
+\r
+ else if (element instanceof FeatureNodeContainer){\r
+ text = ((FeatureNodeContainer)element).getFeature().getTitleCache();\r
}\r
\r
return text;\r
}\r
\r
- \r
- private boolean GetVocabularyType(Modifier term, String vocabularyExpected) {\r
- if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(vocabularyExpected))) {\r
+ /** Function dertmining which vocabulary is the term part of\r
+ *\r
+ * @param term\r
+ * @param vocabularyExpected\r
+ * @return\r
+ */\r
+ private boolean GetVocabularyType(DefinedTerm term, String vocabularyExpected) {\r
+ if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(vocabularyExpected))) {\r
+ return true;\r
+ }\r
+ else if ((term.getVocabulary() != null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) {\r
return true;\r
}\r
- else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) {\r
+ else if ((vocabularyExpected.equals(UsageTermCollection.ethnicGroupLabel)) && ((term.getPartOf() != null))) {\r
return true;\r
}\r
- return false;\r
+ return false;\r
}\r
+\r
+ /** {@inheritDoc} */\r
@Override\r
public StyledString getStyledText(Object element) {\r
return new StyledString(this.getText(element),\r
StyledString.QUALIFIER_STYLER);\r
}\r
- \r
- private static List<Language> getLanguageList(){\r
- return Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});\r
- }\r
+\r
+\r
\r
}\r