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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/*
* StatusPane.java
*
* Created on March 20, 2001, 3:30 PM
*/
package org.cristalise.gui.tabs;
/**
* @author abranson
* @version
*/
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import org.cristalise.gui.MainFrame;
import org.cristalise.gui.tree.NodeAgent;
import org.cristalise.kernel.entity.proxy.MemberSubscription;
import org.cristalise.kernel.entity.proxy.ProxyObserver;
import org.cristalise.kernel.persistency.ClusterStorage;
import org.cristalise.kernel.process.Gateway;
import org.cristalise.kernel.property.Property;
import org.cristalise.kernel.utils.Language;
/**
* Pane to display all work orders that this agent can execute, and activate
* them on request from the user. Subscribes to NodeItem for Property objects.
* @version $Revision: 1.44 $ $Date: 2005/08/31 07:21:20 $
* @author $Author: abranson $
*/
public class PropertiesPane extends ItemTabPane implements ProxyObserver<Property>, ActionListener {
Box propertyBox;
JButton eraseButton;
boolean subbed = false;
HashMap<String, JLabel> loadedProps = new HashMap<String, JLabel>();
JLabel domTitle;
DomainPathAdmin domAdmin;
public PropertiesPane() {
super("Properties", "Properties");
initPanel();
// Create box container for properties
getGridBagConstraints();
c.gridx = 0; c.gridy = 1;
c.anchor = GridBagConstraints.NORTHWEST;
c.fill = GridBagConstraints.NONE;
c.weightx = 1.0; c.weighty = 2.0;
propertyBox = Box.createVerticalBox();
gridbag.setConstraints(propertyBox, c);
add(propertyBox);
if (MainFrame.isAdmin) { // edit dompath
c.gridy++;
c.fill = GridBagConstraints.NONE;
c.weighty=0.0;
domTitle = new JLabel("Domain Paths", titleIcon, SwingConstants.LEFT);
domTitle.setFont(titleFont);
domTitle.setForeground(headingColor);
gridbag.setConstraints(domTitle, c);
add(domTitle);
c.gridy++;
c.fill = GridBagConstraints.BOTH;
c.weighty=1.0;
domAdmin = new DomainPathAdmin();
gridbag.setConstraints(domAdmin, c);
add(domAdmin);
if (Gateway.getProperties().getBoolean("EnableItemErase")) {
c.gridy++;
c.fill = GridBagConstraints.NONE;
eraseButton = new JButton(Language.translate("Erase!"));
eraseButton.addActionListener(this);
eraseButton.setActionCommand("Erase Item");
gridbag.setConstraints(eraseButton, c);
add(eraseButton);
}
}
}
@Override
public void reload() {
Gateway.getStorage().clearCache(sourceItem.getItemPath(), ClusterStorage.PROPERTY);
loadedProps = new HashMap<String, JLabel>();
initForItem(sourceItem);
}
@Override
public void run() {
Thread.currentThread().setName("Property Pane Builder");
if (sourceItem instanceof NodeAgent) {
remove(domAdmin);
remove(domTitle);
eraseButton.setEnabled(false);
}
else if (domAdmin != null)
domAdmin.setEntity(sourceItem.getItem());
propertyBox.removeAll();
propertyBox.add(Box.createGlue());
revalidate();
sourceItem.getItem().subscribe(new MemberSubscription<Property>(this, ClusterStorage.PROPERTY, true));
}
/**
*
*/
@Override
public void add(Property newProp) {
JLabel propLabel = loadedProps.get(newProp.getName());
if (propLabel == null) { // new prop
JPanel summaryPanel = new JPanel(new GridLayout(0,2));
summaryPanel.add(new JLabel(Language.translate(newProp.getName()) + ":"));
Box valueBox = Box.createHorizontalBox();
propLabel = new JLabel(newProp.getValue());
loadedProps.put(newProp.getName(), propLabel);
valueBox.add(propLabel);
if (MainFrame.isAdmin && newProp.isMutable()) {
JButton editButton = new JButton("...");
editButton.setMargin(new Insets(0,0,0,0));
editButton.setActionCommand(newProp.getName());
editButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
String oldVal = loadedProps.get(e.getActionCommand()).getText();
String newVal = (String)JOptionPane.showInputDialog(null, "Enter new value for "+e.getActionCommand(), "Edit Property",
JOptionPane.QUESTION_MESSAGE, null, null, oldVal);
if (newVal!=null && !(newVal.equals(oldVal))) {
try {
(sourceItem.getItem()).setProperty(MainFrame.userAgent, e.getActionCommand(), newVal);
} catch (Exception ex) {
MainFrame.exceptionDialog(ex);
}
}
}
});
valueBox.add(Box.createVerticalStrut(7));
valueBox.add(editButton);
}
summaryPanel.add(valueBox);
propertyBox.add(Box.createVerticalStrut(7));
propertyBox.add(summaryPanel);
}
propLabel.setText(newProp.getValue());
revalidate();
}
@Override
public void remove(String id) {
String propName = id.substring(id.lastIndexOf("/")+1);
JLabel propbox = loadedProps.get(propName);
if (propbox!= null) propbox.setText("DELETED");
revalidate();
}
@Override
public void actionPerformed(ActionEvent e) {
String[] params;
String predefStep;
if (JOptionPane.showConfirmDialog(this,
"Are you sure?",
e.getActionCommand(),
JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
return;
if (e.getActionCommand().equals("Erase Item")) {
params = new String[0];
predefStep = "Erase";
}
else
return;
try {
MainFrame.userAgent.execute(sourceItem.getItem(), predefStep, params);
} catch (Exception ex) {
MainFrame.exceptionDialog(ex);
}
}
@Override
public void control(String control, String msg) {
// TODO Auto-generated method stub
}
}
|