root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / EditionUtilities.java @ 4862
History | View | Annotate | Download (4.26 KB)
1 | 3808 | fjp | package com.iver.cit.gvsig; |
---|---|---|---|
2 | |||
3 | 4430 | fjp | import java.util.ArrayList; |
4 | |||
5 | 3808 | fjp | import com.iver.andami.PluginServices; |
6 | 4850 | fjp | import com.iver.cit.gvsig.fmap.DriverException; |
7 | 3808 | fjp | import com.iver.cit.gvsig.fmap.FMap; |
8 | 4850 | fjp | import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
9 | 4430 | fjp | import com.iver.cit.gvsig.fmap.layers.FLayer; |
10 | 3808 | fjp | import com.iver.cit.gvsig.fmap.layers.FLayers; |
11 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
12 | 4850 | fjp | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
13 | 3808 | fjp | import com.iver.cit.gvsig.gui.View; |
14 | import com.iver.cit.gvsig.project.ProjectView; |
||
15 | |||
16 | /**
|
||
17 | * @author fjp
|
||
18 | *
|
||
19 | * Clase con m?todos muy ?tiles a la hora de hacer nuevas extensiones, y otras
|
||
20 | * cosas que puedan ser gen?ricas para este plugin.
|
||
21 | *
|
||
22 | */
|
||
23 | public class EditionUtilities { |
||
24 | |||
25 | public static final int EDITION_STATUS_NO_EDITION = 0; |
||
26 | public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 1; |
||
27 | public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE = 2; |
||
28 | public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE = 3; |
||
29 | public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 4; |
||
30 | public static int getEditionStatus() |
||
31 | { |
||
32 | int status = EDITION_STATUS_NO_EDITION;
|
||
33 | com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
||
34 | .getActiveView(); |
||
35 | if (f == null) |
||
36 | return status;
|
||
37 | |||
38 | if (f.getClass() == View.class) { |
||
39 | View vista = (View) f; |
||
40 | ProjectView model = vista.getModel(); |
||
41 | FMap mapa = model.getMapContext(); |
||
42 | |||
43 | FLayers capas = mapa.getLayers(); |
||
44 | |||
45 | int numActiveVectorial = 0; |
||
46 | int numActiveVectorialEditable = 0; |
||
47 | for (int i = 0; i < capas.getLayersCount(); i++) { |
||
48 | if (capas.getLayer(i) instanceof FLyrVect && |
||
49 | capas.getLayer(i).isActive()) { |
||
50 | numActiveVectorial++; |
||
51 | if (capas.getLayer(i).isEditing())
|
||
52 | numActiveVectorialEditable++; |
||
53 | } |
||
54 | } |
||
55 | if (numActiveVectorialEditable == 1) |
||
56 | return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
||
57 | if (numActiveVectorialEditable > 1) |
||
58 | return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
|
||
59 | if (numActiveVectorial == 1) |
||
60 | return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE;
|
||
61 | if (numActiveVectorial > 1) |
||
62 | return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE;
|
||
63 | |||
64 | } |
||
65 | |||
66 | return status;
|
||
67 | } |
||
68 | |||
69 | 4430 | fjp | public static FLayer[] getActiveAndEditedLayers() |
70 | { |
||
71 | int status = EDITION_STATUS_NO_EDITION;
|
||
72 | com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
||
73 | .getActiveView(); |
||
74 | if (f == null) |
||
75 | return null; |
||
76 | |||
77 | if (f.getClass() == View.class) { |
||
78 | View vista = (View) f; |
||
79 | ProjectView model = vista.getModel(); |
||
80 | FMap mapa = model.getMapContext(); |
||
81 | |||
82 | ArrayList resul = new ArrayList(); |
||
83 | |||
84 | FLayers capas = mapa.getLayers(); |
||
85 | |||
86 | int numActiveVectorial = 0; |
||
87 | int numActiveVectorialEditable = 0; |
||
88 | for (int i = 0; i < capas.getLayersCount(); i++) { |
||
89 | if (capas.getLayer(i) instanceof FLyrVect && |
||
90 | capas.getLayer(i).isActive()) { |
||
91 | numActiveVectorial++; |
||
92 | if (capas.getLayer(i).isEditing())
|
||
93 | { |
||
94 | numActiveVectorialEditable++; |
||
95 | resul.add(capas.getLayer(i)); |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | return (FLayer[]) resul.toArray(new FLayer[0]); |
||
100 | |||
101 | } |
||
102 | |||
103 | return null; |
||
104 | } |
||
105 | |||
106 | 4850 | fjp | public static FieldDescription[] getFieldsDescription(FLyrVect lyrVect) |
107 | { |
||
108 | SelectableDataSource sds; |
||
109 | FieldDescription[] fieldsDescrip = null; |
||
110 | try {
|
||
111 | sds = lyrVect.getRecordset(); |
||
112 | 4862 | fjp | // Para evitar el PK.
|
113 | int numFields = sds.getFieldNames().length; //-sds.getPKCardinality(); |
||
114 | 4850 | fjp | fieldsDescrip = new FieldDescription[numFields];
|
115 | for (int i = 0; i < numFields; i++) { |
||
116 | fieldsDescrip[i] = new FieldDescription();
|
||
117 | fieldsDescrip[i].setFieldType(sds.getFieldType(i)); |
||
118 | fieldsDescrip[i].setFieldName(sds.getFieldName(i)); |
||
119 | 4862 | fjp | fieldsDescrip[i].setFieldLength(sds.getFieldWidth(i)); |
120 | System.out.println("Campo " + sds.getFieldName(i) + " con ancho= " + sds.getFieldWidth(i)); |
||
121 | 4850 | fjp | } |
122 | } catch (DriverException e) {
|
||
123 | e.printStackTrace(); |
||
124 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
125 | e.printStackTrace(); |
||
126 | } |
||
127 | return fieldsDescrip;
|
||
128 | } |
||
129 | 3808 | fjp | } |