svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / imp / DefaultAppgvSIGManager.java @ 36443
History | View | Annotate | Download (10.6 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 |
|
39 |
import org.gvsig.about.AboutLocator; |
40 |
import org.gvsig.about.AboutManager; |
41 |
import org.gvsig.andami.Launcher; |
42 |
import org.gvsig.andami.PluginServices; |
43 |
import org.gvsig.andami.iconthemes.IconThemeManager; |
44 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
45 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
46 |
import org.gvsig.app.ApplicationManager; |
47 |
import org.gvsig.app.PreferencesNode; |
48 |
import org.gvsig.app.extension.Version; |
49 |
import org.gvsig.app.gui.WizardPanel; |
50 |
import org.gvsig.app.prepareAction.PrepareContext; |
51 |
import org.gvsig.app.prepareAction.PrepareContextView; |
52 |
import org.gvsig.app.prepareAction.PrepareDataStore; |
53 |
import org.gvsig.app.prepareAction.PrepareDataStoreParameters; |
54 |
import org.gvsig.app.prepareAction.PrepareLayer; |
55 |
import org.gvsig.app.project.DefaultProject; |
56 |
import org.gvsig.app.project.Project; |
57 |
import org.gvsig.app.project.ProjectManager; |
58 |
import org.gvsig.app.project.documents.Document; |
59 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
60 |
import org.gvsig.fmap.crs.CRSFactory; |
61 |
import org.gvsig.fmap.dal.DALLocator; |
62 |
import org.gvsig.fmap.dal.DataManager; |
63 |
import org.gvsig.fmap.dal.DataStore; |
64 |
import org.gvsig.fmap.dal.DataStoreParameters; |
65 |
import org.gvsig.fmap.geom.GeometryLocator; |
66 |
import org.gvsig.fmap.geom.GeometryManager; |
67 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
68 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
69 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
70 |
import org.gvsig.gui.IColorTablesFactory; |
71 |
import org.gvsig.symbology.swing.SymbologySwingLocator; |
72 |
import org.gvsig.tools.ToolsLocator; |
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 |
public void registerPrepareOpenDataStore(PrepareDataStore action) { |
158 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
159 |
ep.append(action.getName(), action.getDescription(), action); |
160 |
} |
161 |
|
162 |
public void registerPrepareOpenDataStoreParameters( |
163 |
PrepareDataStoreParameters action) { |
164 |
ExtensionPoint ep = epManager |
165 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
166 |
ep.append(action.getName(), action.getDescription(), action); |
167 |
|
168 |
|
169 |
} |
170 |
|
171 |
@SuppressWarnings("unchecked") |
172 |
public FLayer prepareOpenLayer(FLayer layer,
|
173 |
PrepareContextView context) |
174 |
throws Exception { |
175 |
|
176 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
177 |
|
178 |
if (ep.getCount() == 0) { |
179 |
return layer;
|
180 |
} |
181 |
FLayer result = layer; |
182 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
183 |
PrepareLayer prepare; |
184 |
while (iter.hasNext()) {
|
185 |
prepare = (PrepareLayer) iter.next().create(); |
186 |
result = prepare.prepare(layer, context); |
187 |
} |
188 |
|
189 |
return result;
|
190 |
|
191 |
} |
192 |
|
193 |
public void registerPrepareOpenLayer(PrepareLayer action) { |
194 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
195 |
ep.append(action.getName(), action.getDescription(), action); |
196 |
} |
197 |
|
198 |
public void registerAddTableWizard(String name, String description, |
199 |
Class<? extends WizardPanel> wpClass) { |
200 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
201 |
ep.append(name, description, wpClass); |
202 |
} |
203 |
|
204 |
@SuppressWarnings("unchecked") |
205 |
public List<WizardPanel> getWizardPanels() throws Exception { |
206 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
207 |
List<WizardPanel> result = new ArrayList<WizardPanel>(); |
208 |
Iterator<Extension> iter = ep.iterator();
|
209 |
while (iter.hasNext()) {
|
210 |
result.add((WizardPanel) iter.next().create()); |
211 |
} |
212 |
return result;
|
213 |
} |
214 |
|
215 |
public DataManager getDataManager() {
|
216 |
return DALLocator.getDataManager();
|
217 |
} |
218 |
|
219 |
public GeometryManager getGeometryManager() {
|
220 |
return GeometryLocator.getGeometryManager();
|
221 |
} |
222 |
|
223 |
public PersistenceManager getPersistenceManager() {
|
224 |
return ToolsLocator.getPersistenceManager();
|
225 |
} |
226 |
|
227 |
public DisposableManager getDisposableManager() {
|
228 |
return ToolsLocator.getDisposableManager();
|
229 |
} |
230 |
|
231 |
public DynObjectManager getDynObjectManager() {
|
232 |
return ToolsLocator.getDynObjectManager();
|
233 |
} |
234 |
|
235 |
public ExtensionPointManager getExtensionPointManager() {
|
236 |
return ToolsLocator.getExtensionPointManager();
|
237 |
} |
238 |
|
239 |
public ProjectManager getProjectManager() {
|
240 |
return ProjectManager.getInstance();
|
241 |
} |
242 |
|
243 |
public MDIManager getUIManager() {
|
244 |
return PluginServices.getMDIManager();
|
245 |
} |
246 |
|
247 |
public MapContextManager getMapContextManager() {
|
248 |
return MapContextLocator.getMapContextManager();
|
249 |
} |
250 |
|
251 |
public IProjection getCRS(String code) { |
252 |
return CRSFactory.getCRS(code);
|
253 |
} |
254 |
|
255 |
public IconThemeManager getIconThemeManager() {
|
256 |
return IconThemeManager.getIconThemeManager();
|
257 |
} |
258 |
|
259 |
public String getArgument(String name) { |
260 |
return PluginServices.getArgumentByName(name);
|
261 |
} |
262 |
|
263 |
public String[] getArguments() { |
264 |
return PluginServices.getArguments();
|
265 |
} |
266 |
|
267 |
public String getFromClipboard() { |
268 |
return PluginServices.getFromClipboard();
|
269 |
} |
270 |
|
271 |
public void putInClipboard(String data) { |
272 |
PluginServices.putInClipboard(data); |
273 |
} |
274 |
|
275 |
public Project getCurrentProject() {
|
276 |
return ProjectManager.getInstance().getCurrentProject();
|
277 |
} |
278 |
|
279 |
public PreferencesNode getPreferences(String node) { |
280 |
if( node.equalsIgnoreCase("project")) { |
281 |
return DefaultProject.getPreferences();
|
282 |
} |
283 |
return new DefaultPreferencesNode(node); |
284 |
} |
285 |
|
286 |
public PreferencesNode getPreferences() {
|
287 |
return new DefaultPreferencesNode(); |
288 |
} |
289 |
|
290 |
public Version getVersion() {
|
291 |
return version;
|
292 |
} |
293 |
|
294 |
public AboutManager getAbout() {
|
295 |
AboutManager manager = AboutLocator.getManager(); |
296 |
return manager;
|
297 |
} |
298 |
|
299 |
public IColorTablesFactory getColorTablesFactory() {
|
300 |
return SymbologySwingLocator.getSwingManager().getColorTablesFactory();
|
301 |
} |
302 |
|
303 |
public void registerColorTablesFactory(IColorTablesFactory factory) { |
304 |
SymbologySwingLocator.getSwingManager().setColorTablesFactory(factory); |
305 |
|
306 |
} |
307 |
|
308 |
public IWindow getActiveWindow() {
|
309 |
try {
|
310 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
311 |
return window;
|
312 |
} catch (Exception ex) { |
313 |
return null; |
314 |
} |
315 |
} |
316 |
|
317 |
public Document getActiveDocument() { |
318 |
Project project = this.getCurrentProject();
|
319 |
if( project == null ) { |
320 |
return null; |
321 |
} |
322 |
return project.getActiveDocument();
|
323 |
} |
324 |
|
325 |
public Document getActiveDocument(String documentTypeName) { |
326 |
Document document = this.getActiveDocument(); |
327 |
if( document!= null && document.getTypeName().equalsIgnoreCase(documentTypeName) ) { |
328 |
return document;
|
329 |
} |
330 |
return null; |
331 |
} |
332 |
|
333 |
public Document getActiveDocument(Class<? extends Document> documentClass) { |
334 |
Document document = this.getActiveDocument(); |
335 |
if( documentClass.isInstance(document) ) {
|
336 |
return document;
|
337 |
} |
338 |
return null; |
339 |
} |
340 |
|
341 |
public IDocumentWindow getDocumentWindow(Document document) { |
342 |
Class<? extends IDocumentWindow> defaultDocumentClass = |
343 |
document.getFactory().getMainWindowClass(); |
344 |
return (IDocumentWindow) this.getUIManager().getSingletonWindow(defaultDocumentClass, document); |
345 |
} |
346 |
|
347 |
public String getLocaleLanguage() { |
348 |
return Launcher.getAndamiConfig().getLocaleLanguage();
|
349 |
} |
350 |
|
351 |
} |