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 | 3808 | fjp | package com.iver.cit.gvsig; |
---|---|---|---|
2 | |||
3 | 10873 | caballero | import java.sql.Connection; |
4 | 4430 | fjp | import java.util.ArrayList; |
5 | |||
6 | 3808 | fjp | import com.iver.andami.PluginServices; |
7 | 4850 | fjp | import com.iver.cit.gvsig.fmap.DriverException; |
8 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
9 | 10884 | jorpiell | import com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver; |
10 | 5558 | fjp | import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
11 | import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
||
12 | 5595 | fjp | import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
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 | 9380 | jmvivo | import com.iver.cit.gvsig.fmap.layers.LayersIterator; |
17 | 8765 | jjdelcerro | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
18 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
19 | 3808 | fjp | |
20 | /**
|
||
21 | * @author fjp
|
||
22 | 8765 | jjdelcerro | *
|
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 | 8765 | jjdelcerro | |
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 | 8765 | jjdelcerro | 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 | 10873 | caballero | |
52 | 9380 | jmvivo | LayersIterator iter = new LayersIterator(capas);
|
53 | 10873 | caballero | |
54 | 9380 | 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 | 9380 | jmvivo | if (capa.isEditing())
|
61 | 3808 | fjp | numActiveVectorialEditable++; |
62 | } |
||
63 | 10873 | caballero | |
64 | } |
||
65 | |||
66 | 9380 | jmvivo | if (numActiveVectorialEditable == 1 && numActiveVectorial == 1) |
67 | 3808 | fjp | return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
68 | 9380 | 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 | 8765 | jjdelcerro | |
75 | 3808 | fjp | } |
76 | 8765 | jjdelcerro | |
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 | 8765 | jjdelcerro | IProjectView model = vista.getModel(); |
91 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
92 | 8765 | jjdelcerro | |
93 | 4430 | fjp | ArrayList resul = new ArrayList(); |
94 | |||
95 | FLayers capas = mapa.getLayers(); |
||
96 | |||
97 | int numActiveVectorial = 0; |
||
98 | int numActiveVectorialEditable = 0; |
||
99 | 10873 | caballero | |
100 | 9380 | 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 | 9380 | jmvivo | if (capa.isEditing())
|
108 | 4430 | fjp | { |
109 | numActiveVectorialEditable++; |
||
110 | 9380 | jmvivo | resul.add(capa); |
111 | 4430 | fjp | } |
112 | } |
||
113 | 9380 | jmvivo | |
114 | 4430 | fjp | } |
115 | 9380 | jmvivo | if (resul.isEmpty())
|
116 | return null; |
||
117 | 10873 | caballero | |
118 | 4430 | fjp | return (FLayer[]) resul.toArray(new FLayer[0]); |
119 | 8765 | jjdelcerro | |
120 | 4430 | fjp | } |
121 | 8765 | jjdelcerro | |
122 | 4430 | fjp | return null; |
123 | } |
||
124 | 5558 | fjp | |
125 | public static ILayerDefinition createLayerDefinition(FLyrVect layer) throws DriverException { |
||
126 | 5595 | fjp | LayerDefinition lyrDef; |
127 | if (layer.getSource().getDriver() instanceof VectorialDatabaseDriver) |
||
128 | { |
||
129 | 11292 | caballero | VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) layer.getSource().getDriver(); |
130 | 8765 | jjdelcerro | return dbDriver.getLyrDef();
|
131 | 5558 | fjp | } |
132 | 5595 | fjp | 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 | 8765 | jjdelcerro | } |
144 | 5595 | fjp | } |
145 | 5558 | fjp | return lyrDef;
|
146 | } |
||
147 | 8765 | jjdelcerro | |
148 | 3808 | fjp | } |