Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / AutoCompletePolygonExtension.java @ 38564

History | View | Annotate | Download (2.09 KB)

1
package org.gvsig.editing;
2

    
3
import org.gvsig.andami.IconThemeHelper;
4
import org.gvsig.andami.PluginServices;
5
import org.gvsig.andami.messages.NotificationManager;
6
import org.gvsig.andami.plugins.Extension;
7
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
8
import org.gvsig.editing.gui.cad.tools.AutoCompletePolygon;
9
import org.gvsig.fmap.dal.exception.ReadException;
10
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
11
import org.gvsig.fmap.mapcontrol.MapControl;
12

    
13

    
14
public class AutoCompletePolygonExtension extends Extension {
15
        private DefaultViewPanel view;
16

    
17
        private MapControl mapControl;
18

    
19
        private AutoCompletePolygon theTool;
20

    
21
        public void initialize() {
22
                theTool = new AutoCompletePolygon();
23
                CADExtension.addCADTool("_autocompletepolygon", theTool);
24
                registerIcons();
25
        }
26
        private void registerIcons(){
27
                IconThemeHelper.registerIcon("action", "layer-insert-autopolygon", this);
28
        }
29
        public void execute(String actionCommand) {
30
                CADExtension.initFocus();
31
                if (actionCommand.equals("layer-insert-autopolygon")) {
32
                        CADExtension.setCADTool("_autocompletepolygon", true);
33
                        CADExtension.getEditionManager().setMapControl(mapControl);
34
                }
35
                CADExtension.getCADToolAdapter().configureMenu();
36

    
37
        }
38

    
39
        public boolean isEnabled() {
40
                try {
41
                        if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
42
                                view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
43
                                mapControl = view.getMapControl();
44
                                if (CADExtension.getEditionManager().getActiveLayerEdited() == null)
45
                                        return false;
46
                                FLyrVect lv = (FLyrVect) CADExtension.getEditionManager()
47
                                                .getActiveLayerEdited().getLayer();
48
                                if (theTool.isApplicable(lv.getShapeType())) {
49
                                        return true;
50
                                }
51
                        }
52
                } catch (ReadException e) {
53
                        NotificationManager.addError(e.getMessage(), e);
54
                }
55
                return false;
56
        }
57

    
58
        public boolean isVisible() {
59
                if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
60
                        return true;
61
                return false;
62
        }
63

    
64
}