Completed name relations list wizard for property sheet. Edit existing relations...
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / view / propertysheetsupport / namerelationswizard / NameRelationWizard.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.view.propertysheetsupport.namerelationswizard;
11
12 import org.apache.log4j.Logger;
13 import org.eclipse.jface.util.IPropertyChangeListener;
14 import org.eclipse.jface.util.PropertyChangeEvent;
15 import org.eclipse.jface.wizard.IWizardPage;
16 import org.eclipse.jface.wizard.Wizard;
17
18 import eu.etaxonomy.taxeditor.ITaxEditorConstants;
19 import eu.etaxonomy.taxeditor.actions.cdm.CreateNameRelationAction;
20
21 /**
22 * @author p.ciardelli
23 * @created 04.06.2008
24 * @version 1.0
25 */
26 public class NameRelationWizard extends Wizard {
27 private static final Logger logger = Logger
28 .getLogger(NameRelationWizard.class);
29
30 public static final String ID = "eu.etaxonomy.taxeditor.namerelationwizard";
31
32 private NameRelationWizardModel relationModel;
33
34 public NameRelationWizard(NameRelationWizardModel relationModel) {
35 super();
36
37 this.relationModel = relationModel;
38 }
39
40 public void addPages() {
41 IWizardPage chooseNamePage = new ChooseRelatedNameWizardPage(relationModel);
42 addPage(chooseNamePage);
43 IWizardPage chooseRelationPage = new ChooseRelationTypeWizardPage(relationModel);
44 addPage(chooseRelationPage);
45 }
46
47 @Override
48 public boolean performFinish() {
49 CreateNameRelationAction nameRelationAction = new CreateNameRelationAction(relationModel.getFromName(),
50 relationModel.getType(),
51 relationModel.getToName());
52 // if (relationModel.getNameRelationsList() != null) {
53
54 // Action will notify when relation has been created
55 nameRelationAction.addPropertyChangeListener(new IPropertyChangeListener() {
56 @Override
57 public void propertyChange(PropertyChangeEvent event) {
58 logger.warn(event.getProperty());
59 if (event.getProperty().equals(
60 ITaxEditorConstants.NAMERELATION)) {
61 logger.warn("checking name relations list");
62 if (relationModel.getNameRelationsList() != null) {
63 logger.warn("clearing name relations");
64 relationModel.getNameRelationsList().clear();
65 relationModel.getNameRelationsList().addAll(relationModel.getBaseName().getNameRelations());
66 }
67 }
68
69 }
70 });
71 // }
72 nameRelationAction.run();
73 return true;
74 }
75 }