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