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