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.propertysheet.namerelations.wizard;
|
11
|
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
|
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;
|
19
|
|
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;
|
23
|
|
24
|
/**
|
25
|
* @author p.ciardelli
|
26
|
* @created 06.06.2008
|
27
|
* @version 1.0
|
28
|
*/
|
29
|
public class NameRelationsListWizard extends Wizard {
|
30
|
private static final Logger logger = Logger
|
31
|
.getLogger(NameRelationsListWizard.class);
|
32
|
|
33
|
private TaxonNameBase name;
|
34
|
|
35
|
private WritableList nameRelationsTemp;
|
36
|
|
37
|
public NameRelationsListWizard(TaxonNameBase name) {
|
38
|
super();
|
39
|
|
40
|
this.name = name;
|
41
|
|
42
|
initNameRelationsList();
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
*
|
47
|
*/
|
48
|
private void initNameRelationsList() {
|
49
|
nameRelationsTemp = new WritableList();
|
50
|
nameRelationsTemp.addAll(name.getNameRelations());
|
51
|
}
|
52
|
|
53
|
public void addPages() {
|
54
|
IWizardPage chooseNamePage = new ListNameRelationsWizardPage(name, nameRelationsTemp);
|
55
|
addPage(chooseNamePage);
|
56
|
}
|
57
|
|
58
|
/* (non-Javadoc)
|
59
|
* @see org.eclipse.jface.wizard.Wizard#performFinish()
|
60
|
*/
|
61
|
@Override
|
62
|
public boolean performFinish() {
|
63
|
|
64
|
Set<NameRelationship> nameRelations = name.getNameRelations();
|
65
|
Set<NameRelationship> removeRelations = new HashSet<NameRelationship>();
|
66
|
|
67
|
for (NameRelationship relation : nameRelations) {
|
68
|
|
69
|
// Remove any relations no longer in temporary list
|
70
|
if (!nameRelationsTemp.contains(relation)) {
|
71
|
removeRelations.add(relation);
|
72
|
} else {
|
73
|
|
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(),
|
79
|
relation.getType(),
|
80
|
relation.getRuleConsidered());
|
81
|
} else {
|
82
|
name.addRelationshipFromName(relation.getFromName(),
|
83
|
relation.getType(),
|
84
|
relation.getRuleConsidered());
|
85
|
}
|
86
|
}
|
87
|
}
|
88
|
}
|
89
|
for (NameRelationship relation : removeRelations) {
|
90
|
name.removeNameRelationship(relation);
|
91
|
}
|
92
|
|
93
|
return true;
|
94
|
}
|
95
|
|
96
|
/* (non-Javadoc)
|
97
|
* @see org.eclipse.jface.wizard.Wizard#performCancel()
|
98
|
*/
|
99
|
public boolean performCancel() {
|
100
|
// Remove all temporary relationships
|
101
|
Set<NameRelationship> nameRelations = name.getNameRelations();
|
102
|
Set<NameRelationship> removeRelations = new HashSet<NameRelationship>();
|
103
|
|
104
|
for (NameRelationship relation : nameRelations) {
|
105
|
if (relation instanceof TemporaryNameRelationship) {
|
106
|
removeRelations.add(relation);
|
107
|
}
|
108
|
}
|
109
|
for (NameRelationship relation : removeRelations) {
|
110
|
name.removeNameRelationship(relation);
|
111
|
}
|
112
|
return true;
|
113
|
}
|
114
|
}
|