/**\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.DefinedTerm;\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.State;\r
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\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
- * The context listener will call this class when the uses view is being loaded.\r
- * It checks if the uses view's necessary terms are present in the database. \r
- * It will persist the terms that aren't present, using the CDMLib's services classes. \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
- \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
- }\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
- \r
- //retrieve terms and vocabularies from db\r
- Feature featureUseRecord = (Feature) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseRecordFeature);\r
- Feature featureUseSummary = (Feature) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseSummaryFeature);\r
- \r
- ConversationHolder conversation = CdmStore.createConversation();\r
- \r
- \r
- //create use marker type if not exists\r
- createUseMarkerType(conversation);\r
- \r
- //create state vocabulary if not exists\r
- createStateVocabulary(monitor, conversation);\r
- \r
- //create state vocabulary if not exists\r
- createCountryVocabulary(monitor, conversation);\r
- \r
- //create plant part vocabulary\r
- createPlantVocabulary(monitor, conversation);\r
- \r
- //create human group vocabulary\r
- createHumanGroupVocabulary(monitor, conversation);\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
- if (palmWebFeatureTree != null){\r
- FeatureNode useRecFeatureNode = FeatureNode.NewInstance(featureUseRecord);\r
- palmWebFeatureTree.getRoot().addChild(useRecFeatureNode);\r
- }else{\r
- StoreUtil.warn(getClass(), "No current feature tree available to add useRecord feature");\r
- }\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
- if (palmWebFeatureTree != null){\r
- FeatureNode useSumFeatureNode = FeatureNode.NewInstance(featureUseSummary);\r
- palmWebFeatureTree.getRoot().addChild(useSumFeatureNode);\r
- }else{\r
- StoreUtil.warn(getClass(), "No current feature tree available to add use summary feature");\r
- }\r
- }\r
- \r
- CdmStore.getService(IVocabularyService.class).saveOrUpdate(featureVocabulary);\r
- if (palmWebFeatureTree != null){\r
- CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(palmWebFeatureTree);\r
- }\r
- conversation.commit(true);\r
- \r
- }\r
- conversation.close(); \r
- }\r
-\r
\r
- private void createHumanGroupVocabulary(IProgressMonitor monitor,ConversationHolder conversation) {\r
- TermVocabulary<DefinedTerm> humanGroupVocabulary = (TermVocabulary<DefinedTerm>) CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidHumanGroupVocabulary);\r
- if (humanGroupVocabulary == null){\r
- monitor.subTask("create human group vocabulary");\r
- URI termSourceUri = null;\r
- try {\r
- termSourceUri = new URI("eu.etaxonomy.cdm.model.description.DefinedTerm");\r
- } catch (URISyntaxException e) {\r
- e.printStackTrace();\r
- }\r
- \r
- //FIXME:3.3MC----\r
- //humanGroupVocabulary = TermVocabulary.NewInstance(UsageTermCollection.humanGroupLabel, UsageTermCollection.humanGroupLabel, null, termSourceUri);\r
- humanGroupVocabulary = null;\r
- humanGroupVocabulary.setUuid(UsageTermCollection.uuidHumanGroupVocabulary);\r
- //FIXME:3.3MC----\r
- \r
- //FIXME:3.3MC----\r
- //DefinedTerm newDummyModifier = DefinedTerm.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);\r
- DefinedTerm newDummyModifier = null;\r
- newDummyModifier.setUuid(UsageTermCollection.uuidHumanGroupDummy);\r
- //FIXME:3.3MC----\r
- \r
- //FIXME:3.3MC----\r
- //DefinedTerm newSubDummyModifier = DefinedTerm.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);\r
- DefinedTerm newSubDummyModifier = null;\r
- newSubDummyModifier.setUuid(UsageTermCollection.uuidEthnicGroupDummy);\r
- //FIXME:3.3MC----\r
- \r
- newDummyModifier.addIncludes(newSubDummyModifier);\r
- humanGroupVocabulary.addTerm(newDummyModifier);\r
- CdmStore.getService(IVocabularyService.class).saveOrUpdate(humanGroupVocabulary);\r
- conversation.commit(true);\r
- }\r
+ public UseObjectManager() {\r
+ CdmStore.getContextManager().addContextListener(this);\r
}\r
\r
\r
- private void createPlantVocabulary(IProgressMonitor monitor, ConversationHolder conversation) {\r
- TermVocabulary<DefinedTerm> plantPartVocabulary = (TermVocabulary<DefinedTerm>) CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidPlantPartVocabulary);\r
- if (plantPartVocabulary == null){\r
- monitor.subTask("create plant part vocabulary");\r
- URI termSourceUri = null;\r
- try {\r
- termSourceUri = new URI("eu.etaxonomy.cdm.model.description.DefinedTerm");\r
- } catch (URISyntaxException e) {\r
- e.printStackTrace();\r
- }\r
- //FIXME:3.3MC----\r
- //plantPartVocabulary = TermVocabulary.NewInstance(UsageTermCollection.plantPartLabel, UsageTermCollection.plantPartLabel, null, termSourceUri);\r
- plantPartVocabulary = null;\r
- plantPartVocabulary.setUuid(UsageTermCollection.uuidPlantPartVocabulary);\r
- //FIXME:3.3MC----\r
- \r
- //FIXME:3.3MC----\r
- //DefinedTerm newDummyModifier = DefinedTerm.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);\r
- DefinedTerm newDummyModifier = null;\r
- newDummyModifier.setUuid(UsageTermCollection.uuidPlantPartDummy);\r
- plantPartVocabulary.addTerm(newDummyModifier);\r
- //FIXME:3.3MC----\r
- \r
- CdmStore.getService(IVocabularyService.class).saveOrUpdate(plantPartVocabulary);\r
- conversation.commit(true);\r
- }\r
- }\r
-\r
-\r
- private void createCountryVocabulary(IProgressMonitor monitor, ConversationHolder conversation) {\r
- TermVocabulary<DefinedTerm> countryVocabulary = (TermVocabulary<DefinedTerm>) CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidCountryVocabulary);\r
- if (countryVocabulary == null){\r
- monitor.subTask("create country vocabulary");\r
- URI termSourceUri = null;\r
- try {\r
- termSourceUri = new URI("eu.etaxonomy.cdm.model.description.DefinedTerm");\r
- } catch (URISyntaxException e) {\r
- e.printStackTrace();\r
- }\r
- //FIXME:3.3MC----\r
- //countryVocabulary = TermVocabulary.NewInstance(UsageTermCollection.countryLabel, UsageTermCollection.countryLabel, null, termSourceUri);\r
- countryVocabulary = null;\r
- countryVocabulary.setUuid(UsageTermCollection.uuidCountryVocabulary);\r
- //FIXME:3.3MC----\r
- \r
- //FIXME:3.3MC----\r
- //DefinedTerm newDummyModifier = DefinedTerm.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);\r
- DefinedTerm newDummyModifier = null;\r
- newDummyModifier.setUuid(UsageTermCollection.uuidCountryDummy);\r
- //FIXME:3.3MC----\r
- countryVocabulary.addTerm(newDummyModifier);\r
- CdmStore.getService(IVocabularyService.class).saveOrUpdate(countryVocabulary);\r
- conversation.commit(true);\r
- }\r
+ @Override\r
+ public void contextRefresh(IProgressMonitor monitor) {\r
+ monitor.subTask("Reset usage data");\r
+ MessagingUtils.warn(getClass(), "Reset usage data");\r
+ UseObjectStore.reset();\r
}\r
\r
\r
- private void createStateVocabulary(IProgressMonitor monitor, ConversationHolder conversation) {\r
- TermVocabulary<State> stateVocabulary = (TermVocabulary<State>) CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidUseCategoryVocabulary);\r
- if (stateVocabulary == null){\r
- monitor.subTask("create state vocabulary");\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
- //FIXME:3.3MC----\r
- //stateVocabulary = TermVocabulary.NewInstance(UsageTermCollection.useCategoryVocabularyLabel, UsageTermCollection.useCategoryVocabularyLabel, null, termSourceUri);\r
- stateVocabulary = null;\r
- stateVocabulary.setUuid(UsageTermCollection.uuidUseCategoryVocabulary);\r
- //FIXME:3.3MC----\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
+ @Override\r
+ public void contextStart(IMemento memento, IProgressMonitor monitor) {\r
+// monitor.subTask("Starting the Uses View");\r
+// MessagingUtils.warn(getClass(), "Starting Uses View warn");\r
+ UseObjectStore.reset();\r
}\r
\r
\r
- private void createUseMarkerType(ConversationHolder conversation) {\r
- MarkerType useMarkertype = (MarkerType) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseMarkerType);\r
- if (useMarkertype == null){\r
- useMarkertype = MarkerType.NewInstance(UsageTermCollection.useMakerLabel, UsageTermCollection.useMakerLabel, null);\r
- useMarkertype.setUuid( UsageTermCollection.uuidUseMarkerType);\r
- TermVocabulary<MarkerType> markerTypeVocabulary = (TermVocabulary<MarkerType>)CdmStore.getService(IVocabularyService.class).find((UsageTermCollection.uuidMarkersVocabulary));\r
- markerTypeVocabulary.addTerm(useMarkertype);\r
- CdmStore.getService(IVocabularyService.class).saveOrUpdate(markerTypeVocabulary);\r
- conversation.commit(true);\r
- }\r
- }\r
}\r