root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / EditionUtilities.java @ 29616
History | View | Annotate | Download (4.32 KB)
1 |
package org.gvsig.editing; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import org.gvsig.andami.PluginServices; |
6 |
import org.gvsig.app.project.documents.view.IProjectView; |
7 |
import org.gvsig.app.project.documents.view.gui.View; |
8 |
import org.gvsig.fmap.mapcontext.MapContext; |
9 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
10 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
11 |
import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
12 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
13 |
|
14 |
|
15 |
/**
|
16 |
* @author fjp
|
17 |
*
|
18 |
* Clase con m?todos muy ?tiles a la hora de hacer nuevas extensiones, y otras
|
19 |
* cosas que puedan ser gen?ricas para este plugin.
|
20 |
*
|
21 |
*/
|
22 |
public class EditionUtilities { |
23 |
|
24 |
public static final int EDITION_STATUS_NO_EDITION = 0; |
25 |
public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 1; |
26 |
public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE = 2; |
27 |
public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE = 3; |
28 |
public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 4; |
29 |
public static int getEditionStatus() |
30 |
{ |
31 |
int status = EDITION_STATUS_NO_EDITION;
|
32 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
33 |
.getActiveWindow(); |
34 |
if (f == null) |
35 |
return status;
|
36 |
|
37 |
if (f instanceof View) { |
38 |
View vista = (View) f; |
39 |
IProjectView model = vista.getModel(); |
40 |
MapContext mapa = model.getMapContext(); |
41 |
|
42 |
FLayers capas = mapa.getLayers(); |
43 |
|
44 |
int numActiveVectorial = 0; |
45 |
int numActiveVectorialEditable = 0; |
46 |
|
47 |
LayersIterator iter = new LayersIterator(capas);
|
48 |
|
49 |
FLayer capa; |
50 |
while (iter.hasNext()) {
|
51 |
capa = iter.nextLayer(); |
52 |
if (capa instanceof FLyrVect && |
53 |
capa.isActive() && capa.isAvailable()) { |
54 |
numActiveVectorial++; |
55 |
if (capa.isEditing())
|
56 |
numActiveVectorialEditable++; |
57 |
} |
58 |
|
59 |
} |
60 |
|
61 |
if (numActiveVectorialEditable == 1 && numActiveVectorial == 1) |
62 |
return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
63 |
if (numActiveVectorialEditable > 1 && numActiveVectorial == numActiveVectorialEditable) |
64 |
return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
65 |
if (numActiveVectorial == 1) |
66 |
return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE;
|
67 |
if (numActiveVectorial > 1) |
68 |
return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE;
|
69 |
|
70 |
} |
71 |
|
72 |
return status;
|
73 |
} |
74 |
|
75 |
public static FLayer[] getActiveAndEditedLayers() |
76 |
{ |
77 |
int status = EDITION_STATUS_NO_EDITION;
|
78 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
79 |
.getActiveWindow(); |
80 |
if (f == null) |
81 |
return null; |
82 |
|
83 |
if (f instanceof View) { |
84 |
View vista = (View) f; |
85 |
IProjectView model = vista.getModel(); |
86 |
MapContext mapa = model.getMapContext(); |
87 |
|
88 |
ArrayList resul = new ArrayList(); |
89 |
|
90 |
FLayers capas = mapa.getLayers(); |
91 |
|
92 |
int numActiveVectorial = 0; |
93 |
int numActiveVectorialEditable = 0; |
94 |
|
95 |
LayersIterator iter = new LayersIterator(capas);
|
96 |
FLayer capa; |
97 |
while (iter.hasNext()) {
|
98 |
capa = iter.nextLayer(); |
99 |
if (capa instanceof FLyrVect && |
100 |
capa.isActive()) { |
101 |
numActiveVectorial++; |
102 |
if (capa.isEditing())
|
103 |
{ |
104 |
numActiveVectorialEditable++; |
105 |
resul.add(capa); |
106 |
} |
107 |
} |
108 |
|
109 |
} |
110 |
if (resul.isEmpty())
|
111 |
return null; |
112 |
|
113 |
return (FLayer[]) resul.toArray(new FLayer[0]); |
114 |
|
115 |
} |
116 |
|
117 |
return null; |
118 |
} |
119 |
|
120 |
// public static ILayerDefinition createLayerDefinition(FLyrVect layer) throws ReadDriverException {
|
121 |
// LayerDefinition lyrDef;
|
122 |
// if (layer.getSource().getDriver() instanceof IVectorialDatabaseDriver)
|
123 |
// {
|
124 |
// VectorialEditableAdapter vea = (VectorialEditableAdapter)layer.getSource();
|
125 |
// IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) vea.getDriver();
|
126 |
//
|
127 |
// DBLayerDefinition dbldef=dbDriver.getLyrDef();
|
128 |
// dbldef.setFieldsDesc(vea.getFieldsDescription());
|
129 |
// return dbldef;
|
130 |
// }
|
131 |
// lyrDef = new LayerDefinition();
|
132 |
// lyrDef.setShapeType(layer.getShapeType());
|
133 |
// lyrDef.setProjection(layer.getProjection());
|
134 |
// lyrDef.setName(layer.getName());
|
135 |
// lyrDef.setFieldsDesc(layer.getRecordset().getFieldsDescription());
|
136 |
// return lyrDef;
|
137 |
// }
|
138 |
|
139 |
} |