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 8, 2020
1 parent df43668 commit 6c5c49a
Show file tree
Hide file tree
Showing 55 changed files with 428 additions and 1,421 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
package org.locationtech.udig.bookmarks.internal.command;

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;

Expand Down Expand Up @@ -47,15 +46,15 @@ protected void runImpl( IProgressMonitor monitor ) throws Exception {
.getResourceSet().getResource(mapID, true).getContents().get(0));
ApplicationGIS.openMap(map);
IViewportModel v = map.getViewportModel();

final ReferencedEnvelope bookmarkEnvelope = target.getEnvelope();
final Envelope viewportBounds = v.getBounds();

final CoordinateReferenceSystem viewportCrs = v.getCRS();
final CoordinateReferenceSystem bookmarkCrs = bookmarkEnvelope.getCoordinateReferenceSystem();

final ReferencedEnvelope bookmarkedEnvelopeInVieportCRS;

if(bookmarkCrs.equals(viewportCrs)){
bookmarkedEnvelopeInVieportCRS = bookmarkEnvelope;
}else{
Expand All @@ -71,12 +70,9 @@ protected void runImpl( IProgressMonitor monitor ) throws Exception {
}
}

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,6 +34,7 @@
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.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 All @@ -50,7 +51,7 @@
/**
* Represents a problem or issue with a feature. The map containing the feature and the
* FeatureEditor will both be show. The map will be zoomed to show the feature.
*
*
* @author jones
* @since 1.0.0
*/
Expand All @@ -60,7 +61,7 @@ public class FeatureIssue extends AbstractIssue {
private static final String LAYER_KEY = "layer"; //$NON-NLS-1$
private static final String PROJECT_KEY = "project"; //$NON-NLS-1$
private static final String FEATURE_KEY = "feature"; //$NON-NLS-1$

private SimpleFeature feature;
private String viewid;
private FeatureEditorLoader featureEditorLoader;
Expand All @@ -75,33 +76,33 @@ public class FeatureIssue extends AbstractIssue {
private static boolean testing=false;

public FeatureIssue( ){

}

public FeatureIssue( Priority priority, String description, ILayer containingLayer, SimpleFeature feature, String groupId ) {
assert groupId!=null && priority!=null && containingLayer!=null && feature!=null;

setPriority(priority);
setDescription(description);
this.layer=containingLayer;
this.feature = feature;
featureEditorLoader = ApplicationGISInternal.getFeatureEditorLoader(feature);
viewid = featureEditorLoader.getViewId();

setGroupId(groupId);
setBounds(new ReferencedEnvelope(feature.getBounds()));
}

@Override
public void setId( String id ) {
super.setId(id);
}

@Override
public String getEditorID() {
return MapEditorWithPalette.ID;
}

@Override
public IEditorInput getEditorInput() {
return new MapEditorInput(getLayer().getMap());
Expand All @@ -110,11 +111,12 @@ public IEditorInput getEditorInput() {
@Override
public String getViewPartId() {
if( viewid==null ){

}
return viewid;
}

@Override
public String getProblemObject() {
SimpleFeature feature = getFeature();
SimpleFeatureType featureType = feature.getFeatureType();
Expand All @@ -135,23 +137,25 @@ public String getProblemObject() {

private String getAttribute(SimpleFeature feature, SimpleFeatureType featureType,
String attName) {
int attributeIndex = featureType.indexOf(attName);
int attributeIndex = featureType.indexOf(attName);
if ( attributeIndex!=-1 ){
Object attribute = feature.getAttribute(attributeIndex);
return attribute.toString();
}
return null;
}

@Override
public void fixIssue( IViewPart part, IEditorPart editor ) {
if( getLayer() == null ){
Display.getDefault().asyncExec(new Runnable() {
public void run() {
@Override
public void run() {
Shell parent = Display.getCurrent().getActiveShell();
String title = Messages.FeatureIssue_DialogText;
String message = Messages.FeatureIssue_DialogMessage;
MessageDialog.openInformation(parent, title, message);

}
});
return;
Expand All @@ -169,18 +173,20 @@ public void run() {
if( tool !=null ){
tool.run();
}
NavCommand zoom = context.getNavigationFactory().createSetViewportBBoxCommand(
NavCommand zoom = new SetViewportBBoxCommand(
bounds, crs);
context.sendASyncCommand(zoom);
composite.getCommands().add(context.getSelectionFactory().createFIDSelectCommand(getLayer(),getFeature()));
composite.getCommands().add(context.getEditFactory().createSetEditFeatureCommand(getFeature(), getLayer()));
context.sendASyncCommand(composite);
}

public String getExtensionID() {
@Override
public String getExtensionID() {
return EXT_ID;
}

@Override
public void init( IMemento memento, IMemento viewMemento, String issueId, String groupId, ReferencedEnvelope bounds ) {
if( !testing || memento!=null ){
mapID=memento.getString(MAP_KEY);
Expand All @@ -194,6 +200,7 @@ public void init( IMemento memento, IMemento viewMemento, String issueId, String
setBounds(bounds);
}

@Override
public void save( IMemento memento ) {
memento.putString(MAP_KEY, getLayer().getMap().getID().toString());
memento.putString(LAYER_KEY, getLayer().getID().toString());
Expand Down Expand Up @@ -248,7 +255,7 @@ private ILayer getLayer() {
}
if( foundMap==null )
throw new IllegalStateException("This issue is not legal for this uDig instance because the map:"+mapID+" cannot be found."); //$NON-NLS-1$//$NON-NLS-2$

List<ILayer> layers= foundMap.getMapLayers();
for( ILayer layer : layers ) {
if( layer.getID().toString().equals(layerID) ){
Expand All @@ -268,5 +275,5 @@ public static void setTesting( boolean b ) {
testing=b;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.locationtech.udig.location.internal.Messages;
import org.locationtech.udig.project.IMap;
import org.locationtech.udig.project.command.NavCommand;
import org.locationtech.udig.project.internal.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.ui.ApplicationGIS;
import org.locationtech.udig.ui.SearchPart;

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 @@ -5,6 +5,7 @@
import org.easymock.EasyMock;
import org.eclipse.core.runtime.IProgressMonitor;
import org.junit.Test;
import org.locationtech.udig.project.command.navigation.SetScaleCommand;
import org.locationtech.udig.project.internal.render.ViewportModel;

public class SetScaleCommandTest {
Expand All @@ -13,12 +14,6 @@ public class SetScaleCommandTest {

private static final double PREVIOUS_SCALE = 1 / 500;

@Test
public void testCopy() throws Exception {
SetScaleCommand setScaleCommand = new SetScaleCommand(SCALE_TO_SET);
assertNotSame(setScaleCommand, setScaleCommand.copy());
}

@Test
public void ifModelIsSetSetScaleIsCalled() throws Exception {
SetScaleCommand setScaleCommand = new SetScaleCommand(SCALE_TO_SET);
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.geotools.geometry.jts.JTS;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.udig.project.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.internal.Map;
import org.locationtech.udig.project.internal.command.navigation.SetViewportBBoxCommand;
import org.locationtech.udig.project.ui.internal.MapEditorPart;
import org.locationtech.udig.project.ui.internal.Messages;
import org.locationtech.udig.project.ui.internal.ProjectUIPlugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbench;
import org.locationtech.udig.project.command.factory.EditCommandFactory;
import org.locationtech.udig.project.command.factory.NavigationCommandFactory;
import org.locationtech.udig.project.command.factory.SelectionCommandFactory;
import org.locationtech.udig.project.internal.AbstractContext;
import org.locationtech.udig.project.ui.commands.DrawCommandFactory;
Expand Down Expand Up @@ -61,13 +60,6 @@ public interface ToolContext extends IToolContext, AbstractContext {
*/
EditCommandFactory getEditFactory();

/**
* Returns a NavigationCommandFactory
*
* @return a NavigationCommandFactory
* @deprecated Please use navigation commands directly
*/
NavigationCommandFactory getNavigationFactory();
/**
* Returns the current workbench.
* <p>
Expand Down
Loading

0 comments on commit 6c5c49a

Please sign in to comment.