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