Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / EditionUtilities.java @ 38544

History | View | Annotate | Download (4.4 KB)

1 29616 jpiera
package org.gvsig.editing;
2 3808 fjp
3 4430 fjp
import java.util.ArrayList;
4
5 29616 jpiera
import org.gvsig.andami.PluginServices;
6 31496 jjdelcerro
import org.gvsig.app.project.documents.view.ViewDocument;
7
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
8 21666 vcaballero
import org.gvsig.fmap.mapcontext.MapContext;
9
import org.gvsig.fmap.mapcontext.layers.FLayer;
10
import org.gvsig.fmap.mapcontext.layers.FLayers;
11
import org.gvsig.fmap.mapcontext.layers.LayersIterator;
12
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
13
14 3808 fjp
15
/**
16
 * @author fjp
17 7410 caballero
 *
18 3808 fjp
 * Clase con m?todos muy ?tiles a la hora de hacer nuevas extensiones, y otras
19
 * cosas que puedan ser gen?ricas para este plugin.
20
 *
21
 */
22
public class EditionUtilities {
23 7410 caballero
24 3808 fjp
        public static final int EDITION_STATUS_NO_EDITION = 0;
25
        public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 1;
26
        public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE = 2;
27
        public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE = 3;
28
        public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 4;
29
        public static int getEditionStatus()
30
        {
31
                int status = EDITION_STATUS_NO_EDITION;
32 29616 jpiera
        org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
33 6880 cesar
        .getActiveWindow();
34 3808 fjp
        if (f == null)
35
                return status;
36
37 31496 jjdelcerro
        if (f instanceof DefaultViewPanel) {
38
                DefaultViewPanel vista = (DefaultViewPanel) f;
39
                ViewDocument model = vista.getModel();
40 6878 cesar
                MapContext mapa = model.getMapContext();
41 3808 fjp
42
                FLayers capas = mapa.getLayers();
43
44
                int numActiveVectorial = 0;
45
                int numActiveVectorialEditable = 0;
46 10626 caballero
47 9371 jmvivo
                LayersIterator iter = new LayersIterator(capas);
48 10626 caballero
49 9371 jmvivo
                FLayer capa;
50
                while (iter.hasNext()) {
51
                        capa = iter.nextLayer();
52
                        if (capa instanceof FLyrVect &&
53
                                        capa.isActive() && capa.isAvailable()) {
54 3808 fjp
                                numActiveVectorial++;
55 9371 jmvivo
                                if (capa.isEditing())
56 3808 fjp
                                        numActiveVectorialEditable++;
57
                        }
58 10626 caballero
59
                }
60
61 9377 jmvivo
                if (numActiveVectorialEditable == 1 && numActiveVectorial == 1)
62 3808 fjp
                        return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
63 9377 jmvivo
                if (numActiveVectorialEditable > 1 && numActiveVectorial == numActiveVectorialEditable)
64 3808 fjp
                        return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
65
                if (numActiveVectorial == 1)
66
                        return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE;
67
                if (numActiveVectorial > 1)
68
                        return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE;
69 7410 caballero
70 3808 fjp
        }
71 7410 caballero
72 3808 fjp
                return status;
73
        }
74
75 4430 fjp
        public static FLayer[] getActiveAndEditedLayers()
76
        {
77
                int status = EDITION_STATUS_NO_EDITION;
78 29616 jpiera
        org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
79 6880 cesar
        .getActiveWindow();
80 4430 fjp
        if (f == null)
81
                return null;
82
83 31496 jjdelcerro
        if (f instanceof DefaultViewPanel) {
84
                DefaultViewPanel vista = (DefaultViewPanel) f;
85
                ViewDocument model = vista.getModel();
86 6878 cesar
                MapContext mapa = model.getMapContext();
87 7410 caballero
88 4430 fjp
                ArrayList resul = new ArrayList();
89
90
                FLayers capas = mapa.getLayers();
91
92
                int numActiveVectorial = 0;
93
                int numActiveVectorialEditable = 0;
94 10626 caballero
95 9371 jmvivo
                LayersIterator iter = new LayersIterator(capas);
96
                FLayer capa;
97
                while (iter.hasNext()) {
98
                        capa = iter.nextLayer();
99
                        if (capa instanceof FLyrVect &&
100
                                        capa.isActive()) {
101 4430 fjp
                                numActiveVectorial++;
102 9371 jmvivo
                                if (capa.isEditing())
103 4430 fjp
                                {
104
                                        numActiveVectorialEditable++;
105 9371 jmvivo
                                        resul.add(capa);
106 4430 fjp
                                }
107
                        }
108 9371 jmvivo
109 4430 fjp
                }
110 9371 jmvivo
                if (resul.isEmpty())
111
                        return null;
112 10626 caballero
113 4430 fjp
                       return (FLayer[]) resul.toArray(new FLayer[0]);
114 7410 caballero
115 4430 fjp
        }
116 7410 caballero
117 4430 fjp
                return null;
118
        }
119 5558 fjp
120 22986 vcaballero
//        public static ILayerDefinition createLayerDefinition(FLyrVect layer) throws ReadDriverException {
121
//                LayerDefinition lyrDef;
122
//                if (layer.getSource().getDriver() instanceof IVectorialDatabaseDriver)
123
//                {
124
//                        VectorialEditableAdapter vea = (VectorialEditableAdapter)layer.getSource();
125
//                        IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) vea.getDriver();
126
//
127
//                        DBLayerDefinition dbldef=dbDriver.getLyrDef();
128
//                        dbldef.setFieldsDesc(vea.getFieldsDescription());
129
//                        return dbldef;
130
//                }
131
//                lyrDef = new LayerDefinition();
132
//                lyrDef.setShapeType(layer.getShapeType());
133
//                lyrDef.setProjection(layer.getProjection());
134
//                lyrDef.setName(layer.getName());
135
//                        lyrDef.setFieldsDesc(layer.getRecordset().getFieldsDescription());
136
//                return lyrDef;
137
//        }
138 12888 caballero
139 3808 fjp
}