svn-gvsig-desktop / tags / v2_0_0_Build_2040 / applications / appgvSIG / src / org / gvsig / app / imp / DefaultAppgvSIGManager.java @ 37235
History | View | Annotate | Download (12.3 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 org.cresques.cts.IProjection; |
38 |
import org.gvsig.about.AboutLocator; |
39 |
import org.gvsig.about.AboutManager; |
40 |
import org.gvsig.andami.Launcher; |
41 |
import org.gvsig.andami.PluginServices; |
42 |
import org.gvsig.andami.iconthemes.IconThemeManager; |
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.IColorTablesFactory; |
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 |
|
80 |
|
81 |
|
82 |
|
83 |
/**
|
84 |
* @author jmvivo
|
85 |
*
|
86 |
*/
|
87 |
public class DefaultAppgvSIGManager implements ApplicationManager { |
88 |
|
89 |
private static final String EPNAME_PREPARE_OPEN_DATASTORE = "org.gvsig.datastore.open.prepare"; //"PrepareOpenDataStore"; |
90 |
private static final String EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS = "org.gvsig.datastoreparameters.open.prepare"; //"PrepareOpenDataStoreParameters"; |
91 |
private static final String EPNAME_PREPARE_OPEN_LAYER = "org.gvsig.layer.open.prepare"; // "PrepareOpenLayer"; |
92 |
|
93 |
private static final String EPNAME_ADD_TABLE_WIZARD = "AddLayerWizard"; |
94 |
|
95 |
private ExtensionPointManager epManager;
|
96 |
|
97 |
private Version version;
|
98 |
|
99 |
public DefaultAppgvSIGManager() {
|
100 |
epManager = ToolsLocator.getExtensionPointManager(); |
101 |
epManager.add(EPNAME_PREPARE_OPEN_DATASTORE, |
102 |
"Actions to do when open a DataStore");
|
103 |
epManager.add(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS, |
104 |
"Actions to do before open a DataStore with parameters");
|
105 |
epManager.add(EPNAME_PREPARE_OPEN_LAYER, |
106 |
"Actions to do after create a Layer");
|
107 |
epManager.add(EPNAME_ADD_TABLE_WIZARD, |
108 |
"Wizards to add new document table");
|
109 |
|
110 |
version = new Version();
|
111 |
} |
112 |
|
113 |
/* (non-Javadoc)
|
114 |
* @see org.gvsig.appGvSigManager#pepareOpenDataSource(org.gvsig.fmap.dal.DataStore)
|
115 |
*/
|
116 |
@SuppressWarnings("unchecked") |
117 |
public DataStore pepareOpenDataSource(DataStore store,
|
118 |
PrepareContext context) throws Exception { |
119 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
120 |
if (ep.getCount() == 0) { |
121 |
return store;
|
122 |
} |
123 |
DataStore result = store; |
124 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
125 |
PrepareDataStore prepare; |
126 |
while (iter.hasNext()) {
|
127 |
prepare = (PrepareDataStore) iter.next().create(); |
128 |
result = prepare.prepare(store, context); |
129 |
} |
130 |
return result;
|
131 |
} |
132 |
|
133 |
/* (non-Javadoc)
|
134 |
* @see org.gvsig.appGvSigManager#prepareOpenDataStoreParameters(org.gvsig.fmap.dal.DataStoreParameters)
|
135 |
*/
|
136 |
@SuppressWarnings("unchecked") |
137 |
public DataStoreParameters prepareOpenDataStoreParameters(
|
138 |
DataStoreParameters storeParameters, PrepareContext context) |
139 |
throws Exception { |
140 |
|
141 |
ExtensionPoint ep = epManager |
142 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
143 |
if (ep.getCount() == 0) { |
144 |
return storeParameters;
|
145 |
} |
146 |
DataStoreParameters result = storeParameters; |
147 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
148 |
PrepareDataStoreParameters prepare; |
149 |
while (iter.hasNext()) {
|
150 |
prepare = (PrepareDataStoreParameters) iter.next().create(); |
151 |
result = prepare.prepare(storeParameters, context); |
152 |
} |
153 |
|
154 |
return result;
|
155 |
} |
156 |
|
157 |
/*
|
158 |
* (non-Javadoc)
|
159 |
* @see org.gvsig.app.ApplicationManager#prepareOpenDataStoreParameters(java.util.List, org.gvsig.app.prepareAction.PrepareContext)
|
160 |
*/
|
161 |
@SuppressWarnings("unchecked") |
162 |
public List<DataStoreParameters> prepareOpenDataStoreParameters( |
163 |
List<DataStoreParameters> storeParameters, PrepareContext context)
|
164 |
throws Exception { |
165 |
|
166 |
ExtensionPoint ep = epManager |
167 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
168 |
if (ep.getCount() == 0) { |
169 |
return storeParameters;
|
170 |
} |
171 |
|
172 |
List<DataStoreParameters> result = new ArrayList<DataStoreParameters>(); |
173 |
|
174 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
175 |
List<PrepareDataStoreParameters> prepareList = new ArrayList<PrepareDataStoreParameters>(); |
176 |
while (iter.hasNext()) {
|
177 |
prepareList.add((PrepareDataStoreParameters) iter.next().create()); |
178 |
} |
179 |
|
180 |
for (int i = 0; i < storeParameters.size(); i++) { |
181 |
DataStoreParameters param = storeParameters.get(i); |
182 |
for (int j = 0; j < prepareList.size(); j++) { |
183 |
prepareList.get(j).pre(param, context); |
184 |
} |
185 |
} |
186 |
|
187 |
for (int i = 0; i < storeParameters.size(); i++) { |
188 |
DataStoreParameters param = storeParameters.get(i); |
189 |
if(param != null) { |
190 |
for (int j = 0; j < prepareList.size(); j++) { |
191 |
param = prepareList.get(j).prepare(param, context); |
192 |
if(param == null) |
193 |
break;
|
194 |
} |
195 |
if(param != null) |
196 |
result.add(param); |
197 |
} |
198 |
} |
199 |
|
200 |
for (int i = 0; i < storeParameters.size(); i++) { |
201 |
DataStoreParameters param = storeParameters.get(i); |
202 |
for (int j = 0; j < prepareList.size(); j++) { |
203 |
prepareList.get(j).post(param, context); |
204 |
} |
205 |
} |
206 |
|
207 |
return result;
|
208 |
} |
209 |
|
210 |
public void registerPrepareOpenDataStore(PrepareDataStore action) { |
211 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
212 |
ep.append(action.getName(), action.getDescription(), action); |
213 |
} |
214 |
|
215 |
public void registerPrepareOpenDataStoreParameters( |
216 |
PrepareDataStoreParameters action) { |
217 |
ExtensionPoint ep = epManager |
218 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
219 |
ep.append(action.getName(), action.getDescription(), action); |
220 |
|
221 |
|
222 |
} |
223 |
|
224 |
@SuppressWarnings("unchecked") |
225 |
public FLayer prepareOpenLayer(FLayer layer,
|
226 |
PrepareContextView context) |
227 |
throws Exception { |
228 |
|
229 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
230 |
|
231 |
if (ep.getCount() == 0) { |
232 |
return layer;
|
233 |
} |
234 |
FLayer result = layer; |
235 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
236 |
PrepareLayer prepare; |
237 |
while (iter.hasNext()) {
|
238 |
prepare = (PrepareLayer) iter.next().create(); |
239 |
result = prepare.prepare(layer, context); |
240 |
} |
241 |
|
242 |
return result;
|
243 |
|
244 |
} |
245 |
|
246 |
public void registerPrepareOpenLayer(PrepareLayer action) { |
247 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
248 |
ep.append(action.getName(), action.getDescription(), action); |
249 |
} |
250 |
|
251 |
public void registerAddTableWizard(String name, String description, |
252 |
Class<? extends WizardPanel> wpClass) { |
253 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
254 |
ep.append(name, description, wpClass); |
255 |
} |
256 |
|
257 |
@SuppressWarnings("unchecked") |
258 |
public List<WizardPanel> getWizardPanels() throws Exception { |
259 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
260 |
List<WizardPanel> result = new ArrayList<WizardPanel>(); |
261 |
Iterator<Extension> iter = ep.iterator();
|
262 |
while (iter.hasNext()) {
|
263 |
result.add((WizardPanel) iter.next().create()); |
264 |
} |
265 |
return result;
|
266 |
} |
267 |
|
268 |
public DataManager getDataManager() {
|
269 |
return DALLocator.getDataManager();
|
270 |
} |
271 |
|
272 |
public GeometryManager getGeometryManager() {
|
273 |
return GeometryLocator.getGeometryManager();
|
274 |
} |
275 |
|
276 |
public PersistenceManager getPersistenceManager() {
|
277 |
return ToolsLocator.getPersistenceManager();
|
278 |
} |
279 |
|
280 |
public DisposableManager getDisposableManager() {
|
281 |
return ToolsLocator.getDisposableManager();
|
282 |
} |
283 |
|
284 |
public DynObjectManager getDynObjectManager() {
|
285 |
return ToolsLocator.getDynObjectManager();
|
286 |
} |
287 |
|
288 |
public ExtensionPointManager getExtensionPointManager() {
|
289 |
return ToolsLocator.getExtensionPointManager();
|
290 |
} |
291 |
|
292 |
public ProjectManager getProjectManager() {
|
293 |
return ProjectManager.getInstance();
|
294 |
} |
295 |
|
296 |
public MDIManager getUIManager() {
|
297 |
return PluginServices.getMDIManager();
|
298 |
} |
299 |
|
300 |
public MapContextManager getMapContextManager() {
|
301 |
return MapContextLocator.getMapContextManager();
|
302 |
} |
303 |
|
304 |
public DataTypesManager getDataTypesManager() {
|
305 |
return ToolsLocator.getDataTypesManager();
|
306 |
} |
307 |
|
308 |
public IProjection getCRS(String code) { |
309 |
return CRSFactory.getCRS(code);
|
310 |
} |
311 |
|
312 |
public IconThemeManager getIconThemeManager() {
|
313 |
return IconThemeManager.getIconThemeManager();
|
314 |
} |
315 |
|
316 |
public String getArgument(String name) { |
317 |
return PluginServices.getArgumentByName(name);
|
318 |
} |
319 |
|
320 |
public String[] getArguments() { |
321 |
return PluginServices.getArguments();
|
322 |
} |
323 |
|
324 |
public String getFromClipboard() { |
325 |
return PluginServices.getFromClipboard();
|
326 |
} |
327 |
|
328 |
public void putInClipboard(String data) { |
329 |
PluginServices.putInClipboard(data); |
330 |
} |
331 |
|
332 |
public Project getCurrentProject() {
|
333 |
return ProjectManager.getInstance().getCurrentProject();
|
334 |
} |
335 |
|
336 |
public PreferencesNode getPreferences(String node) { |
337 |
if( node.equalsIgnoreCase("project")) { |
338 |
return DefaultProject.getPreferences();
|
339 |
} |
340 |
return new DefaultPreferencesNode(node); |
341 |
} |
342 |
|
343 |
public PreferencesNode getPreferences() {
|
344 |
return new DefaultPreferencesNode(); |
345 |
} |
346 |
|
347 |
public Version getVersion() {
|
348 |
return version;
|
349 |
} |
350 |
|
351 |
public AboutManager getAbout() {
|
352 |
AboutManager manager = AboutLocator.getManager(); |
353 |
return manager;
|
354 |
} |
355 |
|
356 |
public IColorTablesFactory getColorTablesFactory() {
|
357 |
return SymbologySwingLocator.getSwingManager().getColorTablesFactory();
|
358 |
} |
359 |
|
360 |
public void registerColorTablesFactory(IColorTablesFactory factory) { |
361 |
SymbologySwingLocator.getSwingManager().setColorTablesFactory(factory); |
362 |
|
363 |
} |
364 |
|
365 |
public IWindow getActiveWindow() {
|
366 |
try {
|
367 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
368 |
return window;
|
369 |
} catch (Exception ex) { |
370 |
return null; |
371 |
} |
372 |
} |
373 |
|
374 |
public Document getActiveDocument() { |
375 |
Project project = this.getCurrentProject();
|
376 |
if( project == null ) { |
377 |
return null; |
378 |
} |
379 |
return project.getActiveDocument();
|
380 |
} |
381 |
|
382 |
public Document getActiveDocument(String documentTypeName) { |
383 |
Document document = this.getActiveDocument(); |
384 |
if( document!= null && document.getTypeName().equalsIgnoreCase(documentTypeName) ) { |
385 |
return document;
|
386 |
} |
387 |
return null; |
388 |
} |
389 |
|
390 |
public Document getActiveDocument(Class<? extends Document> documentClass) { |
391 |
Document document = this.getActiveDocument(); |
392 |
if( documentClass.isInstance(document) ) {
|
393 |
return document;
|
394 |
} |
395 |
return null; |
396 |
} |
397 |
|
398 |
public IDocumentWindow getDocumentWindow(Document document) { |
399 |
Class<? extends IDocumentWindow> defaultDocumentClass = |
400 |
document.getFactory().getMainWindowClass(); |
401 |
return (IDocumentWindow) this.getUIManager().getSingletonWindow(defaultDocumentClass, document); |
402 |
} |
403 |
|
404 |
public String getLocaleLanguage() { |
405 |
return Launcher.getAndamiConfig().getLocaleLanguage();
|
406 |
} |
407 |
|
408 |
} |