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