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 @ 40596
History | View | Annotate | Download (15.7 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.ui.mdiFrame.MainFrame; |
42 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
43 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
44 |
import org.gvsig.app.ApplicationManager; |
45 |
import org.gvsig.app.PreferencesNode; |
46 |
import org.gvsig.app.extension.Version; |
47 |
import org.gvsig.app.gui.WizardPanel; |
48 |
import org.gvsig.app.prepareAction.PrepareContext; |
49 |
import org.gvsig.app.prepareAction.PrepareContextView; |
50 |
import org.gvsig.app.prepareAction.PrepareDataStore; |
51 |
import org.gvsig.app.prepareAction.PrepareDataStoreParameters; |
52 |
import org.gvsig.app.prepareAction.PrepareLayer; |
53 |
import org.gvsig.app.project.DefaultProject; |
54 |
import org.gvsig.app.project.Project; |
55 |
import org.gvsig.app.project.ProjectManager; |
56 |
import org.gvsig.app.project.documents.Document; |
57 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
58 |
import org.gvsig.fmap.crs.CRSFactory; |
59 |
import org.gvsig.fmap.dal.DALLocator; |
60 |
import org.gvsig.fmap.dal.DataManager; |
61 |
import org.gvsig.fmap.dal.DataStore; |
62 |
import org.gvsig.fmap.dal.DataStoreParameters; |
63 |
import org.gvsig.fmap.geom.GeometryLocator; |
64 |
import org.gvsig.fmap.geom.GeometryManager; |
65 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
66 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
67 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
68 |
import org.gvsig.gui.ColorTablesFactory; |
69 |
import org.gvsig.symbology.swing.SymbologySwingLocator; |
70 |
import org.gvsig.tools.ToolsLocator; |
71 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
72 |
import org.gvsig.tools.dispose.DisposableManager; |
73 |
import org.gvsig.tools.dynobject.DynObjectManager; |
74 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
75 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
76 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
77 |
import org.gvsig.tools.persistence.PersistenceManager; |
78 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
79 |
import org.gvsig.tools.swing.icontheme.IconThemeManager; |
80 |
import org.slf4j.Logger; |
81 |
import org.slf4j.LoggerFactory; |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
/**
|
87 |
* @author jmvivo
|
88 |
*
|
89 |
*/
|
90 |
public class DefaultAppgvSIGManager implements ApplicationManager { |
91 |
|
92 |
@SuppressWarnings("unused") |
93 |
private static Logger logger = LoggerFactory.getLogger(DefaultAppgvSIGManager.class); |
94 |
|
95 |
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 |
|
99 |
private static final String EPNAME_ADD_TABLE_WIZARD = "AddLayerWizard"; |
100 |
|
101 |
private ExtensionPointManager epManager;
|
102 |
|
103 |
private Version version;
|
104 |
|
105 |
public DefaultAppgvSIGManager() {
|
106 |
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 |
version = new Version();
|
117 |
} |
118 |
|
119 |
/* (non-Javadoc)
|
120 |
* @see org.gvsig.appGvSigManager#pepareOpenDataSource(org.gvsig.fmap.dal.DataStore)
|
121 |
*/
|
122 |
@SuppressWarnings("unchecked") |
123 |
public DataStore pepareOpenDataSource(DataStore store,
|
124 |
PrepareContext context) throws Exception { |
125 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
126 |
if (ep.getCount() == 0) { |
127 |
return store;
|
128 |
} |
129 |
DataStore result = store; |
130 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
131 |
PrepareDataStore prepare; |
132 |
while (iter.hasNext()) {
|
133 |
prepare = (PrepareDataStore) iter.next().create(); |
134 |
result = prepare.prepare(store, context); |
135 |
} |
136 |
return result;
|
137 |
} |
138 |
|
139 |
/* (non-Javadoc)
|
140 |
* @see org.gvsig.appGvSigManager#prepareOpenDataStoreParameters(org.gvsig.fmap.dal.DataStoreParameters)
|
141 |
*/
|
142 |
@SuppressWarnings("unchecked") |
143 |
public DataStoreParameters prepareOpenDataStoreParameters(
|
144 |
DataStoreParameters storeParameters, PrepareContext context) |
145 |
throws Exception { |
146 |
|
147 |
ExtensionPoint ep = epManager |
148 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
149 |
if (ep.getCount() == 0) { |
150 |
return storeParameters;
|
151 |
} |
152 |
DataStoreParameters result = storeParameters; |
153 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
154 |
PrepareDataStoreParameters prepare; |
155 |
while (iter.hasNext()) {
|
156 |
prepare = (PrepareDataStoreParameters) iter.next().create(); |
157 |
result = prepare.prepare(storeParameters, context); |
158 |
} |
159 |
|
160 |
return result;
|
161 |
} |
162 |
|
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 |
|
172 |
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 |
public void registerPrepareOpenDataStore(PrepareDataStore action) { |
217 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
218 |
ep.append(action.getName(), action.getDescription(), action); |
219 |
} |
220 |
|
221 |
public void registerPrepareOpenDataStoreParameters( |
222 |
PrepareDataStoreParameters action) { |
223 |
ExtensionPoint ep = epManager |
224 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
225 |
ep.append(action.getName(), action.getDescription(), action); |
226 |
|
227 |
|
228 |
} |
229 |
|
230 |
@SuppressWarnings("unchecked") |
231 |
public FLayer prepareOpenLayer(FLayer layer,
|
232 |
PrepareContextView context) |
233 |
throws Exception { |
234 |
|
235 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
236 |
|
237 |
if (ep.getCount() == 0) { |
238 |
return layer;
|
239 |
} |
240 |
FLayer result = layer; |
241 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
242 |
PrepareLayer prepare; |
243 |
while (iter.hasNext()) {
|
244 |
prepare = (PrepareLayer) iter.next().create(); |
245 |
result = prepare.prepare(result, context); |
246 |
} |
247 |
|
248 |
return result;
|
249 |
|
250 |
} |
251 |
|
252 |
public void registerPrepareOpenLayer(PrepareLayer action) { |
253 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
254 |
ep.append(action.getName(), action.getDescription(), action); |
255 |
} |
256 |
|
257 |
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 |
@SuppressWarnings("unchecked") |
264 |
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 |
|
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 |
public DataTypesManager getDataTypesManager() {
|
311 |
return ToolsLocator.getDataTypesManager();
|
312 |
} |
313 |
|
314 |
public IProjection getCRS(String code) { |
315 |
return CRSFactory.getCRS(code);
|
316 |
} |
317 |
|
318 |
public IconThemeManager getIconThemeManager() {
|
319 |
return ToolsSwingLocator.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 |
return version;
|
355 |
} |
356 |
|
357 |
public AboutManager getAbout() {
|
358 |
AboutManager manager = AboutLocator.getManager(); |
359 |
return manager;
|
360 |
} |
361 |
|
362 |
public ColorTablesFactory getColorTablesFactory() {
|
363 |
return SymbologySwingLocator.getSwingManager().getColorTablesFactory();
|
364 |
} |
365 |
|
366 |
public void registerColorTablesFactory(ColorTablesFactory factory) { |
367 |
SymbologySwingLocator.getSwingManager().setColorTablesFactory(factory); |
368 |
|
369 |
} |
370 |
|
371 |
public IWindow getActiveWindow() {
|
372 |
try {
|
373 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
374 |
return window;
|
375 |
} catch (Exception ex) { |
376 |
return null; |
377 |
} |
378 |
} |
379 |
|
380 |
public Document getActiveDocument() { |
381 |
return this.getActiveDocument((Class<? extends Document>)null); |
382 |
} |
383 |
|
384 |
public Document getActiveDocument(String documentTypeName) { |
385 |
Document document = this.getActiveDocument(); |
386 |
if( document!= null && document.getTypeName().equalsIgnoreCase(documentTypeName) ) { |
387 |
return document;
|
388 |
} |
389 |
return null; |
390 |
} |
391 |
|
392 |
public Document getActiveDocument(Class<? extends Document> documentClass) { |
393 |
Project project = this.getCurrentProject();
|
394 |
if( project == null ) { |
395 |
return null; |
396 |
} |
397 |
return project.getActiveDocument(documentClass);
|
398 |
} |
399 |
|
400 |
public IDocumentWindow getDocumentWindow(Document document) { |
401 |
Class<? extends IDocumentWindow> defaultDocumentClass = |
402 |
document.getFactory().getMainWindowClass(); |
403 |
return (IDocumentWindow) this.getUIManager().getSingletonWindow(defaultDocumentClass, document); |
404 |
} |
405 |
|
406 |
public String getLocaleLanguage() { |
407 |
return Launcher.getAndamiConfig().getLocaleLanguage();
|
408 |
} |
409 |
|
410 |
public void message(String message, int message_type) { |
411 |
MainFrame main = PluginServices.getMainFrame(); |
412 |
main.message(message, message_type); |
413 |
} |
414 |
|
415 |
public void messageDialog(String message, String title, int messageType) { |
416 |
MainFrame main = PluginServices.getMainFrame(); |
417 |
main.messageDialog(message, title, messageType); |
418 |
} |
419 |
|
420 |
public void messageDialog(String message, String[] messageArgs, |
421 |
String title, int messageType) { |
422 |
MainFrame main = PluginServices.getMainFrame(); |
423 |
main.messageDialog(message, messageArgs, title, messageType); |
424 |
} |
425 |
|
426 |
public int confirmDialog(String message, String title, int optionType, |
427 |
int messageType) {
|
428 |
MainFrame main = PluginServices.getMainFrame(); |
429 |
return main.confirmDialog(message, title, optionType, messageType);
|
430 |
} |
431 |
|
432 |
public String inputDialog(String message, String title, int messageType, |
433 |
String initialValue) {
|
434 |
MainFrame main = PluginServices.getMainFrame(); |
435 |
return main.inputDialog(message, title, messageType, initialValue);
|
436 |
} |
437 |
|
438 |
public String inputDialog(String message, String title) { |
439 |
MainFrame main = PluginServices.getMainFrame(); |
440 |
return main.inputDialog(message, title);
|
441 |
} |
442 |
|
443 |
public void showDialog(Component contents, String title) { |
444 |
MainFrame main = PluginServices.getMainFrame(); |
445 |
main.showDialog(contents, title); |
446 |
} |
447 |
|
448 |
public Component createComponent(Class<? extends Component> theClass, |
449 |
Object... parameters) {
|
450 |
MainFrame main = PluginServices.getMainFrame(); |
451 |
return main.createComponentWithParams(theClass, parameters);
|
452 |
} |
453 |
|
454 |
public Component createComponentWithParams( |
455 |
Class<? extends Component> theClass, Object[] parameters) { |
456 |
MainFrame main = PluginServices.getMainFrame(); |
457 |
return main.createComponentWithParams(theClass, parameters);
|
458 |
} |
459 |
|
460 |
|
461 |
public File[] showChooserDialog( |
462 |
final String title, |
463 |
final int type, // SAVE_DIALOG / OPEN_DIALOG |
464 |
final int selectionMode, // JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES |
465 |
final boolean multiselection, |
466 |
final File initialPath, |
467 |
final FileFilter filter, |
468 |
final boolean fileHidingEnabled |
469 |
) { |
470 |
MainFrame main = PluginServices.getMainFrame(); |
471 |
return main.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled);
|
472 |
} |
473 |
|
474 |
public File[] showOpenDirectoryDialog(String title, File initialPath) { |
475 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false); |
476 |
} |
477 |
|
478 |
|
479 |
public File[] showOpenFileDialog(String title, File initialPath) { |
480 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
481 |
} |
482 |
|
483 |
|
484 |
public File[] showSaveFileDialog(String title, File initialPath) { |
485 |
return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
486 |
} |
487 |
|
488 |
public String translate(String message, String... args) { |
489 |
return org.gvsig.i18n.Messages.translate(message, args);
|
490 |
} |
491 |
|
492 |
public Component getRootComponent() { |
493 |
return (Component) PluginServices.getMainFrame(); |
494 |
} |
495 |
|
496 |
public void refreshMenusAndToolBars() { |
497 |
PluginServices.getMainFrame().refreshControls(); |
498 |
} |
499 |
|
500 |
|
501 |
} |