Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / StartEditing.java @ 4892

History | View | Annotate | Download (4.51 KB)

1
package com.iver.cit.gvsig;
2

    
3
import com.iver.andami.PluginServices;
4
import com.iver.andami.plugins.Extension;
5
import com.iver.cit.gvsig.fmap.FMap;
6
import com.iver.cit.gvsig.fmap.MapControl;
7
import com.iver.cit.gvsig.fmap.edition.EditionException;
8
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
9
import com.iver.cit.gvsig.fmap.layers.FBitSet;
10
import com.iver.cit.gvsig.fmap.layers.FLayer;
11
import com.iver.cit.gvsig.fmap.layers.FLayers;
12
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
13
import com.iver.cit.gvsig.gui.View;
14
import com.iver.cit.gvsig.gui.cad.CADTool;
15
import com.iver.cit.gvsig.gui.tokenmarker.ConsoleToken;
16
import com.iver.cit.gvsig.project.ProjectTable;
17
import com.iver.cit.gvsig.project.ProjectView;
18
import com.iver.utiles.console.jedit.KeywordMap;
19
import com.iver.utiles.console.jedit.Token;
20

    
21
/**
22
 * DOCUMENT ME!
23
 *
24
 * @author Vicente Caballero Navarro
25
 */
26
public class StartEditing implements Extension {
27
        /**
28
         * @see com.iver.andami.plugins.Extension#inicializar()
29
         */
30
        public void inicializar() {
31
        }
32

    
33
        /**
34
         * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
35
         */
36
        public void execute(String actionCommand) {
37
                com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
38
                                .getActiveView();
39

    
40
                if (f instanceof View) {
41
                        View vista = (View) f;
42
                        CADTool[] cadtools=CADExtension.getCADTools();
43
                        KeywordMap keywordMap=new KeywordMap(true);
44
                        for (int i=0;i<cadtools.length;i++){
45
                                keywordMap.add(cadtools[i].getName(),Token.KEYWORD2);
46
                                keywordMap.add(cadtools[i].toString(),Token.KEYWORD3);
47

    
48
                        }
49
                        ConsoleToken consoletoken= new ConsoleToken(keywordMap);
50

    
51
                        vista.getConsolePanel().setTokenMarker(consoletoken);
52
                        vista.showConsole();
53
                        MapControl mapControl = (MapControl) vista.getMapControl();
54
                        ProjectView model = vista.getModel();
55
                        FMap mapa = model.getMapContext();
56
                        FLayers layers = mapa.getLayers();
57

    
58
                        for (int i = 0; i < layers.getLayersCount(); i++) {
59
                                if (layers.getLayer(i) instanceof FLyrVect
60
                                                && layers.getLayer(i).isActive()) {
61
                                        /*
62
                                         * for (int j = 0; j < i; j++) {
63
                                         * layers.getLayer(j).setVisible(false); }
64
                                         */
65

    
66
                                        FLyrVect lv = (FLyrVect) layers.getLayer(i);
67
                                        // lv.setVisible(true);
68
                                        lv.addLayerListener(CADExtension.getEditionManager());
69
                                        lv.setEditing(true);
70
                                        VectorialEditableAdapter vea = (VectorialEditableAdapter) lv
71
                                                        .getSource();
72
                                        // TODO: Provisional, para que al poner
73
                                        // un tema en edici?n el CADToolAdapter se entere
74
                                        CADExtension.getCADToolAdapter().setVectorialAdapter(vea);
75
                                        vea.getCommandRecord().addCommandListener(mapControl);
76
                                        // Si existe una tabla asociada a esta capa se cambia su
77
                                        // modelo por el VectorialEditableAdapter.
78
                                        ProjectExtension pe = (ProjectExtension) PluginServices
79
                                                        .getExtension(ProjectExtension.class);
80
                                        ProjectTable pt = pe.getProject().getTable(lv);
81
                                        if (pt != null)
82
                                                pt.setModel(vea);
83

    
84
                                        return;
85
                                }
86
                        }
87

    
88
                        /*
89
                         * PluginServices.getMDIManager().setWaitCursor(); try { if
90
                         * (((FLyrVect) capa).getSource().getDriver().getClass() ==
91
                         * DXFCadDriver.class) { if (JOptionPane.showConfirmDialog(
92
                         * (Component) PluginServices.getMainFrame(), "Todas las geometr?as
93
                         * del formato DXF no se pueden editar, de momento podemos editar:
94
                         * Line, Point, Polyline, Arc, Circle y Ellipse. \n El resto de
95
                         * geometr?as se perder?n con la edici?n. \n ?Desea continuar?") ==
96
                         * JOptionPane.YES_OPTION) { capa.startEdition();
97
                         * vista.getMapControl().setCadTool("selection"); } else { } } else {
98
                         * capa.startEdition();
99
                         * vista.getMapControl().setCadTool("selection"); } } catch
100
                         * (EditionException e) { // TODO Auto-generated catch block
101
                         * e.printStackTrace(); }
102
                         * PluginServices.getMDIManager().restoreCursor();
103
                         */
104
                        // vista.getMapControl().drawMap(false);
105
                }
106
        }
107

    
108
        /**
109
         * @see com.iver.andami.plugins.Extension#isEnabled()
110
         */
111
        public boolean isEnabled() {
112
                View f = (View) PluginServices.getMDIManager().getActiveView();
113

    
114
                if (f == null) {
115
                        return false;
116
                }
117

    
118
                FLayer[] selected = f.getModel().getMapContext().getLayers()
119
                                .getActives();
120
                if (selected.length == 1 && selected[0] instanceof FLyrVect) {
121
                        if (selected[0].isEditing())
122
                                return false;
123
                        else
124
                                return true;
125
                }
126
                return false;
127
        }
128

    
129
        /**
130
         * @see com.iver.andami.plugins.Extension#isVisible()
131
         */
132
        public boolean isVisible() {
133
                com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
134
                                .getActiveView();
135

    
136
                if (f == null) {
137
                        return false;
138
                }
139

    
140
                if (f.getClass() == View.class) {
141
                        return true;
142
                } else {
143
                        return false;
144
                }
145
        }
146
}