svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / imp / DefaultAppgvSIGManager.java @ 39484
History | View | Annotate | Download (15.8 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.io.File; |
35 |
import java.util.ArrayList; |
36 |
import java.util.Iterator; |
37 |
import java.util.List; |
38 |
|
39 |
import javax.swing.JFileChooser; |
40 |
import javax.swing.filechooser.FileFilter; |
41 |
|
42 |
import org.cresques.cts.IProjection; |
43 |
import org.gvsig.about.AboutLocator; |
44 |
import org.gvsig.about.AboutManager; |
45 |
import org.gvsig.andami.Launcher; |
46 |
import org.gvsig.andami.PluginServices; |
47 |
import org.gvsig.andami.ui.mdiFrame.MainFrame; |
48 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
49 |
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 |
import org.gvsig.app.gui.WizardPanel; |
54 |
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 |
import org.gvsig.app.project.documents.Document; |
63 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
64 |
import org.gvsig.fmap.crs.CRSFactory; |
65 |
import org.gvsig.fmap.dal.DALLocator; |
66 |
import org.gvsig.fmap.dal.DataManager; |
67 |
import org.gvsig.fmap.dal.DataStore; |
68 |
import org.gvsig.fmap.dal.DataStoreParameters; |
69 |
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 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
74 |
import org.gvsig.gui.ColorTablesFactory; |
75 |
import org.gvsig.symbology.swing.SymbologySwingLocator; |
76 |
import org.gvsig.tools.ToolsLocator; |
77 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
78 |
import org.gvsig.tools.dispose.DisposableManager; |
79 |
import org.gvsig.tools.dynobject.DynObjectManager; |
80 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
81 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
82 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
83 |
import org.gvsig.tools.persistence.PersistenceManager; |
84 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
85 |
import org.gvsig.tools.swing.icontheme.IconThemeManager; |
86 |
import org.slf4j.Logger; |
87 |
import org.slf4j.LoggerFactory; |
88 |
|
89 |
|
90 |
|
91 |
|
92 |
/**
|
93 |
* @author jmvivo
|
94 |
*
|
95 |
*/
|
96 |
public class DefaultAppgvSIGManager implements ApplicationManager { |
97 |
|
98 |
@SuppressWarnings("unused") |
99 |
private static Logger logger = LoggerFactory.getLogger(DefaultAppgvSIGManager.class); |
100 |
|
101 |
private static final String EPNAME_PREPARE_OPEN_DATASTORE = "org.gvsig.datastore.open.prepare"; //"PrepareOpenDataStore"; |
102 |
private static final String EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS = "org.gvsig.datastoreparameters.open.prepare"; //"PrepareOpenDataStoreParameters"; |
103 |
private static final String EPNAME_PREPARE_OPEN_LAYER = "org.gvsig.layer.open.prepare"; // "PrepareOpenLayer"; |
104 |
|
105 |
private static final String EPNAME_ADD_TABLE_WIZARD = "AddLayerWizard"; |
106 |
|
107 |
private ExtensionPointManager epManager;
|
108 |
|
109 |
private Version version;
|
110 |
|
111 |
public DefaultAppgvSIGManager() {
|
112 |
epManager = ToolsLocator.getExtensionPointManager(); |
113 |
epManager.add(EPNAME_PREPARE_OPEN_DATASTORE, |
114 |
"Actions to do when open a DataStore");
|
115 |
epManager.add(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS, |
116 |
"Actions to do before open a DataStore with parameters");
|
117 |
epManager.add(EPNAME_PREPARE_OPEN_LAYER, |
118 |
"Actions to do after create a Layer");
|
119 |
epManager.add(EPNAME_ADD_TABLE_WIZARD, |
120 |
"Wizards to add new document table");
|
121 |
|
122 |
version = new Version();
|
123 |
} |
124 |
|
125 |
/* (non-Javadoc)
|
126 |
* @see org.gvsig.appGvSigManager#pepareOpenDataSource(org.gvsig.fmap.dal.DataStore)
|
127 |
*/
|
128 |
@SuppressWarnings("unchecked") |
129 |
public DataStore pepareOpenDataSource(DataStore store,
|
130 |
PrepareContext context) throws Exception { |
131 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
132 |
if (ep.getCount() == 0) { |
133 |
return store;
|
134 |
} |
135 |
DataStore result = store; |
136 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
137 |
PrepareDataStore prepare; |
138 |
while (iter.hasNext()) {
|
139 |
prepare = (PrepareDataStore) iter.next().create(); |
140 |
result = prepare.prepare(store, context); |
141 |
} |
142 |
return result;
|
143 |
} |
144 |
|
145 |
/* (non-Javadoc)
|
146 |
* @see org.gvsig.appGvSigManager#prepareOpenDataStoreParameters(org.gvsig.fmap.dal.DataStoreParameters)
|
147 |
*/
|
148 |
@SuppressWarnings("unchecked") |
149 |
public DataStoreParameters prepareOpenDataStoreParameters(
|
150 |
DataStoreParameters storeParameters, PrepareContext context) |
151 |
throws Exception { |
152 |
|
153 |
ExtensionPoint ep = epManager |
154 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
155 |
if (ep.getCount() == 0) { |
156 |
return storeParameters;
|
157 |
} |
158 |
DataStoreParameters result = storeParameters; |
159 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
160 |
PrepareDataStoreParameters prepare; |
161 |
while (iter.hasNext()) {
|
162 |
prepare = (PrepareDataStoreParameters) iter.next().create(); |
163 |
result = prepare.prepare(storeParameters, context); |
164 |
} |
165 |
|
166 |
return result;
|
167 |
} |
168 |
|
169 |
/*
|
170 |
* (non-Javadoc)
|
171 |
* @see org.gvsig.app.ApplicationManager#prepareOpenDataStoreParameters(java.util.List, org.gvsig.app.prepareAction.PrepareContext)
|
172 |
*/
|
173 |
@SuppressWarnings("unchecked") |
174 |
public List<DataStoreParameters> prepareOpenDataStoreParameters( |
175 |
List<DataStoreParameters> storeParameters, PrepareContext context)
|
176 |
throws Exception { |
177 |
|
178 |
ExtensionPoint ep = epManager |
179 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
180 |
if (ep.getCount() == 0) { |
181 |
return storeParameters;
|
182 |
} |
183 |
|
184 |
List<DataStoreParameters> result = new ArrayList<DataStoreParameters>(); |
185 |
|
186 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
187 |
List<PrepareDataStoreParameters> prepareList = new ArrayList<PrepareDataStoreParameters>(); |
188 |
while (iter.hasNext()) {
|
189 |
prepareList.add((PrepareDataStoreParameters) iter.next().create()); |
190 |
} |
191 |
|
192 |
for (int i = 0; i < storeParameters.size(); i++) { |
193 |
DataStoreParameters param = storeParameters.get(i); |
194 |
for (int j = 0; j < prepareList.size(); j++) { |
195 |
prepareList.get(j).pre(param, context); |
196 |
} |
197 |
} |
198 |
|
199 |
for (int i = 0; i < storeParameters.size(); i++) { |
200 |
DataStoreParameters param = storeParameters.get(i); |
201 |
if(param != null) { |
202 |
for (int j = 0; j < prepareList.size(); j++) { |
203 |
param = prepareList.get(j).prepare(param, context); |
204 |
if(param == null) |
205 |
break;
|
206 |
} |
207 |
if(param != null) |
208 |
result.add(param); |
209 |
} |
210 |
} |
211 |
|
212 |
for (int i = 0; i < storeParameters.size(); i++) { |
213 |
DataStoreParameters param = storeParameters.get(i); |
214 |
for (int j = 0; j < prepareList.size(); j++) { |
215 |
prepareList.get(j).post(param, context); |
216 |
} |
217 |
} |
218 |
|
219 |
return result;
|
220 |
} |
221 |
|
222 |
public void registerPrepareOpenDataStore(PrepareDataStore action) { |
223 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
224 |
ep.append(action.getName(), action.getDescription(), action); |
225 |
} |
226 |
|
227 |
public void registerPrepareOpenDataStoreParameters( |
228 |
PrepareDataStoreParameters action) { |
229 |
ExtensionPoint ep = epManager |
230 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
231 |
ep.append(action.getName(), action.getDescription(), action); |
232 |
|
233 |
|
234 |
} |
235 |
|
236 |
@SuppressWarnings("unchecked") |
237 |
public FLayer prepareOpenLayer(FLayer layer,
|
238 |
PrepareContextView context) |
239 |
throws Exception { |
240 |
|
241 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
242 |
|
243 |
if (ep.getCount() == 0) { |
244 |
return layer;
|
245 |
} |
246 |
FLayer result = layer; |
247 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
248 |
PrepareLayer prepare; |
249 |
while (iter.hasNext()) {
|
250 |
prepare = (PrepareLayer) iter.next().create(); |
251 |
result = prepare.prepare(result, context); |
252 |
} |
253 |
|
254 |
return result;
|
255 |
|
256 |
} |
257 |
|
258 |
public void registerPrepareOpenLayer(PrepareLayer action) { |
259 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
260 |
ep.append(action.getName(), action.getDescription(), action); |
261 |
} |
262 |
|
263 |
public void registerAddTableWizard(String name, String description, |
264 |
Class<? extends WizardPanel> wpClass) { |
265 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
266 |
ep.append(name, description, wpClass); |
267 |
} |
268 |
|
269 |
@SuppressWarnings("unchecked") |
270 |
public List<WizardPanel> getWizardPanels() throws Exception { |
271 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
272 |
List<WizardPanel> result = new ArrayList<WizardPanel>(); |
273 |
Iterator<Extension> iter = ep.iterator();
|
274 |
while (iter.hasNext()) {
|
275 |
result.add((WizardPanel) iter.next().create()); |
276 |
} |
277 |
return result;
|
278 |
} |
279 |
|
280 |
public DataManager getDataManager() {
|
281 |
return DALLocator.getDataManager();
|
282 |
} |
283 |
|
284 |
public GeometryManager getGeometryManager() {
|
285 |
return GeometryLocator.getGeometryManager();
|
286 |
} |
287 |
|
288 |
public PersistenceManager getPersistenceManager() {
|
289 |
return ToolsLocator.getPersistenceManager();
|
290 |
} |
291 |
|
292 |
public DisposableManager getDisposableManager() {
|
293 |
return ToolsLocator.getDisposableManager();
|
294 |
} |
295 |
|
296 |
public DynObjectManager getDynObjectManager() {
|
297 |
return ToolsLocator.getDynObjectManager();
|
298 |
} |
299 |
|
300 |
public ExtensionPointManager getExtensionPointManager() {
|
301 |
return ToolsLocator.getExtensionPointManager();
|
302 |
} |
303 |
|
304 |
public ProjectManager getProjectManager() {
|
305 |
return ProjectManager.getInstance();
|
306 |
} |
307 |
|
308 |
public MDIManager getUIManager() {
|
309 |
return PluginServices.getMDIManager();
|
310 |
} |
311 |
|
312 |
public MapContextManager getMapContextManager() {
|
313 |
return MapContextLocator.getMapContextManager();
|
314 |
} |
315 |
|
316 |
public DataTypesManager getDataTypesManager() {
|
317 |
return ToolsLocator.getDataTypesManager();
|
318 |
} |
319 |
|
320 |
public IProjection getCRS(String code) { |
321 |
return CRSFactory.getCRS(code);
|
322 |
} |
323 |
|
324 |
public IconThemeManager getIconThemeManager() {
|
325 |
return ToolsSwingLocator.getIconThemeManager();
|
326 |
} |
327 |
|
328 |
public String getArgument(String name) { |
329 |
return PluginServices.getArgumentByName(name);
|
330 |
} |
331 |
|
332 |
public String[] getArguments() { |
333 |
return PluginServices.getArguments();
|
334 |
} |
335 |
|
336 |
public String getFromClipboard() { |
337 |
return PluginServices.getFromClipboard();
|
338 |
} |
339 |
|
340 |
public void putInClipboard(String data) { |
341 |
PluginServices.putInClipboard(data); |
342 |
} |
343 |
|
344 |
public Project getCurrentProject() {
|
345 |
return ProjectManager.getInstance().getCurrentProject();
|
346 |
} |
347 |
|
348 |
public PreferencesNode getPreferences(String node) { |
349 |
if( node.equalsIgnoreCase("project")) { |
350 |
return DefaultProject.getPreferences();
|
351 |
} |
352 |
return new DefaultPreferencesNode(node); |
353 |
} |
354 |
|
355 |
public PreferencesNode getPreferences() {
|
356 |
return new DefaultPreferencesNode(); |
357 |
} |
358 |
|
359 |
public Version getVersion() {
|
360 |
return version;
|
361 |
} |
362 |
|
363 |
public AboutManager getAbout() {
|
364 |
AboutManager manager = AboutLocator.getManager(); |
365 |
return manager;
|
366 |
} |
367 |
|
368 |
public ColorTablesFactory getColorTablesFactory() {
|
369 |
return SymbologySwingLocator.getSwingManager().getColorTablesFactory();
|
370 |
} |
371 |
|
372 |
public void registerColorTablesFactory(ColorTablesFactory factory) { |
373 |
SymbologySwingLocator.getSwingManager().setColorTablesFactory(factory); |
374 |
|
375 |
} |
376 |
|
377 |
public IWindow getActiveWindow() {
|
378 |
try {
|
379 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
380 |
return window;
|
381 |
} catch (Exception ex) { |
382 |
return null; |
383 |
} |
384 |
} |
385 |
|
386 |
public Document getActiveDocument() { |
387 |
return this.getActiveDocument((Class<? extends Document>)null); |
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 |
Project project = this.getCurrentProject();
|
400 |
if( project == null ) { |
401 |
return null; |
402 |
} |
403 |
return project.getActiveDocument(documentClass);
|
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 |
|
467 |
public File[] showChooserDialog( |
468 |
final String title, |
469 |
final int type, // SAVE_DIALOG / OPEN_DIALOG |
470 |
final int selectionMode, // JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES |
471 |
final boolean multiselection, |
472 |
final File initialPath, |
473 |
final FileFilter filter, |
474 |
final boolean fileHidingEnabled |
475 |
) { |
476 |
MainFrame main = PluginServices.getMainFrame(); |
477 |
return main.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled);
|
478 |
} |
479 |
|
480 |
public File[] showOpenDirectoryDialog(String title, File initialPath) { |
481 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false); |
482 |
} |
483 |
|
484 |
|
485 |
public File[] showOpenFileDialog(String title, File initialPath) { |
486 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
487 |
} |
488 |
|
489 |
|
490 |
public File[] showSaveFileDialog(String title, File initialPath) { |
491 |
return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
492 |
} |
493 |
|
494 |
public String translate(String message, String... args) { |
495 |
return org.gvsig.i18n.Messages.translate(message, args);
|
496 |
} |
497 |
|
498 |
public Component getRootComponent() { |
499 |
return (Component) PluginServices.getMainFrame(); |
500 |
} |
501 |
|
502 |
public void refreshMenusAndToolBars() { |
503 |
PluginServices.getMainFrame().refreshControls(); |
504 |
} |
505 |
|
506 |
|
507 |
} |