root / branches / v2_0_0_prep / libraries / org.gvsig.newlayer / org.gvsig.newlayer.lib / org.gvsig.newlayer.lib.impl / src / main / java / org / gvsig / newlayer / impl / DefaultNewLayerManager.java @ 37891
History | View | Annotate | Download (5.65 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 |
package org.gvsig.newlayer.impl; |
23 |
|
24 |
import java.net.URL; |
25 |
import java.util.ArrayList; |
26 |
import java.util.HashMap; |
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
29 |
import java.util.Map; |
30 |
|
31 |
import javax.swing.ImageIcon; |
32 |
|
33 |
import org.slf4j.Logger; |
34 |
import org.slf4j.LoggerFactory; |
35 |
|
36 |
import org.gvsig.fmap.mapcontext.MapContext; |
37 |
import org.gvsig.newlayer.NewLayerManager; |
38 |
import org.gvsig.newlayer.NewLayerProviderFactory; |
39 |
import org.gvsig.newlayer.NewLayerService; |
40 |
import org.gvsig.newlayer.NewLayerWizard; |
41 |
import org.gvsig.newlayer.impl.preferences.DefaultNewLayerPreferencesComponent; |
42 |
import org.gvsig.newlayer.preferences.NewLayerPreferencesComponent; |
43 |
import org.gvsig.tools.ToolsLocator; |
44 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
45 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
46 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
47 |
import org.gvsig.tools.service.ServiceException; |
48 |
|
49 |
/**
|
50 |
* Default {@link NewLayerManager} implementation.
|
51 |
*
|
52 |
* @author gvSIG Team
|
53 |
* @version $Id$
|
54 |
*/
|
55 |
public class DefaultNewLayerManager implements NewLayerManager { |
56 |
|
57 |
private static final Logger LOG = LoggerFactory |
58 |
.getLogger(DefaultNewLayerManager.class); |
59 |
|
60 |
final static private String EP_NEWLAYER_NAME = "NewLayer.manager.providers"; |
61 |
final static private String EP_NEWLAYER_DESCRIPTION = "NewLayer providers"; |
62 |
|
63 |
private Map<NewLayerProviderFactory, Boolean> providerStatus; |
64 |
|
65 |
/**
|
66 |
* Empty constructor.
|
67 |
*/
|
68 |
public DefaultNewLayerManager() {
|
69 |
providerStatus = new HashMap<NewLayerProviderFactory, Boolean>(); |
70 |
} |
71 |
|
72 |
public NewLayerService createNewLayerService(MapContext mapContext) {
|
73 |
return new DefaultNewLayerService(this, mapContext); |
74 |
} |
75 |
|
76 |
public void registerProvider(NewLayerProviderFactory factory) { |
77 |
ExtensionPoint ep = getNewLayerProvidersExtensionPoint(); |
78 |
ep.append(factory.getName(), factory.getDescription(), factory); |
79 |
} |
80 |
|
81 |
public NewLayerWizard createNewLayerWizard(NewLayerService service) {
|
82 |
URL iconURL =
|
83 |
getClass().getClassLoader().getResource( |
84 |
"org/gvsig/newlayer/lib/impl/images/newlayericon.png");
|
85 |
ImageIcon logo = null; |
86 |
if (iconURL != null) { |
87 |
logo = new ImageIcon(iconURL); |
88 |
} |
89 |
|
90 |
return new DefaultNewLayerWizard(logo, service); |
91 |
} |
92 |
|
93 |
public NewLayerProviderFactory getNewLayerProviderFactory(
|
94 |
String providerName) throws ServiceException { |
95 |
ExtensionPoint ep = getNewLayerProvidersExtensionPoint(); |
96 |
try {
|
97 |
return (NewLayerProviderFactory) ep.create(providerName);
|
98 |
} catch (InstantiationException e) { |
99 |
throw new RuntimeException(e); |
100 |
} catch (IllegalAccessException e) { |
101 |
throw new RuntimeException(e); |
102 |
} |
103 |
} |
104 |
|
105 |
public void enableProvider(NewLayerProviderFactory factory, Boolean value) { |
106 |
providerStatus.put(factory, Boolean.valueOf(value));
|
107 |
} |
108 |
|
109 |
public NewLayerPreferencesComponent createNewLayerProvidersPreferences() {
|
110 |
return new DefaultNewLayerPreferencesComponent(); |
111 |
} |
112 |
|
113 |
public List<NewLayerProviderFactory> getProviders() { |
114 |
ExtensionPoint ep = getNewLayerProvidersExtensionPoint(); |
115 |
List<NewLayerProviderFactory> providers =
|
116 |
new ArrayList<NewLayerProviderFactory>(); |
117 |
@SuppressWarnings("unchecked") |
118 |
Iterator<Extension> it = ep.iterator();
|
119 |
|
120 |
while (it.hasNext()) {
|
121 |
Extension extension = (Extension) it.next(); |
122 |
NewLayerProviderFactory factory; |
123 |
try {
|
124 |
factory = (NewLayerProviderFactory) extension.create(); |
125 |
} catch (InstantiationException e) { |
126 |
LOG.warn( |
127 |
"Can't create NewLayerProviderFactory "
|
128 |
+ extension.getName(), e); |
129 |
continue;
|
130 |
} catch (IllegalAccessException e) { |
131 |
LOG.warn( |
132 |
"Can't create NewLayerProviderFactory "
|
133 |
+ extension.getName(), e); |
134 |
continue;
|
135 |
} |
136 |
providers.add(factory); |
137 |
} |
138 |
|
139 |
return providers;
|
140 |
} |
141 |
|
142 |
private ExtensionPoint getNewLayerProvidersExtensionPoint() {
|
143 |
ExtensionPointManager epmgr = ToolsLocator.getExtensionPointManager(); |
144 |
return
|
145 |
epmgr.add(EP_NEWLAYER_NAME, EP_NEWLAYER_DESCRIPTION); |
146 |
} |
147 |
|
148 |
public List<NewLayerProviderFactory> getProviders(STORETYPE filter) { |
149 |
// TODO use filters
|
150 |
// if (filter == STORETYPE.TABULAR){
|
151 |
// if (!factory.isSpatial()){
|
152 |
// providers.add(factory);
|
153 |
// }
|
154 |
// } else {
|
155 |
// }
|
156 |
return getProviders();
|
157 |
} |
158 |
|
159 |
public boolean isProviderEnabled(NewLayerProviderFactory factory) { |
160 |
Boolean status = providerStatus.get(factory);
|
161 |
return status == null ? true : status.booleanValue(); |
162 |
} |
163 |
|
164 |
} |