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