-// $Id$
/**
* Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
+ * European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
- *
+ *
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
package eu.etaxonomy.taxeditor.ui.section.name;
-import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
+import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
import eu.etaxonomy.cdm.model.name.NameRelationship;
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType;
-import eu.etaxonomy.taxeditor.ui.forms.RootElement;
-import eu.etaxonomy.taxeditor.ui.selection.NameSelectionElement;
-import eu.etaxonomy.taxeditor.ui.term.NameRelationshipTypeComboElement;
+import eu.etaxonomy.cdm.model.name.TaxonName;
+import eu.etaxonomy.cdm.model.term.TermRelationshipType;
+import eu.etaxonomy.taxeditor.l10n.Messages;
+import eu.etaxonomy.taxeditor.ui.AbstractEntityCollectionElementWizardPage;
+import eu.etaxonomy.taxeditor.ui.combo.RelationshipTypeCombo;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
/**
* <p>
* NameRelationshipWizardPage class.
* </p>
- *
+ *
* @author n.hoffmann
* @created Jun 1, 2010
* @version 1.0
*/
-public class NameRelationshipWizardPage extends WizardPage implements
- IPropertyChangeListener {
+public class NameRelationshipWizardPage extends AbstractEntityCollectionElementWizardPage {
- private final CdmFormFactory formFactory;
+ private EntitySelectionElement<TaxonName> selection_relatedTo;
- private NameSelectionElement selection_relatedTo;
+ private RelationshipTypeCombo combo_relationshipType;
- private NameRelationshipTypeComboElement combo_relationshipType;
+ private final TaxonName entity;
- private final NameRelationshipDetailSection callingSection;
+ private RelationshipTermBase type;
- private final TaxonNameBase entity;
-
- private NameRelationshipType type;
-
- private TaxonNameBase toName;
-
- private RootElement rootElement;
+ private TaxonName relatedName;
+ boolean inverse;
/**
* <p>
* Constructor for NameRelationshipWizardPage.
* </p>
- *
+ *
* @param callingSection
* a
* {@link eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection}
* object.
*/
protected NameRelationshipWizardPage(
- NameRelationshipDetailSection callingSection) {
- super("NameRelationshipWizardPage");
- setTitle("New Name Relationship");
- setDescription(callingSection.getEntity().getTitleCache());
- this.callingSection = callingSection;
+ NameRelationshipDetailSection callingSection, CdmFormFactory formFactory) {
+ super("NameRelationshipWizardPage", formFactory); //$NON-NLS-1$
+ setTitle("New Name Relationship"); //$NON-NLS-1$
+ //setDescription(callingSection.getEntity().getTitleCache());
+ setDescription(Messages.NameRelationshipWizardPage_description);
this.entity = callingSection.getEntity();
- this.formFactory = callingSection.getFormFactory();
formFactory.addPropertyChangeListener(this);
}
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
* .Composite)
/** {@inheritDoc} */
@Override
public void createControl(Composite parent) {
- this.setPageComplete(false);
-
- Composite control = formFactory.createComposite(parent);
-
- control.setLayout(CdmFormFactory.LAYOUT(2, false));
+ super.createControl(parent);
- rootElement = new RootElement(formFactory, control);
+ combo_relationshipType = formFactory.createNameRelationshipTypeCombo(rootElement,
+ entity.getNameCache(), SWT.NULL, false,null);
- combo_relationshipType = (NameRelationshipTypeComboElement) formFactory
- .createTermComboElement(TermComboType.NAMERELATIONSHIP,
- rootElement, "Name Relationship Type", null, SWT.NULL);
- selection_relatedTo = (NameSelectionElement) formFactory
- .createSelectionElement(SelectionType.NAME,
- ((NameRelationshipWizard) getWizard())
- .getConversationHolder(), rootElement,
- "Related to", null, NameSelectionElement.DEFAULT,
- SWT.NULL);
+ selection_relatedTo = formFactory
+ .createSelectionElement(TaxonName.class, rootElement,
+ "",this.entity, EntitySelectionElement.ALL,
+ SWT.NULL, true);
- setControl(control);
}
/**
* <p>
* getNameRelationship
* </p>
- *
+ *
* @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
*/
public NameRelationship getNameRelationship() {
- return entity.addRelationshipToName(toName, type, null, null, null);
+ NameRelationship rel;
+ if (inverse){
+ rel = entity.addRelationshipFromName(relatedName, (NameRelationshipType)type, null, null, null, null);
+ }else{
+ rel = entity.addRelationshipToName(relatedName, (NameRelationshipType)type, null, null, null, null);
+ }
+ return rel;
}
/** {@inheritDoc} */
return;
}
Object eventSource = event.getSource();
- if (eventSource == combo_relationshipType) {
- type = combo_relationshipType.getSelection();
+ if (eventSource == combo_relationshipType && combo_relationshipType.getSelection() != null) {
+ type = combo_relationshipType.getSelection().getTerm();
+ this.inverse = combo_relationshipType.getSelection().isInverse();
} else if (eventSource == selection_relatedTo) {
- toName = selection_relatedTo.getEntity();
+ relatedName = selection_relatedTo.getEntity();
+
}
- boolean complete = type != null && toName != null;
+ boolean complete = type != null && relatedName != null;
setPageComplete(complete);
}
- /** {@inheritDoc} */
- @Override
- public void dispose() {
- rootElement.removeElements();
- formFactory.removePropertyChangeListener(this);
- super.dispose();
- }
}