Statistics
| Revision:

root / trunk / extensions / extDataLocator / src / com / iver / gvsig / datalocator / DataLocatorExtension.java @ 6877

History | View | Annotate | Download (5.35 KB)

1 2257 jmorell
/*
2
 * Created on 22-jun-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package com.iver.gvsig.datalocator;
45
46 5750 fjp
import java.util.prefs.Preferences;
47
48 2257 jmorell
import com.iver.andami.PluginServices;
49
import com.iver.andami.plugins.Extension;
50 5750 fjp
import com.iver.andami.ui.mdiManager.ViewInfo;
51 2257 jmorell
import com.iver.cit.gvsig.fmap.FMap;
52 2399 jmorell
import com.iver.cit.gvsig.fmap.layers.FLayer;
53
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
54 2257 jmorell
import com.iver.cit.gvsig.gui.View;
55
import com.iver.cit.gvsig.project.ProjectView;
56
import com.iver.gvsig.datalocator.gui.DataSelectionPanel;
57
58
/**
59 2276 jmorell
 * The DataLocatorExtension class allows to make a quick zoom based on an
60
 * alphanumeric attribute.
61 2257 jmorell
 *
62
 * @author jmorell
63
 */
64 5005 jorpiell
public class DataLocatorExtension extends Extension {
65 5750 fjp
66
        boolean bFirstTimeOpened = false;
67 2257 jmorell
68
    /* (non-Javadoc)
69
     * @see com.iver.andami.plugins.Extension#inicializar()
70
     */
71 5005 jorpiell
    public void initialize() {
72 5750 fjp
            bFirstTimeOpened = false;
73 2257 jmorell
74
    }
75
76
    /* (non-Javadoc)
77
     * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
78
     */
79
    public void execute(String actionCommand) {
80
                View vista = (View)PluginServices.getMDIManager().getActiveView();
81 2276 jmorell
                FMap mapContext = vista.getModel().getMapContext();
82 2257 jmorell
                DataSelectionPanel dataSelectionPanel = new DataSelectionPanel(mapContext);
83 5750 fjp
                ViewInfo vi = dataSelectionPanel.getViewInfo();
84
                vi.setX(Preferences.userRoot().getInt("gvSIG.DataLocator.x", vi.getX()));
85
                vi.setY(Preferences.userRoot().getInt("gvSIG.DataLocator.y", vi.getY()));
86
//                vi.setWidth(Preferences.userRoot().getInt("gvSIG.DataLocator.w", vi.getWidth()));
87
//                vi.setHeight(Preferences.userRoot().getInt("gvSIG.DataLocator.h", vi.getHeight()));
88
89 2257 jmorell
                PluginServices.getMDIManager().addView(dataSelectionPanel);
90 5750 fjp
91
                bFirstTimeOpened = true;
92 2257 jmorell
    }
93
94
    /* (non-Javadoc)
95
     * @see com.iver.andami.plugins.Extension#isEnabled()
96
     */
97
    public boolean isEnabled() {
98 6877 cesar
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
99 5750 fjp
                 .getActiveView();
100
                if (f == null) {
101
                    return false;
102
                }
103
                if (f.getClass() == View.class) {
104
                        // Si la vista tiene el tema con el que est? configurado
105
                        // el DataLocator y el usuario ha decidido que se abra
106
                        // autom?ticamente, la abrimos inmediatamente.
107
                        if (!bFirstTimeOpened)
108
                        {
109
                                View vista = (View) f;
110
                            ProjectView model = vista.getModel();
111
                            FMap mapContext = model.getMapContext();
112
                            int userOpen = Preferences.userRoot().getInt("gvSIG.DataLocator.open_first_time", -1);
113
                            if (userOpen == 1)
114
                            {
115
                                        String layerName = Preferences.userRoot().get("LAYERNAME_FOR_DATA_LOCATION", "");
116
                                        FLayer lyr = mapContext.getLayers().getLayer(layerName);
117
                                        if (lyr != null)
118
                                        {
119
                                                DataSelectionPanel dataSelectionPanel = new DataSelectionPanel(mapContext);
120
                                                ViewInfo vi = dataSelectionPanel.getViewInfo();
121
                                                vi.setX(Preferences.userRoot().getInt("gvSIG.DataLocator.x", vi.getX()));
122
                                                vi.setY(Preferences.userRoot().getInt("gvSIG.DataLocator.y", vi.getY()));
123
//                                                vi.setWidth(Preferences.userRoot().getInt("gvSIG.DataLocator.w", vi.getWidth()));
124
//                                                vi.setHeight(Preferences.userRoot().getInt("gvSIG.DataLocator.h", vi.getHeight()));
125
126
                                                PluginServices.getMDIManager().addView(dataSelectionPanel);
127
                                                bFirstTimeOpened = true;
128
                                        }
129
                            }
130
                        }
131
                }
132 2257 jmorell
        return true;
133
    }
134
135
    /* (non-Javadoc)
136
     * @see com.iver.andami.plugins.Extension#isVisible()
137
     */
138
    public boolean isVisible() {
139 6877 cesar
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
140 2258 jmorell
                 .getActiveView();
141
                if (f == null) {
142
                    return false;
143
                }
144
                if (f.getClass() == View.class) {
145
                    View vista = (View) f;
146
                    ProjectView model = vista.getModel();
147
                    FMap mapa = model.getMapContext();
148 2399 jmorell
            if (mapa.getLayers().getLayersCount() > 0) {
149
                boolean vectLayers = false;
150
                for (int i=0;i<mapa.getLayers().getLayersCount();i++) {
151
                    FLayer lyr = mapa.getLayers().getLayer(i);
152 6778 jmvivo
                    if (lyr instanceof FLyrVect && lyr.isAvailable()) {
153 2399 jmorell
                        vectLayers = true;
154
                        break;
155
                    }
156
                }
157
                return vectLayers;
158
            } else {
159
                return false;
160
            }
161 2258 jmorell
                } else {
162
                    return false;
163
                }
164 2257 jmorell
    }
165
166
}