/**\r
* Copyright (C) 2011 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
* http://www.e-taxonomy.eu\r
-* \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;\r
\r
-import java.net.URI;\r
-import java.net.URISyntaxException;\r
-\r
import org.eclipse.core.runtime.IProgressMonitor;\r
import org.eclipse.ui.IMemento;\r
\r
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;\r
-import eu.etaxonomy.cdm.api.service.IFeatureTreeService;\r
-import eu.etaxonomy.cdm.api.service.ITermService;\r
-import eu.etaxonomy.cdm.api.service.IVocabularyService;\r
-import eu.etaxonomy.cdm.model.common.MarkerType;\r
-import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
-import eu.etaxonomy.cdm.model.description.Feature;\r
-import eu.etaxonomy.cdm.model.description.FeatureNode;\r
-import eu.etaxonomy.cdm.model.description.FeatureTree;\r
-import eu.etaxonomy.cdm.model.description.Modifier;\r
-import eu.etaxonomy.cdm.model.description.State;\r
+import eu.etaxonomy.taxeditor.editor.l10n.Messages;\r
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;\r
+import eu.etaxonomy.taxeditor.model.MessagingUtils;\r
import eu.etaxonomy.taxeditor.store.CdmStore;\r
-import eu.etaxonomy.taxeditor.store.StoreUtil;\r
+import eu.etaxonomy.taxeditor.store.UseObjectStore;\r
\r
/**\r
- * This class sets up the necessary items for the use interface.\r
- * @author a.theys \r
+ * The context listener will call this class when a new context is started.\r
+ * It will reset the UseObjectStore to guarantee the static\r
+ * content of the store will be refreshed each time we load a new context.\r
+ * @author a.theys\r
+ * @author a.mueller\r
* @created mar 13, 2012\r
- * @version 1.0\r
*/\r
public class UseObjectManager extends ContextListenerAdapter{\r
+\r
+ private static final String RESET_USAGE_DATA = Messages.UseObjectManager_RESET_DATA;\r
+\r
+\r
+ public UseObjectManager() {\r
+ CdmStore.getContextManager().addContextListener(this);\r
+ }\r
+\r
+\r
@Override\r
public void contextRefresh(IProgressMonitor monitor) {\r
- monitor.subTask("Refreshing the Uses View");\r
- StoreUtil.warn(getClass(), "Refreshing Uses View warn");\r
- setupNecessaryItems(monitor);\r
+ monitor.subTask(RESET_USAGE_DATA);\r
+ MessagingUtils.warn(getClass(), RESET_USAGE_DATA);\r
+ UseObjectStore.reset();\r
}\r
- \r
- \r
+\r
+\r
@Override\r
public void contextStart(IMemento memento, IProgressMonitor monitor) {\r
- monitor.subTask("Starting the Uses View");\r
- StoreUtil.warn(getClass(), "Starting Uses View warn");\r
- setupNecessaryItems(monitor);\r
- }\r
- \r
- private void setupNecessaryItems(IProgressMonitor monitor) {\r
- MarkerType existingMarkertype = (MarkerType) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseMarkerType);\r
- TermVocabulary<State> stateVocabulary = (TermVocabulary<State>) CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidUseCategoryVocabulary);\r
- Feature featureUseRecord = (Feature) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseRecordFeature);\r
- Feature featureUseSummary = (Feature) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseSummaryFeature);\r
- TermVocabulary<Modifier> countryVocabulary = (TermVocabulary<Modifier>) CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidCountryVocabulary);\r
- TermVocabulary<Modifier> plantPartVocabulary = (TermVocabulary<Modifier>) CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidPlantPartVocabulary);\r
- TermVocabulary<Modifier> humanGroupVocabulary = (TermVocabulary<Modifier>) CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidHumanGroupVocabulary);\r
- \r
- ConversationHolder conversation = CdmStore.createConversation();\r
- if (existingMarkertype == null) {\r
- existingMarkertype = MarkerType.NewInstance(UsageTermCollection.useMakerLabel, UsageTermCollection.useMakerLabel, null);\r
- existingMarkertype.setUuid( UsageTermCollection.uuidUseMarkerType);\r
- TermVocabulary<MarkerType> markerTypeVocabulary = (TermVocabulary<MarkerType>)CdmStore.getService(IVocabularyService.class).find((UsageTermCollection.uuidMarkersVocabulary));\r
- markerTypeVocabulary.addTerm(existingMarkertype);\r
- CdmStore.getService(IVocabularyService.class).saveOrUpdate(markerTypeVocabulary);\r
- conversation.commit(true);\r
- }\r
- if (stateVocabulary == null) {\r
- monitor.subTask("stateVocabulary empty");\r
- URI termSourceUri = null;\r
- try {\r
- termSourceUri = new URI("eu.etaxonomy.cdm.model.description.State");\r
- } catch (URISyntaxException e) {\r
- e.printStackTrace();\r
- }\r
- stateVocabulary = TermVocabulary.NewInstance(UsageTermCollection.useCategoryVocabularyLabel, UsageTermCollection.useCategoryVocabularyLabel, null, termSourceUri);\r
- stateVocabulary.setUuid(UsageTermCollection.uuidUseCategoryVocabulary);\r
- State newDummyState = State.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);\r
- newDummyState.setUuid(UsageTermCollection.uuidUseCategoryDummy);\r
- State newDummySubCat = State.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);\r
- newDummySubCat.setUuid(UsageTermCollection.uuidUseSubCategoryDummy);\r
- newDummyState.addIncludes(newDummySubCat);\r
- stateVocabulary.addTerm(newDummyState);\r
- CdmStore.getService(IVocabularyService.class).saveOrUpdate(stateVocabulary);\r
- conversation.commit(true);\r
- }\r
- if (countryVocabulary == null) {\r
- monitor.subTask("countryVocabulary empty");\r
- URI termSourceUri = null;\r
- try {\r
- termSourceUri = new URI("eu.etaxonomy.cdm.model.description.Modifier");\r
- } catch (URISyntaxException e) {\r
- e.printStackTrace();\r
- }\r
- countryVocabulary = TermVocabulary.NewInstance(UsageTermCollection.countryLabel, UsageTermCollection.countryLabel, null, termSourceUri);\r
- countryVocabulary.setUuid(UsageTermCollection.uuidCountryVocabulary);\r
- Modifier newDummyModifier = Modifier.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);\r
- newDummyModifier.setUuid(UsageTermCollection.uuidCountryDummy);\r
- countryVocabulary.addTerm(newDummyModifier);\r
- CdmStore.getService(IVocabularyService.class).saveOrUpdate(countryVocabulary);\r
- conversation.commit(true);\r
- }\r
- if (plantPartVocabulary == null) {\r
- monitor.subTask("plantPartVocabulary empty");\r
- URI termSourceUri = null;\r
- try {\r
- termSourceUri = new URI("eu.etaxonomy.cdm.model.description.Modifier");\r
- } catch (URISyntaxException e) {\r
- e.printStackTrace();\r
- }\r
- plantPartVocabulary = TermVocabulary.NewInstance(UsageTermCollection.plantPartLabel, UsageTermCollection.plantPartLabel, null, termSourceUri);\r
- plantPartVocabulary.setUuid(UsageTermCollection.uuidPlantPartVocabulary);\r
- Modifier newDummyModifier = Modifier.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);\r
- newDummyModifier.setUuid(UsageTermCollection.uuidPlantPartDummy);\r
- plantPartVocabulary.addTerm(newDummyModifier);\r
- CdmStore.getService(IVocabularyService.class).saveOrUpdate(plantPartVocabulary);\r
- conversation.commit(true);\r
- }\r
- if (humanGroupVocabulary == null) {\r
- monitor.subTask("humanGroupVocabulary empty");\r
- URI termSourceUri = null;\r
- try {\r
- termSourceUri = new URI("eu.etaxonomy.cdm.model.description.Modifier");\r
- } catch (URISyntaxException e) {\r
- e.printStackTrace();\r
- }\r
- humanGroupVocabulary = TermVocabulary.NewInstance(UsageTermCollection.humanGroupLabel, UsageTermCollection.humanGroupLabel, null, termSourceUri);\r
- humanGroupVocabulary.setUuid(UsageTermCollection.uuidHumanGroupVocabulary);\r
- Modifier newDummyModifier = Modifier.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);\r
- newDummyModifier.setUuid(UsageTermCollection.uuidHumanGroupDummy);\r
- Modifier newSubDummyModifier = Modifier.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);\r
- newSubDummyModifier.setUuid(UsageTermCollection.uuidEthnicGroupDummy);\r
- newDummyModifier.addIncludes(newSubDummyModifier);\r
- humanGroupVocabulary.addTerm(newDummyModifier);\r
- CdmStore.getService(IVocabularyService.class).saveOrUpdate(humanGroupVocabulary);\r
- conversation.commit(true);\r
- }\r
- \r
- if(featureUseRecord == null|| featureUseSummary == null) {\r
- TermVocabulary<Feature> featureVocabulary = (TermVocabulary<Feature>)CdmStore.getService(IVocabularyService.class).find((UsageTermCollection.uuidFeatureVocabulary));\r
- FeatureTree palmWebFeatureTree = CdmStore.getService(IFeatureTreeService.class).find(UsageTermCollection.uuidPalmWebFeatureTree);\r
- \r
- if (featureUseRecord == null ) {\r
- featureUseRecord = Feature.NewInstance(UsageTermCollection.useRecordFeatureLabel, UsageTermCollection.useRecordFeatureLabel, null);\r
- featureUseRecord.setUuid(UsageTermCollection.uuidUseRecordFeature);\r
- featureUseRecord.isSupportsCategoricalData();\r
- featureUseRecord.setSupportsCategoricalData(true);\r
- featureVocabulary.addTerm(featureUseRecord);\r
- FeatureNode useRecFeatureNode = FeatureNode.NewInstance(featureUseRecord);\r
- palmWebFeatureTree.getRoot().addChild(useRecFeatureNode);\r
- }\r
- if (featureUseSummary == null) {\r
- featureUseSummary = Feature.NewInstance(UsageTermCollection.useSummaryFeatureLabel, UsageTermCollection.useSummaryFeatureLabel, null);\r
- featureUseSummary.setUuid(UsageTermCollection.uuidUseSummaryFeature);\r
- featureUseSummary.isSupportsTextData();\r
- featureUseSummary.setSupportsTextData(true);\r
- featureVocabulary.addTerm(featureUseSummary);\r
- FeatureNode useSumFeatureNode = FeatureNode.NewInstance(featureUseSummary);\r
- palmWebFeatureTree.getRoot().addChild(useSumFeatureNode);\r
- }\r
- \r
- CdmStore.getService(IVocabularyService.class).saveOrUpdate(featureVocabulary);\r
- CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(palmWebFeatureTree);\r
- conversation.commit(true);\r
- \r
- }\r
- conversation.close(); \r
+// monitor.subTask("Starting the Uses View");\r
+// MessagingUtils.warn(getClass(), "Starting Uses View warn");\r
+ UseObjectStore.reset();\r
}\r
+\r
+\r
}\r