1
2
3
4
5
6 package net.kwfgrid.gwui.gui;
7
8 import javax.swing.*;
9 import javax.swing.border.TitledBorder;
10 import java.awt.BorderLayout;
11 import java.util.List;
12
13 import net.kwfgrid.gworkflowdl.protocol.structure.IStructureObject;
14 import net.kwfgrid.gworkflowdl.protocol.structure.ProtocolWorkflow;
15
16 public abstract class AbstractJTextFieldView extends AbstractWorkflowElementView {
17 public JPanel _view;
18 public JTextField _label;
19
20 /***
21 Constructor.
22 Adds this view as a <code>IStructureListener</code> to the specified workflow.
23 @param target The document containing the displayed element.
24 @param element The displayed element.
25 */
26 protected AbstractJTextFieldView(ProtocolWorkflow target, IStructureObject element) {
27 super(target, element);
28 _view = null;
29 _label = null;
30 }
31
32 /***
33 Get the label to be displayed by this view.
34 */
35 protected abstract String getLabel();
36
37 /***
38 Get the title for this view.
39 */
40 protected abstract String getTitle();
41
42 /***
43 Check if a "objectsAdded" or "objectsRemoved" modification of the structure affects the label displayed by this view.
44 */
45 protected abstract boolean affectsLabel(IStructureObject parent, String namespace, String name, List objects);
46
47 /***
48 Check if a "propertyChanged" modification of the structure affects the label displayed by this view.
49 */
50 protected abstract boolean affectsLabel(IStructureObject parent, String namespace, String name, Object object);
51
52 public void objectsAdded(IStructureObject parent, String namespace, String name, List objects) {
53 if (affectsLabel(parent, namespace, name, objects)) updateView();
54 }
55
56 public void objectsRemoved(IStructureObject parent, String namespace, String name, List objects) {
57 if (affectsLabel(parent, namespace, name, objects)) updateView();
58 }
59
60 public void propertyChanged(IStructureObject parent, String namespace, String name, Object newvalue) {
61 if (affectsLabel(parent, namespace, name, newvalue)) updateView();
62 }
63
64 protected void updateState() {
65 _view.setEnabled(isEnabled());
66 _label.setEnabled(isEnabled());
67 }
68
69 protected void updateView() {
70 updateState();
71 _label.setText(getLabel());
72
73
74
75
76 }
77
78 public JComponent getView() {
79 if (_view == null) {
80 _label = new JTextField(getLabel());
81 _label.setEditable(false);
82 _label.setBorder(null);
83 _view = new JPanel();
84 _view.setBorder(createBorder(getTitle()));
85 _view.setLayout(new BorderLayout());
86 _view.add(_label, BorderLayout.CENTER);
87 }
88 return _view;
89 }
90 }