Newer
Older
Sonia Zorba
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package it.inaf.ia2.tsm.webapp;
import ari.ucidy.UCD;
import ari.ucidy.UCDParser;
import it.inaf.ia2.tsm.webapp.xmlconfig.UCDConfiguration;
import it.inaf.ia2.tsm.webapp.xmlconfig.UserConfiguration;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
/**
*
* @author Sonia Zorba <zorba at oats.inaf.it>
*/
@Named("ucdEditor")
@SessionScoped
public class UCDEditor implements Serializable {
private static final long serialVersionUID = -9117203239681234534L;
@Inject
private ConfigurationData config;
@Inject
private User user;
private boolean viewExisting;
private UCDConfiguration newUCDConfiguration;
private String invalidUCDMessage;
private List<UCDConfiguration> customUCDs;
public void openDialog() {
viewExisting = true;
newUCDConfiguration = new UCDConfiguration();
invalidUCDMessage = null;
// Retriving UCD list of current user
for (UserConfiguration u : config.getData().getUsers()) {
if (u.getUsername().equals(user.getUsername())) {
customUCDs = u.getCustomUCDs();
break;
}
}
}
public boolean isViewExisting() {
return viewExisting;
}
public void setViewExisting(boolean viewExisting) {
this.viewExisting = viewExisting;
invalidUCDMessage = null;
}
public UCDConfiguration getNewUCDConfiguration() {
return newUCDConfiguration;
}
public List<UCDConfiguration> getCustomUCDs() {
return customUCDs;
}
public void addUCD() throws IOException {
invalidUCDMessage = null;
if (newUCDConfiguration.getWord() == null || newUCDConfiguration.getWord().isEmpty()) {
invalidUCDMessage = "Insert the UCD word";
return;
}
// Check if word syntax is valid
UCD ucd = UCDParser.parseUCD(newUCDConfiguration.getWord());
if (ucd.size() != 1 || !ucd.getWord(0).valid) {
invalidUCDMessage = "Invalid UCD word syntax";
return;
}
customUCDs.add(newUCDConfiguration);
newUCDConfiguration = new UCDConfiguration();
config.updateConfigurationFile();
}
public void removeUCD(int index) throws IOException {
customUCDs.remove(index);
config.updateConfigurationFile();
}
/**
* For some reason getCurrentInstance().addMessage doesn't work inside the
* dialog, so this field has been added for setting error message manually.
*/
public String getInvalidUCDMessage() {
return invalidUCDMessage;
}
}