blob: 2a0b34a267a5cc7dceaf1a8e5a9baa584d440574 (
plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
package com.c2kernel.gui.tabs.outcome.form.field;
import java.awt.Component;
import java.util.Enumeration;
import java.util.StringTokenizer;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.text.JTextComponent;
import org.exolab.castor.types.AnyNode;
import org.exolab.castor.xml.schema.AttributeDecl;
import org.exolab.castor.xml.schema.ElementDecl;
import org.exolab.castor.xml.schema.Facet;
import org.exolab.castor.xml.schema.SimpleType;
import com.c2kernel.gui.tabs.outcome.form.StructuralException;
import com.c2kernel.scripting.Script;
import com.c2kernel.utils.Logger;
/*******************************************************************************
*
* $Revision: 1.4 $ $Date: 2005/08/16 13:59:56 $
*
* Copyright (C) 2003 CERN - European Organization for Nuclear Research All
* rights reserved.
******************************************************************************/
public class ComboField extends StringEditField {
JComboBox comboField;
ListOfValues vals;
DefaultComboBoxModel comboModel;
AnyNode listNode;
public ComboField(SimpleType type, AnyNode listNode) {
super();
comboField = new JComboBox();
content = type;
this.listNode = listNode;
createLOV();
}
public String getDefaultValue() {
if (vals.getDefaultKey() != null)
return vals.get(vals.getDefaultKey()).toString();
else
return "";
}
public String getText() {
return vals.get(comboModel.getSelectedItem()).toString();
}
public JTextComponent makeTextField() {
// not used by this control
return null;
}
public void setText(String text) {
comboModel.setSelectedItem(text);
}
public Component getControl() {
return comboField;
}
private void createLOV() {
vals = new ListOfValues();
if (listNode != null) { // schema instructions for list building
String lovType = listNode.getLocalName();
String param = listNode.getFirstChild().getStringValue();
if (lovType.equals("ScriptList"))
populateLOVFromScript(param);
if (lovType.equals("PathList"))
populateLOVFromLDAP(param);
}
// handle enumerations
// TODO: should be ANDed with above results
if (content.hasFacet(Facet.ENUMERATION)) {
//ListOfValues andList = new ListOfValues();
Enumeration enums = content.getFacets(Facet.ENUMERATION);
while (enums.hasMoreElements()) {
Facet thisEnum = (Facet)enums.nextElement();
vals.put(thisEnum.getValue(), thisEnum.getValue(), false);
}
}
comboModel = new DefaultComboBoxModel(vals.keySet().toArray());
comboModel.setSelectedItem(vals.getDefaultKey());
comboField.setModel(comboModel);
}
/**
* @param param
*/
private void populateLOVFromLDAP(String param) {
// TODO '/root/path;prop=val;prop=val'
}
private void populateLOVFromScript(String scriptName) {
try {
StringTokenizer tok = new StringTokenizer(scriptName, "_");
if (tok.countTokens() != 2)
throw new Exception("Invalid LOVScript name");
Script lovscript = new Script(tok.nextToken(), Integer.parseInt(tok.nextToken()));
lovscript.setInputParamValue("LOV", vals);
lovscript.execute();
} catch (Exception ex) {
Logger.exceptionDialog(ex);
}
}
public void setDecl(AttributeDecl model) throws StructuralException {
super.setDecl(model);
createLOV();
}
public void setDecl(ElementDecl model) throws StructuralException {
super.setDecl(model);
createLOV();
}
/**
*
*/
public void setEditable(boolean editable) {
comboField.setEditable(editable);
}
}
|