-// $Id$
/**
-* Copyright (C) 2007 EDIT
-* 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.
-*/
+ * Copyright (C) 2007 EDIT
+ * 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.apache.log4j.Logger;
-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.RootElement;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType;
-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>
+ * <p>
+ * NameRelationshipWizardPage class.
+ * </p>
*
* @author n.hoffmann
* @created Jun 1, 2010
* @version 1.0
*/
-public class NameRelationshipWizardPage extends WizardPage implements IPropertyChangeListener {
-
-
- private static final Logger logger = Logger
- .getLogger(NameRelationshipWizardPage.class);
-
-
- private CdmFormFactory formFactory;
-
-
- private NameSelectionElement selection_relatedTo;
-
+public class NameRelationshipWizardPage extends AbstractEntityCollectionElementWizardPage {
- private NameRelationshipTypeComboElement combo_relationshipType;
+ private EntitySelectionElement<TaxonName> selection_relatedTo;
+ private RelationshipTypeCombo combo_relationshipType;
- private NameRelationshipDetailSection callingSection;
+ private final TaxonName entity;
+ private RelationshipTermBase type;
- private TaxonNameBase entity;
+ private TaxonName relatedName;
+ boolean inverse;
-
- private NameRelationshipType type;
-
-
- private TaxonNameBase toName;
-
-
- private RootElement rootElement;
-
-
/**
- * <p>Constructor for NameRelationshipWizardPage.</p>
+ * <p>
+ * Constructor for NameRelationshipWizardPage.
+ * </p>
*
- * @param callingSection a {@link eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection} object.
+ * @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;
+ protected NameRelationshipWizardPage(
+ 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)
+
+ /*
+ * (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));
-
- rootElement = new RootElement(formFactory, control);
-
- 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, SWT.NULL);
-
- setControl(control);
+ super.createControl(parent);
+
+ combo_relationshipType = formFactory.createNameRelationshipTypeCombo(rootElement,
+ entity.getNameCache(), SWT.NULL, false,null);
+
+
+ selection_relatedTo = formFactory
+ .createSelectionElement(TaxonName.class, rootElement,
+ "",this.entity, EntitySelectionElement.ALL,
+ SWT.NULL, true);
+
}
-
+
/**
- * <p>getNameRelationship</p>
+ * <p>
+ * getNameRelationship
+ * </p>
*
* @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
*/
- public NameRelationship getNameRelationship(){
- return entity.addRelationshipToName(toName, type, null, null, null);
+ public NameRelationship getNameRelationship() {
+ 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} */
+ @Override
public void propertyChange(PropertyChangeEvent event) {
- if(event == null){
+ if (event == null) {
return;
}
Object eventSource = event.getSource();
- if(eventSource == combo_relationshipType){
- type = combo_relationshipType.getSelection();
- }
- else if(eventSource == selection_relatedTo){
- toName = selection_relatedTo.getEntity();
+ if (eventSource == combo_relationshipType && combo_relationshipType.getSelection() != null) {
+ type = combo_relationshipType.getSelection().getTerm();
+ this.inverse = combo_relationshipType.getSelection().isInverse();
+ } else if (eventSource == selection_relatedTo) {
+ relatedName = selection_relatedTo.getEntity();
+
}
-
- setPageComplete(type != null && toName != null);
- }
-
- /** {@inheritDoc} */
- @Override
- public void dispose() {
- rootElement.removeElements();
- formFactory.removePropertyChangeListener(this);
- super.dispose();
+
+ boolean complete = type != null && relatedName != null;
+ setPageComplete(complete);
}
+
}