Statistics
| Revision:

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

History | View | Annotate | Download (4.9 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.andami.PluginServices;
48
import org.gvsig.andami.persistence.serverData.ServerDataPersistence;
49
import org.gvsig.andami.plugins.Extension;
50
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
51
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
52
import org.gvsig.gazetteer.gui.ConnectDialog;
53
import org.gvsig.utils.swing.jcomboServer.ServerData;
54

    
55

    
56
/**
57
 * @author Jorge Piera Llodra (piera_jor@gva.es)
58
 */
59
public class GazetteerExtension extends Extension {
60
        
61
        public static void main(String[] args) {
62
            
63
        }
64

    
65
        public void initialize() {
66
                registerIcons();
67
        }
68

    
69
        private void registerIcons() {
70
                PluginServices.getIconTheme().registerDefault(
71
                                "gazetteer-search",
72
                                this.getClass().getClassLoader().getResource(
73
                                "images/GazzButton.png"));
74
        }
75

    
76
        public void postInitialize() {
77

    
78
        }
79

    
80
        public void execute(String actionCommand) {
81
                actionConnectDialogStart();
82
        }
83

    
84
        private void actionConnectDialogStart() {
85
                System.out.println("Bot?n de Gazeteer pulsado");
86
                restoreServerList();
87
                ConnectDialog connectDialog = new ConnectDialog();
88
                PluginServices.getMDIManager().addWindow(connectDialog);
89
        }
90

    
91
        private void restoreServerList() {
92
                ServerDataPersistence persistence = new ServerDataPersistence(this,
93
                                ServerData.SERVER_TYPE_GAZETTEER);
94

    
95
                ServerData[] servers = persistence.getArrayOfServerData();
96

    
97
                boolean found = false;
98
                for (int i = 0; i < servers.length; i++) {
99
                        if (servers[i].getServiceType().equals(
100
                                        ServerData.SERVER_TYPE_GAZETTEER)) {
101
                                found = true;
102
                        }
103
                }
104

    
105
                if (!found) {
106
                        if (servers.length == 0) {
107
                                servers = getDefaultServers();
108
                        } else {
109
                                ServerData[] newServers = new ServerData[servers.length
110
                                                                         + getDefaultServers().length];
111
                                System.arraycopy(servers, 0, newServers, 0, servers.length);
112
                                System.arraycopy(getDefaultServers(), 0, newServers,
113
                                                servers.length, getDefaultServers().length);
114
                                servers = newServers;
115
                        }
116
                        persistence.setArrayOfServerData(servers);
117
                }
118

    
119
                for (int i = 0; i < servers.length; i++) {
120
                        if (servers[i].getServiceType().equals(
121
                                        ServerData.SERVER_TYPE_GAZETTEER)) {
122
                                ConnectDialog.addServer(servers[i]);
123
                        }
124
                }
125
        }
126

    
127
        /**
128
         * It creates a server list by default
129
         * 
130
         * @return
131
         */
132
        private ServerData[] getDefaultServers() {
133
                ServerData[] servers = new ServerData[0];
134
                Calendar cal = new GregorianCalendar();
135
                Date date = cal.getTime();
136

    
137
//                servers[0] = new ServerData(
138
//                                "httpdescargamedee://middleware.alexandria.ucsb.edu/gaz/adlgaz/dispatch",
139
//                                date, date, ServerData.SERVER_TYPE_GAZETTEER,
140
//                                ServerData.SERVER_SUBTYPE_GAZETTEER_ADL);
141
//                servers[1] = new ServerData(
142
//                                "http://demo.deegree.org:8080/gazetteer/wfs-g", date, date,
143
//                                ServerData.SERVER_TYPE_GAZETTEER,
144
//                                ServerData.SERVER_SUBTYPE_GAZETTEER_WFSG);
145
//                servers[2] = new ServerData(
146
//                                "http://delta.icc.es/webservices/services/IDEC_GeoServeisPort",
147
//                                date, date, ServerData.SERVER_TYPE_GAZETTEER,
148
//                                ServerData.SERVER_SUBTYPE_GAZETTEER_IDEC);
149

    
150
                return servers;
151
        }
152

    
153
        public boolean isEnabled() {
154
                return true;
155
        }
156

    
157
        public boolean isVisible() {
158
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices
159
                .getMDIManager().getActiveWindow();
160

    
161
                if (f == null) {
162
                        return false;
163
                }
164

    
165
                if (f instanceof DefaultViewPanel) {
166
                        if (((DefaultViewPanel) f).getMapControl().getViewPort().getAdjustedExtent() != null) {
167
                                return true;
168
                        }
169
                } else if (f instanceof AbstractViewPanel)
170
                        return true;
171

    
172
                return false;
173
        }
174
}