Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extGazetteer / src / org / gvsig / gazetteer / GazetteerExtension.java @ 28434

History | View | Annotate | Download (5.82 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.gazetteer;
42

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

    
47
import org.gvsig.gazetteer.gui.ConnectDialog;
48
import org.gvsig.gazetteer.impl.DefaultGazetteerLibrary;
49

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

    
57
/**
58
 * @author Jorge Piera Llodra (piera_jor@gva.es)
59
 */
60
public class GazetteerExtension extends Extension {
61
        private GazetteerLibrary gazetteerLibrary = null;
62

    
63
        public static void main(String[] args) {
64
        }
65

    
66
        /*
67
         * (non-Javadoc)
68
         * 
69
         * @see com.iver.andami.plugins.Extension#inicializar()
70
         */
71
        public void initialize() {
72
                gazetteerLibrary = new DefaultGazetteerLibrary();
73
                gazetteerLibrary.initialize();
74
                registerIcons();
75
        }
76

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

    
84
        /*
85
         * (non-Javadoc)
86
         * 
87
         * @see com.iver.andami.plugins.Extension#postInitialize()
88
         */
89
        public void postInitialize() {
90
                gazetteerLibrary.postInitialize();
91
        }
92

    
93
        /*
94
         * (non-Javadoc)
95
         * 
96
         * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
97
         */
98
        public void execute(String actionCommand) {
99
                // JToolBar toolBar =
100
                // (JToolBar)PluginServices.getMainFrame().getComponentByName("Catalogo");
101
                // System.out.println("gjkmgbghb");
102
                // for (int i=0 ; i<toolBar.getComponentCount() ; i++){
103
                // System.out.println(((JButton)toolBar.getComponentAtIndex(i)).getName());
104
                // }
105
                actionConnectDialogStart();
106
        }
107

    
108
        /**
109
         * 
110
         * 
111
         */
112
        private void actionConnectDialogStart() {
113
                System.out.println("Bot?n de Gazeteer pulsado");
114
                restoreServerList();
115
                ConnectDialog connectDialog = new ConnectDialog();
116
                PluginServices.getMDIManager().addWindow(connectDialog);
117
        }
118

    
119
        private void restoreServerList() {
120
                ServerDataPersistence persistence = new ServerDataPersistence(this,
121
                                ServerData.SERVER_TYPE_GAZETTEER);
122

    
123
                ServerData[] servers = persistence.getArrayOfServerData();
124

    
125
                boolean found = false;
126
                for (int i = 0; i < servers.length; i++) {
127
                        if (servers[i].getServiceType().equals(
128
                                        ServerData.SERVER_TYPE_GAZETTEER)) {
129
                                found = true;
130
                        }
131
                }
132

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

    
147
                for (int i = 0; i < servers.length; i++) {
148
                        if (servers[i].getServiceType().equals(
149
                                        ServerData.SERVER_TYPE_GAZETTEER)) {
150
                                ConnectDialog.addServer(servers[i]);
151
                        }
152
                }
153
        }
154

    
155
        /**
156
         * It creates a server list by default
157
         * 
158
         * @return
159
         */
160
        private ServerData[] getDefaultServers() {
161
                ServerData[] servers = new ServerData[3];
162
                Calendar cal = new GregorianCalendar();
163
                Date date = cal.getTime();
164

    
165
                servers[0] = new ServerData(
166
                                "http://middleware.alexandria.ucsb.edu/gaz/adlgaz/dispatch",
167
                                date, date, ServerData.SERVER_TYPE_GAZETTEER,
168
                                ServerData.SERVER_SUBTYPE_GAZETTEER_ADL);
169
                servers[1] = new ServerData(
170
                                "http://demo.deegree.org:8080/gazetteer/wfs-g", date, date,
171
                                ServerData.SERVER_TYPE_GAZETTEER,
172
                                ServerData.SERVER_SUBTYPE_GAZETTEER_WFSG);
173
                servers[2] = new ServerData(
174
                                "http://193.144.250.29/webservices/services/IDEC_GeoServeisPort",
175
                                date, date, ServerData.SERVER_TYPE_GAZETTEER,
176
                                ServerData.SERVER_SUBTYPE_GAZETTEER_IDEC);
177

    
178
                return servers;
179
        }
180

    
181
        /*
182
         * (non-Javadoc)
183
         * 
184
         * @see com.iver.andami.plugins.Extension#isEnabled()
185
         */
186
        public boolean isEnabled() {
187
                return true;
188
        }
189

    
190
        /*
191
         * (non-Javadoc)
192
         * 
193
         * @see com.iver.andami.plugins.Extension#isVisible()
194
         */
195
        public boolean isVisible() {
196
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices
197
                .getMDIManager().getActiveWindow();
198

    
199
                if (f == null) {
200
                        return false;
201
                }
202

    
203
                if (f instanceof View) {
204
                        if (((View) f).getMapControl().getViewPort().getAdjustedExtent() != null) {
205
                                return true;
206
                        }
207
                } else if (f instanceof BaseView)
208
                        return true;
209

    
210
                return false;
211
        }
212
}