root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / imp / DefaultAppgvSIGManager.java @ 38537
History | View | Annotate | Download (13.5 KB)
1 | 26919 | jmvivo | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2009 IVER T.I {{Task}}
|
||
26 | */
|
||
27 | |||
28 | /**
|
||
29 | *
|
||
30 | */
|
||
31 | 29598 | jpiera | package org.gvsig.app.imp; |
32 | 26919 | jmvivo | |
33 | import java.util.ArrayList; |
||
34 | import java.util.Iterator; |
||
35 | import java.util.List; |
||
36 | |||
37 | 38242 | jldominguez | import javax.swing.JOptionPane; |
38 | |||
39 | 31496 | jjdelcerro | import org.cresques.cts.IProjection; |
40 | 38242 | jldominguez | import org.slf4j.Logger; |
41 | import org.slf4j.LoggerFactory; |
||
42 | |||
43 | 34002 | jjdelcerro | import org.gvsig.about.AboutLocator; |
44 | import org.gvsig.about.AboutManager; |
||
45 | 35974 | jjdelcerro | import org.gvsig.andami.Launcher; |
46 | 31496 | jjdelcerro | import org.gvsig.andami.PluginServices; |
47 | import org.gvsig.andami.iconthemes.IconThemeManager; |
||
48 | 35153 | jjdelcerro | import org.gvsig.andami.ui.mdiManager.IWindow; |
49 | 31496 | jjdelcerro | import org.gvsig.andami.ui.mdiManager.MDIManager; |
50 | import org.gvsig.app.ApplicationManager; |
||
51 | import org.gvsig.app.PreferencesNode; |
||
52 | import org.gvsig.app.extension.Version; |
||
53 | 29598 | jpiera | import org.gvsig.app.gui.WizardPanel; |
54 | 31496 | jjdelcerro | import org.gvsig.app.prepareAction.PrepareContext; |
55 | import org.gvsig.app.prepareAction.PrepareContextView; |
||
56 | import org.gvsig.app.prepareAction.PrepareDataStore; |
||
57 | import org.gvsig.app.prepareAction.PrepareDataStoreParameters; |
||
58 | import org.gvsig.app.prepareAction.PrepareLayer; |
||
59 | import org.gvsig.app.project.DefaultProject; |
||
60 | import org.gvsig.app.project.Project; |
||
61 | import org.gvsig.app.project.ProjectManager; |
||
62 | 35191 | jjdelcerro | import org.gvsig.app.project.documents.Document; |
63 | import org.gvsig.app.project.documents.gui.IDocumentWindow; |
||
64 | 31496 | jjdelcerro | import org.gvsig.fmap.crs.CRSFactory; |
65 | import org.gvsig.fmap.dal.DALLocator; |
||
66 | import org.gvsig.fmap.dal.DataManager; |
||
67 | 26919 | jmvivo | import org.gvsig.fmap.dal.DataStore; |
68 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
69 | 31496 | jjdelcerro | import org.gvsig.fmap.geom.GeometryLocator; |
70 | import org.gvsig.fmap.geom.GeometryManager; |
||
71 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
72 | import org.gvsig.fmap.mapcontext.MapContextManager; |
||
73 | 26932 | jmvivo | import org.gvsig.fmap.mapcontext.layers.FLayer; |
74 | 38371 | nbrodin | import org.gvsig.gui.ColorTablesFactory; |
75 | 35974 | jjdelcerro | import org.gvsig.symbology.swing.SymbologySwingLocator; |
76 | 29197 | jmvivo | import org.gvsig.tools.ToolsLocator; |
77 | 36476 | jjdelcerro | import org.gvsig.tools.dataTypes.DataTypesManager; |
78 | 31496 | jjdelcerro | import org.gvsig.tools.dispose.DisposableManager; |
79 | import org.gvsig.tools.dynobject.DynObjectManager; |
||
80 | 29197 | jmvivo | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
81 | 34441 | cordinyana | import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
82 | 29197 | jmvivo | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
83 | 31496 | jjdelcerro | import org.gvsig.tools.persistence.PersistenceManager; |
84 | 26919 | jmvivo | |
85 | |||
86 | |||
87 | 29197 | jmvivo | |
88 | 26919 | jmvivo | /**
|
89 | * @author jmvivo
|
||
90 | *
|
||
91 | */
|
||
92 | 31496 | jjdelcerro | public class DefaultAppgvSIGManager implements ApplicationManager { |
93 | 26919 | jmvivo | |
94 | 38242 | jldominguez | private static Logger logger = LoggerFactory.getLogger(DefaultAppgvSIGManager.class); |
95 | 31496 | jjdelcerro | private static final String EPNAME_PREPARE_OPEN_DATASTORE = "org.gvsig.datastore.open.prepare"; //"PrepareOpenDataStore"; |
96 | private static final String EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS = "org.gvsig.datastoreparameters.open.prepare"; //"PrepareOpenDataStoreParameters"; |
||
97 | private static final String EPNAME_PREPARE_OPEN_LAYER = "org.gvsig.layer.open.prepare"; // "PrepareOpenLayer"; |
||
98 | 26919 | jmvivo | |
99 | 29197 | jmvivo | private static final String EPNAME_ADD_TABLE_WIZARD = "AddLayerWizard"; |
100 | |||
101 | private ExtensionPointManager epManager;
|
||
102 | |||
103 | 34441 | cordinyana | private Version version;
|
104 | 29197 | jmvivo | |
105 | 31496 | jjdelcerro | public DefaultAppgvSIGManager() {
|
106 | 29197 | jmvivo | epManager = ToolsLocator.getExtensionPointManager(); |
107 | epManager.add(EPNAME_PREPARE_OPEN_DATASTORE, |
||
108 | "Actions to do when open a DataStore");
|
||
109 | epManager.add(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS, |
||
110 | "Actions to do before open a DataStore with parameters");
|
||
111 | epManager.add(EPNAME_PREPARE_OPEN_LAYER, |
||
112 | "Actions to do after create a Layer");
|
||
113 | epManager.add(EPNAME_ADD_TABLE_WIZARD, |
||
114 | "Wizards to add new document table");
|
||
115 | |||
116 | 34441 | cordinyana | version = new Version();
|
117 | 26919 | jmvivo | } |
118 | |||
119 | /* (non-Javadoc)
|
||
120 | * @see org.gvsig.appGvSigManager#pepareOpenDataSource(org.gvsig.fmap.dal.DataStore)
|
||
121 | */
|
||
122 | 31496 | jjdelcerro | @SuppressWarnings("unchecked") |
123 | 26919 | jmvivo | public DataStore pepareOpenDataSource(DataStore store,
|
124 | 29197 | jmvivo | PrepareContext context) throws Exception { |
125 | ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
||
126 | if (ep.getCount() == 0) { |
||
127 | 26919 | jmvivo | return store;
|
128 | } |
||
129 | DataStore result = store; |
||
130 | 29197 | jmvivo | Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
131 | PrepareDataStore prepare; |
||
132 | 26919 | jmvivo | while (iter.hasNext()) {
|
133 | 29197 | jmvivo | prepare = (PrepareDataStore) iter.next().create(); |
134 | result = prepare.prepare(store, context); |
||
135 | 26919 | jmvivo | } |
136 | return result;
|
||
137 | } |
||
138 | |||
139 | /* (non-Javadoc)
|
||
140 | * @see org.gvsig.appGvSigManager#prepareOpenDataStoreParameters(org.gvsig.fmap.dal.DataStoreParameters)
|
||
141 | */
|
||
142 | 31496 | jjdelcerro | @SuppressWarnings("unchecked") |
143 | 26919 | jmvivo | public DataStoreParameters prepareOpenDataStoreParameters(
|
144 | 29197 | jmvivo | DataStoreParameters storeParameters, PrepareContext context) |
145 | throws Exception { |
||
146 | |||
147 | ExtensionPoint ep = epManager |
||
148 | .get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
||
149 | if (ep.getCount() == 0) { |
||
150 | 26919 | jmvivo | return storeParameters;
|
151 | } |
||
152 | DataStoreParameters result = storeParameters; |
||
153 | 29197 | jmvivo | Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
154 | PrepareDataStoreParameters prepare; |
||
155 | 26919 | jmvivo | while (iter.hasNext()) {
|
156 | 29197 | jmvivo | prepare = (PrepareDataStoreParameters) iter.next().create(); |
157 | result = prepare.prepare(storeParameters, context); |
||
158 | 26919 | jmvivo | } |
159 | 29197 | jmvivo | |
160 | 26919 | jmvivo | return result;
|
161 | } |
||
162 | 36767 | nbrodin | |
163 | /*
|
||
164 | * (non-Javadoc)
|
||
165 | * @see org.gvsig.app.ApplicationManager#prepareOpenDataStoreParameters(java.util.List, org.gvsig.app.prepareAction.PrepareContext)
|
||
166 | */
|
||
167 | @SuppressWarnings("unchecked") |
||
168 | public List<DataStoreParameters> prepareOpenDataStoreParameters( |
||
169 | List<DataStoreParameters> storeParameters, PrepareContext context)
|
||
170 | throws Exception { |
||
171 | 26919 | jmvivo | |
172 | 36767 | nbrodin | ExtensionPoint ep = epManager |
173 | .get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
||
174 | if (ep.getCount() == 0) { |
||
175 | return storeParameters;
|
||
176 | } |
||
177 | |||
178 | List<DataStoreParameters> result = new ArrayList<DataStoreParameters>(); |
||
179 | |||
180 | Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
||
181 | List<PrepareDataStoreParameters> prepareList = new ArrayList<PrepareDataStoreParameters>(); |
||
182 | while (iter.hasNext()) {
|
||
183 | prepareList.add((PrepareDataStoreParameters) iter.next().create()); |
||
184 | } |
||
185 | |||
186 | for (int i = 0; i < storeParameters.size(); i++) { |
||
187 | DataStoreParameters param = storeParameters.get(i); |
||
188 | for (int j = 0; j < prepareList.size(); j++) { |
||
189 | prepareList.get(j).pre(param, context); |
||
190 | } |
||
191 | } |
||
192 | |||
193 | for (int i = 0; i < storeParameters.size(); i++) { |
||
194 | DataStoreParameters param = storeParameters.get(i); |
||
195 | if(param != null) { |
||
196 | for (int j = 0; j < prepareList.size(); j++) { |
||
197 | param = prepareList.get(j).prepare(param, context); |
||
198 | if(param == null) |
||
199 | break;
|
||
200 | } |
||
201 | if(param != null) |
||
202 | result.add(param); |
||
203 | } |
||
204 | } |
||
205 | |||
206 | for (int i = 0; i < storeParameters.size(); i++) { |
||
207 | DataStoreParameters param = storeParameters.get(i); |
||
208 | for (int j = 0; j < prepareList.size(); j++) { |
||
209 | prepareList.get(j).post(param, context); |
||
210 | } |
||
211 | } |
||
212 | |||
213 | return result;
|
||
214 | } |
||
215 | |||
216 | 26919 | jmvivo | public void registerPrepareOpenDataStore(PrepareDataStore action) { |
217 | 29197 | jmvivo | ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
218 | ep.append(action.getName(), action.getDescription(), action); |
||
219 | 26919 | jmvivo | } |
220 | |||
221 | public void registerPrepareOpenDataStoreParameters( |
||
222 | PrepareDataStoreParameters action) { |
||
223 | 29197 | jmvivo | ExtensionPoint ep = epManager |
224 | .get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
||
225 | ep.append(action.getName(), action.getDescription(), action); |
||
226 | 26919 | jmvivo | |
227 | 29197 | jmvivo | |
228 | 26919 | jmvivo | } |
229 | |||
230 | 31496 | jjdelcerro | @SuppressWarnings("unchecked") |
231 | 26932 | jmvivo | public FLayer prepareOpenLayer(FLayer layer,
|
232 | 29197 | jmvivo | PrepareContextView context) |
233 | throws Exception { |
||
234 | |||
235 | ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
||
236 | |||
237 | if (ep.getCount() == 0) { |
||
238 | 26932 | jmvivo | return layer;
|
239 | } |
||
240 | FLayer result = layer; |
||
241 | 29197 | jmvivo | Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
242 | PrepareLayer prepare; |
||
243 | 26932 | jmvivo | while (iter.hasNext()) {
|
244 | 29197 | jmvivo | prepare = (PrepareLayer) iter.next().create(); |
245 | 38537 | nbrodin | result = prepare.prepare(result, context); |
246 | 26932 | jmvivo | } |
247 | 29197 | jmvivo | |
248 | 26932 | jmvivo | return result;
|
249 | |||
250 | } |
||
251 | |||
252 | public void registerPrepareOpenLayer(PrepareLayer action) { |
||
253 | 29197 | jmvivo | ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
254 | ep.append(action.getName(), action.getDescription(), action); |
||
255 | 26932 | jmvivo | } |
256 | |||
257 | 29197 | jmvivo | public void registerAddTableWizard(String name, String description, |
258 | Class<? extends WizardPanel> wpClass) { |
||
259 | ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
||
260 | ep.append(name, description, wpClass); |
||
261 | } |
||
262 | |||
263 | 31496 | jjdelcerro | @SuppressWarnings("unchecked") |
264 | 29197 | jmvivo | public List<WizardPanel> getWizardPanels() throws Exception { |
265 | ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
||
266 | List<WizardPanel> result = new ArrayList<WizardPanel>(); |
||
267 | Iterator<Extension> iter = ep.iterator();
|
||
268 | while (iter.hasNext()) {
|
||
269 | result.add((WizardPanel) iter.next().create()); |
||
270 | } |
||
271 | return result;
|
||
272 | } |
||
273 | 31496 | jjdelcerro | |
274 | public DataManager getDataManager() {
|
||
275 | return DALLocator.getDataManager();
|
||
276 | } |
||
277 | |||
278 | public GeometryManager getGeometryManager() {
|
||
279 | return GeometryLocator.getGeometryManager();
|
||
280 | } |
||
281 | |||
282 | public PersistenceManager getPersistenceManager() {
|
||
283 | return ToolsLocator.getPersistenceManager();
|
||
284 | } |
||
285 | |||
286 | public DisposableManager getDisposableManager() {
|
||
287 | return ToolsLocator.getDisposableManager();
|
||
288 | } |
||
289 | |||
290 | public DynObjectManager getDynObjectManager() {
|
||
291 | return ToolsLocator.getDynObjectManager();
|
||
292 | } |
||
293 | |||
294 | public ExtensionPointManager getExtensionPointManager() {
|
||
295 | return ToolsLocator.getExtensionPointManager();
|
||
296 | } |
||
297 | |||
298 | public ProjectManager getProjectManager() {
|
||
299 | return ProjectManager.getInstance();
|
||
300 | } |
||
301 | |||
302 | public MDIManager getUIManager() {
|
||
303 | return PluginServices.getMDIManager();
|
||
304 | } |
||
305 | |||
306 | public MapContextManager getMapContextManager() {
|
||
307 | return MapContextLocator.getMapContextManager();
|
||
308 | } |
||
309 | |||
310 | 36476 | jjdelcerro | public DataTypesManager getDataTypesManager() {
|
311 | return ToolsLocator.getDataTypesManager();
|
||
312 | } |
||
313 | |||
314 | 31496 | jjdelcerro | public IProjection getCRS(String code) { |
315 | return CRSFactory.getCRS(code);
|
||
316 | } |
||
317 | |||
318 | public IconThemeManager getIconThemeManager() {
|
||
319 | return IconThemeManager.getIconThemeManager();
|
||
320 | } |
||
321 | |||
322 | public String getArgument(String name) { |
||
323 | return PluginServices.getArgumentByName(name);
|
||
324 | } |
||
325 | |||
326 | public String[] getArguments() { |
||
327 | return PluginServices.getArguments();
|
||
328 | } |
||
329 | |||
330 | public String getFromClipboard() { |
||
331 | return PluginServices.getFromClipboard();
|
||
332 | } |
||
333 | |||
334 | public void putInClipboard(String data) { |
||
335 | PluginServices.putInClipboard(data); |
||
336 | } |
||
337 | |||
338 | public Project getCurrentProject() {
|
||
339 | return ProjectManager.getInstance().getCurrentProject();
|
||
340 | } |
||
341 | |||
342 | public PreferencesNode getPreferences(String node) { |
||
343 | if( node.equalsIgnoreCase("project")) { |
||
344 | return DefaultProject.getPreferences();
|
||
345 | } |
||
346 | return new DefaultPreferencesNode(node); |
||
347 | } |
||
348 | |||
349 | public PreferencesNode getPreferences() {
|
||
350 | return new DefaultPreferencesNode(); |
||
351 | } |
||
352 | |||
353 | public Version getVersion() {
|
||
354 | 34441 | cordinyana | return version;
|
355 | 31496 | jjdelcerro | } |
356 | |||
357 | 34002 | jjdelcerro | public AboutManager getAbout() {
|
358 | AboutManager manager = AboutLocator.getManager(); |
||
359 | return manager;
|
||
360 | } |
||
361 | 34300 | fdiaz | |
362 | 38371 | nbrodin | public ColorTablesFactory getColorTablesFactory() {
|
363 | 35974 | jjdelcerro | return SymbologySwingLocator.getSwingManager().getColorTablesFactory();
|
364 | 34300 | fdiaz | } |
365 | |||
366 | 38371 | nbrodin | public void registerColorTablesFactory(ColorTablesFactory factory) { |
367 | 35974 | jjdelcerro | SymbologySwingLocator.getSwingManager().setColorTablesFactory(factory); |
368 | 34300 | fdiaz | |
369 | } |
||
370 | 35153 | jjdelcerro | |
371 | public IWindow getActiveWindow() {
|
||
372 | try {
|
||
373 | 35191 | jjdelcerro | IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
374 | 35153 | jjdelcerro | return window;
|
375 | } catch (Exception ex) { |
||
376 | return null; |
||
377 | } |
||
378 | } |
||
379 | 35191 | jjdelcerro | |
380 | public Document getActiveDocument() { |
||
381 | Project project = this.getCurrentProject();
|
||
382 | if( project == null ) { |
||
383 | return null; |
||
384 | } |
||
385 | return project.getActiveDocument();
|
||
386 | } |
||
387 | 35153 | jjdelcerro | |
388 | 35191 | jjdelcerro | public Document getActiveDocument(String documentTypeName) { |
389 | Document document = this.getActiveDocument(); |
||
390 | 36007 | fdiaz | if( document!= null && document.getTypeName().equalsIgnoreCase(documentTypeName) ) { |
391 | 35191 | jjdelcerro | return document;
|
392 | } |
||
393 | return null; |
||
394 | } |
||
395 | |||
396 | 36443 | cordinyana | public Document getActiveDocument(Class<? extends Document> documentClass) { |
397 | 35191 | jjdelcerro | Document document = this.getActiveDocument(); |
398 | if( documentClass.isInstance(document) ) {
|
||
399 | return document;
|
||
400 | } |
||
401 | return null; |
||
402 | } |
||
403 | |||
404 | public IDocumentWindow getDocumentWindow(Document document) { |
||
405 | 36443 | cordinyana | Class<? extends IDocumentWindow> defaultDocumentClass = |
406 | document.getFactory().getMainWindowClass(); |
||
407 | 35191 | jjdelcerro | return (IDocumentWindow) this.getUIManager().getSingletonWindow(defaultDocumentClass, document); |
408 | } |
||
409 | 35974 | jjdelcerro | |
410 | public String getLocaleLanguage() { |
||
411 | return Launcher.getAndamiConfig().getLocaleLanguage();
|
||
412 | } |
||
413 | |||
414 | 38242 | jldominguez | /* (non-Javadoc)
|
415 | * @see org.gvsig.app.ApplicationManager#message(java.lang.String, int)
|
||
416 | */
|
||
417 | public void message(String message, int message_type) { |
||
418 | |||
419 | String msg = message;
|
||
420 | if (message.startsWith("_")) { |
||
421 | msg = PluginServices.getText(this, message);
|
||
422 | } |
||
423 | switch (message_type) {
|
||
424 | |||
425 | case JOptionPane.ERROR_MESSAGE: |
||
426 | PluginServices.getMainFrame().getStatusBar().setErrorText(msg); |
||
427 | break;
|
||
428 | case JOptionPane.WARNING_MESSAGE: |
||
429 | PluginServices.getMainFrame().getStatusBar().setWarningText(msg); |
||
430 | break;
|
||
431 | default:
|
||
432 | try {
|
||
433 | throw new IllegalArgumentException("message_type"); |
||
434 | } catch (IllegalArgumentException ex) { |
||
435 | logger.info("Illegal message type in message()", ex);
|
||
436 | |||
437 | } |
||
438 | case JOptionPane.INFORMATION_MESSAGE: |
||
439 | PluginServices.getMainFrame().getStatusBar().setInfoText(msg); |
||
440 | break;
|
||
441 | |||
442 | } |
||
443 | |||
444 | } |
||
445 | 35974 | jjdelcerro | } |