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