svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / imp / DefaultAppgvSIGManager.java @ 34300
History | View | Annotate | Download (8.93 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 |
import java.util.prefs.Preferences; |
37 |
|
38 |
import org.cresques.cts.IProjection; |
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.MDIManager; |
44 |
import org.gvsig.app.ApplicationManager; |
45 |
import org.gvsig.app.PreferencesNode; |
46 |
import org.gvsig.app.extension.Version; |
47 |
import org.gvsig.app.gui.WizardPanel; |
48 |
import org.gvsig.app.prepareAction.PrepareContext; |
49 |
import org.gvsig.app.prepareAction.PrepareContextView; |
50 |
import org.gvsig.app.prepareAction.PrepareDataStore; |
51 |
import org.gvsig.app.prepareAction.PrepareDataStoreParameters; |
52 |
import org.gvsig.app.prepareAction.PrepareLayer; |
53 |
import org.gvsig.app.project.DefaultProject; |
54 |
import org.gvsig.app.project.Project; |
55 |
import org.gvsig.app.project.ProjectManager; |
56 |
import org.gvsig.fmap.crs.CRSFactory; |
57 |
import org.gvsig.fmap.dal.DALLocator; |
58 |
import org.gvsig.fmap.dal.DataManager; |
59 |
import org.gvsig.fmap.dal.DataStore; |
60 |
import org.gvsig.fmap.dal.DataStoreParameters; |
61 |
import org.gvsig.fmap.geom.GeometryLocator; |
62 |
import org.gvsig.fmap.geom.GeometryManager; |
63 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
64 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
65 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
66 |
import org.gvsig.gui.IColorTablesFactory; |
67 |
import org.gvsig.tools.ToolsLocator; |
68 |
import org.gvsig.tools.dispose.DisposableManager; |
69 |
import org.gvsig.tools.dynobject.DynObjectManager; |
70 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
71 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
72 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
73 |
import org.gvsig.tools.persistence.PersistenceManager; |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
/**
|
79 |
* @author jmvivo
|
80 |
*
|
81 |
*/
|
82 |
public class DefaultAppgvSIGManager implements ApplicationManager { |
83 |
|
84 |
private static final String EPNAME_PREPARE_OPEN_DATASTORE = "org.gvsig.datastore.open.prepare"; //"PrepareOpenDataStore"; |
85 |
private static final String EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS = "org.gvsig.datastoreparameters.open.prepare"; //"PrepareOpenDataStoreParameters"; |
86 |
private static final String EPNAME_PREPARE_OPEN_LAYER = "org.gvsig.layer.open.prepare"; // "PrepareOpenLayer"; |
87 |
|
88 |
private static final String EPNAME_ADD_TABLE_WIZARD = "AddLayerWizard"; |
89 |
|
90 |
private ExtensionPointManager epManager;
|
91 |
private IColorTablesFactory factory;
|
92 |
|
93 |
|
94 |
|
95 |
public DefaultAppgvSIGManager() {
|
96 |
epManager = ToolsLocator.getExtensionPointManager(); |
97 |
epManager.add(EPNAME_PREPARE_OPEN_DATASTORE, |
98 |
"Actions to do when open a DataStore");
|
99 |
epManager.add(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS, |
100 |
"Actions to do before open a DataStore with parameters");
|
101 |
epManager.add(EPNAME_PREPARE_OPEN_LAYER, |
102 |
"Actions to do after create a Layer");
|
103 |
epManager.add(EPNAME_ADD_TABLE_WIZARD, |
104 |
"Wizards to add new document table");
|
105 |
|
106 |
} |
107 |
|
108 |
/* (non-Javadoc)
|
109 |
* @see org.gvsig.appGvSigManager#pepareOpenDataSource(org.gvsig.fmap.dal.DataStore)
|
110 |
*/
|
111 |
@SuppressWarnings("unchecked") |
112 |
public DataStore pepareOpenDataSource(DataStore store,
|
113 |
PrepareContext context) throws Exception { |
114 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
115 |
if (ep.getCount() == 0) { |
116 |
return store;
|
117 |
} |
118 |
DataStore result = store; |
119 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
120 |
PrepareDataStore prepare; |
121 |
while (iter.hasNext()) {
|
122 |
prepare = (PrepareDataStore) iter.next().create(); |
123 |
result = prepare.prepare(store, context); |
124 |
} |
125 |
return result;
|
126 |
} |
127 |
|
128 |
/* (non-Javadoc)
|
129 |
* @see org.gvsig.appGvSigManager#prepareOpenDataStoreParameters(org.gvsig.fmap.dal.DataStoreParameters)
|
130 |
*/
|
131 |
@SuppressWarnings("unchecked") |
132 |
public DataStoreParameters prepareOpenDataStoreParameters(
|
133 |
DataStoreParameters storeParameters, PrepareContext context) |
134 |
throws Exception { |
135 |
|
136 |
ExtensionPoint ep = epManager |
137 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
138 |
if (ep.getCount() == 0) { |
139 |
return storeParameters;
|
140 |
} |
141 |
DataStoreParameters result = storeParameters; |
142 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
143 |
PrepareDataStoreParameters prepare; |
144 |
while (iter.hasNext()) {
|
145 |
prepare = (PrepareDataStoreParameters) iter.next().create(); |
146 |
result = prepare.prepare(storeParameters, context); |
147 |
} |
148 |
|
149 |
return result;
|
150 |
} |
151 |
|
152 |
public void registerPrepareOpenDataStore(PrepareDataStore action) { |
153 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
154 |
ep.append(action.getName(), action.getDescription(), action); |
155 |
} |
156 |
|
157 |
public void registerPrepareOpenDataStoreParameters( |
158 |
PrepareDataStoreParameters action) { |
159 |
ExtensionPoint ep = epManager |
160 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
161 |
ep.append(action.getName(), action.getDescription(), action); |
162 |
|
163 |
|
164 |
} |
165 |
|
166 |
@SuppressWarnings("unchecked") |
167 |
public FLayer prepareOpenLayer(FLayer layer,
|
168 |
PrepareContextView context) |
169 |
throws Exception { |
170 |
|
171 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
172 |
|
173 |
if (ep.getCount() == 0) { |
174 |
return layer;
|
175 |
} |
176 |
FLayer result = layer; |
177 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
178 |
PrepareLayer prepare; |
179 |
while (iter.hasNext()) {
|
180 |
prepare = (PrepareLayer) iter.next().create(); |
181 |
result = prepare.prepare(layer, context); |
182 |
} |
183 |
|
184 |
return result;
|
185 |
|
186 |
} |
187 |
|
188 |
public void registerPrepareOpenLayer(PrepareLayer action) { |
189 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
190 |
ep.append(action.getName(), action.getDescription(), action); |
191 |
} |
192 |
|
193 |
public void registerAddTableWizard(String name, String description, |
194 |
Class<? extends WizardPanel> wpClass) { |
195 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
196 |
ep.append(name, description, wpClass); |
197 |
} |
198 |
|
199 |
@SuppressWarnings("unchecked") |
200 |
public List<WizardPanel> getWizardPanels() throws Exception { |
201 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
202 |
List<WizardPanel> result = new ArrayList<WizardPanel>(); |
203 |
Iterator<Extension> iter = ep.iterator();
|
204 |
while (iter.hasNext()) {
|
205 |
result.add((WizardPanel) iter.next().create()); |
206 |
} |
207 |
return result;
|
208 |
} |
209 |
|
210 |
public DataManager getDataManager() {
|
211 |
return DALLocator.getDataManager();
|
212 |
} |
213 |
|
214 |
public GeometryManager getGeometryManager() {
|
215 |
return GeometryLocator.getGeometryManager();
|
216 |
} |
217 |
|
218 |
public PersistenceManager getPersistenceManager() {
|
219 |
return ToolsLocator.getPersistenceManager();
|
220 |
} |
221 |
|
222 |
public DisposableManager getDisposableManager() {
|
223 |
return ToolsLocator.getDisposableManager();
|
224 |
} |
225 |
|
226 |
public DynObjectManager getDynObjectManager() {
|
227 |
return ToolsLocator.getDynObjectManager();
|
228 |
} |
229 |
|
230 |
public ExtensionPointManager getExtensionPointManager() {
|
231 |
return ToolsLocator.getExtensionPointManager();
|
232 |
} |
233 |
|
234 |
public ProjectManager getProjectManager() {
|
235 |
return ProjectManager.getInstance();
|
236 |
} |
237 |
|
238 |
public MDIManager getUIManager() {
|
239 |
return PluginServices.getMDIManager();
|
240 |
} |
241 |
|
242 |
public MapContextManager getMapContextManager() {
|
243 |
return MapContextLocator.getMapContextManager();
|
244 |
} |
245 |
|
246 |
public IProjection getCRS(String code) { |
247 |
return CRSFactory.getCRS(code);
|
248 |
} |
249 |
|
250 |
public IconThemeManager getIconThemeManager() {
|
251 |
return IconThemeManager.getIconThemeManager();
|
252 |
} |
253 |
|
254 |
public String getArgument(String name) { |
255 |
return PluginServices.getArgumentByName(name);
|
256 |
} |
257 |
|
258 |
public String[] getArguments() { |
259 |
return PluginServices.getArguments();
|
260 |
} |
261 |
|
262 |
public String getFromClipboard() { |
263 |
return PluginServices.getFromClipboard();
|
264 |
} |
265 |
|
266 |
public void putInClipboard(String data) { |
267 |
PluginServices.putInClipboard(data); |
268 |
} |
269 |
|
270 |
public Project getCurrentProject() {
|
271 |
return ProjectManager.getInstance().getCurrentProject();
|
272 |
} |
273 |
|
274 |
public PreferencesNode getPreferences(String node) { |
275 |
if( node.equalsIgnoreCase("project")) { |
276 |
return DefaultProject.getPreferences();
|
277 |
} |
278 |
return new DefaultPreferencesNode(node); |
279 |
} |
280 |
|
281 |
public PreferencesNode getPreferences() {
|
282 |
return new DefaultPreferencesNode(); |
283 |
} |
284 |
|
285 |
public Version getVersion() {
|
286 |
return new Version(); |
287 |
} |
288 |
|
289 |
public AboutManager getAbout() {
|
290 |
AboutManager manager = AboutLocator.getManager(); |
291 |
return manager;
|
292 |
} |
293 |
|
294 |
public IColorTablesFactory getColorTablesFactory() {
|
295 |
return this.factory; |
296 |
} |
297 |
|
298 |
public void registerColorTablesFactory(IColorTablesFactory factory) { |
299 |
this.factory = factory;
|
300 |
|
301 |
} |
302 |
} |