root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / EditionUtilities.java @ 31407
History | View | Annotate | Download (4.63 KB)
1 | 3808 | fjp | package com.iver.cit.gvsig; |
---|---|---|---|
2 | |||
3 | 4430 | fjp | import java.util.ArrayList; |
4 | |||
5 | 10626 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
6 | 3808 | fjp | import com.iver.andami.PluginServices; |
7 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
8 | 12888 | caballero | import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
9 | 5558 | fjp | import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
10 | 11971 | caballero | import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver; |
11 | 13881 | jaume | import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
12 | 12888 | caballero | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
13 | 4430 | fjp | import com.iver.cit.gvsig.fmap.layers.FLayer; |
14 | 3808 | fjp | import com.iver.cit.gvsig.fmap.layers.FLayers; |
15 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
16 | 9371 | jmvivo | import com.iver.cit.gvsig.fmap.layers.LayersIterator; |
17 | 7410 | caballero | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
18 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
19 | 3808 | fjp | |
20 | /**
|
||
21 | * @author fjp
|
||
22 | 7410 | caballero | *
|
23 | 3808 | fjp | * 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 | 7410 | caballero | |
29 | 3808 | fjp | 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 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
38 | 6880 | cesar | .getActiveWindow(); |
39 | 3808 | fjp | if (f == null) |
40 | return status;
|
||
41 | |||
42 | 5900 | jorpiell | if (f instanceof View) { |
43 | 3808 | fjp | View vista = (View) f; |
44 | 7410 | caballero | IProjectView model = vista.getModel(); |
45 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
46 | 3808 | fjp | |
47 | FLayers capas = mapa.getLayers(); |
||
48 | |||
49 | int numActiveVectorial = 0; |
||
50 | int numActiveVectorialEditable = 0; |
||
51 | 10626 | caballero | |
52 | 9371 | jmvivo | LayersIterator iter = new LayersIterator(capas);
|
53 | 10626 | caballero | |
54 | 9371 | jmvivo | FLayer capa; |
55 | while (iter.hasNext()) {
|
||
56 | capa = iter.nextLayer(); |
||
57 | if (capa instanceof FLyrVect && |
||
58 | capa.isActive() && capa.isAvailable()) { |
||
59 | 3808 | fjp | numActiveVectorial++; |
60 | 9371 | jmvivo | if (capa.isEditing())
|
61 | 3808 | fjp | numActiveVectorialEditable++; |
62 | } |
||
63 | 10626 | caballero | |
64 | } |
||
65 | |||
66 | 9377 | jmvivo | if (numActiveVectorialEditable == 1 && numActiveVectorial == 1) |
67 | 3808 | fjp | return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
68 | 9377 | jmvivo | if (numActiveVectorialEditable > 1 && numActiveVectorial == numActiveVectorialEditable) |
69 | 3808 | fjp | 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 | 7410 | caballero | |
75 | 3808 | fjp | } |
76 | 7410 | caballero | |
77 | 3808 | fjp | return status;
|
78 | } |
||
79 | |||
80 | 4430 | fjp | public static FLayer[] getActiveAndEditedLayers() |
81 | { |
||
82 | int status = EDITION_STATUS_NO_EDITION;
|
||
83 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
84 | 6880 | cesar | .getActiveWindow(); |
85 | 4430 | fjp | if (f == null) |
86 | return null; |
||
87 | |||
88 | 5900 | jorpiell | if (f instanceof View) { |
89 | 4430 | fjp | View vista = (View) f; |
90 | 7410 | caballero | IProjectView model = vista.getModel(); |
91 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
92 | 7410 | caballero | |
93 | 4430 | fjp | ArrayList resul = new ArrayList(); |
94 | |||
95 | FLayers capas = mapa.getLayers(); |
||
96 | |||
97 | int numActiveVectorial = 0; |
||
98 | int numActiveVectorialEditable = 0; |
||
99 | 10626 | caballero | |
100 | 9371 | jmvivo | 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 | 4430 | fjp | numActiveVectorial++; |
107 | 9371 | jmvivo | if (capa.isEditing())
|
108 | 4430 | fjp | { |
109 | numActiveVectorialEditable++; |
||
110 | 9371 | jmvivo | resul.add(capa); |
111 | 4430 | fjp | } |
112 | } |
||
113 | 9371 | jmvivo | |
114 | 4430 | fjp | } |
115 | 9371 | jmvivo | if (resul.isEmpty())
|
116 | return null; |
||
117 | 10626 | caballero | |
118 | 4430 | fjp | return (FLayer[]) resul.toArray(new FLayer[0]); |
119 | 7410 | caballero | |
120 | 4430 | fjp | } |
121 | 7410 | caballero | |
122 | 4430 | fjp | return null; |
123 | } |
||
124 | 5558 | fjp | |
125 | 10626 | caballero | public static ILayerDefinition createLayerDefinition(FLyrVect layer) throws ReadDriverException { |
126 | 5595 | fjp | LayerDefinition lyrDef; |
127 | 11971 | caballero | if (layer.getSource().getDriver() instanceof IVectorialDatabaseDriver) |
128 | 5595 | fjp | { |
129 | 12888 | caballero | VectorialEditableAdapter vea = (VectorialEditableAdapter)layer.getSource(); |
130 | IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) vea.getDriver(); |
||
131 | |||
132 | DBLayerDefinition dbldef=dbDriver.getLyrDef(); |
||
133 | dbldef.setFieldsDesc(vea.getFieldsDescription()); |
||
134 | return dbldef;
|
||
135 | 5558 | fjp | } |
136 | 10626 | caballero | lyrDef = new LayerDefinition();
|
137 | lyrDef.setShapeType(layer.getShapeType()); |
||
138 | lyrDef.setProjection(layer.getProjection()); |
||
139 | lyrDef.setName(layer.getName()); |
||
140 | lyrDef.setFieldsDesc(layer.getRecordset().getFieldsDescription()); |
||
141 | 5558 | fjp | return lyrDef;
|
142 | } |
||
143 | 7410 | caballero | |
144 | 3808 | fjp | } |