root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / imp / DefaultAppgvSIGManager.java @ 38537
History | View | Annotate | Download (13.5 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.util.ArrayList; |
34 |
import java.util.Iterator; |
35 |
import java.util.List; |
36 |
|
37 |
import javax.swing.JOptionPane; |
38 |
|
39 |
import org.cresques.cts.IProjection; |
40 |
import org.slf4j.Logger; |
41 |
import org.slf4j.LoggerFactory; |
42 |
|
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.iconthemes.IconThemeManager; |
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 |
|
85 |
|
86 |
|
87 |
|
88 |
/**
|
89 |
* @author jmvivo
|
90 |
*
|
91 |
*/
|
92 |
public class DefaultAppgvSIGManager implements ApplicationManager { |
93 |
|
94 |
private static Logger logger = LoggerFactory.getLogger(DefaultAppgvSIGManager.class); |
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 IconThemeManager.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 |
Project project = this.getCurrentProject();
|
382 |
if( project == null ) { |
383 |
return null; |
384 |
} |
385 |
return project.getActiveDocument();
|
386 |
} |
387 |
|
388 |
public Document getActiveDocument(String documentTypeName) { |
389 |
Document document = this.getActiveDocument(); |
390 |
if( document!= null && document.getTypeName().equalsIgnoreCase(documentTypeName) ) { |
391 |
return document;
|
392 |
} |
393 |
return null; |
394 |
} |
395 |
|
396 |
public Document getActiveDocument(Class<? extends Document> documentClass) { |
397 |
Document document = this.getActiveDocument(); |
398 |
if( documentClass.isInstance(document) ) {
|
399 |
return document;
|
400 |
} |
401 |
return null; |
402 |
} |
403 |
|
404 |
public IDocumentWindow getDocumentWindow(Document document) { |
405 |
Class<? extends IDocumentWindow> defaultDocumentClass = |
406 |
document.getFactory().getMainWindowClass(); |
407 |
return (IDocumentWindow) this.getUIManager().getSingletonWindow(defaultDocumentClass, document); |
408 |
} |
409 |
|
410 |
public String getLocaleLanguage() { |
411 |
return Launcher.getAndamiConfig().getLocaleLanguage();
|
412 |
} |
413 |
|
414 |
/* (non-Javadoc)
|
415 |
* @see org.gvsig.app.ApplicationManager#message(java.lang.String, int)
|
416 |
*/
|
417 |
public void message(String message, int message_type) { |
418 |
|
419 |
String msg = message;
|
420 |
if (message.startsWith("_")) { |
421 |
msg = PluginServices.getText(this, message);
|
422 |
} |
423 |
switch (message_type) {
|
424 |
|
425 |
case JOptionPane.ERROR_MESSAGE: |
426 |
PluginServices.getMainFrame().getStatusBar().setErrorText(msg); |
427 |
break;
|
428 |
case JOptionPane.WARNING_MESSAGE: |
429 |
PluginServices.getMainFrame().getStatusBar().setWarningText(msg); |
430 |
break;
|
431 |
default:
|
432 |
try {
|
433 |
throw new IllegalArgumentException("message_type"); |
434 |
} catch (IllegalArgumentException ex) { |
435 |
logger.info("Illegal message type in message()", ex);
|
436 |
|
437 |
} |
438 |
case JOptionPane.INFORMATION_MESSAGE: |
439 |
PluginServices.getMainFrame().getStatusBar().setInfoText(msg); |
440 |
break;
|
441 |
|
442 |
} |
443 |
|
444 |
} |
445 |
} |