package eu.etaxonomy.taxeditor.model;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
-import java.util.Set;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.description.DescriptionBase;
* @return
*/
private void buildLeaf(FeatureNode featureNode){
+ if(featureNode.getFeature() == null){
+ throw new IllegalArgumentException("The given feature node does not have a feature.");
+ }
+
+ Feature feature = (Feature) HibernateProxyHelper.deproxy(featureNode.getFeature());
+
// get feature node container for the given feature
- FeatureNodeContainer container = containerTree.getFeatureNodeContainerByFeature(featureNode.getFeature());
+ FeatureNodeContainer container = containerTree.getFeatureNodeContainer(feature);
// get description elements for the given feature
- List<DescriptionElementBase> elements = containerTree.getDescriptionsElementsForFeature(featureNode.getFeature());
+ List<DescriptionElementBase> elements = containerTree.getDescriptionsElementsForFeature(feature);
// no description elements, so we should also remove the feature node container
if(elements.isEmpty()){
if(container != null){
if(parentFeatureNode.isRoot()){
containerTree.getRoot().addChild(this);
}else{
- FeatureNodeContainer parentContainer = new FeatureNodeContainer(containerTree);
- parentContainer.setFeatureNode(parentFeatureNode);
+ FeatureNodeContainer parentContainer = containerTree.getFeatureNodeContainer(parentFeatureNode);
+ if(parentContainer == null){
+ parentContainer = new FeatureNodeContainer(containerTree);
+ parentContainer.setFeatureNode(parentFeatureNode);
+ }
parentContainer.addChild(this);
}
- public FeatureNodeContainer getFeatureNodeContainerByFeature(Feature feature) {
+ public FeatureNodeContainer getFeatureNodeContainer(Feature feature) {
List<FeatureNodeContainer> leafs = root.getLeafs();
for(FeatureNodeContainer container : leafs){
return null;
}
+ public FeatureNodeContainer getFeatureNodeContainer(FeatureNode featureNode){
+ List<FeatureNodeContainer> leafs = root.getLeafs();
+
+ for(FeatureNodeContainer container : leafs){
+ if(container.getFeatureNode().equals(featureNode)){
+ return container;
+ }
+ }
+ return null;
+ }
+
public void addContainer(FeatureNodeContainer container){
featureNodeContainers.add(container);
}
WizardDialog dialog = new WizardDialog(StoreUtil.getShell(), wizard);
dialog.open();
+
tableViewer.setInput(TermStore.getFeatures());
tableViewer.reveal(selection);
}
import org.eclipse.jface.wizard.Wizard;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.ITermService;
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
import eu.etaxonomy.cdm.model.common.Representation;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.store.TermStore;
* @created 12.06.2009
* @version 1.0
*/
-public class VocabularyTermWizard<T extends DefinedTermBase> extends Wizard {
+public class VocabularyTermWizard<T extends DefinedTermBase> extends Wizard implements IConversationEnabled {
public T term = null;
private Class<T> termClass;
+ private ConversationHolder conversation;
+
/**
* <p>Constructor for VocabularyTermWizard.</p>
*
* @param vocabularyClass a {@link java.lang.Class} object.
*/
- public VocabularyTermWizard(Class<T> vocabularyClass){
- this.termClass = vocabularyClass;
+ public VocabularyTermWizard(Class<T> vocabularyClass){
+ conversation = CdmStore.createConversation();
+ termClass = vocabularyClass;
}
/**
*/
public VocabularyTermWizard(Class<T> vocabularyClass, T selectedTerm){
this(vocabularyClass);
- this.term = selectedTerm;
+ term = (T) CdmStore.getService(ITermService.class).load(selectedTerm.getUuid());
editMode = true;
}
@Override
public boolean performFinish() {
- ConversationHolder conversation = CdmStore.createConversation();
-
if(editMode){
TermStore.updateVocabulary(getTerm());
}else{
TermStore.saveTerm(getTerm());
}
- conversation.commit(false);
+ getConversationHolder().commit(false);
+ getConversationHolder().close();
return true;
}
public T getTerm() {
return term;
}
+
+ public Representation getRepresentation(){
+ return term != null ? term.getRepresentation(CdmStore.getDefaultLanguage()) : null;
+ }
/**
* <p>isEditMode</p>
return termClass;
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
+ */
+ @Override
+ public void update(CdmDataChangeMap changeEvents) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
+ */
+ @Override
+ public ConversationHolder getConversationHolder() {
+ return conversation;
+ }
+
}
import org.eclipse.swt.widgets.Text;
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+import eu.etaxonomy.cdm.model.common.Representation;
/**
* <p>VocabularyTermWizardPage class.</p>
private Text text_label;
private Text text_labelAbbreviation;
private Text text_description;
-
- private T term = null;
/**
* <p>Constructor for VocabularyTermWizardPage.</p>
setControl(composite);
- if(getWizard().getTerm() != null){
- DefinedTermBase<T> term = getWizard().getTerm();
- text_label.setText(term.getLabel());
- // why can't we access labelAbbreviation
-// text_labelAbbreviation.setText(feature.get)
- // why can't we access the term string?
-// text_description.setText(feature.getT)
+ if(getWizard().getRepresentation() != null){
+ Representation representation = getWizard().getRepresentation();
+ text_label.setText(representation.getLabel());
+ text_labelAbbreviation.setText(representation.getAbbreviatedLabel());
+ text_description.setText(representation.getDescription());
}
setPageComplete(false);
*/
/** {@inheritDoc} */
public void modifyText(ModifyEvent e) {
+ Object eventSource = e.getSource();
+ if(eventSource == text_label){
+ getWizard().getRepresentation().setLabel(text_label.getText());
+ }
+ else if(eventSource == text_labelAbbreviation){
+ getWizard().getRepresentation().setAbbreviatedLabel(text_labelAbbreviation.getText());
+ }
+ else if(eventSource == text_description){
+ getWizard().getRepresentation().setText(text_description.getText());
+ }
+
+
if(text_label.getText().length() > 0){
setPageComplete(true);
-
- getWizard().setTerm(text_description.getText(), text_label.getText(), text_labelAbbreviation.getText());
- } else {
+ }
+ else {
setPageComplete(false);
}
}