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