1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.editor.policy.view; |
11 | |
|
12 | |
import java.util.List; |
13 | |
|
14 | |
import javax.swing.JComboBox; |
15 | |
import javax.swing.JComponent; |
16 | |
import javax.swing.JOptionPane; |
17 | |
import javax.swing.JPanel; |
18 | |
import javax.swing.JScrollPane; |
19 | |
|
20 | |
import org.jdesktop.application.Action; |
21 | |
import org.jdesktop.application.ApplicationContext; |
22 | |
import org.jdesktop.beansbinding.BeanProperty; |
23 | |
import org.jdesktop.beansbinding.BindingGroup; |
24 | |
import org.jdesktop.beansbinding.Bindings; |
25 | |
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy; |
26 | |
import org.jdesktop.swingbinding.SwingBindings; |
27 | |
import org.slf4j.Logger; |
28 | |
import org.slf4j.LoggerFactory; |
29 | |
|
30 | |
import com.jgoodies.forms.layout.CellConstraints; |
31 | |
import com.jgoodies.forms.layout.FormLayout; |
32 | |
|
33 | |
import org.openpermis.editor.policy.adapter.AdapterTrader; |
34 | |
import org.openpermis.editor.policy.adapter.overview.Overview; |
35 | |
import org.openpermis.editor.policy.gui.checklist.CheckList; |
36 | |
import org.openpermis.editor.policy.presenter.TargetPresenter; |
37 | |
import org.openpermis.editor.policy.renderer.RendererFactory; |
38 | |
import org.openpermis.policy.bean.ActionBean; |
39 | |
import org.openpermis.policy.bean.DomainBean; |
40 | |
import org.openpermis.policy.bean.PolicyBean; |
41 | |
import org.openpermis.policy.bean.TargetBean; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public class TargetEditor |
48 | |
extends AbstractEditor<TargetPresenter> |
49 | |
{ |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | 0 | private static final Logger LOGGER = |
58 | |
LoggerFactory.getLogger(TargetEditor.class); |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
private JComboBox resourceDomain; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
private CheckList<ActionBean> actionList; |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public TargetEditor ( |
83 | |
ApplicationContext context, AdapterTrader trader, TargetPresenter presenter |
84 | |
) { |
85 | 0 | super(context, trader, presenter); |
86 | 0 | } |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
@Action |
94 | |
public void addAction () { |
95 | 0 | LOGGER.debug("addAction"); |
96 | |
|
97 | |
|
98 | 0 | List<ActionBean> list = this.getPresenter().getActionPool().getPoolList(); |
99 | 0 | for (ActionBean action : list) { |
100 | 0 | if (action.getName().equals("")) { |
101 | 0 | JOptionPane.showMessageDialog( |
102 | |
null, |
103 | |
getResourceMap().getString("defineActionNameMessage"), |
104 | |
getResourceMap().getString("defineActionNameTitle"), |
105 | |
JOptionPane.WARNING_MESSAGE); |
106 | 0 | return; |
107 | |
} |
108 | |
} |
109 | |
|
110 | |
|
111 | 0 | getPresenter().addAction( |
112 | |
new EditPartCommand<ActionBean>(getViewContext())); |
113 | 0 | } |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
@Action |
119 | |
public void addResourceDomain () { |
120 | 0 | LOGGER.debug("addResourceDomain"); |
121 | 0 | getPresenter().addResourceDomain(new EditPartCommand<DomainBean>(getViewContext())); |
122 | 0 | } |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
@Action |
128 | |
public void removeResourceDomain () { |
129 | 0 | LOGGER.debug("removeResourceDomain"); |
130 | 0 | DomainBean activeResourceDomain = this.getPresenter().getActiveResourceDomain(); |
131 | 0 | if (activeResourceDomain != null) { |
132 | 0 | PolicyBean policy = this.getPresenter().getContext().getPolicyBean(); |
133 | 0 | List<TargetBean> parents = policy.getParentTargets(activeResourceDomain); |
134 | 0 | if ((parents.size() > 1) |
135 | |
&& showYesNoDialog("nRefsTitle", "nRefs", JOptionPane.NO_OPTION)) { |
136 | 0 | return; |
137 | |
} |
138 | 0 | getPresenter().removeActiveResourceDomain(activeResourceDomain); |
139 | 0 | } else { |
140 | 0 | LOGGER.debug("no part selected"); |
141 | |
} |
142 | 0 | } |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
@Action |
148 | |
public void removeAction () { |
149 | 0 | LOGGER.debug("removeAction"); |
150 | 0 | ActionBean activeAction = this.actionList.getActivePart(); |
151 | 0 | if (activeAction != null) { |
152 | 0 | PolicyBean policy = this.getPresenter().getContext().getPolicyBean(); |
153 | 0 | List<TargetBean> parents = policy.getParentTargets(this.actionList.getActivePart()); |
154 | 0 | if ((parents.size() > 1) |
155 | |
&& showYesNoDialog("nRefsTitle", "nRefs", JOptionPane.NO_OPTION)) { |
156 | 0 | return; |
157 | |
} |
158 | 0 | getPresenter().removeActiveAction(activeAction); |
159 | 0 | } else { |
160 | 0 | LOGGER.debug("no part selected"); |
161 | |
} |
162 | 0 | } |
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
@Action |
168 | |
public void editResourceDomain () { |
169 | 0 | LOGGER.debug("editResourceDomain"); |
170 | 0 | final DomainBean active = getPresenter().getActiveResourceDomain(); |
171 | 0 | if (active != null) { |
172 | 0 | editPart(active); |
173 | |
} |
174 | 0 | } |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
@Action |
180 | |
public void editAction () { |
181 | 0 | LOGGER.debug("editAction"); |
182 | 0 | final ActionBean active = |
183 | |
(ActionBean) this.actionList.getValueAt( |
184 | |
this.actionList.getSelectionModel().getAnchorSelectionIndex(), 1 |
185 | |
); |
186 | 0 | if (active != null) { |
187 | 0 | editPart(active); |
188 | |
} |
189 | 0 | } |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
@Action |
195 | |
public void close () { |
196 | 0 | LOGGER.debug("close"); |
197 | 0 | closeView(this, false); |
198 | 0 | } |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
@Override |
206 | |
protected void bind (BindingGroup bindings) { |
207 | 0 | bindings.addBinding( |
208 | |
SwingBindings.createJComboBoxBinding( |
209 | |
UpdateStrategy.READ, |
210 | |
getPresenter().getResourceDomainPool().getPoolList(), |
211 | |
this.resourceDomain |
212 | |
) |
213 | |
); |
214 | 0 | bindings.addBinding( |
215 | |
Bindings.createAutoBinding( |
216 | |
UpdateStrategy.READ_WRITE, |
217 | |
getPresenter(), |
218 | |
BeanProperty.create("activeResourceDomain"), |
219 | |
this.resourceDomain, |
220 | |
BeanProperty.create("selectedItem") |
221 | |
) |
222 | |
); |
223 | 0 | this.actionList.bind( |
224 | |
getPresenter().getActionPool().getPoolList(), |
225 | |
getPresenter().getActions() |
226 | |
); |
227 | 0 | } |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
private JComponent resourceDomainChooser () { |
235 | 0 | final FormLayout layout = new FormLayout( |
236 | |
"pref, 2dlu, fill:50dlu:grow, 2dlu, pref", |
237 | |
"pref" |
238 | |
); |
239 | 0 | final JPanel panel = new JPanel(); |
240 | 0 | panel.setLayout(layout); |
241 | 0 | final CellConstraints cc = new CellConstraints(); |
242 | 0 | panel.add(label("resourceDomain"), cc.xy(1, 1)); |
243 | 0 | panel.add(this.resourceDomain, cc.xy(3, 1)); |
244 | 0 | panel.add(toolBar("resourceDomainToolBar"), cc.xy(5, 1)); |
245 | 0 | return panel; |
246 | |
} |
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
private JComponent actionList () { |
252 | 0 | final FormLayout layout = new FormLayout( |
253 | |
"pref, fill:pref:grow", |
254 | |
"pref, fill:pref:grow" |
255 | |
); |
256 | 0 | final JPanel panel = new JPanel(); |
257 | 0 | panel.setLayout(layout); |
258 | 0 | final CellConstraints cc = new CellConstraints(); |
259 | 0 | panel.add(label("actions"), cc.xy(1, 1)); |
260 | 0 | panel.add(toolBar("actionsToolBar"), cc.xy(2, 1)); |
261 | 0 | this.actionList.setVisibleRowCount(5); |
262 | 0 | panel.add(new JScrollPane(this.actionList), cc.xyw(1, 2, 2)); |
263 | 0 | return panel; |
264 | |
} |
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
public void fillContentPane (JPanel panel) { |
270 | 0 | final CellConstraints cc = new CellConstraints(); |
271 | 0 | this.resourceDomain = new JComboBox(); |
272 | 0 | this.resourceDomain.setRenderer( |
273 | |
RendererFactory.createListCellRenderer(this.getAdapteeTrader(), Overview.class) |
274 | |
); |
275 | |
|
276 | 0 | this.actionList = new CheckList<ActionBean>(); |
277 | 0 | this.actionList.setItemRenderer( |
278 | |
RendererFactory.createTableCellRenderer(this.getAdapteeTrader(), Overview.class) |
279 | |
); |
280 | 0 | this.actionList.setDoubleClickAction(getActionMap().get("editAction")); |
281 | 0 | this.actionList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
282 | |
|
283 | 0 | panel.add(resourceDomainChooser(), cc.xy(2, 2)); |
284 | 0 | panel.add(actionList(), cc.xy(2, 4)); |
285 | 0 | } |
286 | |
} |
287 | |
|
288 | |
|