Statistics
| Revision:

gvsig-gazetteer / trunk / extGazetteer / src / org / gvsig / gazetteer / GazetteerExtension.java @ 13

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

    
56

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

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

    
70
        private void registerIcons() {
71
        IconThemeHelper.registerIcon("gazetteer", "gazetteer-search", this);
72
        }
73

    
74
        public void postInitialize() {
75

    
76
        }
77

    
78
        public void execute(String actionCommand) {
79
                actionConnectDialogStart();
80
        }
81

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

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

    
93
                ServerData[] servers = persistence.getArrayOfServerData();
94

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

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

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

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

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

    
148
                return servers;
149
        }
150

    
151
        public boolean isEnabled() {
152
                return true;
153
        }
154

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

    
159
                if (f == null) {
160
                        return false;
161
                }
162

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

    
170
                return false;
171
        }
172
}