root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / imp / DefaultAppGvSigManager.java @ 30118
History | View | Annotate | Download (5.52 KB)
1 | 26919 | jmvivo | /* 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 | 29598 | jpiera | package org.gvsig.app.imp; |
32 | 26919 | jmvivo | |
33 | import java.util.ArrayList; |
||
34 | import java.util.Iterator; |
||
35 | import java.util.List; |
||
36 | |||
37 | 29598 | jpiera | import org.gvsig.app.AppGvSigManager; |
38 | import org.gvsig.app.PrepareContext; |
||
39 | import org.gvsig.app.PrepareContextView; |
||
40 | import org.gvsig.app.PrepareDataStore; |
||
41 | import org.gvsig.app.PrepareDataStoreParameters; |
||
42 | import org.gvsig.app.PrepareLayer; |
||
43 | import org.gvsig.app.gui.WizardPanel; |
||
44 | 26919 | jmvivo | import org.gvsig.fmap.dal.DataStore; |
45 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
46 | 26932 | jmvivo | import org.gvsig.fmap.mapcontext.layers.FLayer; |
47 | 29197 | jmvivo | import org.gvsig.tools.ToolsLocator; |
48 | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
||
49 | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
||
50 | import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
||
51 | 26919 | jmvivo | |
52 | |||
53 | |||
54 | 29197 | jmvivo | |
55 | 26919 | jmvivo | /**
|
56 | * @author jmvivo
|
||
57 | *
|
||
58 | */
|
||
59 | public class DefaultAppGvSigManager implements AppGvSigManager { |
||
60 | |||
61 | 29197 | jmvivo | private static final String EPNAME_PREPARE_OPEN_DATASTORE = "PrepareOpenDataStore"; |
62 | private static final String EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS = "PrepareOpenDataStoreParameters"; |
||
63 | private static final String EPNAME_PREPARE_OPEN_LAYER = "PrepareOpenLayer"; |
||
64 | 26919 | jmvivo | |
65 | 29197 | jmvivo | private static final String EPNAME_ADD_TABLE_WIZARD = "AddLayerWizard"; |
66 | |||
67 | private ExtensionPointManager epManager;
|
||
68 | |||
69 | |||
70 | |||
71 | 26919 | jmvivo | public DefaultAppGvSigManager() {
|
72 | 29197 | jmvivo | epManager = ToolsLocator.getExtensionPointManager(); |
73 | epManager.add(EPNAME_PREPARE_OPEN_DATASTORE, |
||
74 | "Actions to do when open a DataStore");
|
||
75 | epManager.add(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS, |
||
76 | "Actions to do before open a DataStore with parameters");
|
||
77 | epManager.add(EPNAME_PREPARE_OPEN_LAYER, |
||
78 | "Actions to do after create a Layer");
|
||
79 | epManager.add(EPNAME_ADD_TABLE_WIZARD, |
||
80 | "Wizards to add new document table");
|
||
81 | |||
82 | 26919 | jmvivo | } |
83 | |||
84 | /* (non-Javadoc)
|
||
85 | * @see org.gvsig.appGvSigManager#pepareOpenDataSource(org.gvsig.fmap.dal.DataStore)
|
||
86 | */
|
||
87 | public DataStore pepareOpenDataSource(DataStore store,
|
||
88 | 29197 | jmvivo | PrepareContext context) throws Exception { |
89 | ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
||
90 | if (ep.getCount() == 0) { |
||
91 | 26919 | jmvivo | return store;
|
92 | } |
||
93 | DataStore result = store; |
||
94 | 29197 | jmvivo | Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
95 | PrepareDataStore prepare; |
||
96 | 26919 | jmvivo | while (iter.hasNext()) {
|
97 | 29197 | jmvivo | prepare = (PrepareDataStore) iter.next().create(); |
98 | result = prepare.prepare(store, context); |
||
99 | 26919 | jmvivo | } |
100 | return result;
|
||
101 | } |
||
102 | |||
103 | /* (non-Javadoc)
|
||
104 | * @see org.gvsig.appGvSigManager#prepareOpenDataStoreParameters(org.gvsig.fmap.dal.DataStoreParameters)
|
||
105 | */
|
||
106 | public DataStoreParameters prepareOpenDataStoreParameters(
|
||
107 | 29197 | jmvivo | DataStoreParameters storeParameters, PrepareContext context) |
108 | throws Exception { |
||
109 | |||
110 | ExtensionPoint ep = epManager |
||
111 | .get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
||
112 | if (ep.getCount() == 0) { |
||
113 | 26919 | jmvivo | return storeParameters;
|
114 | } |
||
115 | DataStoreParameters result = storeParameters; |
||
116 | 29197 | jmvivo | Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
117 | PrepareDataStoreParameters prepare; |
||
118 | 26919 | jmvivo | while (iter.hasNext()) {
|
119 | 29197 | jmvivo | prepare = (PrepareDataStoreParameters) iter.next().create(); |
120 | result = prepare.prepare(storeParameters, context); |
||
121 | 26919 | jmvivo | } |
122 | 29197 | jmvivo | |
123 | 26919 | jmvivo | return result;
|
124 | } |
||
125 | |||
126 | public void registerPrepareOpenDataStore(PrepareDataStore action) { |
||
127 | 29197 | jmvivo | ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
128 | ep.append(action.getName(), action.getDescription(), action); |
||
129 | 26919 | jmvivo | } |
130 | |||
131 | public void registerPrepareOpenDataStoreParameters( |
||
132 | PrepareDataStoreParameters action) { |
||
133 | 29197 | jmvivo | ExtensionPoint ep = epManager |
134 | .get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
||
135 | ep.append(action.getName(), action.getDescription(), action); |
||
136 | 26919 | jmvivo | |
137 | 29197 | jmvivo | |
138 | 26919 | jmvivo | } |
139 | |||
140 | 26932 | jmvivo | public FLayer prepareOpenLayer(FLayer layer,
|
141 | 29197 | jmvivo | PrepareContextView context) |
142 | throws Exception { |
||
143 | |||
144 | ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
||
145 | |||
146 | if (ep.getCount() == 0) { |
||
147 | 26932 | jmvivo | return layer;
|
148 | } |
||
149 | FLayer result = layer; |
||
150 | 29197 | jmvivo | Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
151 | PrepareLayer prepare; |
||
152 | 26932 | jmvivo | while (iter.hasNext()) {
|
153 | 29197 | jmvivo | prepare = (PrepareLayer) iter.next().create(); |
154 | result = prepare.prepare(layer, context); |
||
155 | 26932 | jmvivo | } |
156 | 29197 | jmvivo | |
157 | 26932 | jmvivo | return result;
|
158 | |||
159 | } |
||
160 | |||
161 | public void registerPrepareOpenLayer(PrepareLayer action) { |
||
162 | 29197 | jmvivo | ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
163 | ep.append(action.getName(), action.getDescription(), action); |
||
164 | 26932 | jmvivo | } |
165 | |||
166 | 29197 | jmvivo | public void registerAddTableWizard(String name, String description, |
167 | Class<? extends WizardPanel> wpClass) { |
||
168 | ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
||
169 | ep.append(name, description, wpClass); |
||
170 | } |
||
171 | |||
172 | public List<WizardPanel> getWizardPanels() throws Exception { |
||
173 | ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
||
174 | List<WizardPanel> result = new ArrayList<WizardPanel>(); |
||
175 | Iterator<Extension> iter = ep.iterator();
|
||
176 | while (iter.hasNext()) {
|
||
177 | result.add((WizardPanel) iter.next().create()); |
||
178 | } |
||
179 | return result;
|
||
180 | } |
||
181 | 26919 | jmvivo | } |