svn-gvsig-desktop / trunk / applications / appgvSIG / src / org / gvsig / fmap / swing / impl / toc / DefaultTOCManager.java @ 37876
History | View | Annotate | Download (7.74 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.
|
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., 59 Temple Place - Suite 330,
|
19 |
* Boston, MA 02111-1307, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.fmap.swing.impl.toc; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
import java.util.Iterator; |
26 |
import java.util.List; |
27 |
|
28 |
import com.iver.cit.gvsig.fmap.MapContext; |
29 |
import com.iver.cit.gvsig.project.documents.IContextMenuAction; |
30 |
import com.iver.cit.gvsig.project.documents.view.toc.actions.OldTocContextMenuAction; |
31 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
32 |
|
33 |
import org.gvsig.fmap.swing.toc.TOC; |
34 |
import org.gvsig.fmap.swing.toc.TOCFactory; |
35 |
import org.gvsig.fmap.swing.toc.TOCManager; |
36 |
import org.gvsig.fmap.swing.toc.action.TOCAction; |
37 |
import org.gvsig.fmap.swing.toc.action.TOCActionAdapter; |
38 |
import org.gvsig.fmap.swing.toc.action.TOCActionFactory; |
39 |
import org.gvsig.fmap.swing.toc.action.TOCActionFactoryAdapter; |
40 |
import org.gvsig.tools.ToolsLocator; |
41 |
import org.gvsig.tools.dynobject.DynObject; |
42 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
43 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
44 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
45 |
import org.gvsig.tools.service.Service; |
46 |
import org.gvsig.tools.service.ServiceException; |
47 |
import org.gvsig.tools.service.spi.AbstractServiceManager; |
48 |
import org.gvsig.tools.service.spi.ServiceFactory; |
49 |
|
50 |
/**
|
51 |
* Default implementation of the TOC manager.
|
52 |
*
|
53 |
*
|
54 |
* @author Juan Lucas Dominguez jldominguez prodevelop es
|
55 |
* @version $Id: DefaultTOCManager.java 37876 2012-02-07 15:12:49Z fpenarrubia $
|
56 |
*
|
57 |
*/
|
58 |
public class DefaultTOCManager extends AbstractServiceManager implements |
59 |
TOCManager { |
60 |
|
61 |
@Override
|
62 |
protected String getRegistryKey() { |
63 |
return "DefaultTOCManager"; |
64 |
} |
65 |
|
66 |
@Override
|
67 |
protected String getRegistryDescription() { |
68 |
return "Default TOC Manager"; |
69 |
} |
70 |
|
71 |
public void addServiceFactory(TOCFactory tf) { |
72 |
addServiceFactory((ServiceFactory) tf); |
73 |
} |
74 |
|
75 |
public void addServiceFactory(TOCActionFactory taf) { |
76 |
addServiceFactory((ServiceFactory) taf); |
77 |
} |
78 |
|
79 |
public void addServiceFactory(IContextMenuAction icma) { |
80 |
TOCActionFactoryAdapter ada = new TOCActionFactoryAdapter(icma);
|
81 |
if (icma instanceof OldTocContextMenuAction) { |
82 |
ada.setName(((OldTocContextMenuAction) icma).getEntry().getClass().toString()); |
83 |
} |
84 |
addServiceFactory(ada); |
85 |
} |
86 |
|
87 |
|
88 |
public TOC createTOC(MapContext mc) throws ServiceException { |
89 |
return createTOC(TOCManager.DEFAULT_TOC_STRING, mc);
|
90 |
} |
91 |
|
92 |
|
93 |
public TOC createTOC(String name, MapContext mc) throws ServiceException { |
94 |
|
95 |
DynObject par = createServiceParameters(name); |
96 |
par.setDynValue(TOCFactory.PARAMETER_MAPCONTEXT_KEY, mc); |
97 |
Service svc = createService(par); |
98 |
|
99 |
if (svc instanceof TOC) { |
100 |
return (TOC) svc;
|
101 |
} else {
|
102 |
throw new ServiceException("Service is not a TOC (?): " |
103 |
+ (svc == null ? "" : svc.getClass().getName()), "", -1); |
104 |
} |
105 |
} |
106 |
|
107 |
|
108 |
public List<TOCAction> getActions(TOC t) throws ServiceException { |
109 |
|
110 |
ArrayList<TOCAction> resp = new ArrayList<TOCAction>(); |
111 |
|
112 |
ExtensionPointManager epm = ToolsLocator.getExtensionPointManager(); |
113 |
ExtensionPoint ep = epm.get(getRegistryKey()); |
114 |
Iterator iter = ep.iterator();
|
115 |
Object item = null; |
116 |
Extension ext = null;
|
117 |
TOCActionFactory taf = null;
|
118 |
DynObject dob = null;
|
119 |
Service svc = null;
|
120 |
|
121 |
try {
|
122 |
while (iter.hasNext()) {
|
123 |
item = iter.next(); |
124 |
if (item instanceof Extension) { |
125 |
ext = (Extension) item; |
126 |
item = ext.create(); |
127 |
if (item instanceof TOCActionFactory) { |
128 |
taf = (TOCActionFactory) item; |
129 |
dob = taf.createParameters(); |
130 |
dob.setDynValue(TOCActionFactory.TOC_PARAMETER_KEY, t); |
131 |
svc = taf.create(dob, this);
|
132 |
if (svc instanceof TOCAction) { |
133 |
resp.add((TOCAction) svc); |
134 |
} |
135 |
} |
136 |
} |
137 |
} |
138 |
} catch (Exception ex) { |
139 |
throw new ServiceException(ex.getMessage(), "", -1); |
140 |
} |
141 |
|
142 |
// ===================================================
|
143 |
// old style registrations
|
144 |
// ===================================================
|
145 |
com.iver.utiles.extensionPoints.ExtensionPoint ep_old = |
146 |
(com.iver.utiles.extensionPoints.ExtensionPoint) ExtensionPointsSingleton |
147 |
.getInstance().get("View_TocActions");
|
148 |
|
149 |
// ep = epm.get("View_TocActions");
|
150 |
iter = ep_old.keySet().iterator(); |
151 |
TOCActionAdapter adap = null;
|
152 |
try {
|
153 |
while (iter.hasNext()) {
|
154 |
item = iter.next(); |
155 |
item = ep_old.get(item); |
156 |
if (item instanceof IContextMenuAction) { |
157 |
adap = new TOCActionAdapter((IContextMenuAction) item, t);
|
158 |
resp.add(adap); |
159 |
} |
160 |
} |
161 |
} catch (Exception ex) { |
162 |
throw new ServiceException(ex.getMessage(), "", -1); |
163 |
} |
164 |
|
165 |
return resp;
|
166 |
|
167 |
|
168 |
} |
169 |
|
170 |
|
171 |
public List<TOCFactory> getTOCFactories() throws ServiceException { |
172 |
|
173 |
ExtensionPointManager epm = ToolsLocator.getExtensionPointManager(); |
174 |
ExtensionPoint ep = epm.get(getRegistryKey()); |
175 |
Iterator iter = ep.iterator();
|
176 |
Object item = null; |
177 |
ArrayList<TOCFactory> resp = new ArrayList<TOCFactory>(); |
178 |
Extension ext = null;
|
179 |
|
180 |
while (iter.hasNext()) {
|
181 |
item = iter.next(); |
182 |
if (item instanceof Extension) { |
183 |
ext = (Extension) item; |
184 |
try {
|
185 |
item = ext.create(); |
186 |
if (item instanceof TOCFactory) { |
187 |
resp.add((TOCFactory) item); |
188 |
} |
189 |
} catch (Exception ex) { |
190 |
throw new ServiceException(ex.getMessage(), "", -1); |
191 |
} |
192 |
} |
193 |
} |
194 |
|
195 |
return resp;
|
196 |
} |
197 |
|
198 |
public void setDefaultTOCFactory(TOCFactory tf) throws ServiceException { |
199 |
addServiceFactory(tf); |
200 |
setDefaultTOCFactory(tf.getName()); |
201 |
} |
202 |
|
203 |
public void setDefaultTOCFactory(String name) throws ServiceException { |
204 |
|
205 |
// TOCManager
|
206 |
ExtensionPointManager epm = ToolsLocator.getExtensionPointManager(); |
207 |
ExtensionPoint ep = epm.get(getRegistryKey()); |
208 |
ep.addAlias(name, TOCManager.DEFAULT_TOC_STRING); |
209 |
} |
210 |
|
211 |
public Service getService(DynObject paramDynObject) throws ServiceException { |
212 |
return null; |
213 |
} |
214 |
|
215 |
public TOCFactory getDefaultTOCFactory() throws ServiceException { |
216 |
ExtensionPointManager epm = ToolsLocator.getExtensionPointManager(); |
217 |
ExtensionPoint ep = epm.get(getRegistryKey()); |
218 |
TOCFactory tff = null;
|
219 |
|
220 |
try {
|
221 |
Extension ext = ep.get(TOCManager.DEFAULT_TOC_STRING); |
222 |
tff = (TOCFactory) ext.create(); |
223 |
return tff;
|
224 |
} catch (Exception e) { |
225 |
throw new ServiceException(e.getMessage(), "", -1); |
226 |
} |
227 |
} |
228 |
|
229 |
// ===========
|
230 |
|
231 |
} |