Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / EditionUtilities.java @ 4430

History | View | Annotate | Download (3.24 KB)

1
package com.iver.cit.gvsig;
2

    
3
import java.util.ArrayList;
4

    
5
import com.iver.andami.PluginServices;
6
import com.iver.cit.gvsig.fmap.FMap;
7
import com.iver.cit.gvsig.fmap.layers.FLayer;
8
import com.iver.cit.gvsig.fmap.layers.FLayers;
9
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
10
import com.iver.cit.gvsig.gui.View;
11
import com.iver.cit.gvsig.project.ProjectView;
12

    
13
/**
14
 * @author fjp
15
 * 
16
 * Clase con m?todos muy ?tiles a la hora de hacer nuevas extensiones, y otras
17
 * cosas que puedan ser gen?ricas para este plugin.
18
 *
19
 */
20
public class EditionUtilities {
21
        
22
        public static final int EDITION_STATUS_NO_EDITION = 0;
23
        public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 1;
24
        public static final int EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE = 2;
25
        public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE = 3;
26
        public static final int EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE = 4;
27
        public static int getEditionStatus()
28
        {
29
                int status = EDITION_STATUS_NO_EDITION;
30
        com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
31
        .getActiveView();
32
        if (f == null)
33
                return status;
34

    
35
        if (f.getClass() == View.class) {
36
                View vista = (View) f;
37
                ProjectView model = vista.getModel();
38
                FMap mapa = model.getMapContext();
39

    
40
                FLayers capas = mapa.getLayers();
41

    
42
                int numActiveVectorial = 0;
43
                int numActiveVectorialEditable = 0;
44
                for (int i = 0; i < capas.getLayersCount(); i++) {
45
                        if (capas.getLayer(i) instanceof FLyrVect &&
46
                                        capas.getLayer(i).isActive()) {
47
                                numActiveVectorial++;
48
                                if (capas.getLayer(i).isEditing())
49
                                        numActiveVectorialEditable++;
50
                        }
51
                }
52
                if (numActiveVectorialEditable == 1)
53
                        return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
54
                if (numActiveVectorialEditable > 1)
55
                        return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE;
56
                if (numActiveVectorial == 1)
57
                        return EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE;
58
                if (numActiveVectorial > 1)
59
                        return EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE;
60
                
61
        }
62
                
63
                return status;
64
        }
65

    
66
        public static FLayer[] getActiveAndEditedLayers()
67
        {
68
                int status = EDITION_STATUS_NO_EDITION;
69
        com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
70
        .getActiveView();
71
        if (f == null)
72
                return null;
73

    
74
        if (f.getClass() == View.class) {
75
                View vista = (View) f;
76
                ProjectView model = vista.getModel();
77
                FMap mapa = model.getMapContext();
78
                
79
                ArrayList resul = new ArrayList();
80

    
81
                FLayers capas = mapa.getLayers();
82

    
83
                int numActiveVectorial = 0;
84
                int numActiveVectorialEditable = 0;
85
                for (int i = 0; i < capas.getLayersCount(); i++) {
86
                        if (capas.getLayer(i) instanceof FLyrVect &&
87
                                        capas.getLayer(i).isActive()) {
88
                                numActiveVectorial++;
89
                                if (capas.getLayer(i).isEditing())
90
                                {
91
                                        numActiveVectorialEditable++;
92
                                        resul.add(capas.getLayer(i));
93
                                }
94
                        }
95
                }
96
                       return (FLayer[]) resul.toArray(new FLayer[0]);
97
                
98
        }
99
                
100
                return null;
101
        }
102
        
103
}