gvsig-catalog / org.gvsig.catalog / trunk / org.gvsig.catalog / org.gvsig.catalog.extension / src / main / java / org / gvsig / catalog / CatalogClientExtension.java @ 144
History | View | Annotate | Download (7.02 KB)
1 | 55 | jbadia | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package org.gvsig.catalog; |
||
42 | |||
43 | 144 | dmartinezizquierdo | import java.io.File; |
44 | import java.io.FileInputStream; |
||
45 | import java.io.FileNotFoundException; |
||
46 | import java.io.IOException; |
||
47 | import java.util.HashMap; |
||
48 | import java.util.Map; |
||
49 | import java.util.Properties; |
||
50 | 55 | jbadia | |
51 | 144 | dmartinezizquierdo | import org.apache.commons.io.IOUtils; |
52 | 55 | jbadia | import org.gvsig.andami.IconThemeHelper; |
53 | import org.gvsig.andami.PluginServices; |
||
54 | 144 | dmartinezizquierdo | import org.gvsig.andami.PluginsLocator; |
55 | 55 | jbadia | import org.gvsig.andami.plugins.Extension; |
56 | import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
||
57 | import org.gvsig.catalog.gui.ConnectDialog; |
||
58 | import org.gvsig.catalog.loaders.ARCIMSLayerLoader; |
||
59 | import org.gvsig.catalog.loaders.LinkLoader; |
||
60 | import org.gvsig.catalog.loaders.PostgisLayerLoader; |
||
61 | import org.gvsig.catalog.loaders.WCSLayerLoader; |
||
62 | import org.gvsig.catalog.loaders.WFSLayerLoader; |
||
63 | import org.gvsig.catalog.loaders.WMSLayerLoader; |
||
64 | import org.gvsig.catalog.schemas.Resource; |
||
65 | import org.gvsig.tools.ToolsLocator; |
||
66 | 144 | dmartinezizquierdo | import org.gvsig.tools.dynobject.DynObject; |
67 | 55 | jbadia | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
68 | import org.gvsig.utils.swing.jcomboServer.ServerData; |
||
69 | 144 | dmartinezizquierdo | import org.slf4j.Logger; |
70 | import org.slf4j.LoggerFactory; |
||
71 | 55 | jbadia | |
72 | |||
73 | |||
74 | |||
75 | /**
|
||
76 | * DOCUMENT ME!
|
||
77 | *
|
||
78 | * @author Luis W. Sevilla
|
||
79 | */
|
||
80 | public class CatalogClientExtension extends Extension { |
||
81 | private static final Logger LOG = LoggerFactory.getLogger(CatalogClientExtension.class); |
||
82 | private static final String CATALOGLAYERS = "CatalogLayers"; |
||
83 | 144 | dmartinezizquierdo | private static final String serversPropsFilename = "servers.properties"; |
84 | 55 | jbadia | |
85 | public void initialize() { |
||
86 | ExtensionPointManager extensionPointManager = ToolsLocator |
||
87 | .getExtensionPointManager(); |
||
88 | extensionPointManager.add(CATALOGLAYERS, "List of possible layers that can be loaded from a catalog");
|
||
89 | registerIcons(); |
||
90 | 144 | dmartinezizquierdo | setPersistence(); |
91 | 55 | jbadia | } |
92 | |||
93 | private void registerIcons(){ |
||
94 | IconThemeHelper.registerIcon("catalog", "catalog-move-down", this); |
||
95 | IconThemeHelper.registerIcon("catalog", "catalog-move-up", this); |
||
96 | IconThemeHelper.registerIcon("catalog", "catalog-server-properties", this); |
||
97 | IconThemeHelper.registerIcon("catalog", "catalog-search", this); |
||
98 | } |
||
99 | |||
100 | public void postInitialize(){ |
||
101 | //Initialazing the layer loaders
|
||
102 | CatalogManager catalogManager = CatalogLocator.getCatalogManager(); |
||
103 | catalogManager.addLayerLoader(Resource.WMS, WMSLayerLoader.class); |
||
104 | catalogManager.addLayerLoader(Resource.POSTGIS, PostgisLayerLoader.class); |
||
105 | catalogManager.addLayerLoader(Resource.WCS, WCSLayerLoader.class); |
||
106 | catalogManager.addLayerLoader(Resource.WEBSITE, LinkLoader.class); |
||
107 | catalogManager.addLayerLoader(Resource.DOWNLOAD, LinkLoader.class); |
||
108 | catalogManager.addLayerLoader(Resource.WFS, WFSLayerLoader.class); |
||
109 | catalogManager.addLayerLoader(Resource.ARCIMS_IMAGE, ARCIMSLayerLoader.class); |
||
110 | catalogManager.addLayerLoader(Resource.ARCIMS_VECTORIAL, ARCIMSLayerLoader.class); |
||
111 | } |
||
112 | |||
113 | public void execute(String actionCommand) { |
||
114 | actionConnectDialogStart(); |
||
115 | } |
||
116 | |||
117 | /**
|
||
118 | * DOCUMENT ME!
|
||
119 | */
|
||
120 | private void actionConnectDialogStart() { |
||
121 | System.out.println("Bot?n Cliente de metadatos pulsado"); |
||
122 | ConnectDialog connectDialog = new ConnectDialog();
|
||
123 | PluginServices.getMDIManager().addWindow(connectDialog); |
||
124 | } |
||
125 | |||
126 | /**
|
||
127 | * It restores a server list. If this list does't exist it create a server
|
||
128 | * list by default.
|
||
129 | */
|
||
130 | 144 | dmartinezizquierdo | private void setPersistence() { |
131 | PluginServices plugin=PluginsLocator.getManager().getPlugin(this.getClass());
|
||
132 | DynObject preferences = plugin.getPluginProperties(); |
||
133 | Map serversMapPersistence = (Map) preferences.getDynValue("servers"); |
||
134 | 55 | jbadia | |
135 | 144 | dmartinezizquierdo | if (serversMapPersistence == null) { |
136 | serversMapPersistence = new HashMap(); |
||
137 | preferences.setDynValue("servers", serversMapPersistence);
|
||
138 | } |
||
139 | addDefaultServers(serversMapPersistence); |
||
140 | 55 | jbadia | |
141 | 144 | dmartinezizquierdo | CatalogManager cm= CatalogLocator.getCatalogManager(); |
142 | cm.setServersPersistence(serversMapPersistence); |
||
143 | 55 | jbadia | } |
144 | |||
145 | /**
|
||
146 | 144 | dmartinezizquierdo | * Loads servers from a properties file
|
147 | * @param serversMapPersistence
|
||
148 | 55 | jbadia | */
|
149 | 144 | dmartinezizquierdo | private void addDefaultServers(Map serversMapPersistence) { |
150 | PluginServices plugin=PluginsLocator.getManager().getPlugin(this.getClass());
|
||
151 | //Lee los servidores del properties y los mezcla con los que hay en la persistencia
|
||
152 | Properties prop = new Properties(); |
||
153 | File propFile = new File(plugin.getPluginDirectory(), serversPropsFilename); |
||
154 | FileInputStream fis = null; |
||
155 | try {
|
||
156 | fis = new FileInputStream(propFile); |
||
157 | prop.load(fis); |
||
158 | } catch (FileNotFoundException e) { |
||
159 | LOG.info("Properties file '" + propFile.getAbsolutePath() + "' not found", e); |
||
160 | } catch (IOException e) { |
||
161 | LOG.info("Error reading properties file '" + propFile.getAbsolutePath() + "'.", e); |
||
162 | } finally {
|
||
163 | IOUtils.closeQuietly(fis); |
||
164 | } |
||
165 | for (int i = 0; i < prop.size(); i++) { |
||
166 | String serverKey="server[" + i + "]"; |
||
167 | String subtypeKey="subtype[" + i + "]"; |
||
168 | if (prop.containsKey(serverKey) && prop.containsKey(subtypeKey)){
|
||
169 | Object value = prop.get(serverKey);
|
||
170 | String host=value.toString();
|
||
171 | if (!serversMapPersistence.containsKey(host)){
|
||
172 | Object subType=prop.get(subtypeKey);
|
||
173 | if (subType!=null){ |
||
174 | ServerData server = new ServerData(host, ServerData.SERVER_TYPE_CATALOG, subType.toString());
|
||
175 | serversMapPersistence.put(host, server); |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | } |
||
180 | 55 | jbadia | } |
181 | |||
182 | public boolean isEnabled() { |
||
183 | return true; |
||
184 | } |
||
185 | |||
186 | public boolean isVisible() { |
||
187 | org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
||
188 | .getActiveWindow(); |
||
189 | |||
190 | if (f == null) { |
||
191 | return false; |
||
192 | } |
||
193 | |||
194 | return (f instanceof AbstractViewPanel); |
||
195 | } |
||
196 | } |