Statistics
| Revision:

svn-gvsig-desktop / tags / Root_gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / StartEditing.java @ 1648

History | View | Annotate | Download (3.75 KB)

1
/*
2
 * Created on 21-feb-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,
21
       USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig;
46

    
47
import com.iver.andami.PluginServices;
48
import com.iver.andami.plugins.Extension;
49

    
50
import com.iver.cit.gvsig.fmap.FMap;
51
import com.iver.cit.gvsig.fmap.edition.EditionException;
52
import com.iver.cit.gvsig.fmap.layers.FLayer;
53
import com.iver.cit.gvsig.fmap.layers.layerOperations.EditableVectorialLayer;
54
import com.iver.cit.gvsig.gui.View;
55
import com.iver.cit.gvsig.project.ProjectView;
56

    
57

    
58
/**
59
 * DOCUMENT ME!
60
 *
61
 * @author Fernando Gonz?lez Cort?s
62
 */
63
public class StartEditing implements Extension {
64
        /**
65
         * @see com.iver.andami.plugins.Extension#inicializar()
66
         */
67
        public void inicializar() {
68
        }
69

    
70
        /**
71
         * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
72
         */
73
        public void execute(String actionCommand) {
74
                com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
75
                                                                                                                         .getActiveView();
76

    
77
                if (f.getClass() == View.class) {
78
                        View vista = (View) f;
79
                        ProjectView model = vista.getModel();
80
                        FMap mapa = model.getMapContext();
81
                        final EditableVectorialLayer capa = (EditableVectorialLayer) mapa.getLayers().getActives()[0];
82
                                PluginServices.backgroundExecution(new Runnable() {
83
                                        public void run() {
84
                                                try {
85
                                                        capa.startEdition();
86
                                                } catch (EditionException e) {
87
                                                        e.printStackTrace();
88
                                                }
89
                                        }
90
                                });
91
                }
92
        }
93

    
94
        /**
95
         * @see com.iver.andami.plugins.Extension#isEnabled()
96
         */
97
        public boolean isEnabled() {
98
                com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
99
                                                                                                                         .getActiveView();
100

    
101
                if (f == null) {
102
                        return false;
103
                }
104

    
105
                if (f.getClass() == View.class) {
106
                        View vista = (View) f;
107
                        ProjectView model = vista.getModel();
108
                        FMap mapa = model.getMapContext();
109

    
110
                        FLayer[] capas = mapa.getLayers().getActives();
111

    
112
                        for (int i = 0; i < capas.length; i++) {
113
                                if (!(capas[i] instanceof EditableVectorialLayer)) {
114
                                        return false;
115
                                }
116
                        }
117
                        return true;
118
                }
119

    
120
                return false;
121
        }
122

    
123
        /**
124
         * @see com.iver.andami.plugins.Extension#isVisible()
125
         */
126
        public boolean isVisible() {
127
                com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
128
                                                                                                                         .getActiveView();
129

    
130
                if (f == null) {
131
                        return false;
132
                }
133

    
134
                if (f.getClass() == View.class) {
135
                        View vista = (View) f;
136
                        ProjectView model = vista.getModel();
137
                        FMap mapa = model.getMapContext();
138

    
139
                        if (mapa.getLayers().getActives().length == 1){
140
                                if (mapa.getLayers().getActives()[0] instanceof EditableVectorialLayer){
141
                                        if (!((EditableVectorialLayer) mapa.getLayers().getActives()[0]).isEditing()){
142
                                                return true;
143
                                        }
144
                                }
145
                        }
146
                } 
147
                return false;
148
        }
149
}