1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.editor.policy.presenter; |
11 | |
|
12 | |
import java.net.URI; |
13 | |
|
14 | |
import org.jdesktop.observablecollections.ObservableList; |
15 | |
import org.jdesktop.observablecollections.ObservableListListener; |
16 | |
import org.slf4j.Logger; |
17 | |
import org.slf4j.LoggerFactory; |
18 | |
|
19 | |
import org.openpermis.editor.policy.beans.PropertyChange; |
20 | |
import org.openpermis.editor.policy.command.ActionRemoveCommand; |
21 | |
import org.openpermis.editor.policy.command.CollectionAddCommand; |
22 | |
import org.openpermis.editor.policy.command.CommandDispatcher; |
23 | |
import org.openpermis.editor.policy.command.CompositeCommand; |
24 | |
import org.openpermis.editor.policy.command.PoolRemoveCommand; |
25 | |
import org.openpermis.editor.policy.command.ResourceDomainRemoveCommand; |
26 | |
import org.openpermis.editor.policy.gui.binding.ObservableListAdapter; |
27 | |
import org.openpermis.editor.policy.view.EditPartCommand; |
28 | |
import org.openpermis.policy.ParameterList; |
29 | |
import org.openpermis.policy.bean.ActionBean; |
30 | |
import org.openpermis.policy.bean.DomainBean; |
31 | |
import org.openpermis.policy.bean.TargetBean; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class TargetPresenter |
38 | |
extends PartPresenter<TargetBean> |
39 | |
{ |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | private static final Logger LOGGER = |
48 | |
LoggerFactory.getLogger(TargetPresenter.class); |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
private DomainBean activeResourceDomain; |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
private final ObservableList<ActionBean> actions; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
private final ObservableListListener actionsUpdater; |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
public TargetPresenter ( |
80 | |
TargetBean model, CommandDispatcher dispatcher, PolicyContext context |
81 | |
) { |
82 | 0 | super(model, context); |
83 | 0 | LOGGER.debug("Presenter for [{}].", model); |
84 | 0 | updateResourceDomain(); |
85 | 0 | this.actions = createActionList(model); |
86 | 0 | this.actionsUpdater = new ObservableListAdapter<ActionBean>() { |
87 | |
@Override |
88 | 0 | protected void listChanged (ObservableList<ActionBean> list) { |
89 | 0 | updateActionsAtModel(); |
90 | 0 | } |
91 | |
}; |
92 | 0 | this.actions.addObservableListListener(this.actionsUpdater); |
93 | 0 | } |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
private ObservableList<ActionBean> createActionList (TargetBean model) { |
104 | 0 | return createCollectionAtPresenter(model.getActions()); |
105 | |
} |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
private void updateActionsAtModel () { |
112 | 0 | LOGGER.debug("updateActionsAtModel"); |
113 | 0 | change("actions", getPartBeanFactory().createActionCollection(this.actions)); |
114 | 0 | } |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
private void updateActionsAtPresenter () { |
121 | 0 | LOGGER.debug("updateActionsAtPresenter"); |
122 | 0 | updateCollectionAtPresenter(getModel().getActions(), this.actions, this.actionsUpdater); |
123 | 0 | } |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public ObservableList<ActionBean> getActions () { |
131 | 0 | return this.actions; |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public DomainBean getActiveResourceDomain () { |
140 | 0 | return this.activeResourceDomain; |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
public void setActiveResourceDomain (DomainBean activeResourceDomainBean) { |
149 | 0 | if (activeResourceDomainBean != null) { |
150 | 0 | LOGGER.debug("setActiveResourceDomain [{}].", activeResourceDomainBean); |
151 | 0 | final DomainBean current = getModel().getResourceDomain(); |
152 | 0 | if (sameSerial(current, activeResourceDomainBean)) { |
153 | 0 | updateActiveResourceDomain(activeResourceDomainBean); |
154 | |
} else { |
155 | 0 | change(getModel(), "resourceDomain", activeResourceDomainBean); |
156 | |
} |
157 | |
} |
158 | 0 | } |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
private void updateActiveResourceDomain (DomainBean activeResourceDomainBean) { |
166 | 0 | final DomainBean oldValue = this.activeResourceDomain; |
167 | 0 | this.activeResourceDomain = activeResourceDomainBean; |
168 | 0 | firePropertyChange("activeResourceDomain", oldValue, this.activeResourceDomain); |
169 | 0 | } |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
public void removeActiveResourceDomain (DomainBean resourceDomain) { |
176 | 0 | execute( |
177 | |
new CompositeCommand( |
178 | |
new ResourceDomainRemoveCommand(resourceDomain), |
179 | |
new PoolRemoveCommand<DomainBean>( |
180 | |
this.getResourceDomainPool(), resourceDomain) |
181 | |
) |
182 | |
); |
183 | 0 | } |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
public void removeActiveAction (ActionBean activeAction) { |
190 | 0 | if (activeAction != null) { |
191 | 0 | execute( |
192 | |
new CompositeCommand( |
193 | |
new ActionRemoveCommand(activeAction), |
194 | |
new PoolRemoveCommand<ActionBean>(this.getActionPool(), activeAction) |
195 | |
) |
196 | |
); |
197 | |
} |
198 | 0 | } |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
public void addResourceDomain (EditPartCommand<DomainBean> editPartCommand) { |
204 | 0 | final DomainBean domain = getContext().getPartBeanFactory().createDomain(null); |
205 | 0 | editPartCommand.setPart(domain); |
206 | 0 | execute( |
207 | |
new CompositeCommand( |
208 | |
createChangeCommand(getModel(), "resourceDomain", domain), |
209 | |
editPartCommand |
210 | |
) |
211 | |
); |
212 | 0 | } |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
private String getIdentity (DomainBean domain) { |
221 | 0 | if (domain != null) { |
222 | 0 | final URI identity = domain.getIdentity(); |
223 | 0 | if (identity != null) { |
224 | 0 | return identity.toString(); |
225 | |
} |
226 | |
} |
227 | 0 | return ""; |
228 | |
} |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
public void addAction (EditPartCommand<ActionBean> editPartCommand) { |
234 | 0 | final ActionBean newAction = getContext().getPartBeanFactory(). |
235 | |
createAction("", ParameterList.empty()); |
236 | 0 | editPartCommand.setPart(newAction); |
237 | 0 | execute( |
238 | |
new CompositeCommand( |
239 | |
new CollectionAddCommand<ActionBean>(getModel(), newAction, "actions"), |
240 | |
editPartCommand |
241 | |
) |
242 | |
); |
243 | 0 | } |
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
@PropertyChange(bean = TargetBean.class, property = "resourceDomain") |
252 | |
public void updateResourceDomain () { |
253 | 0 | final DomainBean domain = getModel().getResourceDomain(); |
254 | 0 | LOGGER.debug("updateResourceDomain({}).", domain); |
255 | 0 | updateActiveResourceDomain(domain); |
256 | 0 | setTitleParameters(getIdentity(domain)); |
257 | 0 | } |
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
@PropertyChange(bean = TargetBean.class, property = "actions") |
264 | |
public void updateActions () { |
265 | 0 | LOGGER.debug("updateActions"); |
266 | 0 | updateActionsAtPresenter(); |
267 | 0 | } |
268 | |
|
269 | |
|
270 | |
} |