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