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 29616 jpiera
package org.gvsig.editing;
2 27221 vcaballero
3 38564 jjdelcerro
import org.gvsig.andami.IconThemeHelper;
4 29616 jpiera
import org.gvsig.andami.PluginServices;
5
import org.gvsig.andami.messages.NotificationManager;
6
import org.gvsig.andami.plugins.Extension;
7 31496 jjdelcerro
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
8 29616 jpiera
import org.gvsig.editing.gui.cad.tools.AutoCompletePolygon;
9 27221 vcaballero
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 31496 jjdelcerro
        private DefaultViewPanel view;
16 27221 vcaballero
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 38564 jjdelcerro
                IconThemeHelper.registerIcon("action", "layer-insert-autopolygon", this);
28 27221 vcaballero
        }
29
        public void execute(String actionCommand) {
30
                CADExtension.initFocus();
31 38564 jjdelcerro
                if (actionCommand.equals("layer-insert-autopolygon")) {
32 27221 vcaballero
                        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 31496 jjdelcerro
                                view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
43 27221 vcaballero
                                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
}