Package org.locationtech.udig.project.command

Examples of org.locationtech.udig.project.command.UndoableMapCommand


     * @param property  name of the attribute to modify
     * @param value new value
     * @param item TODO
     */
    protected void makeModification( SimpleFeature feature, ILayer layer, String property, Object value, Item item ) {
        UndoableMapCommand c =
            EditCommandFactory.getInstance().createSetAttributeCommand(feature, layer, property, value);
        map.sendCommandASync(c);
    }
View Full Code Here


            monitor.beginTask(getName(), commandsRan.size()*12);
            monitor.worked(2);
            for( EventBehaviour behaviour : behaviours ) {

                if( canUnlock(behaviour) && behaviour.isValid(handler, event, eventType)){
                    UndoableMapCommand c=null;
                    try{
                        c=behaviour.getCommand(handler, event, eventType);
                        if( c==null )
                            continue;
                        IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10);
                        c.setMap(getMap());
                        if (c instanceof PostDeterminedEffectCommand) {
                            PostDeterminedEffectCommand command = (PostDeterminedEffectCommand) c;
                            if( command.execute(submonitor) )
                                commandsRan.add(command);
                        }else{
                        c.run(submonitor);
                        commandsRan.add(c);
                        }
                        submonitor.done();
                    }catch(Exception e){
                        behaviour.handleError(handler, e, c);
View Full Code Here

    public UndoableMapCommand getCommand( EditToolHandler handler ) {
        List<Behaviour> behaviours=new ArrayList<Behaviour>(this.behaviours);
        for( Behaviour mode : behaviours ) {
            if( mode.isValid(handler) ){
                UndoableMapCommand c=null;
                try{
                    c=mode.getCommand(handler);
                    EditPlugin.trace(EditPlugin.BEHAVIOUR,
                            "  Running mode: " + mode.getClass().getName(), null); //$NON-NLS-1$
                   
View Full Code Here

      // delete the features that suffered split
      List<SimpleFeature> featuresThatSufferedSplit = builder.getFeaturesThatSufferedSplit();

      for (SimpleFeature feature : featuresThatSufferedSplit) {

          UndoableMapCommand command = cmdFac.createDeleteFeature(feature, selectedLayer);
         
        undoableCommands.add(command);
        ProjectPlugin.log(className + " - Delete original feature: " + ((Geometry) feature.getDefaultGeometry()).toText()); //$NON-NLS-1$
      }
      // add the new features
      List<SimpleFeature> splitResult = builder.getSplitResult();
      for (SimpleFeature feature : splitResult) {
          UndoableMapCommand command = cmdFac.createAddFeatureCommand(feature, selectedLayer);
        undoableCommands.add(command);
        ProjectPlugin.log(className + " - Split result: " + ((Geometry) feature.getDefaultGeometry()).toText()); //$NON-NLS-1$
      }
      // modify the neighbor features.
      builder.buildNeighbours();
      List<SimpleFeature> modifiedNeighbour = builder.getNeighbourResult();
      for (SimpleFeature neighbor : modifiedNeighbour) {

          for( SimpleFeature original : originalFeatureList ) {
                    if(original.getID().equals(neighbor.getID())){
                        UndoableMapCommand command = new ModifyGeometryFeatureCommand(original.getID(), (Geometry)neighbor.getDefaultGeometry(), (Geometry)original.getDefaultGeometry(), this.selectedLayer);
                        undoableCommands.add(command);

                        ProjectPlugin.log(className + " - Neighbour result: " + ((Geometry) neighbor.getDefaultGeometry()).toText()); //$NON-NLS-1$
                    }
                }
View Full Code Here

                        EditToolHandler editToolHandler = ((AbstractEditTool) tool).getHandler();
                        List<Behaviour> behaviours = editToolHandler.getCancelBehaviours();
                        UndoableComposite compositeCommand = new UndoableComposite();
                        for( Behaviour behaviour : behaviours ) {
                            if (behaviour.isValid(editToolHandler)) {
                                UndoableMapCommand command = behaviour.getCommand(editToolHandler);
                                if (command != null)
                                    compositeCommand.getCommands().add(command);
                            }
                        }
                        if (!compositeCommand.getCommands().isEmpty())
                            editToolHandler.getContext().sendASyncCommand(compositeCommand);
                    }

                    return null;
                }
            };

        }
        ICommandService service = (ICommandService) PlatformUI.getWorkbench().getAdapter(
                ICommandService.class);

        Command command = service.getCommand("org.locationtech.udig.tool.edit.clearAction"); //$NON-NLS-1$
        command.setHandler(clearEditBlackboardHandler);
       
        if(clearEditBlackboardCommandListener == null){
            clearEditBlackboardCommandListener  =  new ICommandListener(){

                public void commandChanged( CommandEvent commandEvent ) {
                    if (commandEvent.isHandledChanged()) {
                        commandEvent.getCommand().removeCommandListener(this);
                        clearEditBlackboardCommandListener = null;
                       
                        IMap map = ApplicationGIS.getActiveMap();
                        resetBlackboards(map);
                    }
                }

            };
            command.addCommandListener(clearEditBlackboardCommandListener);
        }
    }
View Full Code Here

        handler.getEditBlackboard().addPoint(100,0, handler.getCurrentShape());
        handler.getEditBlackboard().addPoint(100,100, handler.getCurrentShape());
        handler.getEditBlackboard().addPoint(0,100, handler.getCurrentShape());
        handler.getEditBlackboard().addPoint(0,0, handler.getCurrentShape());
       
        UndoableMapCommand command = behavior.getCommand(handler, event, EventType.RELEASED);
       
        command.setMap((Map) handler.getContext().getMap());
        if (command instanceof PostDeterminedEffectCommand) {
            PostDeterminedEffectCommand c = (PostDeterminedEffectCommand) command;
            c.execute(new NullProgressMonitor());
        }else{
            command.run(new NullProgressMonitor());
        }
       
        assertEquals("Current shape should equal new hole", editGeom.getHoles().get(0), handler.getCurrentShape()); //$NON-NLS-1$
        assertEquals("A point should have been added to hole", Point.valueOf(10,10), handler.getCurrentShape().getPoint(0)); //$NON-NLS-1$
        assertEquals( EditState.CREATING, handler.getCurrentState());
       
        command.rollback(new NullProgressMonitor());

        assertEquals( editGeom.getShell(), handler.getCurrentShape());
        assertEquals(0, editGeom.getHoles().size());
        assertEquals( EditState.MODIFYING, handler.getCurrentState());
       
View Full Code Here

        bb.addPoint(30,30,hole);
        bb.addPoint(30,20,hole);
        bb.addPoint(20,20,hole);
       
        behaviour=new AcceptChangesBehaviour(Polygon.class, false);       
        UndoableMapCommand command = behaviour.getCommand(handler);
        command.setMap(handler.getContext().getMap());
        command.run(new NullProgressMonitor());

        assertFalse(handler.getCurrentGeom().isChanged());
        LineString shell = ((Polygon)feature.getDefaultGeometry()).getExteriorRing();
        assertEquals(4, shell.getCoordinates().length);
        assertEquals(toCoord(bb,10,10), shell.getCoordinates()[0]);
View Full Code Here

        bb.addPoint(30,20,hole);
        bb.addPoint(30,30,hole);
        bb.addPoint(20,20,hole);
       
        behaviour=new AcceptChangesBehaviour(Polygon.class, false);
        UndoableMapCommand command = behaviour.getCommand(handler);
        command.setMap(handler.getContext().getMap());
        command.run(new NullProgressMonitor());
        assertFalse(handler.getCurrentGeom().isChanged());
        LineString shell = ((Polygon)((MultiPolygon)feature.getDefaultGeometry()).getGeometryN(0)).getExteriorRing();
        assertEquals(4, shell.getCoordinates().length);
        assertEquals(toCoord(bb,10,10), shell.getCoordinates()[0]);
        assertEquals(toCoord(bb,40,10), shell.getCoordinates()[1]);
View Full Code Here

        ((TestLayer)handler.getContext().getMap().getMapLayers().get(0)).setSchema(type);
        ((Map)handler.getContext().getMap()).getEditManagerInternal().setEditFeature(feature, layer);
       
        // test create LineString
        behaviour=new AcceptChangesBehaviour(LineString.class, false);
        UndoableMapCommand command = behaviour.getCommand(handler);
        command.setMap(handler.getContext().getMap());
        command.run(new NullProgressMonitor());
        assertFalse(handler.getCurrentGeom().isChanged());
        assertEquals(2, ((GeometryCollection)feature.getDefaultGeometry()).getGeometryN(0).getCoordinates().length);
        assertEquals(toCoord(bb,10,10), ((GeometryCollection)feature.getDefaultGeometry()).getGeometryN(0).getCoordinates()[0]);
        assertEquals(toCoord(bb,40,10), ((GeometryCollection)feature.getDefaultGeometry()).getGeometryN(0).getCoordinates()[1]);
        features = layer.getResource(FeatureSource.class, null).getFeatures().features();
        next=features.next();
        assertEquals(2, ((GeometryCollection)next.getDefaultGeometry()).getGeometryN(0).getCoordinates().length);
        assertEquals( toCoord(bb,10,10), ((GeometryCollection)next.getDefaultGeometry()).getGeometryN(0).getCoordinates()[0] );
        assertEquals( toCoord(bb,40,10), ((GeometryCollection)next.getDefaultGeometry()).getGeometryN(0).getCoordinates()[1] );
        assertEquals(MultiLineString.class, feature.getDefaultGeometry().getClass());

        // test create LinearRing
        behaviour=new AcceptChangesBehaviour(LinearRing.class, false);
        handler.getCurrentGeom().setChanged(true);
        command = behaviour.getCommand(handler);
        command.setMap(handler.getContext().getMap());
        command.run(new NullProgressMonitor());
        assertEquals(4, ((GeometryCollection)feature.getDefaultGeometry()).getGeometryN(0).getCoordinates().length);
        assertEquals(toCoord(bb,10,10), ((GeometryCollection)feature.getDefaultGeometry()).getGeometryN(0).getCoordinates()[0]);
        assertEquals(toCoord(bb,40,10), ((GeometryCollection)feature.getDefaultGeometry()).getGeometryN(0).getCoordinates()[1]);
        assertEquals(toCoord(bb,10,10), ((GeometryCollection)feature.getDefaultGeometry()).getGeometryN(0).getCoordinates()[2]);
        assertEquals(toCoord(bb,10,10), ((GeometryCollection)feature.getDefaultGeometry()).getGeometryN(0).getCoordinates()[3]);
View Full Code Here

        bb.addPoint(10,10,editGeom.getShell());
        bb.addPoint(40,10,editGeom.getShell());
       
        // test create LineString
        behaviour=new AcceptChangesBehaviour(LineString.class, false);
        UndoableMapCommand command = behaviour.getCommand(handler);
        command.setMap(handler.getContext().getMap());
        command.run(new NullProgressMonitor());
        assertFalse(handler.getCurrentGeom().isChanged());
        assertEquals(toCoord(bb,10,10), ((Geometry) feature.getDefaultGeometry()).getCoordinates()[0]);
        assertEquals(toCoord(bb,40,10), ((Geometry) feature.getDefaultGeometry()).getCoordinates()[1]);
        assertEquals(2, ((Geometry) feature.getDefaultGeometry()).getCoordinates().length);
        features = layer.getResource(FeatureSource.class, null).getFeatures().features();
        next=features.next();
        assertEquals( toCoord(bb,10,10), ((Geometry) next.getDefaultGeometry()).getCoordinates()[0] );
        assertEquals( toCoord(bb,40,10), ((Geometry) next.getDefaultGeometry()).getCoordinates()[1] );
        assertEquals(LineString.class, feature.getDefaultGeometry().getClass());
       

        // test create LinearRing
        behaviour=new AcceptChangesBehaviour(LinearRing.class, false);
        handler.getCurrentGeom().setChanged(true);
        command = behaviour.getCommand(handler);
        command.setMap(handler.getContext().getMap());
        command.run(new NullProgressMonitor());
        assertEquals(4, ((Geometry) feature.getDefaultGeometry()).getCoordinates().length);
        assertEquals(toCoord(bb,10,10), ((Geometry) feature.getDefaultGeometry()).getCoordinates()[0]);
        assertEquals(toCoord(bb,40,10), ((Geometry) feature.getDefaultGeometry()).getCoordinates()[1]);
        assertEquals(toCoord(bb,10,10), ((Geometry) feature.getDefaultGeometry()).getCoordinates()[2]);
        assertEquals(toCoord(bb,10,10), ((Geometry) feature.getDefaultGeometry()).getCoordinates()[3]);
View Full Code Here

TOP

Related Classes of org.locationtech.udig.project.command.UndoableMapCommand

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.