svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / EditionUtilities.java @ 40557
History | View | Annotate | Download (5.34 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.editing; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
|
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.app.project.documents.view.ViewDocument; |
30 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
31 |
import org.gvsig.fmap.mapcontext.MapContext; |
32 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
33 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
34 |
import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
35 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
36 |
|
37 |
|
38 |
/**
|
39 |
* @author fjp
|
40 |
*
|
41 |
* Clase con m?todos muy ?tiles a la hora de hacer nuevas extensiones, y otras
|
42 |
* cosas que puedan ser gen?ricas para este plugin.
|
43 |
*
|
44 |
*/
|
45 |
public class EditionUtilities { |
46 |
|
47 |
public static final int EDITION_STATUS_NO_EDITION = 0; |
48 |
public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 1; |
49 |
public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE = 2; |
50 |
public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE = 3; |
51 |
public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 4; |
52 |
public static int getEditionStatus() |
53 |
{ |
54 |
int status = EDITION_STATUS_NO_EDITION;
|
55 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
56 |
.getActiveWindow(); |
57 |
if (f == null) |
58 |
return status;
|
59 |
|
60 |
if (f instanceof DefaultViewPanel) { |
61 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
62 |
ViewDocument model = vista.getModel(); |
63 |
MapContext mapa = model.getMapContext(); |
64 |
|
65 |
FLayers capas = mapa.getLayers(); |
66 |
|
67 |
int numActiveVectorial = 0; |
68 |
int numActiveVectorialEditable = 0; |
69 |
|
70 |
LayersIterator iter = new LayersIterator(capas);
|
71 |
|
72 |
FLayer capa; |
73 |
while (iter.hasNext()) {
|
74 |
capa = iter.nextLayer(); |
75 |
if (capa instanceof FLyrVect && |
76 |
capa.isActive() && capa.isAvailable()) { |
77 |
numActiveVectorial++; |
78 |
if (capa.isEditing())
|
79 |
numActiveVectorialEditable++; |
80 |
} |
81 |
|
82 |
} |
83 |
|
84 |
if (numActiveVectorialEditable == 1 && numActiveVectorial == 1) |
85 |
return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
86 |
if (numActiveVectorialEditable > 1 && numActiveVectorial == numActiveVectorialEditable) |
87 |
return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
88 |
if (numActiveVectorial == 1) |
89 |
return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE;
|
90 |
if (numActiveVectorial > 1) |
91 |
return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE;
|
92 |
|
93 |
} |
94 |
|
95 |
return status;
|
96 |
} |
97 |
|
98 |
public static FLayer[] getActiveAndEditedLayers() |
99 |
{ |
100 |
int status = EDITION_STATUS_NO_EDITION;
|
101 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
102 |
.getActiveWindow(); |
103 |
if (f == null) |
104 |
return null; |
105 |
|
106 |
if (f instanceof DefaultViewPanel) { |
107 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
108 |
ViewDocument model = vista.getModel(); |
109 |
MapContext mapa = model.getMapContext(); |
110 |
|
111 |
ArrayList resul = new ArrayList(); |
112 |
|
113 |
FLayers capas = mapa.getLayers(); |
114 |
|
115 |
int numActiveVectorial = 0; |
116 |
int numActiveVectorialEditable = 0; |
117 |
|
118 |
LayersIterator iter = new LayersIterator(capas);
|
119 |
FLayer capa; |
120 |
while (iter.hasNext()) {
|
121 |
capa = iter.nextLayer(); |
122 |
if (capa instanceof FLyrVect && |
123 |
capa.isActive()) { |
124 |
numActiveVectorial++; |
125 |
if (capa.isEditing())
|
126 |
{ |
127 |
numActiveVectorialEditable++; |
128 |
resul.add(capa); |
129 |
} |
130 |
} |
131 |
|
132 |
} |
133 |
if (resul.isEmpty())
|
134 |
return null; |
135 |
|
136 |
return (FLayer[]) resul.toArray(new FLayer[0]); |
137 |
|
138 |
} |
139 |
|
140 |
return null; |
141 |
} |
142 |
|
143 |
// public static ILayerDefinition createLayerDefinition(FLyrVect layer) throws ReadDriverException {
|
144 |
// LayerDefinition lyrDef;
|
145 |
// if (layer.getSource().getDriver() instanceof IVectorialDatabaseDriver)
|
146 |
// {
|
147 |
// VectorialEditableAdapter vea = (VectorialEditableAdapter)layer.getSource();
|
148 |
// IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) vea.getDriver();
|
149 |
//
|
150 |
// DBLayerDefinition dbldef=dbDriver.getLyrDef();
|
151 |
// dbldef.setFieldsDesc(vea.getFieldsDescription());
|
152 |
// return dbldef;
|
153 |
// }
|
154 |
// lyrDef = new LayerDefinition();
|
155 |
// lyrDef.setShapeType(layer.getShapeType());
|
156 |
// lyrDef.setProjection(layer.getProjection());
|
157 |
// lyrDef.setName(layer.getName());
|
158 |
// lyrDef.setFieldsDesc(layer.getRecordset().getFieldsDescription());
|
159 |
// return lyrDef;
|
160 |
// }
|
161 |
|
162 |
} |