Statistics
| Revision:

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

History | View | Annotate | Download (5.14 KB)

1
package com.iver.cit.gvsig;
2

    
3
import com.hardcode.gdbms.engine.data.driver.DriverException;
4
import com.iver.andami.PluginServices;
5
import com.iver.andami.plugins.Extension;
6
import com.iver.cit.gvsig.fmap.FMap;
7
import com.iver.cit.gvsig.fmap.MapControl;
8
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
9
import com.iver.cit.gvsig.fmap.layers.FLayer;
10
import com.iver.cit.gvsig.fmap.layers.FLayers;
11
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
12
import com.iver.cit.gvsig.gui.Table;
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.ProjectFactory;
17
import com.iver.cit.gvsig.project.ProjectTable;
18
import com.iver.cit.gvsig.project.ProjectView;
19
import com.iver.utiles.console.jedit.KeywordMap;
20
import com.iver.utiles.console.jedit.Token;
21

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

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

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

    
50
                        }
51
                        ConsoleToken consoletoken= new ConsoleToken(keywordMap);
52

    
53
                        vista.getConsolePanel().setTokenMarker(consoletoken);
54
                        vista.showConsole();
55
                        MapControl mapControl = (MapControl) vista.getMapControl();
56
                        EditionManager editionManager=CADExtension.getEditionManager();
57
                        editionManager.setMapControl(mapControl);
58

    
59
                        ProjectView model = vista.getModel();
60
                        FMap mapa = model.getMapContext();
61
                        FLayers layers = mapa.getLayers();
62
                        for (int i = 0; i < layers.getLayersCount(); i++) {
63
                                if (layers.getLayer(i) instanceof FLyrVect
64
                                                && layers.getLayer(i).isActive()) {
65
                                        /*
66
                                         * for (int j = 0; j < i; j++) {
67
                                         * layers.getLayer(j).setVisible(false); }
68
                                         */
69

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

    
93
                        /*
94
                         * PluginServices.getMDIManager().setWaitCursor(); try { if
95
                         * (((FLyrVect) capa).getSource().getDriver().getClass() ==
96
                         * DXFCadDriver.class) { if (JOptionPane.showConfirmDialog(
97
                         * (Component) PluginServices.getMainFrame(), "Todas las geometr?as
98
                         * del formato DXF no se pueden editar, de momento podemos editar:
99
                         * Line, Point, Polyline, Arc, Circle y Ellipse. \n El resto de
100
                         * geometr?as se perder?n con la edici?n. \n ?Desea continuar?") ==
101
                         * JOptionPane.YES_OPTION) { capa.startEdition();
102
                         * vista.getMapControl().setCadTool("selection"); } else { } } else {
103
                         * capa.startEdition();
104
                         * vista.getMapControl().setCadTool("selection"); } } catch
105
                         * (EditionException e) { // TODO Auto-generated catch block
106
                         * e.printStackTrace(); }
107
                         * PluginServices.getMDIManager().restoreCursor();
108
                         */
109
                        // vista.getMapControl().drawMap(false);
110
                }
111
        }
112
         private void changeModelTable(ProjectTable pt){
113
             com.iver.andami.ui.mdiManager.View[] views = (com.iver.andami.ui.mdiManager.View[]) PluginServices.getMDIManager().getAllViews();
114

    
115
                 for (int i=0 ; i<views.length ; i++){
116
                         if (views[i] instanceof Table){
117
                                 Table table=(Table)views[i];
118
                                 ProjectTable model =table.getModel();
119
                                 if (model.equals(pt)){
120
                                                 table.setModel(pt);
121
                                 }
122
                         }
123
                 }
124
    }
125
        /**
126
         * @see com.iver.andami.plugins.IExtension#isEnabled()
127
         */
128
        public boolean isEnabled() {
129
                View f = (View) PluginServices.getMDIManager().getActiveView();
130

    
131
                if (f == null) {
132
                        return false;
133
                }
134

    
135
                FLayer[] selected = f.getModel().getMapContext().getLayers()
136
                                .getActives();
137
                if (selected.length == 1 && selected[0] instanceof FLyrVect) {
138
                        if (selected[0].isEditing())
139
                                return false;
140
                        else
141
                                return true;
142
                }
143
                return false;
144
        }
145

    
146
        /**
147
         * @see com.iver.andami.plugins.IExtension#isVisible()
148
         */
149
        public boolean isVisible() {
150
                com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
151
                                .getActiveView();
152

    
153
                if (f == null) {
154
                        return false;
155
                }
156

    
157
                if (f.getClass() == View.class) {
158
                        return true;
159
                } else {
160
                        return false;
161
                }
162
        }
163
}