Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extTopology / src / org / gvsig / topology / TopologyCommandsExtension.java @ 20409

History | View | Annotate | Download (5.58 KB)

1 17056 azabala
/*
2
 * Created on 10-abr-2006
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
/* CVS MESSAGES:
45
*
46
* $Id:
47
* $Log:
48
*/
49
package org.gvsig.topology;
50
51
import java.util.HashMap;
52
import java.util.Map;
53
54 17639 azabala
import org.gvsig.topology.project.documents.view.toc.actions.TopologyPropertiesTocMenuEntry;
55 17056 azabala
import org.gvsig.topology.ui.util.GUIUtil;
56
57
import com.iver.andami.PluginServices;
58
import com.iver.andami.plugins.Extension;
59
import com.iver.andami.ui.mdiManager.IWindow;
60
import com.iver.cit.gvsig.fmap.MapContext;
61
import com.iver.cit.gvsig.fmap.MapControl;
62
import com.iver.cit.gvsig.fmap.layers.FLayer;
63
import com.iver.cit.gvsig.fmap.layers.LayersIterator;
64
import com.iver.cit.gvsig.project.documents.view.IProjectView;
65
import com.iver.cit.gvsig.project.documents.view.gui.View;
66 17639 azabala
import com.iver.utiles.extensionPoints.ExtensionPoints;
67
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
68 17137 azabala
import com.iver.utiles.swing.threads.TopologyValidationTask;
69 17056 azabala
70 17137 azabala
/**
71
 * Commands for a topology selected in the TOC.
72
 *
73
 * @author Alvaro Zabala
74
 *
75
 */
76
public class TopologyCommandsExtension extends Extension {
77 17056 azabala
78
        public void execute(String actionCommand) {
79
                if(actionCommand.equalsIgnoreCase("SAVE_TOPOLOGY")){
80
                        com.iver.andami.ui.mdiManager.IWindow f =
81
                                PluginServices.getMDIManager().getActiveWindow();
82
                        View vista = (View) f;
83
                        IProjectView model = vista.getModel();
84
                        MapContext mapContext = model.getMapContext();
85
                        LayersIterator it = new LayersIterator(mapContext.getLayers());
86
                        while (it.hasNext())
87
                        {
88
                                FLayer aux = (FLayer) it.next();
89
                                if (!aux.isActive())
90
                                        continue;
91
92
                                if(aux instanceof Topology)
93
                                {
94
                                        Topology topology = (Topology) aux;
95 17639 azabala
                                        String selectedFile = GUIUtil.getInstance().selectFile("xml", "xml", false);
96 17056 azabala
                                        Map<String, Object> storageParams = new HashMap<String, Object>();
97
                                        storageParams.put(TopologyPersister.FILE_PARAM_NAME, selectedFile);
98
                                        //TODO Hacer la carga de la topologia en un ITask para no dejar la GUI
99
                                        //congelada. Adem?s, chequear que las capas que se referencian existen,
100
                                        //y si no est?n en el TOC se cargan
101
                                        TopologyPersister.persist(topology, storageParams);
102
                                        return;
103
                                }
104
                        }//while
105 17137 azabala
                }else if(actionCommand.equalsIgnoreCase("EVALUATE_TOPOLOGY")){
106
                        com.iver.andami.ui.mdiManager.IWindow f =
107
                                PluginServices.getMDIManager().getActiveWindow();
108
                        View vista = (View) f;
109
                        IProjectView model = vista.getModel();
110
                        MapContext mapContext = model.getMapContext();
111
                        LayersIterator it = new LayersIterator(mapContext.getLayers());
112
                        while (it.hasNext())
113
                        {
114
                                FLayer aux = (FLayer) it.next();
115
                                if (!aux.isActive())
116
                                        continue;
117
118
                                if(aux instanceof Topology)
119
                                {
120
                                        Topology topology = (Topology) aux;
121 18999 azabala
                                        PluginServices.cancelableBackgroundExecution(new TopologyValidationTask(topology, mapContext));
122 17137 azabala
                                }
123
                        }//while
124 17056 azabala
                }
125
126
        }
127
128
        public void initialize() {
129
                PluginServices.getIconTheme().registerDefault(
130
                                "save-topology",
131
                                this.getClass().getClassLoader().getResource("images/save-topology.png")
132
                );
133 17137 azabala
134
                PluginServices.getIconTheme().registerDefault(
135
                                "evaluate-topology",
136
                                this.getClass().getClassLoader().getResource("images/evaluate-topology2.png")
137
                );
138 17639 azabala
139
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
140
            extensionPoints.add("View_TocActions","TopologyProperties",new TopologyPropertiesTocMenuEntry());
141 17056 azabala
        }
142
143
        public boolean isEnabled() {
144
                IWindow window = PluginServices.getMDIManager().getActiveWindow();
145
                if (window instanceof View)
146
                {
147
                        View v = (View) window;
148
                MapControl mapCtrl = v.getMapControl();
149
                        MapContext map = mapCtrl.getMapContext();
150
151
                        LayersIterator it = new LayersIterator(map.getLayers());
152
                        while (it.hasNext())
153
                        {
154
                                FLayer aux = (FLayer) it.next();
155
                                if(! aux.isActive())
156
                                        continue;
157
                                if(aux instanceof Topology)
158
                                        return true;
159
                        }//while
160
                }//if
161
                return false;
162
        }
163
164
        public boolean isVisible() {
165
                IWindow window = PluginServices.getMDIManager().getActiveWindow();
166
                if (window instanceof View)
167
                {
168
                        View v = (View) window;
169
                MapControl mapCtrl = v.getMapControl();
170
                        MapContext map = mapCtrl.getMapContext();
171
172
                        LayersIterator it = new LayersIterator(map.getLayers());
173
                        while (it.hasNext())
174
                        {
175
                                FLayer aux = (FLayer) it.next();
176
                                if(aux instanceof Topology)
177
                                        return true;
178
                        }//while
179
                }//if
180
                return false;
181
        }
182
183
}