Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_RELEASE / extensions / extCAD / src / com / iver / cit / gvsig / EditionUtilities.java @ 9167

History | View | Annotate | Download (4.23 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 6878 cesar
import com.iver.cit.gvsig.fmap.MapContext;
8 5558 fjp
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
9
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition;
10 5595 fjp
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver;
11 4430 fjp
import com.iver.cit.gvsig.fmap.layers.FLayer;
12 3808 fjp
import com.iver.cit.gvsig.fmap.layers.FLayers;
13
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
14 8765 jjdelcerro
import com.iver.cit.gvsig.project.documents.view.IProjectView;
15
import com.iver.cit.gvsig.project.documents.view.gui.View;
16 3808 fjp
17
/**
18
 * @author fjp
19 8765 jjdelcerro
 *
20 3808 fjp
 * Clase con m?todos muy ?tiles a la hora de hacer nuevas extensiones, y otras
21
 * cosas que puedan ser gen?ricas para este plugin.
22
 *
23
 */
24
public class EditionUtilities {
25 8765 jjdelcerro
26 3808 fjp
        public static final int EDITION_STATUS_NO_EDITION = 0;
27
        public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 1;
28
        public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE = 2;
29
        public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE = 3;
30
        public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 4;
31
        public static int getEditionStatus()
32
        {
33
                int status = EDITION_STATUS_NO_EDITION;
34 6877 cesar
        com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
35 6880 cesar
        .getActiveWindow();
36 3808 fjp
        if (f == null)
37
                return status;
38
39 5900 jorpiell
        if (f instanceof View) {
40 3808 fjp
                View vista = (View) f;
41 8765 jjdelcerro
                IProjectView model = vista.getModel();
42 6878 cesar
                MapContext mapa = model.getMapContext();
43 3808 fjp
44
                FLayers capas = mapa.getLayers();
45
46
                int numActiveVectorial = 0;
47
                int numActiveVectorialEditable = 0;
48
                for (int i = 0; i < capas.getLayersCount(); i++) {
49
                        if (capas.getLayer(i) instanceof FLyrVect &&
50 6779 jmvivo
                                        capas.getLayer(i).isActive() && capas.getLayer(i).isAvailable()) {
51 3808 fjp
                                numActiveVectorial++;
52
                                if (capas.getLayer(i).isEditing())
53
                                        numActiveVectorialEditable++;
54
                        }
55
                }
56
                if (numActiveVectorialEditable == 1)
57
                        return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
58
                if (numActiveVectorialEditable > 1)
59
                        return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
60
                if (numActiveVectorial == 1)
61
                        return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE;
62
                if (numActiveVectorial > 1)
63
                        return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE;
64 8765 jjdelcerro
65 3808 fjp
        }
66 8765 jjdelcerro
67 3808 fjp
                return status;
68
        }
69
70 4430 fjp
        public static FLayer[] getActiveAndEditedLayers()
71
        {
72
                int status = EDITION_STATUS_NO_EDITION;
73 6877 cesar
        com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
74 6880 cesar
        .getActiveWindow();
75 4430 fjp
        if (f == null)
76
                return null;
77
78 5900 jorpiell
        if (f instanceof View) {
79 4430 fjp
                View vista = (View) f;
80 8765 jjdelcerro
                IProjectView model = vista.getModel();
81 6878 cesar
                MapContext mapa = model.getMapContext();
82 8765 jjdelcerro
83 4430 fjp
                ArrayList resul = new ArrayList();
84
85
                FLayers capas = mapa.getLayers();
86
87
                int numActiveVectorial = 0;
88
                int numActiveVectorialEditable = 0;
89
                for (int i = 0; i < capas.getLayersCount(); i++) {
90
                        if (capas.getLayer(i) instanceof FLyrVect &&
91
                                        capas.getLayer(i).isActive()) {
92
                                numActiveVectorial++;
93
                                if (capas.getLayer(i).isEditing())
94
                                {
95
                                        numActiveVectorialEditable++;
96
                                        resul.add(capas.getLayer(i));
97
                                }
98
                        }
99
                }
100
                       return (FLayer[]) resul.toArray(new FLayer[0]);
101 8765 jjdelcerro
102 4430 fjp
        }
103 8765 jjdelcerro
104 4430 fjp
                return null;
105
        }
106 5558 fjp
107
        public static ILayerDefinition createLayerDefinition(FLyrVect layer) throws DriverException {
108 5595 fjp
                LayerDefinition lyrDef;
109
                if (layer.getSource().getDriver() instanceof VectorialDatabaseDriver)
110
                {
111
                        VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) layer.getSource().getDriver();
112 8765 jjdelcerro
                        return dbDriver.getLyrDef();
113 5558 fjp
                }
114 5595 fjp
                else
115
                {
116
                        lyrDef = new LayerDefinition();
117
                        lyrDef.setShapeType(layer.getShapeType());
118
                        lyrDef.setProjection(layer.getProjection());
119
                        lyrDef.setName(layer.getName());
120
                        try {
121
                                lyrDef.setFieldsDesc(layer.getRecordset().getFieldsDescription());
122
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
123
                                e.printStackTrace();
124
                                throw new DriverException(e);
125 8765 jjdelcerro
                        }
126 5595 fjp
                }
127 5558 fjp
                return lyrDef;
128
        }
129 8765 jjdelcerro
130 3808 fjp
}