Statistics
| Revision:

svn-gvsig-desktop / branches / CatalogYNomenclator_v1_1_0_1005 / extensions / extCatalogYNomenclator / src / es / gva / cit / gvsig / catalogClient / CatalogClientExtension.java @ 12758

History | View | Annotate | Download (6.26 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.catalogClient;
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.utiles.extensionPoints.ExtensionPoint;
52
import com.iver.utiles.extensionPoints.ExtensionPoints;
53
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
54
import com.iver.utiles.swing.jcomboServer.ServerData;
55

    
56
import es.gva.cit.catalogClient.csw.drivers.CSWCatalogServiceDriver;
57
import es.gva.cit.catalogClient.srw.drivers.SRWCatalogServiceDriver;
58
import es.gva.cit.catalogClient.utils.CatalogDriverRegister;
59
import es.gva.cit.catalogClient.z3950.drivers.Z3950CatalogServiceDriver;
60
import es.gva.cit.gvsig.catalogClient.gui.ConnectDialog;
61

    
62

    
63
/**
64
 * DOCUMENT ME!
65
 *
66
 * @author Luis W. Sevilla
67
 */
68
public class CatalogClientExtension extends Extension {
69
    /* (non-Javadoc)
70
     * @see com.iver.andami.plugins.Extension#inicializar()
71
     */
72
    public void initialize() {
73
        System.out.println("A?ado CatalogClientModule");
74
        ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
75
        ExtensionPoint extensionPoint = new ExtensionPoint("CatalogLayers","Lista de capas que se pueden cargar desde el catalogo.");
76
        extensionPoints.put(extensionPoint);        
77
    }
78
    
79
    /*
80
     * (non-Javadoc)
81
     * @see com.iver.andami.plugins.Extension#postInitialize()
82
     */
83
    public void postInitialize(){
84
            CatalogDriverRegister register = CatalogDriverRegister.getInstance();
85
                register.register(new Z3950CatalogServiceDriver());
86
                register.register(new SRWCatalogServiceDriver());
87
                register.register(new CSWCatalogServiceDriver());
88
    }
89

    
90
    /* (non-Javadoc)
91
     * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
92
     */
93
    public void execute(String actionCommand) {
94
        actionConnectDialogStart();
95
    }
96

    
97
    /**
98
     * DOCUMENT ME!
99
     */
100
    private void actionConnectDialogStart() {
101
        System.out.println("Bot?n Cliente de metadatos pulsado");
102
        restoreServerList();
103

    
104
        ConnectDialog connectDialog = new ConnectDialog();
105
        PluginServices.getMDIManager().addWindow(connectDialog);
106
    }
107

    
108
    /**
109
     * It restores a server list. If this list does't exist it create  a server
110
     * list by default.
111
     */
112
    private void restoreServerList() {
113
        ServerDataPersistence persistence = new ServerDataPersistence(this,ServerData.SERVER_TYPE_CATALOG);
114
        
115
        ServerData[] servers = persistence.getArrayOfServerData();
116
        
117
        boolean found = false;
118
        for (int i=0 ; i<servers.length ; i++){
119
            if (servers[i].getServiceType().equals(ServerData.SERVER_TYPE_CATALOG)){
120
                found = true;
121
            }
122
        }       
123
        
124
        if (!found){
125
             if (servers.length == 0){
126
                servers = getDefaultServers();
127
            }else{
128
                ServerData[] newServers = new ServerData[servers.length + getDefaultServers().length ];
129
                System.arraycopy(servers, 0, newServers, 0, servers.length);
130
                System.arraycopy(getDefaultServers(), 0, newServers, servers.length, getDefaultServers().length);
131
                servers = newServers;
132
            }
133
            persistence.setArrayOfServerData(servers);
134
        }
135
         
136
        
137
        for (int i = 0; i < servers.length; i++) {
138
            if (servers[i].getServiceType().equals(ServerData.SERVER_TYPE_CATALOG)){
139
                ConnectDialog.addServer(servers[i]);
140
            }
141
        }
142
        
143
        
144
    }
145

    
146
    /**
147
     * It creates a server list by default
148
     *
149
     * @return
150
     */
151
    private ServerData[] getDefaultServers() {
152
        ServerData[] servers = new ServerData[4];
153
        Calendar cal = new GregorianCalendar();
154
        Date date = cal.getTime();
155

    
156
        
157
        servers[0] = new ServerData("http://delta.icc.es/indicio/csw", date, date, ServerData.SERVER_TYPE_CATALOG, ServerData.SERVER_SUBTYPE_CATALOG_CSW);
158
        servers[1] = new ServerData("mapas.euitto.upm.es:2100", date, date, ServerData.SERVER_TYPE_CATALOG, ServerData.SERVER_SUBTYPE_CATALOG_Z3950);
159
        servers[2] = new ServerData("193.43.36.137:2100", date, date, ServerData.SERVER_TYPE_CATALOG, ServerData.SERVER_SUBTYPE_CATALOG_Z3950);
160
        servers[3] = new ServerData("http://idee.unizar.es/SRW/servlet/search/ExplainSOAP",date,date,ServerData.SERVER_TYPE_CATALOG,ServerData.SERVER_SUBTYPE_CATALOG_SRW);
161
        return servers;
162
    }
163

    
164
    /* (non-Javadoc)
165
     * @see com.iver.andami.plugins.Extension#isEnabled()
166
     */
167
    public boolean isEnabled() {
168
        return true;
169
    }
170

    
171
    /* (non-Javadoc)
172
     * @see com.iver.andami.plugins.Extension#isVisible()
173
     */
174
    public boolean isVisible() {
175
        com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
176
                                                             .getActiveWindow();
177

    
178
        if (f == null) {
179
            return false;
180
        }
181

    
182
        return (f instanceof BaseView);
183
    }
184
}