2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.propertysheet
.namerelations
.wizard
;
12 import java
.util
.HashSet
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.core
.databinding
.observable
.list
.WritableList
;
17 import org
.eclipse
.jface
.wizard
.IWizardPage
;
18 import org
.eclipse
.jface
.wizard
.Wizard
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
21 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
22 import eu
.etaxonomy
.taxeditor
.propertysheet
.namerelations
.wizard
.ChooseRelationWizardPage
.TemporaryNameRelationship
;
29 public class NameRelationsListWizard
extends Wizard
{
30 private static final Logger logger
= Logger
31 .getLogger(NameRelationsListWizard
.class);
33 private TaxonNameBase name
;
35 private WritableList nameRelationsTemp
;
37 public NameRelationsListWizard(TaxonNameBase name
) {
42 initNameRelationsList();
48 private void initNameRelationsList() {
49 nameRelationsTemp
= new WritableList();
50 nameRelationsTemp
.addAll(name
.getNameRelations());
53 public void addPages() {
54 IWizardPage chooseNamePage
= new ListNameRelationsWizardPage(name
, nameRelationsTemp
);
55 addPage(chooseNamePage
);
59 * @see org.eclipse.jface.wizard.Wizard#performFinish()
62 public boolean performFinish() {
64 Set
<NameRelationship
> nameRelations
= name
.getNameRelations();
65 Set
<NameRelationship
> removeRelations
= new HashSet
<NameRelationship
>();
67 for (NameRelationship relation
: nameRelations
) {
69 // Remove any relations no longer in temporary list
70 if (!nameRelationsTemp
.contains(relation
)) {
71 removeRelations
.add(relation
);
74 // Replace temporary relationship w real one
75 if (relation
instanceof TemporaryNameRelationship
) {
76 removeRelations
.add(relation
);
77 if (name
.equals(relation
.getFromName())) {
78 name
.addRelationshipToName(relation
.getToName(),
80 relation
.getRuleConsidered());
82 name
.addRelationshipFromName(relation
.getFromName(),
84 relation
.getRuleConsidered());
89 for (NameRelationship relation
: removeRelations
) {
90 name
.removeNameRelationship(relation
);
97 * @see org.eclipse.jface.wizard.Wizard#performCancel()
99 public boolean performCancel() {
100 // Remove all temporary relationships
101 Set
<NameRelationship
> nameRelations
= name
.getNameRelations();
102 Set
<NameRelationship
> removeRelations
= new HashSet
<NameRelationship
>();
104 for (NameRelationship relation
: nameRelations
) {
105 if (relation
instanceof TemporaryNameRelationship
) {
106 removeRelations
.add(relation
);
109 for (NameRelationship relation
: removeRelations
) {
110 name
.removeNameRelationship(relation
);