Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.geocoding.extension / src / org / gvsig / geocoding / extension / RelateGeocodingResultsExtension.java @ 32526

History | View | Annotate | Download (4.68 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 Prodevelop S.L. main development
26
 */
27

    
28
package org.gvsig.geocoding.extension;
29

    
30

    
31
import java.util.List;
32

    
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.andami.plugins.Extension;
35
import org.gvsig.andami.preferences.IPreference;
36
import org.gvsig.andami.preferences.IPreferenceExtension;
37
import org.gvsig.andami.ui.mdiManager.IWindow;
38
import org.gvsig.app.project.documents.table.TableDocument;
39
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
40
import org.gvsig.app.project.documents.view.gui.IView;
41
import org.gvsig.fmap.mapcontext.layers.FLayer;
42
import org.gvsig.fmap.mapcontext.layers.FLayers;
43
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
44
import org.gvsig.geocoding.GeocodingLibrary;
45
import org.gvsig.geocoding.gui.relation.RelatePanel;
46
import org.gvsig.geocoding.impl.DefaultGeocodingLibrary;
47
import org.gvsig.geocoding.utils.GeocodingExtTags;
48
import org.gvsig.tools.library.Library;
49
import org.slf4j.Logger;
50
import org.slf4j.LoggerFactory;
51

    
52

    
53
/**
54
 * Geocoding Extension. This extension geoposition in the map one postal
55
 * address.
56
 * 
57
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
58
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
59
 */
60

    
61
public class RelateGeocodingResultsExtension extends Extension implements
62
                IPreferenceExtension {
63

    
64
        
65

    
66
        private static final Logger log = LoggerFactory
67
                        .getLogger(RelateGeocodingResultsExtension.class);
68

    
69
        private GeocodingController control = null;
70

    
71
        /**
72
         * constructor
73
         */
74
        public RelateGeocodingResultsExtension(){
75
                control = GeocodingController.getInstance();        
76
        }
77
        
78
        /**
79
         * execute
80
         */
81
        public void execute(String actionCommand) {
82

    
83
                if (actionCommand.equalsIgnoreCase(GeocodingExtTags.RELATEGEOCODING)) {                                        
84
                        
85
                        //get layer from gvSIG view
86
                        FLyrVect lyr = control.getSelectedFLyrVect();
87
                        // set FLayer in panel
88
                        RelatePanel panel = control.getGRelPanel();
89
                        panel.setLyr(lyr);
90
                        // fill combo with project tables
91
                        panel.putTablesInCombo();                        
92
                        //put visible panel
93
                        PluginServices.getMDIManager().addWindow(control.getGRelPanel());
94
                        control.getGRelPanel().setVisible(true);
95
                        
96
                }
97
        }
98

    
99
        /**
100
         * This method initializes some parameters of the extension
101
         */
102
        public void initialize() {
103

    
104
                Library lib = new DefaultGeocodingLibrary();
105
                lib.initialize();                
106
        }
107

    
108
        /**
109
         * This method puts available the extension
110
         * 
111
         * @return true or false
112
         */
113
        public boolean isEnabled() {
114

    
115
                 IWindow window = PluginServices.getMDIManager().getActiveWindow();
116
                if (window instanceof IView) {
117
                        DefaultViewPanel vi = (DefaultViewPanel) window;
118
                        FLayers lyrs = vi.getMapControl().getMapContext().getLayers();
119
                        if (lyrs != null && lyrs.getLayersCount() > 0) {
120
                                if (lyrs.getActives().length > 0) {
121
                                        FLayer lyr = lyrs.getActives()[0];
122
                                        if (lyr instanceof FLyrVect) {
123
//                                                FLyrVect ly = (FLyrVect) lyr;
124
//                                                List<TableDocument> tables = control.getListgvSIGTables();
125
//                                                Object obj = ly.getProperty(GeocodingExtTags.GEOCODINGPROPERTY);
126
//                                                if (obj instanceof TableDocument
127
//                                                                && tables.size() > 0) {
128
//                                                        return true;
129
//                                                }
130
                                                return true;
131
                                        }
132
                                }
133
                        }
134
                }
135
                return false;
136
        }
137

    
138
        /**
139
         * This method puts visible the extension
140
         * 
141
         * @return true or false
142
         */
143
        public boolean isVisible() {
144
                IWindow window = PluginServices.getMDIManager().getActiveWindow();
145
                // Visible when there are views in the window
146
                if (window instanceof IView) {
147
                        return true;
148
                }
149
                return false;
150
        }
151

    
152
        public IPreference[] getPreferencesPages() {
153

    
154
                return null;
155
        }
156
        
157
        /**
158
         * 
159
         */
160
        public void postInitialize() {
161
                Library api = new GeocodingLibrary();
162
                api.postInitialize();
163
        }
164

    
165
}