1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.editor.policy.view; |
11 | |
|
12 | |
import java.awt.Component; |
13 | |
import java.awt.Container; |
14 | |
import java.net.URI; |
15 | |
|
16 | |
import javax.swing.JComponent; |
17 | |
import javax.swing.JList; |
18 | |
import javax.swing.JPanel; |
19 | |
import javax.swing.JScrollPane; |
20 | |
import javax.swing.JTextField; |
21 | |
|
22 | |
import org.jdesktop.application.Action; |
23 | |
import org.jdesktop.application.ApplicationContext; |
24 | |
import org.jdesktop.beansbinding.BeanProperty; |
25 | |
import org.jdesktop.beansbinding.Binding; |
26 | |
import org.jdesktop.beansbinding.BindingGroup; |
27 | |
import org.jdesktop.beansbinding.Bindings; |
28 | |
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy; |
29 | |
import org.slf4j.Logger; |
30 | |
import org.slf4j.LoggerFactory; |
31 | |
|
32 | |
import com.jgoodies.forms.layout.CellConstraints; |
33 | |
import com.jgoodies.forms.layout.FormLayout; |
34 | |
|
35 | |
import org.openpermis.editor.policy.adapter.AdapterTrader; |
36 | |
import org.openpermis.editor.policy.gui.ActionForwarder; |
37 | |
import org.openpermis.editor.policy.gui.binding.ErrorBindingListener; |
38 | |
import org.openpermis.editor.policy.gui.binding.UriConverter; |
39 | |
import org.openpermis.editor.policy.presenter.DomainPresenter; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public class DomainEditor |
46 | |
extends AbstractEditor<DomainPresenter> |
47 | |
{ |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | private static final Logger LOGGER = |
56 | |
LoggerFactory.getLogger(DomainEditor.class); |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
private JTextField identity; |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public DomainEditor ( |
75 | |
ApplicationContext context, AdapterTrader trader, DomainPresenter presenter |
76 | |
) { |
77 | 0 | super(context, trader, presenter); |
78 | 0 | } |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
@Action |
86 | |
public void addSubDomain () { |
87 | 0 | LOGGER.debug("addSubDomain"); |
88 | 0 | } |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
@Action |
94 | |
public void removeSubDomain () { |
95 | 0 | LOGGER.debug("removeSubDomain"); |
96 | 0 | } |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
@Action |
102 | |
public void editSubDomain () { |
103 | 0 | LOGGER.debug("editSubDomain"); |
104 | 0 | } |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
@Action |
110 | |
public void close () { |
111 | 0 | LOGGER.debug("close"); |
112 | 0 | closeView(this, false); |
113 | 0 | } |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
@Override |
121 | |
protected void bind (BindingGroup bindings) { |
122 | 0 | final Binding<DomainPresenter, URI, JTextField, String> identityBinding = |
123 | |
Bindings.createAutoBinding( |
124 | |
UpdateStrategy.READ_WRITE, |
125 | |
getPresenter(), |
126 | |
BeanProperty.<DomainPresenter, URI>create("identity"), |
127 | |
this.identity, |
128 | |
BeanProperty.<JTextField, String>create("text_ON_ACTION_OR_FOCUS_LOST") |
129 | |
); |
130 | 0 | identityBinding.setConverter(new UriConverter()); |
131 | 0 | identityBinding.addBindingListener( |
132 | |
new ErrorBindingListener( |
133 | |
this, |
134 | |
getResourceMap(), |
135 | |
this.identity, |
136 | |
"identityError" |
137 | |
) |
138 | |
); |
139 | 0 | bindings.addBinding(identityBinding); |
140 | 0 | } |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
private JComponent headerIdentity () { |
148 | 0 | final FormLayout layout = new FormLayout( |
149 | |
"pref, 2dlu, fill:50dlu:grow, 2dlu, pref", |
150 | |
"pref" |
151 | |
); |
152 | 0 | final JPanel panel = new JPanel(); |
153 | 0 | panel.setLayout(layout); |
154 | 0 | final CellConstraints cc = new CellConstraints(); |
155 | 0 | panel.add(label("identity"), cc.xy(1, 1)); |
156 | 0 | panel.add(this.identity, cc.xy(3, 1)); |
157 | 0 | return panel; |
158 | |
} |
159 | |
|
160 | |
private void disable (Component parent) { |
161 | 0 | parent.setEnabled(false); |
162 | 0 | if (parent instanceof Container) { |
163 | 0 | for (Component child : ((Container) parent).getComponents()) { |
164 | 0 | disable(child); |
165 | |
} |
166 | |
} |
167 | 0 | } |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
private JComponent list (String label, String toolBar) { |
173 | 0 | final FormLayout layout = new FormLayout( |
174 | |
"pref, fill:pref:grow", |
175 | |
"pref, fill:pref:grow" |
176 | |
); |
177 | 0 | final JPanel panel = new JPanel(); |
178 | 0 | panel.setLayout(layout); |
179 | 0 | final CellConstraints cc = new CellConstraints(); |
180 | 0 | panel.add(label(label), cc.xy(1, 1)); |
181 | 0 | panel.add(toolBar(toolBar), cc.xy(2, 1)); |
182 | 0 | panel.add(new JScrollPane(new JList()), cc.xyw(1, 2, 2)); |
183 | |
|
184 | 0 | disable(panel); |
185 | 0 | return panel; |
186 | |
} |
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
public void fillContentPane (JPanel panel) { |
192 | 0 | final CellConstraints cc = new CellConstraints(); |
193 | 0 | this.identity = new JTextField(); |
194 | 0 | panel.add(headerIdentity(), cc.xy(2, 2)); |
195 | 0 | panel.add(list("subDomains", "subDomainsToolBar"), cc.xy(2, 4)); |
196 | |
|
197 | |
|
198 | 0 | this.identity.addActionListener(new ActionForwarder(getActionMap().get("close"))); |
199 | |
|
200 | 0 | } |
201 | |
|
202 | |
} |