Skip to content

Commit

Permalink
finished prototypes of shortest path tools
Browse files Browse the repository at this point in the history
  • Loading branch information
svzdvd committed Jul 6, 2010
1 parent 98d08d8 commit bfdae6b
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 52 deletions.
29 changes: 28 additions & 1 deletion plugin.xml
Expand Up @@ -35,7 +35,7 @@
<enablement></enablement>
</operation>
<operation
class="net.refractions.udig.catalog.neo4j.GenerateLineStringNetworkOp"
class="net.refractions.udig.catalog.neo4j.findpath.GenerateLineStringNetworkOp"
enablesFor="1"
id="net.refractions.udig.catalog.neo4j.generateLineNetworkOp"
name="Create Line Network"
Expand All @@ -51,5 +51,32 @@
<enablement></enablement>
</operation>
</extension>
<extension
point="net.refractions.udig.mapgraphic.mapgraphic">
<mapGraphic
class="net.refractions.udig.catalog.neo4j.findpath.GraphMapGraphic"
icon="icons/etool16/path.png"
id="net.refractions.udig.catalog.neo4j.mapGraphic"
name="Neo4j Network">
</mapGraphic>
</extension>
<extension
point="net.refractions.udig.project.ui.tool">
<modalTool
class="net.refractions.udig.catalog.neo4j.findpath.WayPointTool"
icon="icons/etool16/graph.png"
id="net.refractions.udig.catalog.neo4j.waypointtool"
name="Add Way Point"
onToolbar="true">
</modalTool>
<actionTool
class="net.refractions.udig.catalog.neo4j.findpath.FindPathTool"
icon="icons/etool16/path.png"
id="net.refractions.udig.catalog.neo4j.findpathtool"
name="Find Path"
onToolbar="true">
<enablement></enablement>
</actionTool>
</extension>

</plugin>
28 changes: 28 additions & 0 deletions src/net/refractions/udig/catalog/neo4j/Activator.java
Expand Up @@ -6,8 +6,13 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.refractions.udig.catalog.IService;
import net.refractions.udig.project.ILayer;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.geotools.data.DataStore;
import org.neo4j.gis.spatial.geotools.data.Neo4jSpatialDataStore;
Expand Down Expand Up @@ -68,6 +73,29 @@ public void stop(BundleContext context) throws Exception {

super.stop(context);
}

