Statistics
| Revision:

gvsig-catalog / org.gvsig.catalog / branches / org.gvsig.catalog-CSW2.0.2 / org.gvsig.catalog / org.gvsig.catalog.extension / src / main / java / org / gvsig / catalog / CatalogClientExtension.java @ 55

History | View | Annotate | Download (6.38 KB)

1
/* 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
import java.util.Calendar;
44
import java.util.Date;
45
import java.util.GregorianCalendar;
46

    
47
import org.slf4j.Logger;
48
import org.slf4j.LoggerFactory;
49

    
50
import org.gvsig.andami.IconThemeHelper;
51
import org.gvsig.andami.PluginServices;
52
import org.gvsig.andami.persistence.serverData.ServerDataPersistence;
53
import org.gvsig.andami.plugins.Extension;
54
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
55
import org.gvsig.catalog.gui.ConnectDialog;
56
import org.gvsig.catalog.loaders.ARCIMSLayerLoader;
57
import org.gvsig.catalog.loaders.LinkLoader;
58
import org.gvsig.catalog.loaders.PostgisLayerLoader;
59
import org.gvsig.catalog.loaders.WCSLayerLoader;
60
import org.gvsig.catalog.loaders.WFSLayerLoader;
61
import org.gvsig.catalog.loaders.WMSLayerLoader;
62
import org.gvsig.catalog.schemas.Resource;
63
import org.gvsig.tools.ToolsLocator;
64
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
65
import org.gvsig.utils.swing.jcomboServer.ServerData;
66

    
67

    
68

    
69

    
70
/**
71
 * DOCUMENT ME!
72
 *
73
 * @author Luis W. Sevilla
74
 */
75
public class CatalogClientExtension extends Extension {
76
        private static final Logger LOG = LoggerFactory.getLogger(CatalogClientExtension.class);
77
        private static final String CATALOGLAYERS = "CatalogLayers";
78

    
79
        public void initialize() {
80
                ExtensionPointManager extensionPointManager = ToolsLocator
81
                    .getExtensionPointManager();
82
                extensionPointManager.add(CATALOGLAYERS, "List of possible layers that can be loaded from a catalog");
83
                registerIcons();
84
        }
85

    
86
        private void registerIcons(){
87
        IconThemeHelper.registerIcon("catalog", "catalog-move-down", this);
88
        IconThemeHelper.registerIcon("catalog", "catalog-move-up", this);
89
        IconThemeHelper.registerIcon("catalog", "catalog-server-properties", this);
90
        IconThemeHelper.registerIcon("catalog", "catalog-search", this);
91
        }
92

    
93
        public void postInitialize(){
94
                //Initialazing the layer loaders
95
                CatalogManager catalogManager = CatalogLocator.getCatalogManager();
96
                catalogManager.addLayerLoader(Resource.WMS, WMSLayerLoader.class);
97
                catalogManager.addLayerLoader(Resource.POSTGIS, PostgisLayerLoader.class);
98
                catalogManager.addLayerLoader(Resource.WCS, WCSLayerLoader.class);
99
                catalogManager.addLayerLoader(Resource.WEBSITE, LinkLoader.class);
100
                catalogManager.addLayerLoader(Resource.DOWNLOAD, LinkLoader.class);
101
                catalogManager.addLayerLoader(Resource.WFS, WFSLayerLoader.class);
102
                catalogManager.addLayerLoader(Resource.ARCIMS_IMAGE, ARCIMSLayerLoader.class);
103
                catalogManager.addLayerLoader(Resource.ARCIMS_VECTORIAL, ARCIMSLayerLoader.class);
104
        }
105

    
106
        public void execute(String actionCommand) {
107
                actionConnectDialogStart();
108
        }
109

    
110
        /**
111
         * DOCUMENT ME!
112
         */
113
        private void actionConnectDialogStart() {
114
                System.out.println("Bot?n Cliente de metadatos pulsado");
115
                restoreServerList();
116

    
117
                ConnectDialog connectDialog = new ConnectDialog();
118
                PluginServices.getMDIManager().addWindow(connectDialog);
119
        }
120

    
121
        /**
122
         * It restores a server list. If this list does't exist it create  a server
123
         * list by default.
124
         */
125
        private void restoreServerList() {
126
                ServerDataPersistence persistence =
127
                                new ServerDataPersistence(ServerData.SERVER_TYPE_CATALOG);
128

    
129
                ServerData[] servers = persistence.getArrayOfServerData();
130

    
131
                boolean found = false;
132
                for (int i=0 ; i<servers.length ; i++){
133
                        if (servers[i].getServiceType().equals(ServerData.SERVER_TYPE_CATALOG)){
134
                                found = true;
135
                        }
136
                }       
137

    
138
                if (!found){
139
                        if (servers.length == 0){
140
                                servers = getDefaultServers();
141
                        }else{
142
                                ServerData[] newServers = new ServerData[servers.length + getDefaultServers().length ];
143
                                System.arraycopy(servers, 0, newServers, 0, servers.length);
144
                                System.arraycopy(getDefaultServers(), 0, newServers, servers.length, getDefaultServers().length);
145
                                servers = newServers;
146
                        }
147
                        persistence.setArrayOfServerData(servers);
148
                }
149

    
150

    
151
                for (int i = 0; i < servers.length; i++) {
152
                        if (servers[i].getServiceType().equals(ServerData.SERVER_TYPE_CATALOG)){
153
                                ConnectDialog.addServer(servers[i]);
154
                        }
155
                }
156

    
157

    
158
        }
159

    
160
        /**
161
         * It creates a server list by default
162
         *
163
         * @return
164
         */
165
        private ServerData[] getDefaultServers() {
166
                ServerData[] servers = new ServerData[0];
167
                Calendar cal = new GregorianCalendar();
168
                Date date = cal.getTime();
169

    
170
                //servers[0] = new ServerData("http://delta.icc.es/indicio/csw", date, date, ServerData.SERVER_TYPE_CATALOG, ServerData.SERVER_SUBTYPE_CATALOG_CSW);
171
                //servers[1] = new ServerData("mapas.euitto.upm.es:2100", date, date, ServerData.SERVER_TYPE_CATALOG, ServerData.SERVER_SUBTYPE_CATALOG_Z3950);
172
                //servers[2] = new ServerData("193.43.36.137:2100", date, date, ServerData.SERVER_TYPE_CATALOG, ServerData.SERVER_SUBTYPE_CATALOG_Z3950);
173
                //servers[3] = new ServerData("http://idee.unizar.es/SRW/servlet/search/ExplainSOAP",date,date,ServerData.SERVER_TYPE_CATALOG,ServerData.SERVER_SUBTYPE_CATALOG_SRW);
174
                return servers;
175
        }
176

    
177
        public boolean isEnabled() {
178
                return true;
179
        }
180

    
181
        public boolean isVisible() {
182
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
183
                .getActiveWindow();
184

    
185
                if (f == null) {
186
                        return false;
187
                }
188

    
189
                return (f instanceof AbstractViewPanel);
190
        }
191
}