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