svn-gvsig-desktop / tags / v2_0_0_Build_2061 / applications / appgvSIG / src / org / gvsig / app / imp / DefaultAppgvSIGManager.java @ 39427
History | View | Annotate | Download (14.6 KB)
1 |
/* 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 |
package org.gvsig.app.imp; |
32 |
|
33 |
import java.awt.Component; |
34 |
import java.util.ArrayList; |
35 |
import java.util.Iterator; |
36 |
import java.util.List; |
37 |
|
38 |
import org.cresques.cts.IProjection; |
39 |
import org.gvsig.about.AboutLocator; |
40 |
import org.gvsig.about.AboutManager; |
41 |
import org.gvsig.andami.Launcher; |
42 |
import org.gvsig.andami.PluginServices; |
43 |
import org.gvsig.andami.ui.mdiFrame.MainFrame; |
44 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
45 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
46 |
import org.gvsig.app.ApplicationManager; |
47 |
import org.gvsig.app.PreferencesNode; |
48 |
import org.gvsig.app.extension.Version; |
49 |
import org.gvsig.app.gui.WizardPanel; |
50 |
import org.gvsig.app.prepareAction.PrepareContext; |
51 |
import org.gvsig.app.prepareAction.PrepareContextView; |
52 |
import org.gvsig.app.prepareAction.PrepareDataStore; |
53 |
import org.gvsig.app.prepareAction.PrepareDataStoreParameters; |
54 |
import org.gvsig.app.prepareAction.PrepareLayer; |
55 |
import org.gvsig.app.project.DefaultProject; |
56 |
import org.gvsig.app.project.Project; |
57 |
import org.gvsig.app.project.ProjectManager; |
58 |
import org.gvsig.app.project.documents.Document; |
59 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
60 |
import org.gvsig.fmap.crs.CRSFactory; |
61 |
import org.gvsig.fmap.dal.DALLocator; |
62 |
import org.gvsig.fmap.dal.DataManager; |
63 |
import org.gvsig.fmap.dal.DataStore; |
64 |
import org.gvsig.fmap.dal.DataStoreParameters; |
65 |
import org.gvsig.fmap.geom.GeometryLocator; |
66 |
import org.gvsig.fmap.geom.GeometryManager; |
67 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
68 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
69 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
70 |
import org.gvsig.gui.ColorTablesFactory; |
71 |
import org.gvsig.symbology.swing.SymbologySwingLocator; |
72 |
import org.gvsig.tools.ToolsLocator; |
73 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
74 |
import org.gvsig.tools.dispose.DisposableManager; |
75 |
import org.gvsig.tools.dynobject.DynObjectManager; |
76 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
77 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
78 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
79 |
import org.gvsig.tools.persistence.PersistenceManager; |
80 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
81 |
import org.gvsig.tools.swing.icontheme.IconThemeManager; |
82 |
import org.slf4j.Logger; |
83 |
import org.slf4j.LoggerFactory; |
84 |
|
85 |
|
86 |
|
87 |
|
88 |
/**
|
89 |
* @author jmvivo
|
90 |
*
|
91 |
*/
|
92 |
public class DefaultAppgvSIGManager implements ApplicationManager { |
93 |
|
94 |
@SuppressWarnings("unused") |
95 |
private static Logger logger = LoggerFactory.getLogger(DefaultAppgvSIGManager.class); |
96 |
|
97 |
private static final String EPNAME_PREPARE_OPEN_DATASTORE = "org.gvsig.datastore.open.prepare"; //"PrepareOpenDataStore"; |
98 |
private static final String EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS = "org.gvsig.datastoreparameters.open.prepare"; //"PrepareOpenDataStoreParameters"; |
99 |
private static final String EPNAME_PREPARE_OPEN_LAYER = "org.gvsig.layer.open.prepare"; // "PrepareOpenLayer"; |
100 |
|
101 |
private static final String EPNAME_ADD_TABLE_WIZARD = "AddLayerWizard"; |
102 |
|
103 |
private ExtensionPointManager epManager;
|
104 |
|
105 |
private Version version;
|
106 |
|
107 |
public DefaultAppgvSIGManager() {
|
108 |
epManager = ToolsLocator.getExtensionPointManager(); |
109 |
epManager.add(EPNAME_PREPARE_OPEN_DATASTORE, |
110 |
"Actions to do when open a DataStore");
|
111 |
epManager.add(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS, |
112 |
"Actions to do before open a DataStore with parameters");
|
113 |
epManager.add(EPNAME_PREPARE_OPEN_LAYER, |
114 |
"Actions to do after create a Layer");
|
115 |
epManager.add(EPNAME_ADD_TABLE_WIZARD, |
116 |
"Wizards to add new document table");
|
117 |
|
118 |
version = new Version();
|
119 |
} |
120 |
|
121 |
/* (non-Javadoc)
|
122 |
* @see org.gvsig.appGvSigManager#pepareOpenDataSource(org.gvsig.fmap.dal.DataStore)
|
123 |
*/
|
124 |
@SuppressWarnings("unchecked") |
125 |
public DataStore pepareOpenDataSource(DataStore store,
|
126 |
PrepareContext context) throws Exception { |
127 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
128 |
if (ep.getCount() == 0) { |
129 |
return store;
|
130 |
} |
131 |
DataStore result = store; |
132 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
133 |
PrepareDataStore prepare; |
134 |
while (iter.hasNext()) {
|
135 |
prepare = (PrepareDataStore) iter.next().create(); |
136 |
result = prepare.prepare(store, context); |
137 |
} |
138 |
return result;
|
139 |
} |
140 |
|
141 |
/* (non-Javadoc)
|
142 |
* @see org.gvsig.appGvSigManager#prepareOpenDataStoreParameters(org.gvsig.fmap.dal.DataStoreParameters)
|
143 |
*/
|
144 |
@SuppressWarnings("unchecked") |
145 |
public DataStoreParameters prepareOpenDataStoreParameters(
|
146 |
DataStoreParameters storeParameters, PrepareContext context) |
147 |
throws Exception { |
148 |
|
149 |
ExtensionPoint ep = epManager |
150 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
151 |
if (ep.getCount() == 0) { |
152 |
return storeParameters;
|
153 |
} |
154 |
DataStoreParameters result = storeParameters; |
155 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
156 |
PrepareDataStoreParameters prepare; |
157 |
while (iter.hasNext()) {
|
158 |
prepare = (PrepareDataStoreParameters) iter.next().create(); |
159 |
result = prepare.prepare(storeParameters, context); |
160 |
} |
161 |
|
162 |
return result;
|
163 |
} |
164 |
|
165 |
/*
|
166 |
* (non-Javadoc)
|
167 |
* @see org.gvsig.app.ApplicationManager#prepareOpenDataStoreParameters(java.util.List, org.gvsig.app.prepareAction.PrepareContext)
|
168 |
*/
|
169 |
@SuppressWarnings("unchecked") |
170 |
public List<DataStoreParameters> prepareOpenDataStoreParameters( |
171 |
List<DataStoreParameters> storeParameters, PrepareContext context)
|
172 |
throws Exception { |
173 |
|
174 |
ExtensionPoint ep = epManager |
175 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
176 |
if (ep.getCount() == 0) { |
177 |
return storeParameters;
|
178 |
} |
179 |
|
180 |
List<DataStoreParameters> result = new ArrayList<DataStoreParameters>(); |
181 |
|
182 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
183 |
List<PrepareDataStoreParameters> prepareList = new ArrayList<PrepareDataStoreParameters>(); |
184 |
while (iter.hasNext()) {
|
185 |
prepareList.add((PrepareDataStoreParameters) iter.next().create()); |
186 |
} |
187 |
|
188 |
for (int i = 0; i < storeParameters.size(); i++) { |
189 |
DataStoreParameters param = storeParameters.get(i); |
190 |
for (int j = 0; j < prepareList.size(); j++) { |
191 |
prepareList.get(j).pre(param, context); |
192 |
} |
193 |
} |
194 |
|
195 |
for (int i = 0; i < storeParameters.size(); i++) { |
196 |
DataStoreParameters param = storeParameters.get(i); |
197 |
if(param != null) { |
198 |
for (int j = 0; j < prepareList.size(); j++) { |
199 |
param = prepareList.get(j).prepare(param, context); |
200 |
if(param == null) |
201 |
break;
|
202 |
} |
203 |
if(param != null) |
204 |
result.add(param); |
205 |
} |
206 |
} |
207 |
|
208 |
for (int i = 0; i < storeParameters.size(); i++) { |
209 |
DataStoreParameters param = storeParameters.get(i); |
210 |
for (int j = 0; j < prepareList.size(); j++) { |
211 |
prepareList.get(j).post(param, context); |
212 |
} |
213 |
} |
214 |
|
215 |
return result;
|
216 |
} |
217 |
|
218 |
public void registerPrepareOpenDataStore(PrepareDataStore action) { |
219 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
220 |
ep.append(action.getName(), action.getDescription(), action); |
221 |
} |
222 |
|
223 |
public void registerPrepareOpenDataStoreParameters( |
224 |
PrepareDataStoreParameters action) { |
225 |
ExtensionPoint ep = epManager |
226 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
227 |
ep.append(action.getName(), action.getDescription(), action); |
228 |
|
229 |
|
230 |
} |
231 |
|
232 |
@SuppressWarnings("unchecked") |
233 |
public FLayer prepareOpenLayer(FLayer layer,
|
234 |
PrepareContextView context) |
235 |
throws Exception { |
236 |
|
237 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
238 |
|
239 |
if (ep.getCount() == 0) { |
240 |
return layer;
|
241 |
} |
242 |
FLayer result = layer; |
243 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
244 |
PrepareLayer prepare; |
245 |
while (iter.hasNext()) {
|
246 |
prepare = (PrepareLayer) iter.next().create(); |
247 |
result = prepare.prepare(result, context); |
248 |
} |
249 |
|
250 |
return result;
|
251 |
|
252 |
} |
253 |
|
254 |
public void registerPrepareOpenLayer(PrepareLayer action) { |
255 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
256 |
ep.append(action.getName(), action.getDescription(), action); |
257 |
} |
258 |
|
259 |
public void registerAddTableWizard(String name, String description, |
260 |
Class<? extends WizardPanel> wpClass) { |
261 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
262 |
ep.append(name, description, wpClass); |
263 |
} |
264 |
|
265 |
@SuppressWarnings("unchecked") |
266 |
public List<WizardPanel> getWizardPanels() throws Exception { |
267 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
268 |
List<WizardPanel> result = new ArrayList<WizardPanel>(); |
269 |
Iterator<Extension> iter = ep.iterator();
|
270 |
while (iter.hasNext()) {
|
271 |
result.add((WizardPanel) iter.next().create()); |
272 |
} |
273 |
return result;
|
274 |
} |
275 |
|
276 |
public DataManager getDataManager() {
|
277 |
return DALLocator.getDataManager();
|
278 |
} |
279 |
|
280 |
public GeometryManager getGeometryManager() {
|
281 |
return GeometryLocator.getGeometryManager();
|
282 |
} |
283 |
|
284 |
public PersistenceManager getPersistenceManager() {
|
285 |
return ToolsLocator.getPersistenceManager();
|
286 |
} |
287 |
|
288 |
public DisposableManager getDisposableManager() {
|
289 |
return ToolsLocator.getDisposableManager();
|
290 |
} |
291 |
|
292 |
public DynObjectManager getDynObjectManager() {
|
293 |
return ToolsLocator.getDynObjectManager();
|
294 |
} |
295 |
|
296 |
public ExtensionPointManager getExtensionPointManager() {
|
297 |
return ToolsLocator.getExtensionPointManager();
|
298 |
} |
299 |
|
300 |
public ProjectManager getProjectManager() {
|
301 |
return ProjectManager.getInstance();
|
302 |
} |
303 |
|
304 |
public MDIManager getUIManager() {
|
305 |
return PluginServices.getMDIManager();
|
306 |
} |
307 |
|
308 |
public MapContextManager getMapContextManager() {
|
309 |
return MapContextLocator.getMapContextManager();
|
310 |
} |
311 |
|
312 |
public DataTypesManager getDataTypesManager() {
|
313 |
return ToolsLocator.getDataTypesManager();
|
314 |
} |
315 |
|
316 |
public IProjection getCRS(String code) { |
317 |
return CRSFactory.getCRS(code);
|
318 |
} |
319 |
|
320 |
public IconThemeManager getIconThemeManager() {
|
321 |
return ToolsSwingLocator.getIconThemeManager();
|
322 |
} |
323 |
|
324 |
public String getArgument(String name) { |
325 |
return PluginServices.getArgumentByName(name);
|
326 |
} |
327 |
|
328 |
public String[] getArguments() { |
329 |
return PluginServices.getArguments();
|
330 |
} |
331 |
|
332 |
public String getFromClipboard() { |
333 |
return PluginServices.getFromClipboard();
|
334 |
} |
335 |
|
336 |
public void putInClipboard(String data) { |
337 |
PluginServices.putInClipboard(data); |
338 |
} |
339 |
|
340 |
public Project getCurrentProject() {
|
341 |
return ProjectManager.getInstance().getCurrentProject();
|
342 |
} |
343 |
|
344 |
public PreferencesNode getPreferences(String node) { |
345 |
if( node.equalsIgnoreCase("project")) { |
346 |
return DefaultProject.getPreferences();
|
347 |
} |
348 |
return new DefaultPreferencesNode(node); |
349 |
} |
350 |
|
351 |
public PreferencesNode getPreferences() {
|
352 |
return new DefaultPreferencesNode(); |
353 |
} |
354 |
|
355 |
public Version getVersion() {
|
356 |
return version;
|
357 |
} |
358 |
|
359 |
public AboutManager getAbout() {
|
360 |
AboutManager manager = AboutLocator.getManager(); |
361 |
return manager;
|
362 |
} |
363 |
|
364 |
public ColorTablesFactory getColorTablesFactory() {
|
365 |
return SymbologySwingLocator.getSwingManager().getColorTablesFactory();
|
366 |
} |
367 |
|
368 |
public void registerColorTablesFactory(ColorTablesFactory factory) { |
369 |
SymbologySwingLocator.getSwingManager().setColorTablesFactory(factory); |
370 |
|
371 |
} |
372 |
|
373 |
public IWindow getActiveWindow() {
|
374 |
try {
|
375 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
376 |
return window;
|
377 |
} catch (Exception ex) { |
378 |
return null; |
379 |
} |
380 |
} |
381 |
|
382 |
public Document getActiveDocument() { |
383 |
Project project = this.getCurrentProject();
|
384 |
if( project == null ) { |
385 |
return null; |
386 |
} |
387 |
return project.getActiveDocument();
|
388 |
} |
389 |
|
390 |
public Document getActiveDocument(String documentTypeName) { |
391 |
Document document = this.getActiveDocument(); |
392 |
if( document!= null && document.getTypeName().equalsIgnoreCase(documentTypeName) ) { |
393 |
return document;
|
394 |
} |
395 |
return null; |
396 |
} |
397 |
|
398 |
public Document getActiveDocument(Class<? extends Document> documentClass) { |
399 |
Document document = this.getActiveDocument(); |
400 |
if( documentClass.isInstance(document) ) {
|
401 |
return document;
|
402 |
} |
403 |
return null; |
404 |
} |
405 |
|
406 |
public IDocumentWindow getDocumentWindow(Document document) { |
407 |
Class<? extends IDocumentWindow> defaultDocumentClass = |
408 |
document.getFactory().getMainWindowClass(); |
409 |
return (IDocumentWindow) this.getUIManager().getSingletonWindow(defaultDocumentClass, document); |
410 |
} |
411 |
|
412 |
public String getLocaleLanguage() { |
413 |
return Launcher.getAndamiConfig().getLocaleLanguage();
|
414 |
} |
415 |
|
416 |
public void message(String message, int message_type) { |
417 |
MainFrame main = PluginServices.getMainFrame(); |
418 |
main.message(message, message_type); |
419 |
} |
420 |
|
421 |
public void messageDialog(String message, String title, int messageType) { |
422 |
MainFrame main = PluginServices.getMainFrame(); |
423 |
main.messageDialog(message, title, messageType); |
424 |
} |
425 |
|
426 |
public void messageDialog(String message, String[] messageArgs, |
427 |
String title, int messageType) { |
428 |
MainFrame main = PluginServices.getMainFrame(); |
429 |
main.messageDialog(message, messageArgs, title, messageType); |
430 |
} |
431 |
|
432 |
public int confirmDialog(String message, String title, int optionType, |
433 |
int messageType) {
|
434 |
MainFrame main = PluginServices.getMainFrame(); |
435 |
return main.confirmDialog(message, title, optionType, messageType);
|
436 |
} |
437 |
|
438 |
public String inputDialog(String message, String title, int messageType, |
439 |
String initialValue) {
|
440 |
MainFrame main = PluginServices.getMainFrame(); |
441 |
return main.inputDialog(message, title, messageType, initialValue);
|
442 |
} |
443 |
|
444 |
public String inputDialog(String message, String title) { |
445 |
MainFrame main = PluginServices.getMainFrame(); |
446 |
return main.inputDialog(message, title);
|
447 |
} |
448 |
|
449 |
public void showDialog(Component contents, String title) { |
450 |
MainFrame main = PluginServices.getMainFrame(); |
451 |
main.showDialog(contents, title); |
452 |
} |
453 |
|
454 |
public Component createComponent(Class<? extends Component> theClass, |
455 |
Object... parameters) {
|
456 |
MainFrame main = PluginServices.getMainFrame(); |
457 |
return main.createComponentWithParams(theClass, parameters);
|
458 |
} |
459 |
|
460 |
public Component createComponentWithParams( |
461 |
Class<? extends Component> theClass, Object[] parameters) { |
462 |
MainFrame main = PluginServices.getMainFrame(); |
463 |
return main.createComponentWithParams(theClass, parameters);
|
464 |
} |
465 |
|
466 |
public String translate(String message, String... args) { |
467 |
return org.gvsig.i18n.Messages.translate(message, args);
|
468 |
} |
469 |
|
470 |
public Component getRootComponent() { |
471 |
return (Component) PluginServices.getMainFrame(); |
472 |
} |
473 |
|
474 |
public void refreshMenusAndToolBars() { |
475 |
PluginServices.getMainFrame().refreshControls(); |
476 |
} |
477 |
} |