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