Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ContextView |
|
| 1.2;1.2 | ||||
ContextView$1 |
|
| 1.2;1.2 | ||||
ContextView$2 |
|
| 1.2;1.2 | ||||
ContextView$3 |
|
| 1.2;1.2 | ||||
ContextView$4 |
|
| 1.2;1.2 |
1 | /* | |
2 | * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport | |
3 | * (http://www.vbs.admin.ch) | |
4 | * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch) | |
5 | * All rights reserved. | |
6 | * | |
7 | * Licensed under the Open Permis License which accompanies this distribution, | |
8 | * and is available at http://www.openpermis.org/BSDlicenceKent.txt | |
9 | */ | |
10 | package org.openpermis.editor.policy.view; | |
11 | ||
12 | import java.util.Set; | |
13 | ||
14 | import javax.swing.JComponent; | |
15 | ||
16 | import org.jdesktop.application.ApplicationContext; | |
17 | import org.jdesktop.swingx.JXFrame; | |
18 | import org.slf4j.Logger; | |
19 | import org.slf4j.LoggerFactory; | |
20 | ||
21 | import org.openpermis.editor.policy.adapter.AdapterTrader; | |
22 | import org.openpermis.editor.policy.gui.dock.DockControl; | |
23 | import org.openpermis.editor.policy.gui.dock.DockControlListener; | |
24 | import org.openpermis.editor.policy.gui.event.EventDispatcher; | |
25 | import org.openpermis.editor.policy.gui.event.EventSupport; | |
26 | import org.openpermis.editor.policy.presenter.PolicyContext; | |
27 | import org.openpermis.policy.bean.PartBean; | |
28 | import org.openpermis.policy.bean.PolicyBean; | |
29 | ||
30 | ||
31 | /** | |
32 | * Abstract view implementation that provides a view context. | |
33 | * @since 0.1.0 | |
34 | */ | |
35 | public abstract class ContextView | |
36 | extends AbstractView | |
37 | implements ViewContext, DockControlListener | |
38 | { | |
39 | ||
40 | //---- Static | |
41 | ||
42 | /** | |
43 | * The logger object of this class. | |
44 | * @since 0.1.0 | |
45 | */ | |
46 | 0 | private static final Logger LOGGER = |
47 | LoggerFactory.getLogger(ContextView.class); | |
48 | ||
49 | //---- State | |
50 | ||
51 | /** | |
52 | * The dock control of this view context. | |
53 | * @since 0.1.0 | |
54 | */ | |
55 | private final DockControl dockControl; | |
56 | ||
57 | /** | |
58 | * Event support used to notify view context listeners. | |
59 | * @since 0.1.0 | |
60 | */ | |
61 | private final EventSupport<ViewContextListener> eventSupport; | |
62 | ||
63 | //---- Constructors | |
64 | ||
65 | /** | |
66 | * Creates a context view for the specified application context. | |
67 | * @param context the application context used to lookup the action and resource map. | |
68 | * @param frame the frame to attach the context view to. | |
69 | * @since 0.1.0 | |
70 | */ | |
71 | public ContextView (ApplicationContext context, AdapterTrader trader, JXFrame frame) { | |
72 | 0 | super(context, trader); |
73 | 0 | this.eventSupport = new EventSupport<ViewContextListener>(); |
74 | 0 | this.dockControl = new DockControl(frame); |
75 | 0 | this.dockControl.addDockControlListener(this); |
76 | 0 | } |
77 | ||
78 | //---- Methods | |
79 | ||
80 | /** | |
81 | * Notifies all tool views managed that the policy and the dispatcher have changed. | |
82 | * @param policy the new policy that is active. | |
83 | * @param context the policy context to use. | |
84 | * @since 0.1.0 | |
85 | */ | |
86 | protected void refresh (PolicyBean policy, PolicyContext context) { | |
87 | 0 | for (Tool view : this.dockControl.getToolViews()) { |
88 | 0 | view.refresh(policy, context); |
89 | } | |
90 | 0 | } |
91 | ||
92 | /** | |
93 | * Returns a set of all editor views. | |
94 | * @return the currently showing editor views. | |
95 | * @since 0.1.0 | |
96 | */ | |
97 | protected Set<Editor> getEditorViews () { | |
98 | 0 | return this.dockControl.getEditorViews(); |
99 | } | |
100 | ||
101 | /** | |
102 | * Activates an already opened editor. | |
103 | * @param editor the editor to activate. | |
104 | * @since 0.1.0 | |
105 | */ | |
106 | protected void activateEditor (Editor editor) { | |
107 | 0 | LOGGER.debug("Activating editor [{}].", editor.getTitle()); |
108 | 0 | this.dockControl.openView(editor); |
109 | 0 | } |
110 | ||
111 | //---- AbstractView | |
112 | ||
113 | /** | |
114 | * @since 0.1.0 | |
115 | */ | |
116 | @Override | |
117 | protected JComponent createContentPane () { | |
118 | 0 | return this.dockControl.getContentArea(); |
119 | } | |
120 | ||
121 | //---- ViewContext | |
122 | ||
123 | /** | |
124 | * @since 0.1.0 | |
125 | */ | |
126 | public void addViewContextListener (ViewContextListener listener) { | |
127 | 0 | this.eventSupport.addListener(listener); |
128 | 0 | } |
129 | ||
130 | /** | |
131 | * @since 0.1.0 | |
132 | */ | |
133 | public void removeViewContextListener (ViewContextListener listener) { | |
134 | 0 | this.eventSupport.removeListener(listener); |
135 | 0 | } |
136 | ||
137 | /** | |
138 | * @since 0.1.0 | |
139 | */ | |
140 | @Override | |
141 | public abstract Editor editPart (PartBean part); | |
142 | ||
143 | /** | |
144 | * @since 0.3.0 | |
145 | */ | |
146 | @Override | |
147 | public abstract boolean canEditPart (PartBean part); | |
148 | ||
149 | /** | |
150 | * @since 0.1.0 | |
151 | */ | |
152 | public void updateViewTitle (View view) { | |
153 | 0 | this.dockControl.updateViewTitle(view); |
154 | 0 | } |
155 | ||
156 | /** | |
157 | * @since 0.1.0 | |
158 | */ | |
159 | @Override | |
160 | public void openView (View view) { | |
161 | 0 | this.dockControl.openView(view); |
162 | 0 | } |
163 | ||
164 | /** | |
165 | * @since 0.1.0 | |
166 | */ | |
167 | @Override | |
168 | public boolean closeView (View view, boolean force) { | |
169 | 0 | if (this.dockControl.closeView(view, force)) { |
170 | 0 | if (view instanceof Editor) { |
171 | 0 | ((Editor) view).dispose(); |
172 | } | |
173 | 0 | return true; |
174 | } | |
175 | 0 | return false; |
176 | } | |
177 | ||
178 | //---- DockControlListener | |
179 | ||
180 | /** | |
181 | * @since 0.1.0 | |
182 | */ | |
183 | public void viewActivated (final View view) { | |
184 | // Forward event to view context listeners. | |
185 | 0 | this.eventSupport.dispatchEvent( |
186 | new EventDispatcher<ViewContextListener>() { | |
187 | 0 | public void dispatch (ViewContextListener listener) { |
188 | 0 | listener.viewActivated(view); |
189 | 0 | } |
190 | } | |
191 | ); | |
192 | 0 | } |
193 | ||
194 | /** | |
195 | * @since 0.1.0 | |
196 | */ | |
197 | public void viewDeactivated (final View view) { | |
198 | // Forward event to view context listeners. | |
199 | 0 | this.eventSupport.dispatchEvent( |
200 | new EventDispatcher<ViewContextListener>() { | |
201 | 0 | public void dispatch (ViewContextListener listener) { |
202 | 0 | listener.viewDeactivated(view); |
203 | 0 | } |
204 | } | |
205 | ); | |
206 | 0 | } |
207 | ||
208 | /** | |
209 | * @since 0.1.0 | |
210 | */ | |
211 | public void viewClosed (final View view) { | |
212 | 0 | view.detach(this); |
213 | // Forward event to view context listeners. | |
214 | 0 | this.eventSupport.dispatchEvent( |
215 | new EventDispatcher<ViewContextListener>() { | |
216 | 0 | public void dispatch (ViewContextListener listener) { |
217 | 0 | listener.viewClosed(view); |
218 | 0 | } |
219 | } | |
220 | ); | |
221 | 0 | } |
222 | ||
223 | /** | |
224 | * @since 0.1.0 | |
225 | */ | |
226 | public void viewOpened (final View view) { | |
227 | 0 | view.attach(this); |
228 | // Forward event to view context listeners. | |
229 | 0 | this.eventSupport.dispatchEvent( |
230 | new EventDispatcher<ViewContextListener>() { | |
231 | 0 | public void dispatch (ViewContextListener listener) { |
232 | 0 | listener.viewOpened(view); |
233 | 0 | } |
234 | } | |
235 | ); | |
236 | 0 | } |
237 | ||
238 | } |