-\r
+/**\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
+\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.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.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 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+Messages.UsesLabelProvider_NO_LABEL;\r
+ }\r
+ else {\r
+ text = USE + text;\r
+ }\r
+ }\r
+ else if (element instanceof CategoricalData) {\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
+ 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 (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
+ if (isPlantPartAbsent) {\r
+ text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;\r
+ }\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
+ 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
+ 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
+ if (isCountryAbsent) {\r
+ text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;\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
+ }\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
-public class UsesLabelProvider extends ColumnLabelProvider implements IStyledLabelProvider {\r
+ ((CategoricalData)element).putModifyingText(CdmStore.getDefaultLanguage(), dataportalString);\r
+ }\r
+ return text;\r
+ }\r
\r
- public String getText(Object element) {\r
- /*return DescriptionHelper.getLabel(element);\r
- \r
- for (Marker marker : element.getMarkers()) {\r
- if (marker.getMarkerType().getTitleCache().equals("use")) {\r
- return "Use: " + text;\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
- String text = ((DescriptionBase)element).getTitleCache();\r
- if (text == null || text.length() == 0) {\r
- text = "No label provided";\r
}\r
- \r
- return "Use: " + text;\r
- } \r
- \r
+\r
+ else if (element instanceof FeatureNodeContainer){\r
+ text = ((FeatureNodeContainer)element).getFeature().getTitleCache();\r
+ }\r
+\r
+ return text;\r
+ }\r
+\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 ((vocabularyExpected.equals(UsageTermCollection.ethnicGroupLabel)) && ((term.getPartOf() != null))) {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ /** {@inheritDoc} */\r
@Override\r
public StyledString getStyledText(Object element) {\r
- return new StyledString(this.getText(element), StyledString.QUALIFIER_STYLER);\r
+ return new StyledString(this.getText(element),\r
+ StyledString.QUALIFIER_STYLER);\r
}\r
\r
+\r
+\r
}\r