From 9f34503a9a6ea44d54a76bbcef8507c7df9162ef Mon Sep 17 00:00:00 2001 From: Sebastian <89982771+sschulz92@users.noreply.github.com> Date: Mon, 1 Nov 2021 21:26:57 +0100 Subject: [PATCH] Replace 'SubProgressmonitor' with 'SubMonitor' in 'udig.tool' (#567) * Replace 'SubProgressmonitor' with 'SubMonitor' in 'udig.tool' --- .../udig/tools/edit/BehaviourCommand.java | 98 +++++---- .../tools/edit/EventBehaviourCommand.java | 106 +++++---- .../commands/CreateAndSelectNewFeature.java | 82 ++++--- .../CreateDialogAndSelectNewFeature.java | 68 +++--- ...eateNewOrSelectExistingFeatureCommand.java | 11 +- .../commands/DeselectEditGeomCommand.java | 70 +++--- .../commands/DifferenceFeatureCommand.java | 208 ++++++++++-------- .../edit/commands/InsertVertexCommand.java | 90 ++++---- .../edit/commands/MoveVertexCommand.java | 83 +++---- .../SelectFeatureAsEditFeatureCommand.java | 125 ++++++----- .../SelectFeaturesInFilterCommand.java | 90 ++++---- .../tools/edit/commands/SplitLineCommand.java | 184 +++++++++------- .../select/commands/SetAOILayerCommand.java | 127 +++++------ 13 files changed, 739 insertions(+), 603 deletions(-) diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/BehaviourCommand.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/BehaviourCommand.java index 1871361cda..d43263db9a 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/BehaviourCommand.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/BehaviourCommand.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -12,73 +13,76 @@ import java.util.LinkedList; import java.util.List; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; import org.locationtech.udig.project.command.AbstractCommand; import org.locationtech.udig.project.command.PostDeterminedEffectCommand; import org.locationtech.udig.project.command.UndoableMapCommand; import org.locationtech.udig.tool.edit.internal.Messages; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; - /** - * Command used by (@link org.locationtech.udig.tools.edit.EditToolHandler} and - * {@link org.locationtech.udig.tools.edit.OrderedCompositeEventBehavior} for executing the + * Command used by (@link org.locationtech.udig.tools.edit.EditToolHandler} and + * {@link org.locationtech.udig.tools.edit.OrderedCompositeEventBehavior} for executing the * behaviours in a tool. - * + * * @author jones * @since 1.1.0 */ public class BehaviourCommand extends AbstractCommand implements PostDeterminedEffectCommand { private List behaviours; - private List commandsRan=new LinkedList(); + + private List commandsRan = new LinkedList<>(); + private EditToolHandler handler; public BehaviourCommand(List behaviours, EditToolHandler handler) { - this.behaviours=behaviours; - this.handler=handler; + this.behaviours = behaviours; + this.handler = handler; } - - - public boolean execute( IProgressMonitor monitor ) throws Exception { - if( commandsRan.isEmpty() ){ - monitor.beginTask(getName(), commandsRan.size()*12); + + @Override + public boolean execute(IProgressMonitor monitor) throws Exception { + if (commandsRan.isEmpty()) { + monitor.beginTask(getName(), commandsRan.size() * 12); monitor.worked(2); - for( Behaviour behaviour : behaviours ) { - monitor.beginTask(getName(), behaviours.size()*12); + for (Behaviour behaviour : behaviours) { + monitor.beginTask(getName(), behaviours.size() * 12); monitor.worked(2); - if( behaviour.isValid(handler)){ - UndoableMapCommand c=null; - try{ - c=behaviour.getCommand(handler); - if( c==null ) + if (behaviour.isValid(handler)) { + UndoableMapCommand c = null; + try { + c = behaviour.getCommand(handler); + if (c == null) continue; c.setMap(getMap()); - IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10); + IProgressMonitor submonitor = SubMonitor.convert(monitor, 10); if (c instanceof PostDeterminedEffectCommand) { PostDeterminedEffectCommand command = (PostDeterminedEffectCommand) c; - if( command.execute(submonitor) ) + if (command.execute(submonitor)) commandsRan.add(command); - }else{ - c.run(submonitor); - commandsRan.add(c); + } else { + c.run(submonitor); + commandsRan.add(c); } submonitor.done(); - }catch(Exception e){ - EditPlugin.trace( e.getClass().getName()+" executing "+c+":"+e.getMessage(), e); + } catch (Exception e) { + EditPlugin.trace( + e.getClass().getName() + " executing " + c + ":" + e.getMessage(), //$NON-NLS-1$ //$NON-NLS-2$ + e); behaviour.handleError(handler, e, c); } } } - }else{ - monitor.beginTask(getName(), commandsRan.size()*12); + } else { + monitor.beginTask(getName(), commandsRan.size() * 12); monitor.worked(2); - for( UndoableMapCommand command : commandsRan ) { + for (UndoableMapCommand command : commandsRan) { command.setMap(getMap()); - IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10); + IProgressMonitor submonitor = SubMonitor.convert(monitor, 10); if (command instanceof PostDeterminedEffectCommand) { - ((PostDeterminedEffectCommand)command).execute(submonitor); - }else{ + ((PostDeterminedEffectCommand) command).execute(submonitor); + } else { command.run(submonitor); } submonitor.done(); @@ -87,32 +91,34 @@ public boolean execute( IProgressMonitor monitor ) throws Exception { return !commandsRan.isEmpty(); } - String name=Messages.EventBehaviourCommand_name; + String name = Messages.EventBehaviourCommand_name; + @Override public String getName() { return name; } - - public void setName( String name ) { + + public void setName(String name) { this.name = name; } - public void rollback( IProgressMonitor monitor ) throws Exception { - monitor.beginTask(getName(), commandsRan.size()*12); + @Override + public void rollback(IProgressMonitor monitor) throws Exception { + monitor.beginTask(getName(), commandsRan.size() * 12); monitor.worked(2); - for(int i = commandsRan.size()-1; i>=0; i--) - { + for (int i = commandsRan.size() - 1; i >= 0; i--) { UndoableMapCommand command = commandsRan.get(i); command.setMap(getMap()); - IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10); + IProgressMonitor submonitor = SubMonitor.convert(monitor, 10); command.rollback(submonitor); submonitor.done(); } } - - public void run( IProgressMonitor monitor ) throws Exception { - throw new UnsupportedOperationException("PostDeterminedEffectCommands do not use the run method"); //$NON-NLS-1$ + @Override + public void run(IProgressMonitor monitor) throws Exception { + throw new UnsupportedOperationException( + "PostDeterminedEffectCommands do not use the run method"); //$NON-NLS-1$ } } diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/EventBehaviourCommand.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/EventBehaviourCommand.java index 04d5aa14c3..c703192c25 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/EventBehaviourCommand.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/EventBehaviourCommand.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -12,76 +13,80 @@ import java.util.LinkedList; import java.util.List; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; import org.locationtech.udig.project.command.AbstractCommand; import org.locationtech.udig.project.command.PostDeterminedEffectCommand; import org.locationtech.udig.project.command.UndoableMapCommand; import org.locationtech.udig.project.ui.render.displayAdapter.MapMouseEvent; import org.locationtech.udig.tool.edit.internal.Messages; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; - /** - * Command used by (@link org.locationtech.udig.tools.edit.EditToolHandler} and - * {@link org.locationtech.udig.tools.edit.OrderedCompositeEventBehavior} for executing the + * Command used by (@link org.locationtech.udig.tools.edit.EditToolHandler} and + * {@link org.locationtech.udig.tools.edit.OrderedCompositeEventBehavior} for executing the * behaviours in a tool. - * + * * @author jones * @since 1.1.0 */ public class EventBehaviourCommand extends AbstractCommand implements PostDeterminedEffectCommand { private List behaviours; - private List commandsRan=new LinkedList(); + + private List commandsRan = new LinkedList<>(); + private EditToolHandler handler; + private MapMouseEvent event; + private EventType eventType; public EventBehaviourCommand(List behaviours, EditToolHandler handler, MapMouseEvent event, EventType eventType) { - this.behaviours=behaviours; - this.handler=handler; - this.event=event; - this.eventType=eventType; + this.behaviours = behaviours; + this.handler = handler; + this.event = event; + this.eventType = eventType; } - - public boolean execute( IProgressMonitor monitor ) throws Exception { - if( commandsRan.isEmpty() ){ - monitor.beginTask(getName(), commandsRan.size()*12); + + @Override + public boolean execute(IProgressMonitor monitor) throws Exception { + if (commandsRan.isEmpty()) { + monitor.beginTask(getName(), commandsRan.size() * 12); monitor.worked(2); - for( EventBehaviour behaviour : behaviours ) { + 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 ) + 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); + IProgressMonitor submonitor = SubMonitor.convert(monitor, 10); c.setMap(getMap()); if (c instanceof PostDeterminedEffectCommand) { PostDeterminedEffectCommand command = (PostDeterminedEffectCommand) c; - if( command.execute(submonitor) ) + if (command.execute(submonitor)) commandsRan.add(command); - }else{ - c.run(submonitor); - commandsRan.add(c); + } else { + c.run(submonitor); + commandsRan.add(c); } submonitor.done(); - }catch(Exception e){ + } catch (Exception e) { behaviour.handleError(handler, e, c); } } } - }else{ - monitor.beginTask(getName(), commandsRan.size()*12); + } else { + monitor.beginTask(getName(), commandsRan.size() * 12); monitor.worked(2); - for( UndoableMapCommand command : commandsRan ) { + for (UndoableMapCommand command : commandsRan) { command.setMap(getMap()); - IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10); + IProgressMonitor submonitor = SubMonitor.convert(monitor, 10); if (command instanceof PostDeterminedEffectCommand) { - ((PostDeterminedEffectCommand)command).execute(submonitor); - }else{ + ((PostDeterminedEffectCommand) command).execute(submonitor); + } else { command.run(submonitor); } submonitor.done(); @@ -93,44 +98,49 @@ public boolean execute( IProgressMonitor monitor ) throws Exception { /** * Returns true if the handler is unlocked or the behaviour has the correct key. - * + * * @param behaviour trying to run * @return Returns true if the handler is unlocked or the behaviour has the correct key. */ - private boolean canUnlock( EventBehaviour behaviour ) { - if( !handler.isLocked() ) + private boolean canUnlock(EventBehaviour behaviour) { + if (!handler.isLocked()) return true; if (behaviour instanceof LockingBehaviour) { LockingBehaviour locker = (LockingBehaviour) behaviour; - EditPlugin.trace(EditPlugin.HANDLER_LOCK, "Can unlock: "+(handler.behaviourLock==locker.getKey(handler)), null); //$NON-NLS-1$ - return handler.behaviourLock==locker.getKey(handler); + EditPlugin.trace(EditPlugin.HANDLER_LOCK, + "Can unlock: " + (handler.behaviourLock == locker.getKey(handler)), null); //$NON-NLS-1$ + return handler.behaviourLock == locker.getKey(handler); } return false; } - String name=Messages.EventBehaviourCommand_name; + String name = Messages.EventBehaviourCommand_name; + @Override public String getName() { return name; } - - public void setName( String name ) { + + public void setName(String name) { this.name = name; } - public void rollback( IProgressMonitor monitor ) throws Exception { - monitor.beginTask(getName(), commandsRan.size()*12); + @Override + public void rollback(IProgressMonitor monitor) throws Exception { + monitor.beginTask(getName(), commandsRan.size() * 12); monitor.worked(2); - for( UndoableMapCommand command : commandsRan ) { + for (UndoableMapCommand command : commandsRan) { command.setMap(getMap()); - IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10); + IProgressMonitor submonitor = SubMonitor.convert(monitor, 10); command.rollback(submonitor); submonitor.done(); } } - public void run( IProgressMonitor monitor ) throws Exception { - throw new UnsupportedOperationException("PostDeterminedEffectCommands do not use the run method"); //$NON-NLS-1$ + @Override + public void run(IProgressMonitor monitor) throws Exception { + throw new UnsupportedOperationException( + "PostDeterminedEffectCommands do not use the run method"); //$NON-NLS-1$ } } diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateAndSelectNewFeature.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateAndSelectNewFeature.java index bd74a777c5..32beff83f7 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateAndSelectNewFeature.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateAndSelectNewFeature.java @@ -12,6 +12,9 @@ import java.util.Collections; import java.util.List; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.geotools.data.FeatureEvent; import org.locationtech.udig.core.internal.FeatureUtils; import org.locationtech.udig.project.ILayer; import org.locationtech.udig.project.command.AbstractCommand; @@ -24,34 +27,38 @@ import org.locationtech.udig.tools.edit.support.EditUtils; import org.locationtech.udig.tools.edit.support.Point; import org.locationtech.udig.tools.edit.support.PrimitiveShape; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.geotools.data.FeatureEvent; import org.opengis.feature.simple.SimpleFeature; import org.opengis.filter.Filter; /** * Creates a new feature and sets it as the EditFeature - * + * * @author jones * @since 1.1.0 */ public class CreateAndSelectNewFeature extends AbstractCommand implements UndoableMapCommand { private Layer layer; + private SimpleFeature feature; + private AddFeatureCommand addFeatureCommand; + private SimpleFeature oldFeature; + private ILayer oldLayer; + private EditGeom geom; + private String oldID; + private Filter oldSelection; + private boolean deselectCreatedFeature; /** * New instance - * + * * @param geom the EditGeom to update with the new feature's fid (after the fid has been added) * @param feature the feature created from the geom and that will be added to to the layer. * @param layer the layer to add the feature from. It must have a FeatureStore resource @@ -59,15 +66,16 @@ public class CreateAndSelectNewFeature extends AbstractCommand implements Undoab * If false the layer will be notified that the feature is selected an it should not be * rendered. */ - public CreateAndSelectNewFeature( EditGeom geom, SimpleFeature feature, ILayer layer, - boolean deselectCreatedFeature ) { + public CreateAndSelectNewFeature(EditGeom geom, SimpleFeature feature, ILayer layer, + boolean deselectCreatedFeature) { this.layer = (Layer) layer; this.feature = feature; this.geom = geom; this.deselectCreatedFeature = deselectCreatedFeature; } - public void run( IProgressMonitor monitor ) throws Exception { + @Override + public void run(IProgressMonitor monitor) throws Exception { monitor.beginTask(getName(), 14); monitor.worked(2); boolean prev = layer.eDeliver(); @@ -75,27 +83,27 @@ public void run( IProgressMonitor monitor ) throws Exception { layer.eSetDeliver(false); addFeatureCommand = new AddFeatureCommand(feature, layer); addFeatureCommand.setMap(getMap()); - SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 10); - + SubMonitor subMonitor = SubMonitor.convert(monitor, 10); + // run the addFeature command (should result in a featureId we can use for selection) - addFeatureCommand.run(subProgressMonitor); - subProgressMonitor.done(); + addFeatureCommand.run(subMonitor); + subMonitor.done(); this.oldFeature = getMap().getEditManager().getEditFeature(); this.oldLayer = getMap().getEditManager().getEditLayer(); this.oldID = geom.getFeatureIDRef().get(); - + String fid = addFeatureCommand.getFid(); - if( fid != null ){ - System.out.println("Create and select feature:"+fid ); - } - else { - System.out.println("Create and select feature did not produce a feature id to select" ); + if (fid != null) { + System.out.println("Create and select feature:" + fid); //$NON-NLS-1$ + } else { + System.out.println( + "Create and select feature did not produce a feature id to select"); //$NON-NLS-1$ } geom.getFeatureIDRef().set(fid); SimpleFeature newFeature = addFeatureCommand.getNewFeature(); - getMap().getEditManagerInternal().setEditFeature(newFeature,layer); + getMap().getEditManagerInternal().setEditFeature(newFeature, layer); oldSelection = layer.getFilter(); Filter filter = fid == null ? null : FeatureUtils.id(fid); @@ -105,16 +113,16 @@ public void run( IProgressMonitor monitor ) throws Exception { // this is not needed in the other case because the feature will not be rendered layer.eSetDeliver(prev); } else { - EditUtils.instance.refreshLayer(layer, Collections.singleton(fid), null, false, true); + EditUtils.instance.refreshLayer(layer, Collections.singleton(fid), null, false, + true); } // since the layer didn't send an event (see eSetDeliver() above) we need to send the // command - I'm just smacking it not making any real changes - if( filter != null ){ + if (filter != null) { // filter selecting the new feature layer.setFilter(filter); - } - else { - System.out.println("New feature did not have a feature id to select"); + } else { + System.out.println("New feature did not have a feature id to select"); //$NON-NLS-1$ } fireFeatureEvent(prev); @@ -125,22 +133,24 @@ public void run( IProgressMonitor monitor ) throws Exception { monitor.done(); } - private void fireFeatureEvent( boolean prev ) { + private void fireFeatureEvent(boolean prev) { List featureChanges = layer.getFeatureChanges(); layer.eSetDeliver(prev); int index = featureChanges.size() - 1; - if( index != -1 ){ + if (index != -1) { FeatureEvent featureEvent = featureChanges.get(index); featureChanges.set(index, featureEvent); } } + @Override public String getName() { return Messages.CreateAndSetNewFeature_name; } - public void rollback( IProgressMonitor monitor ) throws Exception { + @Override + public void rollback(IProgressMonitor monitor) throws Exception { monitor.beginTask(getName(), 14); monitor.worked(2); boolean prev = layer.eDeliver(); @@ -148,9 +158,9 @@ public void rollback( IProgressMonitor monitor ) throws Exception { layer.eSetDeliver(false); layer.setFilter(oldSelection); - SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 10); - addFeatureCommand.rollback(subProgressMonitor); - subProgressMonitor.done(); + SubMonitor subMonitor = SubMonitor.convert(monitor, 10); + addFeatureCommand.rollback(subMonitor); + subMonitor.done(); geom.getFeatureIDRef().set(oldID); getMap().getEditManagerInternal().setEditFeature(oldFeature, (Layer) oldLayer); @@ -158,21 +168,21 @@ public void rollback( IProgressMonitor monitor ) throws Exception { EditBlackboard bb = geom.getEditBlackboard(); EditGeom newGeom = bb.newGeom(geom.getFeatureIDRef().get(), geom.getShapeType()); PrimitiveShape shell = geom.getShell(); - for( org.locationtech.udig.tools.edit.support.Point point : shell ) { + for (org.locationtech.udig.tools.edit.support.Point point : shell) { bb.addPoint(point.getX(), point.getY(), newGeom.getShell()); } List holes = geom.getHoles(); - for( PrimitiveShape primitiveShape : holes ) { + for (PrimitiveShape primitiveShape : holes) { PrimitiveShape newHole = newGeom.newHole(); - for( Point point2 : primitiveShape ) { + for (Point point2 : primitiveShape) { bb.addPoint(point2.getX(), point2.getY(), newHole); } } geom = newGeom; } else { - EditUtils.instance.refreshLayer(layer, Collections.singleton(addFeatureCommand - .getFid()), null, false, false); + EditUtils.instance.refreshLayer(layer, + Collections.singleton(addFeatureCommand.getFid()), null, false, false); } } finally { layer.eSetDeliver(prev); diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateDialogAndSelectNewFeature.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateDialogAndSelectNewFeature.java index fdaf095265..2fea797fcd 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateDialogAndSelectNewFeature.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateDialogAndSelectNewFeature.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -13,7 +14,7 @@ import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.PlatformUI; @@ -36,26 +37,35 @@ /** * Creates a new feature, prompting the user for some interaction, and sets it as the EditFeature - * + * * @author jody * @since 1.2.0 */ public class CreateDialogAndSelectNewFeature extends AbstractCommand implements UndoableMapCommand { private Layer layer; + private SimpleFeature feature; + private AddFeatureCommand addFeatureCommand; + private SimpleFeature oldFeature; + private ILayer oldLayer; + private EditGeom geom; + private String oldID; + private Filter oldSelection; + private boolean deselectCreatedFeature; + private List panels; /** * New instance - * + * * @param geom the EditGeom to update with the new feature's fid (after the fid has been added) * @param feature the feature created from the geom and that will be added to to the layer. * @param layer the layer to add the feature from. It must have a FeatureStore resource @@ -64,7 +74,7 @@ public class CreateDialogAndSelectNewFeature extends AbstractCommand implements * rendered. * @param popup FeaturePanels used to prompt the user for content */ - public CreateDialogAndSelectNewFeature( EditGeom geom, SimpleFeature feature, ILayer layer, + public CreateDialogAndSelectNewFeature(EditGeom geom, SimpleFeature feature, ILayer layer, boolean deselectCreatedFeature, List popup) { this.layer = (Layer) layer; this.feature = feature; @@ -74,31 +84,33 @@ public CreateDialogAndSelectNewFeature( EditGeom geom, SimpleFeature feature, IL } @Override - public void run( IProgressMonitor monitor ) throws Exception { + public void run(IProgressMonitor monitor) throws Exception { final boolean create[] = new boolean[1]; create[0] = false; - + Display display = PlatformUI.getWorkbench().getDisplay(); - display.syncExec( new Runnable(){ + display.syncExec(new Runnable() { @Override public void run() { - boolean yes = MessageDialog.openConfirm(null, "New Feature", "Panels available "+panels.size() ); + boolean yes = MessageDialog.openConfirm(null, "New Feature", //$NON-NLS-1$ + "Panels available " + panels.size()); //$NON-NLS-1$ create[0] = yes; - } + } }); - if( create[0] == false ){ - return; // user can continue editing? or should we cancel the geometry they were working on... + if (create[0] == false) { + return; // user can continue editing? or should we cancel the geometry they were working + // on... } monitor.beginTask(getName(), 14); monitor.worked(2); boolean prev = layer.eDeliver(); - try { + try { layer.eSetDeliver(false); addFeatureCommand = new AddFeatureCommand(feature, layer); addFeatureCommand.setMap(getMap()); - SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 10); - addFeatureCommand.run(subProgressMonitor); - subProgressMonitor.done(); + SubMonitor subMonitor = SubMonitor.convert(monitor, 10); + addFeatureCommand.run(subMonitor); + subMonitor.done(); this.oldFeature = getMap().getEditManager().getEditFeature(); this.oldLayer = getMap().getEditManager().getEditLayer(); @@ -116,8 +128,8 @@ public void run() { // this is not needed in the other case because the feature will not be rendered layer.eSetDeliver(prev); } else { - EditUtils.instance.refreshLayer(layer, Collections.singleton(addFeatureCommand - .getFid()), null, false, true); + EditUtils.instance.refreshLayer(layer, + Collections.singleton(addFeatureCommand.getFid()), null, false, true); } // since the layer didn't send an event (see eSetDeliver() above) we need to send the @@ -133,7 +145,7 @@ public void run() { monitor.done(); } - private void fireFeatureEvent( boolean prev ) { + private void fireFeatureEvent(boolean prev) { List featureChanges = layer.getFeatureChanges(); layer.eSetDeliver(prev); @@ -148,7 +160,7 @@ public String getName() { } @Override - public void rollback( IProgressMonitor monitor ) throws Exception { + public void rollback(IProgressMonitor monitor) throws Exception { monitor.beginTask(getName(), 14); monitor.worked(2); boolean prev = layer.eDeliver(); @@ -156,9 +168,9 @@ public void rollback( IProgressMonitor monitor ) throws Exception { layer.eSetDeliver(false); layer.setFilter(oldSelection); - SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 10); - addFeatureCommand.rollback(subProgressMonitor); - subProgressMonitor.done(); + SubMonitor subMonitor = SubMonitor.convert(monitor, 10); + addFeatureCommand.rollback(subMonitor); + subMonitor.done(); geom.getFeatureIDRef().set(oldID); getMap().getEditManagerInternal().setEditFeature(oldFeature, (Layer) oldLayer); @@ -166,21 +178,21 @@ public void rollback( IProgressMonitor monitor ) throws Exception { EditBlackboard bb = geom.getEditBlackboard(); EditGeom newGeom = bb.newGeom(geom.getFeatureIDRef().get(), geom.getShapeType()); PrimitiveShape shell = geom.getShell(); - for( org.locationtech.udig.tools.edit.support.Point point : shell ) { + for (org.locationtech.udig.tools.edit.support.Point point : shell) { bb.addPoint(point.getX(), point.getY(), newGeom.getShell()); } List holes = geom.getHoles(); - for( PrimitiveShape primitiveShape : holes ) { + for (PrimitiveShape primitiveShape : holes) { PrimitiveShape newHole = newGeom.newHole(); - for( Point point2 : primitiveShape ) { + for (Point point2 : primitiveShape) { bb.addPoint(point2.getX(), point2.getY(), newHole); } } geom = newGeom; } else { - EditUtils.instance.refreshLayer(layer, Collections.singleton(addFeatureCommand - .getFid()), null, false, false); + EditUtils.instance.refreshLayer(layer, + Collections.singleton(addFeatureCommand.getFid()), null, false, false); } } finally { layer.eSetDeliver(prev); diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateNewOrSelectExistingFeatureCommand.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateNewOrSelectExistingFeatureCommand.java index b756148bf9..402abf1781 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateNewOrSelectExistingFeatureCommand.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/CreateNewOrSelectExistingFeatureCommand.java @@ -11,7 +11,7 @@ package org.locationtech.udig.tools.edit.commands; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; import org.geotools.data.FeatureStore; import org.geotools.data.Query; import org.geotools.feature.FeatureIterator; @@ -34,7 +34,8 @@ * @author jones * @since 1.1.0 */ -public class CreateNewOrSelectExistingFeatureCommand extends AbstractCommand implements UndoableMapCommand { +public class CreateNewOrSelectExistingFeatureCommand extends AbstractCommand + implements UndoableMapCommand { private Geometry geom; @@ -61,7 +62,7 @@ public void run(IProgressMonitor monitor) throws Exception { monitor.beginTask(Messages.CreateOrSetFeature_name, 10); monitor.worked(1); FeatureStore store = layer.getResource(FeatureStore.class, - new SubProgressMonitor(monitor, 2)); + SubMonitor.convert(monitor, 2)); Filter id = FeatureUtils.id(fid); String typeName = store.getSchema().getTypeName(); Query query = new Query(typeName, id); @@ -72,9 +73,9 @@ public void run(IProgressMonitor monitor) throws Exception { iter.close(); } if (createFeature) { - createFeature(new SubProgressMonitor(monitor, 8)); + createFeature(SubMonitor.convert(monitor, 8)); } else { - modifyFeature(new SubProgressMonitor(monitor, 8)); + modifyFeature(SubMonitor.convert(monitor, 8)); } } diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/DeselectEditGeomCommand.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/DeselectEditGeomCommand.java index 9e90617a8b..64ccf936c3 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/DeselectEditGeomCommand.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/DeselectEditGeomCommand.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -17,7 +18,7 @@ import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; import org.geotools.data.FeatureSource; import org.geotools.factory.CommonFactoryFinder; import org.geotools.feature.FeatureCollection; @@ -44,30 +45,38 @@ /** * Removes an EditGeom from the edit blackboard and updates the handler's current geom if it has * been removed. - * + * * @author jones * @since 1.1.0 */ public class DeselectEditGeomCommand extends AbstractCommand implements UndoableMapCommand { private EditToolHandler handler; + private List geoms; + private List removed; + private EditGeom currentGeom; + private PrimitiveShape currentShape; + private EditState currentState; + private boolean removedAll; + private UndoableMapCommand nullEditFeatureCommand; + private ILayer layer; - public DeselectEditGeomCommand( EditToolHandler handler, List geoms ) { + public DeselectEditGeomCommand(EditToolHandler handler, List geoms) { this.handler = handler; this.geoms = geoms; this.layer = handler.getEditLayer(); } - private EditGeom setCurrentGeom( EditGeom newCurrentGeom, PrimitiveShape destination, - PrimitiveShape shape ) { + private EditGeom setCurrentGeom(EditGeom newCurrentGeom, PrimitiveShape destination, + PrimitiveShape shape) { if (currentGeom != null && newCurrentGeom != null && shape == currentShape) { handler.setCurrentShape(destination); return null; @@ -75,7 +84,8 @@ private EditGeom setCurrentGeom( EditGeom newCurrentGeom, PrimitiveShape destina return newCurrentGeom; } - public void run( IProgressMonitor monitor ) throws Exception { + @Override + public void run(IProgressMonitor monitor) throws Exception { monitor.beginTask(Messages.RemoveEditGeomCommand_runTaskMessage, 20); removeGeomsFromBlackboard(); if (removed.contains(handler.getCurrentGeom())) { @@ -83,8 +93,8 @@ public void run( IProgressMonitor monitor ) throws Exception { } Envelope env = new Envelope(); - Set fids = new HashSet(); - for( EditGeom geom : removed ) { + Set fids = new HashSet<>(); + for (EditGeom geom : removed) { if (env.isNull()) { env.init(geom.getShell().getEnvelope()); } else { @@ -96,7 +106,7 @@ public void run( IProgressMonitor monitor ) throws Exception { monitor.done(); } - private Pair newSelection( IProgressMonitor monitor ) + private Pair newSelection(IProgressMonitor monitor) throws IOException { EditBlackboard editBlackboard = handler.getEditBlackboard(layer); @@ -105,26 +115,26 @@ private Pair newSelection( IProgressMonitor monit FilterFactory factory = CommonFactoryFinder .getFilterFactory(GeoTools.getDefaultHints()); - Id id = factory.id(Collections.singleton(factory.featureId(newSelection - .getFeatureIDRef().get()))); + Id id = factory.id( + Collections.singleton(factory.featureId(newSelection.getFeatureIDRef().get()))); - FeatureSource source = layer.getResource(FeatureSource.class, monitor); - FeatureCollection features = source.getFeatures(id); + FeatureSource source = layer + .getResource(FeatureSource.class, monitor); + FeatureCollection features = source.getFeatures(id); FeatureIterator iter = features.features(); try { if (iter.hasNext()) { - return new Pair(newSelection.getShell(), iter - .next()); + return new Pair<>(newSelection.getShell(), iter.next()); } } finally { iter.close(); } } - return new Pair(null, null); + return new Pair<>(null, null); } - private void deselectCurrentEditFeature( IProgressMonitor monitor ) throws Exception { + private void deselectCurrentEditFeature(IProgressMonitor monitor) throws Exception { this.currentGeom = handler.getCurrentGeom(); this.currentShape = handler.getCurrentShape(); this.currentState = handler.getCurrentState(); @@ -137,10 +147,10 @@ private void deselectCurrentEditFeature( IProgressMonitor monitor ) throws Excep handler.setCurrentState(EditState.NONE); } - nullEditFeatureCommand = handler.getContext().getEditFactory().createSetEditFeatureCommand( - newSelection.getRight(), layer); + nullEditFeatureCommand = handler.getContext().getEditFactory() + .createSetEditFeatureCommand(newSelection.getRight(), layer); nullEditFeatureCommand.setMap(getMap()); - nullEditFeatureCommand.run(new SubProgressMonitor(monitor, 10)); + nullEditFeatureCommand.run(SubMonitor.convert(monitor, 10)); } private void removeGeomsFromBlackboard() { @@ -153,22 +163,24 @@ private void removeGeomsFromBlackboard() { } } + @Override public String getName() { return Messages.RemoveEditGeomCommand_commandName; } - public void rollback( IProgressMonitor monitor ) throws Exception { + @Override + public void rollback(IProgressMonitor monitor) throws Exception { monitor.beginTask(Messages.RemoveEditGeomCommand_rollbackTaskMessage, 20); if (currentState != null) handler.setCurrentState(currentState); if (nullEditFeatureCommand != null) - nullEditFeatureCommand.rollback(new SubProgressMonitor(monitor, 10)); + nullEditFeatureCommand.rollback(SubMonitor.convert(monitor, 10)); EditBlackboard bb = handler.getEditBlackboard(layer); EditGeom newCurrentGeom = null; List empty = bb.getGeoms(); - for( EditGeom original : removed ) { - EditGeom inBlackboard = bb.newGeom(original.getFeatureIDRef().get(), original - .getShapeType()); + for (EditGeom original : removed) { + EditGeom inBlackboard = bb.newGeom(original.getFeatureIDRef().get(), + original.getShapeType()); inBlackboard.setChanged(original.isChanged()); if (original == currentGeom) newCurrentGeom = inBlackboard; @@ -176,14 +188,14 @@ public void rollback( IProgressMonitor monitor ) throws Exception { PrimitiveShape destination = inBlackboard.getShell(); newCurrentGeom = setCurrentGeom(newCurrentGeom, destination, original.getShell()); - for( Iterator iter = original.getShell().coordIterator(); iter.hasNext(); ) { + for (Iterator iter = original.getShell().coordIterator(); iter.hasNext();) { bb.addCoordinate(iter.next(), destination); } - for( PrimitiveShape shape : original.getHoles() ) { + for (PrimitiveShape shape : original.getHoles()) { destination = inBlackboard.newHole(); newCurrentGeom = setCurrentGeom(newCurrentGeom, destination, shape); - for( Iterator iter = shape.coordIterator(); iter.hasNext(); ) { + for (Iterator iter = shape.coordIterator(); iter.hasNext();) { bb.addCoordinate(iter.next(), destination); } } diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/DifferenceFeatureCommand.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/DifferenceFeatureCommand.java index 3d1f0de461..6c36f1b080 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/DifferenceFeatureCommand.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/DifferenceFeatureCommand.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -19,7 +20,7 @@ import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; import org.geotools.data.FeatureSource; import org.geotools.data.Query; import org.geotools.factory.CommonFactoryFinder; @@ -65,74 +66,80 @@ /** * Splits a feature based on the current shape in the handler. *

- * After the command the current shape will be set to null and - * the edit blackboard will be cleared. - * + * After the command the current shape will be set to null and the edit blackboard will be cleared. + * * @author jones * @since 1.1.0 */ public class DifferenceFeatureCommand extends AbstractCommand implements UndoableMapCommand { - private EditToolHandler handler; - private PrimitiveShape shape; - private EditState state; - private ILayer layer; + private EditToolHandler handler; + + private PrimitiveShape shape; + + private EditState state; + + private ILayer layer; + private ArrayList geoms; - private EditState endState; - private UndoableComposite writeCommand; - private boolean addedEndVertex = false; + + private EditState endState; + + private UndoableComposite writeCommand; + + private boolean addedEndVertex = false; /** * @param handler */ - public DifferenceFeatureCommand( EditToolHandler handler, EditState endState ) { + public DifferenceFeatureCommand(EditToolHandler handler, EditState endState) { this.handler = handler; this.layer = handler.getEditLayer(); this.endState = endState; } - @SuppressWarnings("unchecked") - public void run( IProgressMonitor monitor ) throws Exception { + @Override + public void run(IProgressMonitor monitor) throws Exception { monitor.beginTask(Messages.DifferenceFeatureCommand_runTaskMessage, 10); monitor.worked(1); this.state = handler.getCurrentState(); this.shape = handler.getCurrentShape(); handler.setCurrentShape(null); - List commands = new ArrayList(); + List commands = new ArrayList<>(); - //check that start point is same as end point + // check that start point is same as end point Point startPoint = shape.getPoint(0); if (!startPoint.equals(shape.getPoint(shape.getNumPoints() - 1))) { addedEndVertex = true; shape.getEditBlackboard().addPoint(startPoint.getX(), startPoint.getY(), shape); } GeometryOperationAnimation indicator = new GeometryOperationAnimation( - PrimitiveShapeIterator.getPathIterator(shape).toShape(), new IsBusyStateProvider( - handler)); + PrimitiveShapeIterator.getPathIterator(shape).toShape(), + new IsBusyStateProvider(handler)); try { AnimationUpdater.runTimer(handler.getContext().getMapDisplay(), indicator); handler.setCurrentState(EditState.BUSY); if (writeCommand == null) { EditBlackboard editBlackboard = handler.getEditBlackboard(layer); - this.geoms = new ArrayList(editBlackboard.getGeoms()); + this.geoms = new ArrayList<>(editBlackboard.getGeoms()); geoms.remove(shape.getEditGeom()); editBlackboard.clear(); - FeatureCollection features = getFeatures(monitor); - if( features == null ){ + FeatureCollection features = getFeatures(monitor); + if (features == null) { return; // did not hit anything } try { - List geoms = new ArrayList(); + List geoms = new ArrayList<>(); geoms.add(createReferenceGeom()); - + SimpleFeature first = runDifferenceOp(features.features(), geoms); - + if (first == null) return; - + createAddFeatureCommands(commands, geoms, first); } finally { monitor.worked(2); @@ -141,7 +148,7 @@ public void run( IProgressMonitor monitor ) throws Exception { } writeCommand.setMap(getMap()); handler.setCurrentState(EditState.COMMITTING); - writeCommand.execute(new SubProgressMonitor(monitor, 5)); + writeCommand.execute(SubMonitor.convert(monitor, 5)); } finally { indicator.setValid(false); handler.setCurrentState(endState); @@ -149,14 +156,14 @@ public void run( IProgressMonitor monitor ) throws Exception { } } - @SuppressWarnings("unchecked") - private void createAddFeatureCommands( List commands, List geoms, SimpleFeature first ) throws IllegalAttributeException { + private void createAddFeatureCommands(List commands, List geoms, + SimpleFeature first) throws IllegalAttributeException { SimpleFeatureType featureType = first.getFeatureType(); if ((geoms.size() > 1 && !featureType.getGeometryDescriptor().getType().getBinding() .isAssignableFrom(MultiPolygon.class)) - || !featureType.getGeometryDescriptor().getType().getBinding().isAssignableFrom( - MultiPolygon.class)) { - for( Geometry geom : geoms ) { + || !featureType.getGeometryDescriptor().getType().getBinding() + .isAssignableFrom(MultiPolygon.class)) { + for (Geometry geom : geoms) { SimpleFeature newFeature = SimpleFeatureBuilder.copy(first); newFeature.setDefaultGeometry(geom); commands.add(handler.getContext().getEditFactory() @@ -166,60 +173,61 @@ private void createAddFeatureCommands( List commands, List geometryCollection ){ - //GeometryFactory factory = FactoryFinder.getGeometryFactory( null ); + static Geometry combineIntoOneGeometry(Collection geometryCollection) { + // GeometryFactory factory = FactoryFinder.getGeometryFactory( null ); GeometryFactory factory = new GeometryFactory(); - - Geometry combined = factory.buildGeometry( geometryCollection ); + + Geometry combined = factory.buildGeometry(geometryCollection); return combined.union(); } - + /** * @param iter - * @param geoms the geometry to remove the features in iter from. IE the geometries that will be diffed. Is - * also the list of resulting geometries. + * @param geoms the geometry to remove the features in iter from. IE the geometries that will be + * diffed. Is also the list of resulting geometries. * @return */ - public static SimpleFeature runDifferenceOp( FeatureIterator iter, List geoms ) { - Geometry createdGeometry = combineIntoOneGeometry( geoms ); - Geometry differenceGeometry = createdGeometry; - SimpleFeature first=null; - try { - - Set featureGeoms = new HashSet(); - while( iter.hasNext() ) { - SimpleFeature f = iter.next(); - - if (first == null){ - first = f; - } - Geometry featureGeometry = (Geometry) f.getDefaultGeometry(); - featureGeoms.add( featureGeometry ); - } - Geometry existingGeometry = combineIntoOneGeometry( featureGeoms ); - if( existingGeometry!=null ){ - differenceGeometry = createdGeometry.difference( existingGeometry ); - } - } finally{ - if( iter!=null ) + public static SimpleFeature runDifferenceOp(FeatureIterator iter, + List geoms) { + Geometry createdGeometry = combineIntoOneGeometry(geoms); + Geometry differenceGeometry = createdGeometry; + SimpleFeature first = null; + try { + + Set featureGeoms = new HashSet<>(); + while (iter.hasNext()) { + SimpleFeature f = iter.next(); + + if (first == null) { + first = f; + } + Geometry featureGeometry = (Geometry) f.getDefaultGeometry(); + featureGeoms.add(featureGeometry); + } + Geometry existingGeometry = combineIntoOneGeometry(featureGeoms); + if (existingGeometry != null) { + differenceGeometry = createdGeometry.difference(existingGeometry); + } + } finally { + if (iter != null) iter.close(); } geoms.clear(); - for( int i=0; i iter * @throws NoninvertibleTransformException * @throws IllegalFilterException */ - private FeatureCollection getFeatures(IProgressMonitor monitor) throws IOException, NoninvertibleTransformException, IllegalFilterException { - FeatureSource source =layer.getResource(FeatureSource.class, new SubProgressMonitor(monitor,2)); + private FeatureCollection getFeatures( + IProgressMonitor monitor) + throws IOException, NoninvertibleTransformException, IllegalFilterException { + FeatureSource source = layer + .getResource(FeatureSource.class, SubMonitor.convert(monitor, 2)); SimpleFeatureType schema = layer.getSchema(); Rectangle bounds = shape.getBounds(); - double[] toTransform = new double[]{bounds.getMinX(), bounds.getMinY(), - bounds.getMaxX(), bounds.getMaxY()}; - handler.getContext().worldToScreenTransform().inverseTransform(toTransform, 0, - toTransform, 0, 2); - ReferencedEnvelope transformedBounds = new ReferencedEnvelope(toTransform[0], toTransform[2], - toTransform[1], toTransform[3], handler.getContext().getCRS()); - - FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints()); + double[] toTransform = new double[] { bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), + bounds.getMaxY() }; + handler.getContext().worldToScreenTransform().inverseTransform(toTransform, 0, toTransform, + 0, 2); + ReferencedEnvelope transformedBounds = new ReferencedEnvelope(toTransform[0], + toTransform[2], toTransform[1], toTransform[3], handler.getContext().getCRS()); + + FilterFactory2 filterFactory = CommonFactoryFinder + .getFilterFactory2(GeoTools.getDefaultHints()); ReferencedEnvelope layerBounds; try { MathTransform transform = layer.mapToLayerTransform(); - layerBounds = new ReferencedEnvelope(JTS.transform(transformedBounds, transform), layer.getCRS()); + layerBounds = new ReferencedEnvelope(JTS.transform(transformedBounds, transform), + layer.getCRS()); } catch (Exception e) { layerBounds = transformedBounds; } String geomAttributeName = layer.getSchema().getGeometryDescriptor().getLocalName(); -// Geometry boundsAsGeom = new GeometryFactory().toGeometry(layerBounds); -// -// Intersects filter = filterFactory.intersects(filterFactory.literal(boundsAsGeom), filterFactory.property(geomAttributeName)); + String srs; try { srs = CRS.lookupIdentifier(layerBounds.getCoordinateReferenceSystem(), false); @@ -265,9 +276,9 @@ private FeatureCollection getFeatures(IProgre ProjectPlugin.getPlugin().log(e); return null; } - BBOX filter = filterFactory.bbox(geomAttributeName, layerBounds.getMinX(), - layerBounds.getMinY(), layerBounds.getMaxX(), layerBounds.getMaxY(), srs); - Query query=new Query(schema.getName().getLocalPart(), filter); + BBOX filter = filterFactory.bbox(geomAttributeName, layerBounds.getMinX(), + layerBounds.getMinY(), layerBounds.getMaxX(), layerBounds.getMaxY(), srs); + Query query = new Query(schema.getName().getLocalPart(), filter); return source.getFeatures(query); } @@ -282,10 +293,12 @@ private Geometry createReferenceGeom() { return fac.createPolygon(ring, new LinearRing[0]); } - public void rollback( IProgressMonitor monitor ) throws Exception { + + @Override + public void rollback(IProgressMonitor monitor) throws Exception { GeometryOperationAnimation indicator = new GeometryOperationAnimation( - PrimitiveShapeIterator.getPathIterator(shape).toShape(), new IsBusyStateProvider( - handler)); + PrimitiveShapeIterator.getPathIterator(shape).toShape(), + new IsBusyStateProvider(handler)); try { monitor.beginTask(Messages.DifferenceFeatureCommand_undoTaskMessage, 10); monitor.worked(1); @@ -294,20 +307,20 @@ public void rollback( IProgressMonitor monitor ) throws Exception { handler.setCurrentState(EditState.BUSY); - SubProgressMonitor submonitor = new SubProgressMonitor(monitor, 5); - writeCommand.rollback(submonitor); - submonitor.done(); + SubMonitor subMonitor = SubMonitor.convert(monitor, 5); + writeCommand.rollback(subMonitor); + subMonitor.done(); EditBlackboard bb = handler.getEditBlackboard(layer); bb.clear(); - for( EditGeom geom : geoms ) { + for (EditGeom geom : geoms) { addGeom(bb, geom); } PrimitiveShape shell = addGeom(bb, shape.getEditGeom()).getShell(); handler.setCurrentShape(shell); if (addedEndVertex) { - bb.removeCoordinate(shape.getNumCoords() - 1, shape - .getCoord(shape.getNumCoords() - 1), shell); + bb.removeCoordinate(shape.getNumCoords() - 1, + shape.getCoord(shape.getNumCoords() - 1), shell); } handler.setCurrentState(state); } catch (Exception e) { @@ -324,21 +337,22 @@ public void rollback( IProgressMonitor monitor ) throws Exception { * @param geom * @return */ - private EditGeom addGeom( EditBlackboard bb, EditGeom geom ) { + private EditGeom addGeom(EditBlackboard bb, EditGeom geom) { EditGeom newGeom = bb.newGeom(geom.getFeatureIDRef().get(), geom.getShapeType()); newGeom.setChanged(geom.isChanged()); - for( PrimitiveShape shape : geom ) { + for (PrimitiveShape shape : geom) { PrimitiveShape newShape = newGeom.getShell(); if (shape != geom.getShell()) newShape = newGeom.newHole(); Coordinate[] coords = shape.coordArray(); - for( int i = 0; i < coords.length; i++ ) { + for (int i = 0; i < coords.length; i++) { bb.addCoordinate(coords[i], newShape); } } return newGeom; } + @Override public String getName() { return Messages.DifferenceFeatureCommand_name; } diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/InsertVertexCommand.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/InsertVertexCommand.java index a36c53cf79..c38051060e 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/InsertVertexCommand.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/InsertVertexCommand.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -9,6 +10,9 @@ */ package org.locationtech.udig.tools.edit.commands; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.locationtech.jts.geom.Coordinate; import org.locationtech.udig.core.IBlockingProvider; import org.locationtech.udig.project.command.AbstractCommand; import org.locationtech.udig.project.command.UndoableMapCommand; @@ -26,93 +30,99 @@ import org.locationtech.udig.tools.edit.support.PrimitiveShape; import org.locationtech.udig.tools.edit.support.Selection; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; - -import org.locationtech.jts.geom.Coordinate; - /** * Command for inserting a Vertex to a {@link org.locationtech.udig.tools.edit.support.EditGeom} - * + * * @author jones * @since 1.1.0 */ public class InsertVertexCommand extends AbstractCommand implements UndoableMapCommand { private final Coordinate toAdd; + private final IBlockingProvider shape; + private final EditBlackboard board; + private int index; + private final IMapDisplay mapDisplay; + private EditToolHandler handler; + private Selection oldSelection; + private Point point; - public InsertVertexCommand(EditToolHandler handler, EditBlackboard board, IMapDisplay display, IBlockingProvider shape, Point toAdd, int index, boolean useSnapping ) { - this.board=board; - this.shape=shape; - this.index=index; - this.mapDisplay=display; - this.handler=handler; + public InsertVertexCommand(EditToolHandler handler, EditBlackboard board, IMapDisplay display, + IBlockingProvider shape, Point toAdd, int index, boolean useSnapping) { + this.board = board; + this.shape = shape; + this.index = index; + this.mapDisplay = display; + this.handler = handler; this.point = toAdd; - this.toAdd=performSnapCalculation(toAdd, useSnapping); + this.toAdd = performSnapCalculation(toAdd, useSnapping); } - private Coordinate performSnapCalculation(Point point, boolean useSnapping) { Coordinate toCoord = board.toCoord(point); - if( useSnapping ){ - Coordinate newCoord = EditUtils.instance.getClosestSnapPoint(handler, board,point,false, - PreferenceUtil.instance().getSnapBehaviour(), handler.getCurrentState()); - if( newCoord!=null ){ - this.point = board.toPoint(newCoord); - return newCoord; + if (useSnapping) { + Coordinate newCoord = EditUtils.instance.getClosestSnapPoint(handler, board, point, + false, PreferenceUtil.instance().getSnapBehaviour(), handler.getCurrentState()); + if (newCoord != null) { + this.point = board.toPoint(newCoord); + return newCoord; + } + return toCoord; } - return toCoord; - } - + return toCoord; } - - public void rollback( IProgressMonitor monitor ) throws Exception { + + @Override + public void rollback(IProgressMonitor monitor) throws Exception { board.startBatchingEvents(); if (handler.getContext().getMapDisplay() != null) { IAnimation animation = new DeleteVertexAnimation(point); AnimationUpdater.runTimer(handler.getContext().getMapDisplay(), animation); } - - board.removeCoordinate(index, toAdd, shape.get(new SubProgressMonitor(monitor, 1))); + + board.removeCoordinate(index, toAdd, shape.get(SubMonitor.convert(monitor, 1))); board.selectionClear(); board.selectionAddAll(oldSelection); board.fireBatchedEvents(); - - if ( getMap()!=null ) + + if (getMap() != null) handler.repaint(); } - public void run( IProgressMonitor monitor ) throws Exception { + @Override + public void run(IProgressMonitor monitor) throws Exception { board.startBatchingEvents(); - PrimitiveShape primitiveShape = shape.get(new SubProgressMonitor(monitor, 1)); - board.insertCoordinate( toAdd, index, primitiveShape); - oldSelection=new Selection(board.getSelection()); + PrimitiveShape primitiveShape = shape.get(SubMonitor.convert(monitor, 1)); + board.insertCoordinate(toAdd, index, primitiveShape); + oldSelection = new Selection(board.getSelection()); oldSelection.disconnect(); board.selectionClear(); board.selectionAdd(point); board.fireBatchedEvents(); - if ( getMap()!=null ) + if (getMap() != null) handler.repaint(); - - if( mapDisplay!=null ){ - IAnimation animation=new AddVertexAnimation(point.getX(), point.getY()); + + if (mapDisplay != null) { + IAnimation animation = new AddVertexAnimation(point.getX(), point.getY()); AnimationUpdater.runTimer(mapDisplay, animation); - handler.repaint(); + handler.repaint(); } } + @Override public String getName() { - return Messages.InsertVertexCommand_name1+toAdd+Messages.InsertVertexCommand_name2+index; + return Messages.InsertVertexCommand_name1 + toAdd + Messages.InsertVertexCommand_name2 + + index; } } diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/MoveVertexCommand.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/MoveVertexCommand.java index e218573015..02c2d559a8 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/MoveVertexCommand.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/MoveVertexCommand.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -9,6 +10,9 @@ */ package org.locationtech.udig.tools.edit.commands; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.locationtech.jts.geom.Coordinate; import org.locationtech.udig.project.ILayer; import org.locationtech.udig.project.command.AbstractCommand; import org.locationtech.udig.project.command.UndoableMapCommand; @@ -22,93 +26,98 @@ import org.locationtech.udig.tools.edit.support.Selection; import org.locationtech.udig.tools.edit.support.SnapBehaviour; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; - -import org.locationtech.jts.geom.Coordinate; - /** * This class manages the movement of a vertex. Once a vertex has been moved this command determines * how much the vertex has moved from its original position so the incremental move can be undone. * Additionally this command performs post-order snapping. It searches the layer below it for the * closest vertex and snaps to that vertex. - * + * * @author jones * @since 1.1.0 */ public class MoveVertexCommand extends AbstractCommand implements UndoableMapCommand { private Point start; + private EditToolHandler handler; + private Selection toMove; + private Point lastPoint; + private MoveSelectionCommand command; + private EditState stateAfterSnap; + private boolean doSnap; + private SnapBehaviour snapBehaviour; - public MoveVertexCommand( Point lastPoint, Selection toMove, - EditToolHandler handler, Point start, EditState stateAfterSnap, boolean doSnap ) { + public MoveVertexCommand(Point lastPoint, Selection toMove, EditToolHandler handler, + Point start, EditState stateAfterSnap, boolean doSnap) { this.lastPoint = lastPoint; this.toMove = toMove; this.handler = handler; this.start = start; - this.stateAfterSnap=stateAfterSnap; - this.doSnap=doSnap; - this.snapBehaviour=PreferenceUtil.instance().getSnapBehaviour(); + this.stateAfterSnap = stateAfterSnap; + this.doSnap = doSnap; + this.snapBehaviour = PreferenceUtil.instance().getSnapBehaviour(); } - public void run( IProgressMonitor monitor ) throws Exception { + @Override + public void run(IProgressMonitor monitor) throws Exception { if (command == null) { ILayer selectedLayer = handler.getEditLayer(); EditBlackboard editBlackboard = handler.getEditBlackboard(selectedLayer); - - Coordinate destinationCoord=null; + + Coordinate destinationCoord = null; Point dest; - destinationCoord = calculateDestinationPoint(editBlackboard, destinationCoord); - - dest=editBlackboard.toPoint(destinationCoord); + destinationCoord = calculateDestinationPoint(editBlackboard, destinationCoord); + + dest = editBlackboard.toPoint(destinationCoord); int deltaX = dest.getX() - lastPoint.getX(); - int deltaY = dest.getY() - - lastPoint.getY(); - if( deltaX!=0 || deltaY!=0 ){ + int deltaY = dest.getY() - lastPoint.getY(); + if (deltaX != 0 || deltaY != 0) { editBlackboard.moveSelection(deltaX, deltaY, toMove); } editBlackboard.setCoords(dest, destinationCoord); - + deltaX = dest.getX() - start.getX(); deltaY = dest.getY() - start.getY(); - - - command=new MoveSelectionCommand(editBlackboard, deltaX, deltaY, toMove ); + + command = new MoveSelectionCommand(editBlackboard, deltaX, deltaY, toMove); command.setMap(getMap()); - }else{ - command.run(new SubProgressMonitor(monitor, 1)); + } else { + command.run(SubMonitor.convert(monitor, 1)); } } - private Coordinate calculateDestinationPoint( EditBlackboard editBlackboard, Coordinate destinationCoord ) { - if( doSnap ){ - destinationCoord = EditUtils.instance.getClosestSnapPoint(handler, editBlackboard, lastPoint, false, - snapBehaviour, stateAfterSnap); + private Coordinate calculateDestinationPoint(EditBlackboard editBlackboard, + Coordinate destinationCoord) { + if (doSnap) { + destinationCoord = EditUtils.instance.getClosestSnapPoint(handler, editBlackboard, + lastPoint, false, snapBehaviour, stateAfterSnap); } Point dest; if (destinationCoord == null) { - dest=editBlackboard.overVertex(lastPoint, PreferenceUtil.instance().getVertexRadius(), true); - if( dest==null ) - dest=lastPoint; + dest = editBlackboard.overVertex(lastPoint, PreferenceUtil.instance().getVertexRadius(), + true); + if (dest == null) + dest = lastPoint; destinationCoord = editBlackboard.toCoord(dest); } return destinationCoord; } + @Override public String getName() { - return Messages.SnapToVertexCommand_name; + return Messages.SnapToVertexCommand_name; } - public void rollback( IProgressMonitor monitor ) throws Exception { - command.rollback(new SubProgressMonitor(monitor, 1)); + @Override + public void rollback(IProgressMonitor monitor) throws Exception { + command.rollback(SubMonitor.convert(monitor, 1)); } } diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SelectFeatureAsEditFeatureCommand.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SelectFeatureAsEditFeatureCommand.java index b4f40ae2a5..321a7d8ea6 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SelectFeatureAsEditFeatureCommand.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SelectFeatureAsEditFeatureCommand.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -13,6 +14,13 @@ import java.util.Iterator; import java.util.List; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.geotools.geometry.jts.ReferencedEnvelope; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.MultiPolygon; +import org.locationtech.jts.geom.Polygon; import org.locationtech.udig.project.ILayer; import org.locationtech.udig.project.command.AbstractCommand; import org.locationtech.udig.project.command.Command; @@ -26,113 +34,120 @@ import org.locationtech.udig.tools.edit.support.EditUtils; import org.locationtech.udig.tools.edit.support.Point; import org.locationtech.udig.tools.edit.support.PrimitiveShape; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.geotools.geometry.jts.ReferencedEnvelope; import org.opengis.feature.simple.SimpleFeature; -import org.locationtech.jts.geom.Coordinate; -import org.locationtech.jts.geom.Geometry; -import org.locationtech.jts.geom.MultiPolygon; -import org.locationtech.jts.geom.Polygon; - /** * Sets the selected feature to be the edit feature. *

    - *
  • Sets the editblack board so it contains the default geometry of the feature.
  • + *
  • Sets the editblack board so it contains the default geometry of the feature.
  • *
  • Sets the edit managers editFeature to be the feature.
  • *
  • Sets the EditToolHandler's currentGeom to be the newly added geom.
  • + * * @author jones * @since 1.1.0 */ -public class SelectFeatureAsEditFeatureCommand extends AbstractCommand implements Command, UndoableMapCommand { +public class SelectFeatureAsEditFeatureCommand extends AbstractCommand + implements Command, UndoableMapCommand { private ILayer selectedLayer; + private SimpleFeature feature; + private EditToolHandler handler; + private UndoableMapCommand unselectcommand; + private UndoableMapCommand command; + private List removed; + private EditGeom currentGeom; + private PrimitiveShape currentShape; + private EditState currentState; + private Point mouse; + private ReferencedEnvelope refreshBounds; - public SelectFeatureAsEditFeatureCommand( EditToolHandler handler, SimpleFeature feature, ILayer selectedLayer, Point mouse ) { - if( mouse==null ) + public SelectFeatureAsEditFeatureCommand(EditToolHandler handler, SimpleFeature feature, + ILayer selectedLayer, Point mouse) { + if (mouse == null) throw new NullPointerException("mouse is null"); //$NON-NLS-1$ - this.handler=handler; - this.feature=feature; - this.selectedLayer=selectedLayer; - this.mouse=mouse; + this.handler = handler; + this.feature = feature; + this.selectedLayer = selectedLayer; + this.mouse = mouse; } - public void run( IProgressMonitor monitor ) throws Exception { + @Override + public void run(IProgressMonitor monitor) throws Exception { monitor.beginTask(Messages.SetGeomCommand_undoTask, 30); EditUtils.instance.cancelHideSelection(selectedLayer); IToolContext context = handler.getContext(); - this.refreshBounds=new ReferencedEnvelope(feature.getBounds()); + this.refreshBounds = new ReferencedEnvelope(feature.getBounds()); EditUtils.instance.refreshLayer(selectedLayer, feature, refreshBounds, false, true); unselectcommand = context.getSelectionFactory().createNoSelectCommand(); - command = context.getEditFactory().createSetEditFeatureCommand(feature, - selectedLayer); - + command = context.getEditFactory().createSetEditFeatureCommand(feature, selectedLayer); + unselectcommand.setMap(getMap()); command.setMap(getMap()); - - unselectcommand.run(new SubProgressMonitor(monitor, 10)); - command.run(new SubProgressMonitor(monitor, 10)); - - this.removed=handler.getEditBlackboard(selectedLayer).getGeoms(); - this.currentGeom=handler.getCurrentGeom(); - this.currentShape=handler.getCurrentShape(); - this.currentState=handler.getCurrentState(); - + + unselectcommand.run(SubMonitor.convert(monitor, 10)); + command.run(SubMonitor.convert(monitor, 10)); + + this.removed = handler.getEditBlackboard(selectedLayer).getGeoms(); + this.currentGeom = handler.getCurrentGeom(); + this.currentShape = handler.getCurrentShape(); + this.currentState = handler.getCurrentState(); + handler.setCurrentState(EditState.MODIFYING); - - Collection geoms = handler.getEditBlackboard(selectedLayer).setGeometries( - (Geometry) feature.getDefaultGeometry(), feature.getID()).values(); + Collection geoms = handler.getEditBlackboard(selectedLayer) + .setGeometries((Geometry) feature.getDefaultGeometry(), feature.getID()).values(); Class type = selectedLayer.getSchema().getGeometryDescriptor().getType().getBinding(); - boolean polygonLayer=Polygon.class.isAssignableFrom(type) || MultiPolygon.class.isAssignableFrom(type); + boolean polygonLayer = Polygon.class.isAssignableFrom(type) + || MultiPolygon.class.isAssignableFrom(type); EditGeom over = EditUtils.instance.getGeomWithMouseOver(geoms, mouse, polygonLayer); handler.setCurrentShape(over.getShell()); monitor.done(); } + @Override public String getName() { return Messages.SetGeomCommand_name; } - public void rollback( IProgressMonitor monitor ) throws Exception { + @Override + public void rollback(IProgressMonitor monitor) throws Exception { monitor.beginTask(Messages.SetGeomCommand_runTask, 30); handler.setCurrentShape(currentShape); EditBlackboard bb = handler.getEditBlackboard(selectedLayer); handler.setCurrentState(currentState); - EditGeom newCurrentGeom=null; + EditGeom newCurrentGeom = null; List empty = bb.getGeoms(); - - for( EditGeom original : removed ) { - EditGeom inBlackboard = bb.newGeom(original.getFeatureIDRef().get(), original.getShapeType()); + + for (EditGeom original : removed) { + EditGeom inBlackboard = bb.newGeom(original.getFeatureIDRef().get(), + original.getShapeType()); inBlackboard.setChanged(original.isChanged()); - if( original == currentGeom ) - newCurrentGeom=inBlackboard; - + if (original == currentGeom) + newCurrentGeom = inBlackboard; + PrimitiveShape destination = inBlackboard.getShell(); newCurrentGeom = setCurrentGeom(newCurrentGeom, destination, original.getShell()); - - for( Iterator iter=original.getShell().coordIterator(); iter.hasNext(); ) { + + for (Iterator iter = original.getShell().coordIterator(); iter.hasNext();) { bb.addCoordinate(iter.next(), destination); } - - for( PrimitiveShape shape : original.getHoles() ) { - destination=inBlackboard.newHole(); + + for (PrimitiveShape shape : original.getHoles()) { + destination = inBlackboard.newHole(); newCurrentGeom = setCurrentGeom(newCurrentGeom, destination, shape); - for( Iterator iter=shape.coordIterator(); iter.hasNext(); ) { + for (Iterator iter = shape.coordIterator(); iter.hasNext();) { bb.addCoordinate(iter.next(), destination); } } @@ -143,13 +158,13 @@ public void rollback( IProgressMonitor monitor ) throws Exception { refreshBounds.expandToInclude(new ReferencedEnvelope(feature.getBounds())); EditUtils.instance.refreshLayer(selectedLayer, feature, refreshBounds, true, false); - command.rollback(new SubProgressMonitor(monitor, 10)); - unselectcommand.rollback(new SubProgressMonitor(monitor, 10)); + command.rollback(SubMonitor.convert(monitor, 10)); + unselectcommand.rollback(SubMonitor.convert(monitor, 10)); } - - private EditGeom setCurrentGeom( EditGeom newCurrentGeom, PrimitiveShape destination, PrimitiveShape shape ) { - if( currentGeom!=null && newCurrentGeom!=null && shape==currentShape ){ + private EditGeom setCurrentGeom(EditGeom newCurrentGeom, PrimitiveShape destination, + PrimitiveShape shape) { + if (currentGeom != null && newCurrentGeom != null && shape == currentShape) { handler.setCurrentShape(destination); } return newCurrentGeom; diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SelectFeaturesInFilterCommand.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SelectFeaturesInFilterCommand.java index 8ee7abfea1..82fed95567 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SelectFeaturesInFilterCommand.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SelectFeaturesInFilterCommand.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -12,7 +13,7 @@ import java.util.ArrayList; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; import org.geotools.data.FeatureStore; import org.geotools.data.Query; import org.geotools.feature.FeatureCollection; @@ -28,81 +29,88 @@ /** * Add all the features to the EditBlackboard that are contained in the filter. - * + * * @author jones * @since 1.1.0 */ public class SelectFeaturesInFilterCommand extends AbstractCommand implements UndoableMapCommand { private Filter filter; + private ILayer layer; + private EditBlackboard bb; + private ArrayList commands; /** * Create new instance + * * @param blackboard blackboard to add selected features - * @param layer layer used to obtain features. Must have a FeatureStore resource. + * @param layer layer used to obtain features. Must have a FeatureStore resource. * @param filter filter used to select features */ - public SelectFeaturesInFilterCommand( EditBlackboard blackboard, ILayer layer, Filter filter ) { - if( !layer.hasResource(FeatureStore.class) ) + public SelectFeaturesInFilterCommand(EditBlackboard blackboard, ILayer layer, Filter filter) { + if (!layer.hasResource(FeatureStore.class)) throw new IllegalArgumentException("Layer must have a FeatureStore resource"); //$NON-NLS-1$ - this.filter=filter; - this.layer=layer; - this.bb=blackboard; + this.filter = filter; + this.layer = layer; + this.bb = blackboard; } - public void run( IProgressMonitor monitor ) throws Exception { + @Override + public void run(IProgressMonitor monitor) throws Exception { monitor.beginTask(Messages.AddFeaturesCommand_taskMessage, 10); monitor.worked(1); - - FeatureStore store=layer.getResource(FeatureStore.class, new SubProgressMonitor(monitor, 2)); + + FeatureStore store = layer.getResource(FeatureStore.class, + SubMonitor.convert(monitor, 2)); String geomAttributeName = layer.getSchema().getGeometryDescriptor().getLocalName(); - String[] desiredProperties = new String[]{geomAttributeName}; - Query query=new Query(layer.getSchema().getTypeName(), filter, - desiredProperties); - FeatureCollection features = store.getFeatures(query); - - FeatureIterator iter=features.features(); - try{ - commands=new ArrayList(); - while( iter.hasNext() ){ - SimpleFeature feature=iter.next(); + String[] desiredProperties = new String[] { geomAttributeName }; + Query query = new Query(layer.getSchema().getTypeName(), filter, desiredProperties); + FeatureCollection features = store.getFeatures(query); + + FeatureIterator iter = features.features(); + try { + commands = new ArrayList<>(); + while (iter.hasNext()) { + SimpleFeature feature = iter.next(); commands.add(new SelectFeatureCommand(bb, feature)); } - float index=0; - float inc=(float)7/commands.size(); - for( UndoableMapCommand command : commands ) { + float index = 0; + float inc = (float) 7 / commands.size(); + for (UndoableMapCommand command : commands) { command.setMap(getMap()); - index+=inc; - SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, (int) index); - command.run(subProgressMonitor); - subProgressMonitor.done(); - if( index>1 ){ - index=0; + index += inc; + SubMonitor subMonitor = SubMonitor.convert(monitor, (int) index); + command.run(subMonitor); + subMonitor.done(); + if (index > 1) { + index = 0; } } - }finally{ + } finally { iter.close(); } - + monitor.done(); - + } + @Override public String getName() { return null; } - public void rollback( IProgressMonitor monitor ) throws Exception { - monitor.beginTask(Messages.AddFeaturesCommand_undoTaskMessage, commands.size()*2); - - for( int i=commands.size()-1; i>-1; i--){ - SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 2); - commands.get(i).rollback(subProgressMonitor); - subProgressMonitor.done(); + @Override + public void rollback(IProgressMonitor monitor) throws Exception { + monitor.beginTask(Messages.AddFeaturesCommand_undoTaskMessage, commands.size() * 2); + + for (int i = commands.size() - 1; i > -1; i--) { + SubMonitor subMonitor = SubMonitor.convert(monitor, 2); + commands.get(i).rollback(subMonitor); + subMonitor.done(); } monitor.done(); } diff --git a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SplitLineCommand.java b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SplitLineCommand.java index 9242abe8fe..d22d3bd00a 100644 --- a/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SplitLineCommand.java +++ b/plugins/org.locationtech.udig.tool.edit/src/org/locationtech/udig/tools/edit/commands/SplitLineCommand.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -18,7 +19,7 @@ import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; import org.geotools.data.FeatureStore; import org.geotools.factory.CommonFactoryFinder; import org.geotools.feature.collection.AdaptorFeatureCollection; @@ -54,37 +55,49 @@ /** * Splits a line at the selected Vertices. - * + * * @author Jesse * @since 1.1.0 */ public class SplitLineCommand extends AbstractCommand implements MapCommand, UndoableCommand { private EditBlackboard editBlackboard; + private IBlockingProvider shapeProvider; + private Set points; + private PrimitiveShape oldshape; + private IBlockingProvider featureProvider; + private IBlockingProvider layerProvider; + private SimpleFeature oldFeature; + private ILayer layer; - private List newFids = new ArrayList(); + + private List newFids = new ArrayList<>(); + private boolean currentShapeSet = false; + private Geometry oldGeometry; + private EditGeom first; /** * New instance - * + * * @param editBlackboard the blackboard that the feature is on. * @param provider the * @param feature * @param evaluationObject * @param points */ - public SplitLineCommand( EditBlackboard editBlackboard, - IBlockingProvider provider, IBlockingProvider featureProvider, - IBlockingProvider layerProvider, Set points ) { + public SplitLineCommand(EditBlackboard editBlackboard, + IBlockingProvider provider, + IBlockingProvider featureProvider, + IBlockingProvider layerProvider, Set points) { this.editBlackboard = editBlackboard; this.shapeProvider = provider; this.layerProvider = layerProvider; @@ -92,32 +105,35 @@ public SplitLineCommand( EditBlackboard editBlackboard, this.points = points; } - public void run( IProgressMonitor monitor ) throws Exception { + @Override + public void run(IProgressMonitor monitor) throws Exception { editBlackboard.startBatchingEvents(); - - oldshape = shapeProvider.get(new SubProgressMonitor(monitor, 1)); - oldFeature = featureProvider.get(new SubProgressMonitor(monitor, 1)); + + oldshape = shapeProvider.get(SubMonitor.convert(monitor, 1)); + oldFeature = featureProvider.get(SubMonitor.convert(monitor, 1)); oldGeometry = (Geometry) oldFeature.getDefaultGeometry(); - layer = layerProvider.get(new SubProgressMonitor(monitor, 1)); + layer = layerProvider.get(SubMonitor.convert(monitor, 1)); editBlackboard.removeGeometries(Collections.singleton(oldshape.getEditGeom())); ShapeType shapeType = oldshape.getEditGeom().getShapeType(); - EditGeom current = editBlackboard.newGeom(oldshape.getEditGeom().getFeatureIDRef().get(), shapeType); + EditGeom current = editBlackboard.newGeom(oldshape.getEditGeom().getFeatureIDRef().get(), + shapeType); first = current; - final Set addedGeoms=new HashSet(); - for( int i = 0; i < oldshape.getNumPoints(); i++ ) { + final Set addedGeoms = new HashSet<>(); + for (int i = 0; i < oldshape.getNumPoints(); i++) { addCoords(current.getShell(), i); if (current.getShell().getNumPoints() > 1 && i < oldshape.getNumPoints() - 1 && points.contains(oldshape.getPoint(i))) { - current = editBlackboard.newGeom("newFeature" + System.currentTimeMillis(), shapeType); //$NON-NLS-1$ + current = editBlackboard.newGeom("newFeature" + System.currentTimeMillis(), //$NON-NLS-1$ + shapeType); List coords = oldshape.getCoordsAt(i); editBlackboard.addCoordinate(coords.get(coords.size() - 1), current.getShell()); addedGeoms.add(current); } } - + editBlackboard.removeGeometries(addedGeoms); if (getCurrentShape() == oldshape) { @@ -125,25 +141,25 @@ public void run( IProgressMonitor monitor ) throws Exception { setCurrentShape(first.getShell()); } - final FeatureStore store = layer.getResource(FeatureStore.class, new SubProgressMonitor( - monitor, 1)); + final FeatureStore store = layer + .getResource(FeatureStore.class, SubMonitor.convert(monitor, 1)); modifyOldFeature(store); createAndAddFeatures(addedGeoms, store); - + editBlackboard.fireBatchedEvents(); } - @SuppressWarnings({"unchecked"}) - private void modifyOldFeature( final FeatureStore store ) throws IOException, IllegalAttributeException { + private void modifyOldFeature(final FeatureStore store) + throws IOException, IllegalAttributeException { FilterFactory fac = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints()); Filter filter = fac.id(FeatureUtils.stringToId(fac, oldFeature.getID())); Geometry g = GeometryCreationUtil.createGeom(LineString.class, first.getShell(), true); if (store.getSchema().getGeometryDescriptor().getType().getBinding() .isAssignableFrom(MultiLineString.class)) - g = new GeometryFactory().createMultiLineString(new LineString[]{(LineString) g}); + g = new GeometryFactory().createMultiLineString(new LineString[] { (LineString) g }); store.modifyFeatures(store.getSchema().getGeometryDescriptor().getName(), g, filter); oldFeature.setDefaultGeometry(g); @@ -156,56 +172,64 @@ private void modifyOldFeature( final FeatureStore addedGeoms, final FeatureStore store ) throws IOException { - newFids = store.addFeatures(new AdaptorFeatureCollection("createAndAddCollection", store.getSchema()){ - - @Override - public int size() { - return addedGeoms.size() - 1; - } - - @Override - protected Iterator openIterator() { - final Iterator iter = addedGeoms.iterator(); - return new Iterator(){ - GeometryFactory factory = new GeometryFactory(); - public boolean hasNext() { - return iter.hasNext(); - } - - @SuppressWarnings("unchecked") - public Object next() { - List attrs = oldFeature.getAttributes(); - try { - SimpleFeature feature = SimpleFeatureBuilder.build(store.getSchema(), attrs, "copyOf"+oldFeature.getID()); - Geometry geom = GeometryCreationUtil.createGeom(LineString.class, iter - .next().getShell(), true); - if (getSchema().getGeometryDescriptor().getType() - .getBinding().isAssignableFrom( - MultiLineString.class)) - geom = factory - .createMultiLineString(new LineString[]{(LineString) geom}); - feature.setDefaultGeometry(geom); - return feature; - } catch (IllegalAttributeException e) { - throw (RuntimeException) new RuntimeException().initCause(e); - } + private void createAndAddFeatures(final Set addedGeoms, + final FeatureStore store) throws IOException { + newFids = store.addFeatures( + new AdaptorFeatureCollection("createAndAddCollection", store.getSchema()) { //$NON-NLS-1$ + + @Override + public int size() { + return addedGeoms.size() - 1; } - public void remove() { + @Override + protected Iterator openIterator() { + final Iterator iter = addedGeoms.iterator(); + return new Iterator() { + GeometryFactory factory = new GeometryFactory(); + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public Object next() { + List attrs = oldFeature.getAttributes(); + try { + SimpleFeature feature = SimpleFeatureBuilder.build( + store.getSchema(), attrs, + "copyOf" + oldFeature.getID()); //$NON-NLS-1$ + Geometry geom = GeometryCreationUtil.createGeom( + LineString.class, iter.next().getShell(), true); + if (getSchema().getGeometryDescriptor().getType().getBinding() + .isAssignableFrom(MultiLineString.class)) + geom = factory.createMultiLineString( + new LineString[] { (LineString) geom }); + feature.setDefaultGeometry(geom); + return feature; + } catch (IllegalAttributeException e) { + throw (RuntimeException) new RuntimeException().initCause(e); + } + } + + @Override + public void remove() { + + } + + }; } - }; - } + @Override + protected void closeIterator(Iterator close) { - @Override - protected void closeIterator( Iterator close ) { - } + } - }); + }); } - private void setCurrentShape( PrimitiveShape shape ) { + private void setCurrentShape(PrimitiveShape shape) { getMap().getBlackboard().put(EditToolHandler.CURRENT_SHAPE, shape); } @@ -213,43 +237,47 @@ private PrimitiveShape getCurrentShape() { return (PrimitiveShape) getMap().getBlackboard().get(EditToolHandler.CURRENT_SHAPE); } - private void addCoords( PrimitiveShape current, int i ) { + private void addCoords(PrimitiveShape current, int i) { List coords = oldshape.getCoordsAt(i); - for( Coordinate coordinate : coords ) { + for (Coordinate coordinate : coords) { editBlackboard.addCoordinate(coordinate, current); } } + @Override public String getName() { return Messages.SplitLineCommand_name; } - public void rollback( IProgressMonitor monitor ) throws Exception { + @Override + public void rollback(IProgressMonitor monitor) throws Exception { editBlackboard.removeGeometries(Collections.singleton(first)); - EditGeom newGeom = editBlackboard.newGeom(oldshape.getEditGeom().getFeatureIDRef().get(), oldshape.getEditGeom().getShapeType()); + EditGeom newGeom = editBlackboard.newGeom(oldshape.getEditGeom().getFeatureIDRef().get(), + oldshape.getEditGeom().getShapeType()); - for( int i = 0; i < oldshape.getNumCoords(); i++ ) { + for (int i = 0; i < oldshape.getNumCoords(); i++) { editBlackboard.addCoordinate(oldshape.getCoord(i), newGeom.getShell()); } if (currentShapeSet) setCurrentShape(newGeom.getShell()); - FeatureStore store = layer.getResource(FeatureStore.class, new SubProgressMonitor(monitor, - 1)); + FeatureStore store = layer.getResource(FeatureStore.class, + SubMonitor.convert(monitor, 1)); FilterFactory factory = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints()); - Set ids = new HashSet(); - for( FeatureId id : newFids ) { - ids.add(id); + Set ids = new HashSet<>(); + for (FeatureId id : newFids) { + ids.add(id); } Id filter = factory.id(ids); store.removeFeatures(filter); Geometry oldType = (Geometry) oldFeature.getDefaultGeometry(); - GeometryDescriptor newType = store.getSchema().getGeometryDescriptor(); - store.modifyFeatures(newType.getName(), oldType, factory.id(FeatureUtils.stringToId(factory, oldFeature.getID()))); + GeometryDescriptor newType = store.getSchema().getGeometryDescriptor(); + store.modifyFeatures(newType.getName(), oldType, + factory.id(FeatureUtils.stringToId(factory, oldFeature.getID()))); oldFeature.setDefaultGeometry(oldGeometry); newFids.clear(); } diff --git a/plugins/org.locationtech.udig.tool.select/src/org/locationtech/udig/tool/select/commands/SetAOILayerCommand.java b/plugins/org.locationtech.udig.tool.select/src/org/locationtech/udig/tool/select/commands/SetAOILayerCommand.java index f799ad402c..cd43735a31 100644 --- a/plugins/org.locationtech.udig.tool.select/src/org/locationtech/udig/tool/select/commands/SetAOILayerCommand.java +++ b/plugins/org.locationtech.udig.tool.select/src/org/locationtech/udig/tool/select/commands/SetAOILayerCommand.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004-2011, Refractions Research Inc. * @@ -14,13 +15,17 @@ import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; import org.geotools.data.FeatureSource; import org.geotools.data.simple.SimpleFeatureCollection; import org.geotools.data.simple.SimpleFeatureIterator; import org.geotools.data.simple.SimpleFeatureSource; import org.geotools.geometry.jts.JTS; import org.geotools.geometry.jts.ReferencedEnvelope; +import org.locationtech.jts.geom.Envelope; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.Polygon; import org.locationtech.udig.aoi.AOIProxy; import org.locationtech.udig.aoi.IAOIService; import org.locationtech.udig.aoi.IAOIStrategy; @@ -39,14 +44,9 @@ import org.opengis.feature.simple.SimpleFeature; import org.opengis.filter.Filter; -import org.locationtech.jts.geom.Envelope; -import org.locationtech.jts.geom.Geometry; -import org.locationtech.jts.geom.GeometryFactory; -import org.locationtech.jts.geom.Polygon; - /** * Queries the current AOI layer (Area of Interest) for selection and updates the AOILayerStrategy - * + * * @see org.locationtech.udig.tools.internal.AOILayerStrategy * @author leviputna * @since 1.2.3 @@ -54,16 +54,19 @@ public class SetAOILayerCommand extends AbstractCommand implements UndoableMapCommand { private Envelope bbox = null; + private ReferencedEnvelope bounds; + private MapMouseEvent mouseEvent; - private static String AOI_LAYER_ID = "org.locationtech.udig.tool.select.internal.aoiLayer"; + + private static String AOI_LAYER_ID = "org.locationtech.udig.tool.select.internal.aoiLayer"; //$NON-NLS-1$ /** * Creates a new instance of SetConndaryCommand - * + * * @param bbox */ - public SetAOILayerCommand( MapMouseEvent e, Envelope bbox ) { + public SetAOILayerCommand(MapMouseEvent e, Envelope bbox) { this.bbox = bbox; this.mouseEvent = e; } @@ -71,36 +74,35 @@ public SetAOILayerCommand( MapMouseEvent e, Envelope bbox ) { /** * @see org.locationtech.udig.project.command.UndoableCommand#rollback() */ - public void rollback( IProgressMonitor monitor ) throws Exception { + @Override + public void rollback(IProgressMonitor monitor) throws Exception { } /** * @see org.locationtech.udig.project.command.MapCommand#run() */ - public void run( IProgressMonitor monitor ) throws Exception { + @Override + public void run(IProgressMonitor monitor) throws Exception { // Get Preference -// boolean zoomToSelection = SelectPlugin.getDefault().getPreferenceStore() -// .getBoolean(SelectionToolPreferencePage.ZOOM_TO_SELECTION); boolean isNavigate = SelectPlugin.getDefault().getPreferenceStore() .getBoolean(SelectionToolPreferencePage.NAVIGATE_SELECTION); - + AOILayerStrategy strategy = getAOILayerStrategy(); ILayer activeLayer = strategy.getActiveLayer(); ILayer previousLayer = strategy.getPreviousLayer(); ILayer nextLayer = strategy.getNextLayer(); - + ILayer selectedLayer = activeLayer; - + // change the layer we are looking at based on navigation Geometry geometry = strategy.getGeometry(); Polygon testLocation = JTS.toGeometry(this.bbox); - if(isNavigate && (mouseEvent.button == MapMouseEvent.BUTTON3)){ - if( previousLayer != null ){ + if (isNavigate && (mouseEvent.button == MapMouseEvent.BUTTON3)) { + if (previousLayer != null) { selectedLayer = previousLayer; - } - else { + } else { // end of the world! updateAOIService(null, null); bounds = getMap().getBounds(null); @@ -108,50 +110,48 @@ public void run( IProgressMonitor monitor ) throws Exception { vmi.zoomToBox(bounds); return; } - } - else if (isNavigate && (mouseEvent.button == MapMouseEvent.BUTTON1)) { + } else if (isNavigate && (mouseEvent.button == MapMouseEvent.BUTTON1)) { selectedLayer = nextLayer != null ? nextLayer : activeLayer; - if( activeLayer != null ){ + if (activeLayer != null) { // please stay on the active layer until you have a geometry - if( geometry == null || !geometry.contains( testLocation)){ + if (geometry == null || !geometry.contains(testLocation)) { // we need a selected geometry before we let people navigate away selectedLayer = activeLayer; } } } - - if( selectedLayer == null){ + + if (selectedLayer == null) { return; // nothing to do! } - if (!selectedLayer.getInteraction(Interaction.AOI)){ + if (!selectedLayer.getInteraction(Interaction.AOI)) { return; // eek! } - // use the bbox to see if we hit anything! + // use the BBox to see if we hit anything! SimpleFeatureCollection featureCollection = getFeaturesInBbox(selectedLayer, bbox, monitor); - + if (featureCollection.isEmpty()) { // the user did not click on anything useful (so sad)! // see if they were trying to click around on the active layer instead! - if( selectedLayer == activeLayer){ + if (selectedLayer == activeLayer) { return; // give up no change to AOI stuffs - } - else { - // quickly test to see if they clicked on a neighbour - SimpleFeatureCollection testCollection = getFeaturesInBbox(activeLayer, bbox, monitor); - if(!testCollection.isEmpty() ){ - // okay let us go to neighbour + } else { + // quickly test to see if they clicked on a neighbor + SimpleFeatureCollection testCollection = getFeaturesInBbox(activeLayer, bbox, + monitor); + if (!testCollection.isEmpty()) { + // okay let us go to neighbor selectedLayer = activeLayer; featureCollection = testCollection; - } - else { + } else { return; // user really did not find anything to click on } } - } + } bounds = featureCollection.getBounds(); Geometry newAOI = unionGeometry(featureCollection); - - updateAOIService(selectedLayer,newAOI ); + + updateAOIService(selectedLayer, newAOI); if (isNavigate) { IMap map = selectedLayer.getMap(); @@ -160,39 +160,40 @@ else if (isNavigate && (mouseEvent.button == MapMouseEvent.BUTTON1)) { } } - /* - * returns an AOILayerStrategy object for quick access + /** + * Returns an AOILayerStrategy object for quick access */ private AOILayerStrategy getAOILayerStrategy() { IAOIService aOIService = PlatformGIS.getAOIService(); - IAOIStrategy aOIStrategy = aOIService.findProxy(AOI_LAYER_ID) - .getStrategy(); + IAOIStrategy aOIStrategy = aOIService.findProxy(AOI_LAYER_ID).getStrategy(); if (aOIStrategy instanceof AOILayerStrategy) { return (AOILayerStrategy) aOIStrategy; } return null; } - - private SimpleFeatureCollection getFeaturesInBbox( ILayer layer, Envelope bbox, - IProgressMonitor monitor ) throws IOException { - SimpleFeatureSource featureSource = (SimpleFeatureSource) layer.getResource( - FeatureSource.class, new SubProgressMonitor(monitor, 1)); + private SimpleFeatureCollection getFeaturesInBbox(ILayer layer, Envelope bbox, + IProgressMonitor monitor) throws IOException { - if (featureSource == null) return null; + SimpleFeatureSource featureSource = (SimpleFeatureSource) layer + .getResource(FeatureSource.class, SubMonitor.convert(monitor, 1)); + + if (featureSource == null) + return null; Filter bboxFilter = layer.createBBoxFilter(bbox, monitor); return featureSource.getFeatures(bboxFilter); } - private Geometry unionGeometry( SimpleFeatureCollection featureCollection ) { - if (featureCollection.size() < 0) return null; + private Geometry unionGeometry(SimpleFeatureCollection featureCollection) { + if (featureCollection.size() < 0) + return null; - List geoms = new ArrayList(); + List geoms = new ArrayList<>(); SimpleFeatureIterator featureIterator = featureCollection.features(); - while( featureIterator.hasNext() ) { + while (featureIterator.hasNext()) { SimpleFeature feature = featureIterator.next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); geoms.add(geometry.reverse()); @@ -205,16 +206,15 @@ private Geometry unionGeometry( SimpleFeatureCollection featureCollection ) { return combined.union(); } - private void updateAOIService( ILayer layer, Geometry newAOI ) - throws IOException { + private void updateAOIService(ILayer layer, Geometry newAOI) throws IOException { IAOIService aOIService = PlatformGIS.getAOIService(); AOIProxy aoiLayerProxy = aOIService.findProxy(AOI_LAYER_ID); - - AOILayerStrategy aOILayerStrategy = (AOILayerStrategy)aoiLayerProxy.getStrategy(); + + AOILayerStrategy aOILayerStrategy = (AOILayerStrategy) aoiLayerProxy.getStrategy(); aOILayerStrategy.setActiveLayer(layer); aOILayerStrategy.setGeometry(newAOI); - - // if the current stragegy does not equal the bounary layer strategy set it + + // if the current strategy does not equal the boundary layer strategy set it if (!aOIService.getProxy().equals(aoiLayerProxy)) { aOIService.setProxy(aoiLayerProxy); } @@ -223,6 +223,7 @@ private void updateAOIService( ILayer layer, Geometry newAOI ) /** * @see org.locationtech.udig.project.command.MapCommand#getName() */ + @Override public String getName() { return Messages.BBoxSelectionCommand_boxSelection; }