public Neo4jSpatialService getLayerService(ILayer layer, IProgressMonitor monitor) {
try {
IService service = layer.getGeoResource().service(monitor);
if (service instanceof Neo4jSpatialService) {
return (Neo4jSpatialService) service;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return null;
}

public ILayer findLayer(String layerName, List<ILayer> layers) {
for (ILayer layer : layers) {
if (layer.getName().equals(layerName)) {
return layer;
}
}
return null;
}

public static Activator getDefault() {
return plugin;
Expand Down
Expand Up @@ -3,6 +3,7 @@
import net.refractions.udig.ui.operations.IOp;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.widgets.Display;
import org.neo4j.gis.spatial.SpatialDatabaseService;
import org.neo4j.gis.spatial.geotools.data.Neo4jSpatialDataStore;
Expand All @@ -14,6 +15,8 @@
public class DeleteNeo4jSpatialLayerOp implements IOp {

public void op(Display display, Object target, IProgressMonitor monitor) throws Exception {
if (monitor == null) monitor = new NullProgressMonitor();

// TODO ask user confirmation!

Neo4jSpatialGeoResource geoResource = (Neo4jSpatialGeoResource) target;
Expand Down
27 changes: 15 additions & 12 deletions src/net/refractions/udig/catalog/neo4j/Neo4jSpatialGeoResource.java
Expand Up @@ -42,7 +42,7 @@ public class Neo4jSpatialGeoResource extends IGeoResource {
}


// Methods
// Public methods

public URL getIdentifier() {
return identifier;
Expand Down Expand Up @@ -98,10 +98,6 @@ public <T> T resolve(Class<T> adaptee, IProgressMonitor monitor) throws IOExcept
return super.resolve(adaptee, monitor);
}

private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource(IProgressMonitor monitor) throws IOException {
return parent.getDataStore(monitor).getFeatureSource(typename);
}

public Style style(IProgressMonitor monitor) {
// don't return a style
return null;
Expand All @@ -127,16 +123,23 @@ public <T> boolean canResolve(Class<T> adaptee) {
public Neo4jSpatialGeoResourceInfo getInfo(IProgressMonitor monitor) throws IOException {
return (Neo4jSpatialGeoResourceInfo) super.getInfo(monitor);
}

protected Neo4jSpatialGeoResourceInfo createInfo(IProgressMonitor monitor) throws IOException{
return new Neo4jSpatialGeoResourceInfo(this, monitor);
}

protected String getTypeName() {

public String getTypeName() {
return typename;
}



// Private methods

private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource(IProgressMonitor monitor) throws IOException {
return parent.getDataStore(monitor).getFeatureSource(typename);
}

protected Neo4jSpatialGeoResourceInfo createInfo(IProgressMonitor monitor) throws IOException{
return new Neo4jSpatialGeoResourceInfo(this, monitor);
}


// Attributes

private Neo4jSpatialService parent;
Expand Down
Expand Up @@ -23,7 +23,7 @@ public class Neo4jSpatialGeoResourceInfo extends IGeoResourceInfo {

// Constructor

Neo4jSpatialGeoResourceInfo(Neo4jSpatialGeoResource neo4jSpatialGeoResource, IProgressMonitor monitor) throws IOException {
Neo4jSpatialGeoResourceInfo(Neo4jSpatialGeoResource neo4jSpatialGeoResource, IProgressMonitor monitor) throws IOException {
this.neo4jSpatialGeoResource = neo4jSpatialGeoResource;

Neo4jSpatialDataStore dataStore = neo4jSpatialGeoResource.service().getDataStore(monitor);
Expand Down
62 changes: 30 additions & 32 deletions src/net/refractions/udig/catalog/neo4j/Neo4jSpatialService.java
Expand Up @@ -20,7 +20,6 @@
import net.refractions.udig.catalog.internal.ResolveDelta;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.neo4j.gis.spatial.geotools.data.Neo4jSpatialDataStore;
import org.neo4j.gis.spatial.geotools.data.Neo4jSpatialDataStoreFactory;

Expand All @@ -42,10 +41,6 @@ public class Neo4jSpatialService extends IService {
// Methods

public <T> T resolve(Class<T> adaptee, IProgressMonitor monitor) throws IOException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}

if (adaptee == null) {
throw new NullPointerException("No adaptor specified");
}
Expand Down Expand Up @@ -84,20 +79,7 @@ public List<Neo4jSpatialGeoResource> resources(IProgressMonitor monitor) throws
public Neo4jSpatialServiceInfo getInfo(IProgressMonitor monitor) throws IOException {
return (Neo4jSpatialServiceInfo) super.getInfo(monitor);
}

protected IServiceInfo createInfo(IProgressMonitor monitor) throws IOException {
if (info == null) {
Neo4jSpatialDataStore dataStore = getDataStore(monitor);
if (dataStore == null) {
// could not connect
return null;
}

info = new Neo4jSpatialServiceInfo(this);
}
return info;
}


public Map<String, Serializable> getConnectionParams() {
return params;
}
Expand All @@ -107,12 +89,12 @@ public void refresh(IProgressMonitor monitor) {
dataStore.clearCache();
resources = null;

// TODO compare old and new resources
// fire an Event for every added or deleted resource
// TODO compare old and new resources and
// fire an Event for every added or deleted resource?
fireChangeEvent(monitor);
}

protected Neo4jSpatialDataStore getDataStore(IProgressMonitor monitor) {
public Neo4jSpatialDataStore getDataStore(IProgressMonitor monitor) {
if (dataStore == null) {
try {
dataStore = Activator.getDefault().getDataStore(params);
Expand All @@ -124,16 +106,6 @@ protected Neo4jSpatialDataStore getDataStore(IProgressMonitor monitor) {
}
return dataStore;
}

private void fireChangeEvent(IProgressMonitor monitor) {
IResolveDelta delta = new ResolveDelta(this, IResolveDelta.Kind.CHANGED);
ResolveChangeEvent event = new ResolveChangeEvent(this, IResolveChangeEvent.Type.POST_CHANGE, delta);

ICatalog catalog = parent(monitor);
if (catalog instanceof CatalogImpl) {
((CatalogImpl) catalog).fire(event);
}
}

public Status getStatus() {
return error != null ? Status.BROKEN : dataStore == null ? Status.NOTCONNECTED : Status.CONNECTED;
Expand All @@ -158,6 +130,32 @@ public File toFile() {
}


// Private methods

protected IServiceInfo createInfo(IProgressMonitor monitor) throws IOException {
if (info == null) {
Neo4jSpatialDataStore dataStore = getDataStore(monitor);
if (dataStore == null) {
// could not connect
return null;
}

info = new Neo4jSpatialServiceInfo(this);
}
return info;
}

private void fireChangeEvent(IProgressMonitor monitor) {
IResolveDelta delta = new ResolveDelta(this, IResolveDelta.Kind.CHANGED);
ResolveChangeEvent event = new ResolveChangeEvent(this, IResolveChangeEvent.Type.POST_CHANGE, delta);

ICatalog catalog = parent(monitor);
if (catalog instanceof CatalogImpl) {
((CatalogImpl) catalog).fire(event);
}
}


// Attributes

private URL url;
Expand Down
11 changes: 11 additions & 0 deletions src/net/refractions/udig/catalog/neo4j/findpath/Constants.java
@@ -0,0 +1,11 @@
package net.refractions.udig.catalog.neo4j.findpath;

public interface Constants {

String BLACKBOARD_WAYPOINTS = "neo4j_waypoints";

String BLACKBOARD_WAYPOINTSLAYER = "neo4j_waypoints_layer";

String BLACKBOARD_PATH = "neo4j_path";

}

0 comments on commit bfdae6b

Please sign in to comment.