Skip to content

Commit

Permalink
Refactoring (Nav)Commands
Browse files Browse the repository at this point in the history
Change-Id: I9a9fba0a7f96014c357a77f22aff213634fe2231
Signed-off-by: Frank Gasdorf <[email protected]>
  • Loading branch information
fgdrf committed Dec 21, 2021
1 parent eb90d59 commit a9410d3
Show file tree
Hide file tree
Showing 51 changed files with 610 additions and 1,013 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import org.locationtech.jts.geom.Envelope;
import org.locationtech.udig.bookmarks.Bookmark;
import org.locationtech.udig.project.IMap;
import org.locationtech.udig.project.command.Command;
import org.locationtech.udig.project.command.navigation.AbstractNavCommand;
import org.locationtech.udig.project.internal.ProjectPlugin;
import org.locationtech.udig.project.internal.command.navigation.AbstractNavCommand;
import org.locationtech.udig.project.render.IViewportModel;
import org.locationtech.udig.project.ui.ApplicationGIS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
Expand Down Expand Up @@ -73,13 +72,9 @@ protected void runImpl(IProgressMonitor monitor) throws Exception {
}

@Override
public Command copy() {
return null;
}

@Override
public String getName() {
return null;
return null; // TODO NLS
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.locationtech.udig.project.IMap;
import org.locationtech.udig.project.IMapCompositionListener;
import org.locationtech.udig.project.MapCompositionEvent;
import org.locationtech.udig.project.command.navigation.SetScaleCommand;
import org.locationtech.udig.project.internal.Map;
import org.locationtech.udig.project.internal.commands.SetScaleCommand;
import org.locationtech.udig.project.render.IViewportModelListener;
import org.locationtech.udig.project.render.ViewportModelEvent;
import org.locationtech.udig.project.ui.ApplicationGIS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.locationtech.udig.project.IProject;
import org.locationtech.udig.project.command.NavCommand;
import org.locationtech.udig.project.command.UndoableComposite;
import org.locationtech.udig.project.internal.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.ui.ApplicationGIS;
import org.locationtech.udig.project.ui.internal.ApplicationGISInternal;
import org.locationtech.udig.project.ui.internal.FeatureEditorLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import org.locationtech.udig.mapgraphic.internal.MapGraphicService;
import org.locationtech.udig.project.ILayer;
import org.locationtech.udig.project.command.UndoableComposite;
import org.locationtech.udig.project.command.factory.BasicCommandFactory;
import org.locationtech.udig.project.internal.Layer;
import org.locationtech.udig.project.internal.Map;
import org.locationtech.udig.project.internal.commands.AddLayerCommand;
import org.locationtech.udig.project.internal.commands.DeleteLayerCommand;
import org.locationtech.udig.project.ui.ApplicationGIS;
import org.locationtech.udig.project.ui.internal.ApplicationGISInternal;
Expand All @@ -39,8 +39,8 @@
* This is a helper class for MapGraphics that should be toggled on and off. Some good candidates
* are: Scalebar and legend.
* <p>
* This Example is the adding a Toggle action for LegendGraphic.
*
* This Example is the adding a Toggle action for LegendGraphic.
*
* <p> The following xml snippet must be added to the plugin.xml</p>
* <p>
* <pre>
Expand Down Expand Up @@ -72,10 +72,10 @@
* protected String getExtensionID() {
* return "legend"; //$NON-NLS-1$
* }
*
*
* public void init( IWorkbenchWindow window ) {
* }
*
*
* }
* </pre>
* </p>
Expand Down Expand Up @@ -151,7 +151,7 @@ private void addLegend() {
if (legendResource == null)
return;
Layer layer = map.getLayerFactory().createLayer(legendResource);
map.sendCommandSync(BasicCommandFactory.getInstance().createAddLayer(layer));
map.sendCommandSync(new AddLayerCommand(layer));
} catch (MalformedURLException e) {
MapGraphicPlugin.log("", e); //$NON-NLS-1$
} catch (IOException e) {
Expand All @@ -164,6 +164,7 @@ private void addLegend() {

protected abstract String getExtensionID();

@Override
public void init( IWorkbenchWindow window ) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.locationtech.udig.project.LayerEvent;
import org.locationtech.udig.project.MapCompositionEvent;
import org.locationtech.udig.project.MapEvent;
import org.locationtech.udig.project.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.internal.Layer;
import org.locationtech.udig.project.internal.Map;
import org.locationtech.udig.project.internal.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.internal.render.ViewportModel;
import org.locationtech.udig.project.render.IViewportModel;
import org.locationtech.udig.project.render.IViewportModelListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
import org.locationtech.udig.printing.ui.internal.PrintingEngine;
import org.locationtech.udig.printing.ui.internal.PrintingPlugin;
import org.locationtech.udig.project.IBlackboard;
import org.locationtech.udig.project.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.internal.Layer;
import org.locationtech.udig.project.internal.Map;
import org.locationtech.udig.project.internal.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.ui.ApplicationGIS;
import org.locationtech.udig.project.ui.BoundsStrategy;
import org.locationtech.udig.project.ui.SelectionStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public void run(IProgressMonitor monitor) throws Exception {
result.ran = true;
}

@Override
public Command copy() {
return null;
}

@Override
public String getName() {
return null;
Expand Down Expand Up @@ -80,11 +75,6 @@ public void run(IProgressMonitor monitor) throws Exception {
result.ran = true;
}

@Override
public Command copy() {
return null;
}

@Override
public String getName() {
return null;
Expand Down Expand Up @@ -115,11 +105,6 @@ public void run(IProgressMonitor monitor) throws Exception {
resultInner.ran = true;
}

@Override
public Command copy() {
return null;
}

@Override
public String getName() {
return null;
Expand All @@ -129,11 +114,6 @@ public String getName() {
result.ran = true;
}

@Override
public Command copy() {
return null;
}

@Override
public String getName() {
return null;
Expand Down Expand Up @@ -173,11 +153,6 @@ public void run() {
});
}

@Override
public Command copy() {
return null;
}

@Override
public String getName() {
return null;
Expand All @@ -190,11 +165,6 @@ public String getName() {
result.ran = true;
}

@Override
public Command copy() {
return null;
}

@Override
public String getName() {
return null;
Expand All @@ -220,11 +190,6 @@ public void run(IProgressMonitor monitor) throws Exception {
result.ran = true;
}

@Override
public Command copy() {
return null;
}

@Override
public String getName() {
return null;
Expand All @@ -250,11 +215,6 @@ public void run(IProgressMonitor monitor) throws Exception {
result.ran = true;
}

@Override
public Command copy() {
return null;
}

@Override
public String getName() {
return null;
Expand Down Expand Up @@ -284,11 +244,6 @@ public void run(IProgressMonitor monitor) throws Exception {
fail();
}

@Override
public Command copy() {
return null;
}

@Override
public String getName() {
return null;
Expand Down Expand Up @@ -341,11 +296,6 @@ public void run(IProgressMonitor monitor) throws Exception {
fail();
}

@Override
public Command copy() {
return null;
}

@Override
public String getName() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.eclipse.core.runtime.IProgressMonitor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.locationtech.udig.project.command.navigation.SetScaleCommand;
import org.locationtech.udig.project.internal.render.ViewportModel;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
Expand All @@ -28,54 +28,48 @@
@RunWith(MockitoJUnitRunner.class)
public class SetScaleCommandTest {

private static final double SCALE_TO_SET = 0.5;
private static final double SCALE_TO_SET = 0.5;

private static final double PREVIOUS_SCALE = 0.3;
private static final double PREVIOUS_SCALE = 0.3;

@Mock
private ViewportModel mockedViewportModel;
@Mock
private ViewportModel mockedViewportModel;

@Mock
private IProgressMonitor monitor;
@Mock
private IProgressMonitor monitor;

@Captor
private ArgumentCaptor<Double> scaleDenominatorCaptor;
@Captor
private ArgumentCaptor<Double> scaleDenominatorCaptor;

@Test
public void testCopy() throws Exception {
SetScaleCommand setScaleCommand = new SetScaleCommand(SCALE_TO_SET);
assertNotSame(setScaleCommand, setScaleCommand.copy());
}
@Test
public void ifModelIsSetSetScaleIsCalled() throws Exception {
when(mockedViewportModel.getScaleDenominator()).thenReturn(PREVIOUS_SCALE);

@Test
public void ifModelIsSetSetScaleIsCalled() throws Exception {
when(mockedViewportModel.getScaleDenominator()).thenReturn(PREVIOUS_SCALE);
SetScaleCommand setScaleCommand = new SetScaleCommand(SCALE_TO_SET);
setScaleCommand.setViewportModel(mockedViewportModel);
setScaleCommand.run(monitor);

SetScaleCommand setScaleCommand = new SetScaleCommand(SCALE_TO_SET);
setScaleCommand.setViewportModel(mockedViewportModel);
setScaleCommand.run(monitor);
verify(mockedViewportModel).setScale(SCALE_TO_SET);
}

verify(mockedViewportModel).setScale(SCALE_TO_SET);
}
@Test
public void rollbackSetsPreviousScaleFromModel() throws Exception {
when(mockedViewportModel.getScaleDenominator()).thenReturn(PREVIOUS_SCALE);

@Test
public void rollbackSetsPreviousScaleFromModel() throws Exception {
when(mockedViewportModel.getScaleDenominator()).thenReturn(PREVIOUS_SCALE);
SetScaleCommand setScaleCommand = new SetScaleCommand(SCALE_TO_SET);
setScaleCommand.setViewportModel(mockedViewportModel);

SetScaleCommand setScaleCommand = new SetScaleCommand(SCALE_TO_SET);
setScaleCommand.setViewportModel(mockedViewportModel);
setScaleCommand.run(monitor);
setScaleCommand.rollback(monitor);

setScaleCommand.run(monitor);
setScaleCommand.rollback(monitor);
verify(mockedViewportModel, times(2)).setScale(scaleDenominatorCaptor.capture());

verify(mockedViewportModel, times(2)).setScale(scaleDenominatorCaptor.capture());
assertEquals(SCALE_TO_SET, scaleDenominatorCaptor.getAllValues().get(0), 0);
assertEquals(PREVIOUS_SCALE, scaleDenominatorCaptor.getAllValues().get(1), 0);
}

assertEquals(SCALE_TO_SET, scaleDenominatorCaptor.getAllValues().get(0), 0);
assertEquals(PREVIOUS_SCALE, scaleDenominatorCaptor.getAllValues().get(1), 0);
}

@Test
public void commandNameNotNull() throws Exception {
assertNotNull("Command name expected", new SetScaleCommand(SCALE_TO_SET).getName());
}
@Test
public void commandNameNotNull() throws Exception {
assertNotNull("Command name expected", new SetScaleCommand(SCALE_TO_SET).getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.locationtech.udig.project.command.Command;
import org.locationtech.udig.project.command.CompositeCommand;
import org.locationtech.udig.project.command.MapCommand;
import org.locationtech.udig.project.internal.command.navigation.SetViewportCenterCommand;
import org.locationtech.udig.project.command.navigation.SetViewportCenterCommand;
import org.locationtech.udig.project.ui.AnimationUpdater;
import org.locationtech.udig.project.ui.ApplicationGIS;
import org.locationtech.udig.project.ui.IAnimation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.PlatformUI;
import org.locationtech.udig.project.internal.commands.SetScaleCommand;
import org.locationtech.udig.project.command.navigation.SetScaleCommand;
import org.locationtech.udig.project.render.IViewportModel;
import org.locationtech.udig.project.render.IViewportModelListener;
import org.locationtech.udig.project.render.ViewportModelEvent.EventType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import org.locationtech.udig.project.ILayer;
import org.locationtech.udig.project.command.MapCommand;
import org.locationtech.udig.project.command.UndoableComposite;
import org.locationtech.udig.project.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.internal.Layer;
import org.locationtech.udig.project.internal.Map;
import org.locationtech.udig.project.internal.ProjectPlugin;
import org.locationtech.udig.project.internal.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.internal.commands.ChangeCRSCommand;
import org.locationtech.udig.project.ui.internal.commands.SetLayerCRSCommand;
import org.locationtech.udig.ui.CRSChooser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import org.eclipse.ui.actions.ActionDelegate;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.udig.project.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.internal.Layer;
import org.locationtech.udig.project.internal.Map;
import org.locationtech.udig.project.internal.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.internal.render.impl.ScaleUtils;
import org.locationtech.udig.project.ui.internal.ProjectUIPlugin;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
Expand Down
Loading

0 comments on commit a9410d3

Please sign in to comment.