1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.editor.policy.view; |
11 | |
|
12 | |
import javax.swing.JComponent; |
13 | |
import javax.swing.JPanel; |
14 | |
import javax.swing.JTextField; |
15 | |
import javax.swing.event.AncestorEvent; |
16 | |
import javax.swing.event.AncestorListener; |
17 | |
|
18 | |
import org.jdesktop.application.Action; |
19 | |
import org.jdesktop.application.ApplicationContext; |
20 | |
import org.jdesktop.beansbinding.BeanProperty; |
21 | |
import org.jdesktop.beansbinding.Binding; |
22 | |
import org.jdesktop.beansbinding.BindingGroup; |
23 | |
import org.jdesktop.beansbinding.Bindings; |
24 | |
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy; |
25 | |
import org.slf4j.Logger; |
26 | |
import org.slf4j.LoggerFactory; |
27 | |
|
28 | |
import com.jgoodies.forms.layout.CellConstraints; |
29 | |
import com.jgoodies.forms.layout.FormLayout; |
30 | |
|
31 | |
import org.openpermis.editor.policy.adapter.AdapterTrader; |
32 | |
import org.openpermis.editor.policy.gui.ActionForwarder; |
33 | |
import org.openpermis.editor.policy.gui.binding.ErrorBindingListener; |
34 | |
import org.openpermis.editor.policy.gui.binding.ObligationNameConverter; |
35 | |
import org.openpermis.editor.policy.presenter.ObligationPresenter; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public class ObligationEditor |
43 | |
extends AbstractEditor<ObligationPresenter> |
44 | |
implements AncestorListener |
45 | |
{ |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 0 | private static final Logger LOGGER = |
54 | |
LoggerFactory.getLogger(ObligationEditor.class); |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
private JTextField text; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public ObligationEditor ( |
73 | |
ApplicationContext context, AdapterTrader trader, ObligationPresenter presenter |
74 | |
) { |
75 | 0 | super(context, trader, presenter); |
76 | 0 | } |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
@Action |
87 | |
public void close () { |
88 | 0 | LOGGER.debug("close"); |
89 | |
|
90 | 0 | closeView(this, false); |
91 | 0 | } |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
@Override |
100 | |
protected void bind (BindingGroup bindings) { |
101 | 0 | final Binding<ObligationPresenter, String, JTextField, String> textBinding = |
102 | |
Bindings.createAutoBinding( |
103 | |
UpdateStrategy.READ_WRITE, |
104 | |
getPresenter(), |
105 | |
BeanProperty.<ObligationPresenter, String>create("text"), |
106 | |
this.text, |
107 | |
BeanProperty.<JTextField, String>create("text_ON_ACTION_OR_FOCUS_LOST") |
108 | |
); |
109 | 0 | textBinding.setConverter(new ObligationNameConverter(this.getPresenter())); |
110 | 0 | textBinding.addBindingListener( |
111 | |
new ErrorBindingListener( |
112 | |
this, |
113 | |
getResourceMap(), |
114 | |
this.text, |
115 | |
"textError" |
116 | |
) |
117 | |
); |
118 | 0 | bindings.addBinding(textBinding); |
119 | 0 | } |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
private JComponent headerName () { |
127 | 0 | final FormLayout layout = new FormLayout( |
128 | |
"fill:pref:grow", |
129 | |
"pref, fill:pref:grow" |
130 | |
); |
131 | 0 | final JPanel panel = new JPanel(); |
132 | 0 | panel.setLayout(layout); |
133 | 0 | final CellConstraints cc = new CellConstraints(); |
134 | 0 | panel.add(label("text"), cc.xy(1, 1)); |
135 | 0 | panel.add(this.text, cc.xy(1, 2)); |
136 | 0 | return panel; |
137 | |
} |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
@Override |
143 | |
public void fillContentPane (JPanel panel) { |
144 | 0 | final CellConstraints cc = new CellConstraints(); |
145 | 0 | this.text = new JTextField(); |
146 | 0 | this.text.addActionListener(new ActionForwarder(getActionMap().get("close"))); |
147 | |
|
148 | 0 | panel.add(headerName(), cc.xy(2, 2)); |
149 | 0 | } |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
public void ancestorAdded (AncestorEvent event) { |
157 | |
|
158 | 0 | } |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
public void ancestorMoved (AncestorEvent event) { |
164 | |
|
165 | 0 | } |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
public void ancestorRemoved (AncestorEvent event) { |
171 | |
|
172 | 0 | } |
173 | |
|
174 | |
} |