svn-gvsig-desktop / tags / v1_0_2_Build_912 / extensions / extCAD / src / com / iver / cit / gvsig / EditionUtilities.java @ 11422
History | View | Annotate | Download (4.58 KB)
1 |
package com.iver.cit.gvsig; |
---|---|
2 |
|
3 |
import java.sql.Connection; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
import com.iver.andami.PluginServices; |
7 |
import com.iver.cit.gvsig.fmap.DriverException; |
8 |
import com.iver.cit.gvsig.fmap.MapContext; |
9 |
import com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver; |
10 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
11 |
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
12 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
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 |
MapContext mapa = model.getMapContext(); |
46 |
|
47 |
FLayers capas = mapa.getLayers(); |
48 |
|
49 |
int numActiveVectorial = 0; |
50 |
int numActiveVectorialEditable = 0; |
51 |
|
52 |
LayersIterator iter = new LayersIterator(capas);
|
53 |
|
54 |
FLayer capa; |
55 |
while (iter.hasNext()) {
|
56 |
capa = iter.nextLayer(); |
57 |
if (capa instanceof FLyrVect && |
58 |
capa.isActive() && capa.isAvailable()) { |
59 |
numActiveVectorial++; |
60 |
if (capa.isEditing())
|
61 |
numActiveVectorialEditable++; |
62 |
} |
63 |
|
64 |
} |
65 |
|
66 |
if (numActiveVectorialEditable == 1 && numActiveVectorial == 1) |
67 |
return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
68 |
if (numActiveVectorialEditable > 1 && numActiveVectorial == numActiveVectorialEditable) |
69 |
return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
70 |
if (numActiveVectorial == 1) |
71 |
return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE;
|
72 |
if (numActiveVectorial > 1) |
73 |
return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE;
|
74 |
|
75 |
} |
76 |
|
77 |
return status;
|
78 |
} |
79 |
|
80 |
public static FLayer[] getActiveAndEditedLayers() |
81 |
{ |
82 |
int status = EDITION_STATUS_NO_EDITION;
|
83 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
84 |
.getActiveWindow(); |
85 |
if (f == null) |
86 |
return null; |
87 |
|
88 |
if (f instanceof View) { |
89 |
View vista = (View) f; |
90 |
IProjectView model = vista.getModel(); |
91 |
MapContext mapa = model.getMapContext(); |
92 |
|
93 |
ArrayList resul = new ArrayList(); |
94 |
|
95 |
FLayers capas = mapa.getLayers(); |
96 |
|
97 |
int numActiveVectorial = 0; |
98 |
int numActiveVectorialEditable = 0; |
99 |
|
100 |
LayersIterator iter = new LayersIterator(capas);
|
101 |
FLayer capa; |
102 |
while (iter.hasNext()) {
|
103 |
capa = iter.nextLayer(); |
104 |
if (capa instanceof FLyrVect && |
105 |
capa.isActive()) { |
106 |
numActiveVectorial++; |
107 |
if (capa.isEditing())
|
108 |
{ |
109 |
numActiveVectorialEditable++; |
110 |
resul.add(capa); |
111 |
} |
112 |
} |
113 |
|
114 |
} |
115 |
if (resul.isEmpty())
|
116 |
return null; |
117 |
|
118 |
return (FLayer[]) resul.toArray(new FLayer[0]); |
119 |
|
120 |
} |
121 |
|
122 |
return null; |
123 |
} |
124 |
|
125 |
public static ILayerDefinition createLayerDefinition(FLyrVect layer) throws DriverException { |
126 |
LayerDefinition lyrDef; |
127 |
if (layer.getSource().getDriver() instanceof VectorialDatabaseDriver) |
128 |
{ |
129 |
VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) layer.getSource().getDriver(); |
130 |
return dbDriver.getLyrDef();
|
131 |
} |
132 |
else
|
133 |
{ |
134 |
lyrDef = new LayerDefinition();
|
135 |
lyrDef.setShapeType(layer.getShapeType()); |
136 |
lyrDef.setProjection(layer.getProjection()); |
137 |
lyrDef.setName(layer.getName()); |
138 |
try {
|
139 |
lyrDef.setFieldsDesc(layer.getRecordset().getFieldsDescription()); |
140 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
141 |
e.printStackTrace(); |
142 |
throw new DriverException(e); |
143 |
} |
144 |
} |
145 |
return lyrDef;
|
146 |
} |
147 |
|
148 |
} |