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
.eclipse
.core
.databinding
.observable
.list
.WritableList
;
16 import org
.eclipse
.jface
.wizard
.IWizardPage
;
17 import org
.eclipse
.jface
.wizard
.Wizard
;
19 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
20 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
21 import eu
.etaxonomy
.taxeditor
.propertysheet
.namerelations
.wizard
.ChooseRelationWizardPage
.TemporaryNameRelationship
;
28 public class NameRelationsListWizard
extends Wizard
{
30 private TaxonNameBase
<?
, ?
> name
;
32 private WritableList nameRelationsTemp
;
34 public NameRelationsListWizard(TaxonNameBase
<?
, ?
> name
) {
39 initNameRelationsList();
45 private void initNameRelationsList() {
46 nameRelationsTemp
= new WritableList();
47 nameRelationsTemp
.addAll(name
.getNameRelations());
50 public void addPages() {
51 IWizardPage chooseNamePage
= new ListNameRelationsWizardPage(name
, nameRelationsTemp
);
52 addPage(chooseNamePage
);
56 * @see org.eclipse.jface.wizard.Wizard#performFinish()
59 public boolean performFinish() {
61 Set
<NameRelationship
> nameRelations
= name
.getNameRelations();
62 Set
<NameRelationship
> removeRelations
= new HashSet
<NameRelationship
>();
64 for (NameRelationship relation
: nameRelations
) {
66 // Remove any relations no longer in temporary list
67 if (!nameRelationsTemp
.contains(relation
)) {
68 removeRelations
.add(relation
);
71 // Replace temporary relationship w real one
72 if (relation
instanceof TemporaryNameRelationship
) {
73 removeRelations
.add(relation
);
74 if (name
.equals(relation
.getFromName())) {
75 name
.addRelationshipToName(relation
.getToName(),
77 relation
.getRuleConsidered());
79 name
.addRelationshipFromName(relation
.getFromName(),
81 relation
.getRuleConsidered());
86 for (NameRelationship relation
: removeRelations
) {
87 name
.removeNameRelationship(relation
);
94 * @see org.eclipse.jface.wizard.Wizard#performCancel()
96 public boolean performCancel() {
97 // Remove all temporary relationships
98 Set
<NameRelationship
> nameRelations
= name
.getNameRelations();
99 Set
<NameRelationship
> removeRelations
= new HashSet
<NameRelationship
>();
101 for (NameRelationship relation
: nameRelations
) {
102 if (relation
instanceof TemporaryNameRelationship
) {
103 removeRelations
.add(relation
);
106 for (NameRelationship relation
: removeRelations
) {
107 name
.removeNameRelationship(relation
);