Statistics
| Revision:

root / trunk / extensions / extCatalogAndGazetteer / src / es / gva / cit / gvsig / gazetteer / GazetteerExtension.java @ 30182

History | View | Annotate | Download (6.44 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 es.gva.cit.gvsig.gazetteer;
42

    
43
import java.util.Calendar;
44
import java.util.Date;
45
import java.util.GregorianCalendar;
46

    
47
import com.iver.andami.PluginServices;
48
import com.iver.andami.persistence.serverData.ServerDataPersistence;
49
import com.iver.andami.plugins.Extension;
50
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
51
import com.iver.cit.gvsig.project.documents.view.gui.View;
52
import com.iver.utiles.swing.jcomboServer.ServerData;
53

    
54
import es.gva.cit.gazetteer.adl.drivers.ADLGazetteerServiceDriver;
55
import es.gva.cit.gazetteer.geonames.GeonamesServiceDriver;
56
import es.gva.cit.gazetteer.idec.drivers.IDECGazetteerServiceDriver;
57
import es.gva.cit.gazetteer.utils.GazetteerDriverRegister;
58
import es.gva.cit.gazetteer.wfs.drivers.WFSServiceDriver;
59
import es.gva.cit.gazetteer.wfsg.drivers.WFSGServiceDriver;
60
import es.gva.cit.gvsig.gazetteer.gui.ConnectDialog;
61

    
62
/**
63
 * @author Jorge Piera Llodra (piera_jor@gva.es)
64
 */
65
public class GazetteerExtension extends Extension {
66

    
67
        public static void main(String[] args) {
68
        }
69

    
70
        /*
71
         * (non-Javadoc)
72
         * 
73
         * @see com.iver.andami.plugins.Extension#inicializar()
74
         */
75
        public void initialize() {
76
                System.out.println("A?ado GazetteerModule");
77
                registerIcons();
78
        }
79

    
80
        private void registerIcons() {
81
                PluginServices.getIconTheme().registerDefault(
82
                                "gazetteer-search",
83
                                this.getClass().getClassLoader().getResource(
84
                                                "images/GazzButton.png"));
85
        }
86

    
87
        /*
88
         * (non-Javadoc)
89
         * 
90
         * @see com.iver.andami.plugins.Extension#postInitialize()
91
         */
92
        public void postInitialize() {
93
                GazetteerDriverRegister register = GazetteerDriverRegister
94
                                .getInstance();
95
                register.register(new ADLGazetteerServiceDriver());
96
                register.register(new WFSServiceDriver());
97
                register.register(new WFSGServiceDriver());
98
                register.register(new IDECGazetteerServiceDriver());
99
                register.register(new GeonamesServiceDriver());
100
        }
101

    
102
        /*
103
         * (non-Javadoc)
104
         * 
105
         * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
106
         */
107
        public void execute(String actionCommand) {
108
                // JToolBar toolBar =
109
                // (JToolBar)PluginServices.getMainFrame().getComponentByName("Catalogo");
110
                // System.out.println("gjkmgbghb");
111
                // for (int i=0 ; i<toolBar.getComponentCount() ; i++){
112
                // System.out.println(((JButton)toolBar.getComponentAtIndex(i)).getName());
113
                // }
114
                actionConnectDialogStart();
115
        }
116

    
117
        /**
118
         * 
119
         * 
120
         */
121
        private void actionConnectDialogStart() {
122
                System.out.println("Bot?n de Gazeteer pulsado");
123
                restoreServerList();
124
                ConnectDialog connectDialog = new ConnectDialog();
125
                PluginServices.getMDIManager().addWindow(connectDialog);
126
        }
127

    
128
        private void restoreServerList() {
129
                ServerDataPersistence persistence = new ServerDataPersistence(this,
130
                                ServerData.SERVER_TYPE_GAZETTEER);
131

    
132
                ServerData[] servers = persistence.getArrayOfServerData();
133

    
134
                boolean found = false;
135
                for (int i = 0; i < servers.length; i++) {
136
                        if (servers[i].getServiceType().equals(
137
                                        ServerData.SERVER_TYPE_GAZETTEER)) {
138
                                found = true;
139
                        }
140
                }
141

    
142
                if (!found) {
143
                        if (servers.length == 0) {
144
                                servers = getDefaultServers();
145
                        } else {
146
                                ServerData[] newServers = new ServerData[servers.length
147
                                                + getDefaultServers().length];
148
                                System.arraycopy(servers, 0, newServers, 0, servers.length);
149
                                System.arraycopy(getDefaultServers(), 0, newServers,
150
                                                servers.length, getDefaultServers().length);
151
                                servers = newServers;
152
                        }
153
                        persistence.setArrayOfServerData(servers);
154
                }
155

    
156
                for (int i = 0; i < servers.length; i++) {
157
                        if (servers[i].getServiceType().equals(
158
                                        ServerData.SERVER_TYPE_GAZETTEER)) {
159
                                ConnectDialog.addServer(servers[i]);
160
                        }
161
                }
162
        }
163

    
164
        /**
165
         * It creates a server list by default
166
         * 
167
         * @return
168
         */
169
        private ServerData[] getDefaultServers() {
170
                ServerData[] servers = new ServerData[4];
171
                Calendar cal = new GregorianCalendar();
172
                Date date = cal.getTime();
173

    
174
                servers[0] = new ServerData(
175
                                "http://middleware.alexandria.ucsb.edu/gaz/adlgaz/dispatch",
176
                                date, date, ServerData.SERVER_TYPE_GAZETTEER,
177
                                ServerData.SERVER_SUBTYPE_GAZETTEER_ADL);
178
                servers[1] = new ServerData(
179
                                "http://demo.deegree.org:8080/gazetteer/wfs-g", date, date,
180
                                ServerData.SERVER_TYPE_GAZETTEER,
181
                                ServerData.SERVER_SUBTYPE_GAZETTEER_WFSG);
182
                servers[2] = new ServerData(
183
                                "http://193.144.250.29/webservices/services/IDEC_GeoServeisPort",
184
                                date, date, ServerData.SERVER_TYPE_GAZETTEER,
185
                                ServerData.SERVER_SUBTYPE_GAZETTEER_IDEC);
186
                servers[3] = new ServerData(
187
                                "www.geonames.org:80",
188
                                date, date, ServerData.SERVER_TYPE_GAZETTEER,
189
                                "Geonames");
190

    
191
                return servers;
192
        }
193

    
194
        /*
195
         * (non-Javadoc)
196
         * 
197
         * @see com.iver.andami.plugins.Extension#isEnabled()
198
         */
199
        public boolean isEnabled() {
200
                return true;
201
        }
202

    
203
        /*
204
         * (non-Javadoc)
205
         * 
206
         * @see com.iver.andami.plugins.Extension#isVisible()
207
         */
208
        public boolean isVisible() {
209
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices
210
                                .getMDIManager().getActiveWindow();
211

    
212
                if (f == null) {
213
                        return false;
214
                }
215

    
216
                if (f instanceof View) {
217
                        if (((View) f).getMapControl().getViewPort().getAdjustedExtent() != null) {
218
                                return true;
219
                        }
220
                } else if (f instanceof BaseView)
221
                        return true;
222

    
223
                return false;
224
        }
225
}