root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / EditionUtilities.java @ 38554
History | View | Annotate | Download (4.68 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 | 38554 | fpenarrubia | if (model == null) |
46 | return status;
|
||
47 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
48 | 3808 | fjp | |
49 | FLayers capas = mapa.getLayers(); |
||
50 | |||
51 | int numActiveVectorial = 0; |
||
52 | int numActiveVectorialEditable = 0; |
||
53 | 10626 | caballero | |
54 | 9371 | jmvivo | LayersIterator iter = new LayersIterator(capas);
|
55 | 10626 | caballero | |
56 | 9371 | jmvivo | FLayer capa; |
57 | while (iter.hasNext()) {
|
||
58 | capa = iter.nextLayer(); |
||
59 | if (capa instanceof FLyrVect && |
||
60 | capa.isActive() && capa.isAvailable()) { |
||
61 | 3808 | fjp | numActiveVectorial++; |
62 | 9371 | jmvivo | if (capa.isEditing())
|
63 | 3808 | fjp | numActiveVectorialEditable++; |
64 | } |
||
65 | 10626 | caballero | |
66 | } |
||
67 | |||
68 | 9377 | jmvivo | if (numActiveVectorialEditable == 1 && numActiveVectorial == 1) |
69 | 3808 | fjp | return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
70 | 9377 | jmvivo | if (numActiveVectorialEditable > 1 && numActiveVectorial == numActiveVectorialEditable) |
71 | 3808 | fjp | return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
72 | if (numActiveVectorial == 1) |
||
73 | return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE;
|
||
74 | if (numActiveVectorial > 1) |
||
75 | return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE;
|
||
76 | 7410 | caballero | |
77 | 3808 | fjp | } |
78 | 7410 | caballero | |
79 | 3808 | fjp | return status;
|
80 | } |
||
81 | |||
82 | 4430 | fjp | public static FLayer[] getActiveAndEditedLayers() |
83 | { |
||
84 | int status = EDITION_STATUS_NO_EDITION;
|
||
85 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
86 | 6880 | cesar | .getActiveWindow(); |
87 | 4430 | fjp | if (f == null) |
88 | return null; |
||
89 | |||
90 | 5900 | jorpiell | if (f instanceof View) { |
91 | 4430 | fjp | View vista = (View) f; |
92 | 7410 | caballero | IProjectView model = vista.getModel(); |
93 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
94 | 7410 | caballero | |
95 | 4430 | fjp | ArrayList resul = new ArrayList(); |
96 | |||
97 | FLayers capas = mapa.getLayers(); |
||
98 | |||
99 | int numActiveVectorial = 0; |
||
100 | int numActiveVectorialEditable = 0; |
||
101 | 10626 | caballero | |
102 | 9371 | jmvivo | LayersIterator iter = new LayersIterator(capas);
|
103 | FLayer capa; |
||
104 | while (iter.hasNext()) {
|
||
105 | capa = iter.nextLayer(); |
||
106 | if (capa instanceof FLyrVect && |
||
107 | capa.isActive()) { |
||
108 | 4430 | fjp | numActiveVectorial++; |
109 | 9371 | jmvivo | if (capa.isEditing())
|
110 | 4430 | fjp | { |
111 | numActiveVectorialEditable++; |
||
112 | 9371 | jmvivo | resul.add(capa); |
113 | 4430 | fjp | } |
114 | } |
||
115 | 9371 | jmvivo | |
116 | 4430 | fjp | } |
117 | 9371 | jmvivo | if (resul.isEmpty())
|
118 | return null; |
||
119 | 10626 | caballero | |
120 | 4430 | fjp | return (FLayer[]) resul.toArray(new FLayer[0]); |
121 | 7410 | caballero | |
122 | 4430 | fjp | } |
123 | 7410 | caballero | |
124 | 4430 | fjp | return null; |
125 | } |
||
126 | 5558 | fjp | |
127 | 10626 | caballero | public static ILayerDefinition createLayerDefinition(FLyrVect layer) throws ReadDriverException { |
128 | 5595 | fjp | LayerDefinition lyrDef; |
129 | 11971 | caballero | if (layer.getSource().getDriver() instanceof IVectorialDatabaseDriver) |
130 | 5595 | fjp | { |
131 | 12888 | caballero | VectorialEditableAdapter vea = (VectorialEditableAdapter)layer.getSource(); |
132 | IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) vea.getDriver(); |
||
133 | |||
134 | DBLayerDefinition dbldef=dbDriver.getLyrDef(); |
||
135 | dbldef.setFieldsDesc(vea.getFieldsDescription()); |
||
136 | return dbldef;
|
||
137 | 5558 | fjp | } |
138 | 10626 | caballero | lyrDef = new LayerDefinition();
|
139 | lyrDef.setShapeType(layer.getShapeType()); |
||
140 | lyrDef.setProjection(layer.getProjection()); |
||
141 | lyrDef.setName(layer.getName()); |
||
142 | lyrDef.setFieldsDesc(layer.getRecordset().getFieldsDescription()); |
||
143 | 5558 | fjp | return lyrDef;
|
144 | } |
||
145 | 7410 | caballero | |
146 | 3808 | fjp | } |