svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / EditionUtilities.java @ 6486
History | View | Annotate | Download (4.32 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.FMap; |
8 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
9 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
10 |
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
11 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
12 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
13 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
14 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
15 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
16 |
import com.iver.cit.gvsig.gui.View; |
17 |
import com.iver.cit.gvsig.project.ProjectView; |
18 |
import com.iver.utiles.NumberUtilities; |
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.View f = PluginServices.getMDIManager() |
38 |
.getActiveView(); |
39 |
if (f == null) |
40 |
return status;
|
41 |
|
42 |
if (f instanceof View) { |
43 |
View vista = (View) f; |
44 |
ProjectView model = vista.getModel(); |
45 |
FMap mapa = model.getMapContext(); |
46 |
|
47 |
FLayers capas = mapa.getLayers(); |
48 |
|
49 |
int numActiveVectorial = 0; |
50 |
int numActiveVectorialEditable = 0; |
51 |
for (int i = 0; i < capas.getLayersCount(); i++) { |
52 |
if (capas.getLayer(i) instanceof FLyrVect && |
53 |
capas.getLayer(i).isActive()) { |
54 |
numActiveVectorial++; |
55 |
if (capas.getLayer(i).isEditing())
|
56 |
numActiveVectorialEditable++; |
57 |
} |
58 |
} |
59 |
if (numActiveVectorialEditable == 1) |
60 |
return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
61 |
if (numActiveVectorialEditable > 1) |
62 |
return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
63 |
if (numActiveVectorial == 1) |
64 |
return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE;
|
65 |
if (numActiveVectorial > 1) |
66 |
return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE;
|
67 |
|
68 |
} |
69 |
|
70 |
return status;
|
71 |
} |
72 |
|
73 |
public static FLayer[] getActiveAndEditedLayers() |
74 |
{ |
75 |
int status = EDITION_STATUS_NO_EDITION;
|
76 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
77 |
.getActiveView(); |
78 |
if (f == null) |
79 |
return null; |
80 |
|
81 |
if (f instanceof View) { |
82 |
View vista = (View) f; |
83 |
ProjectView model = vista.getModel(); |
84 |
FMap mapa = model.getMapContext(); |
85 |
|
86 |
ArrayList resul = new ArrayList(); |
87 |
|
88 |
FLayers capas = mapa.getLayers(); |
89 |
|
90 |
int numActiveVectorial = 0; |
91 |
int numActiveVectorialEditable = 0; |
92 |
for (int i = 0; i < capas.getLayersCount(); i++) { |
93 |
if (capas.getLayer(i) instanceof FLyrVect && |
94 |
capas.getLayer(i).isActive()) { |
95 |
numActiveVectorial++; |
96 |
if (capas.getLayer(i).isEditing())
|
97 |
{ |
98 |
numActiveVectorialEditable++; |
99 |
resul.add(capas.getLayer(i)); |
100 |
} |
101 |
} |
102 |
} |
103 |
return (FLayer[]) resul.toArray(new FLayer[0]); |
104 |
|
105 |
} |
106 |
|
107 |
return null; |
108 |
} |
109 |
|
110 |
public static ILayerDefinition createLayerDefinition(FLyrVect layer) throws DriverException { |
111 |
LayerDefinition lyrDef; |
112 |
if (layer.getSource().getDriver() instanceof VectorialDatabaseDriver) |
113 |
{ |
114 |
VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) layer.getSource().getDriver(); |
115 |
return dbDriver.getLyrDef();
|
116 |
} |
117 |
else
|
118 |
{ |
119 |
lyrDef = new LayerDefinition();
|
120 |
lyrDef.setShapeType(layer.getShapeType()); |
121 |
lyrDef.setProjection(layer.getProjection()); |
122 |
lyrDef.setName(layer.getName()); |
123 |
try {
|
124 |
lyrDef.setFieldsDesc(layer.getRecordset().getFieldsDescription()); |
125 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
126 |
e.printStackTrace(); |
127 |
throw new DriverException(e); |
128 |
} |
129 |
} |
130 |
return lyrDef;
|
131 |
} |
132 |
|
133 |
} |