]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Improve GIS
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 22 Feb 2011 23:27:31 +0000 (23:27 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 22 Feb 2011 23:27:31 +0000 (23:27 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@4172 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

eclipse/plugins/org.argeo.slc.ui.gis/META-INF/MANIFEST.MF
eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/commands.xml [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-osgi.xml
eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/views.xml [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/plugin.xml
eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/ClientGisActivator.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/GisPerspectiveFactory.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/MapViewer.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/commands/LoadLayersFromBackend.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/views/AbstractMapView.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/views/LayersView.java [new file with mode: 0644]

index 31e52742758b5e8b372c8c12d1c8d1e6aaf35908..98ef3f7f3b10fd29728bba0762a74000c5ac89ce 100644 (file)
@@ -1,10 +1,11 @@
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Gis
-Bundle-SymbolicName: org.argeo.slc.client.gis; singleton:=true
+Bundle-SymbolicName: org.argeo.slc.ui.gis; singleton:=true
 Bundle-Version: 0.13.1.SNAPSHOT
-Bundle-Activator: org.argeo.slc.client.gis.ClientGisActivator
-Require-Bundle: org.eclipse.ui,
+Bundle-Activator: org.argeo.slc.ui.gis.ClientGisActivator
+Require-Bundle: org.eclipse.ui;resolution:=optional,
+ org.eclipse.rap.ui;resolution:=optional,
  org.eclipse.core.runtime,
  org.argeo.dep.osgi.jai.imageio;bundle-version="1.1.0"
 Bundle-ActivationPolicy: lazy
@@ -12,9 +13,10 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Import-Package: com.vividsolutions.jts.geom;version="1.10.0",
  org.apache.commons.logging;version="1.1.1",
  org.argeo.eclipse.spring,
+ org.argeo.eclipse.ui,
+ org.argeo.slc,
  org.argeo.slc.geotools,
  org.argeo.slc.geotools.data,
- org.argeo.slc.geotools.swing,
  org.argeo.slc.gis.model,
  org.argeo.slc.jts,
  org.geotools.data,
@@ -24,10 +26,10 @@ Import-Package: com.vividsolutions.jts.geom;version="1.10.0",
  org.geotools.renderer,
  org.geotools.renderer.lite,
  org.geotools.styling,
- org.geotools.swing,
- org.geotools.swing.event,
- org.geotools.swing.tool,
  org.opengis.feature.simple,
+ org.opengis.feature.type,
  org.opengis.geometry,
  org.opengis.referencing.crs,
  org.springframework.osgi.util;version="1.2.1"
+Export-Package: org.argeo.slc.ui.gis,
+ org.argeo.slc.ui.gis.views
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/commands.xml b/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/commands.xml
new file mode 100644 (file)
index 0000000..e9a25af
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+       <bean id="org.argeo.slc.ui.gis.loadLayersFromBackend"
+               class="org.argeo.slc.ui.gis.commands.LoadLayersFromBackend"
+               scope="prototype">
+               <property name="backend" ref="backend" />
+       </bean>
+</beans>
index 69235e815fd8c9f7601bb0206d703dd24249b36d..ca2a5300b0dd537cc9cdcb90994118c03985e977 100644 (file)
@@ -6,7 +6,10 @@
        http://www.springframework.org/schema/beans   \r
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">\r
 \r
-       <reference id="positionProvider" interface="org.argeo.slc.jts.PositionProvider" />\r
+       <!-- <reference id="positionProvider" interface="org.argeo.slc.jts.PositionProvider" \r
+               /> -->\r
 \r
        <reference id="backend" interface="org.argeo.slc.geotools.Backend" />\r
+       <list id="dataStores" interface="org.geotools.data.DataStore" />\r
+\r
 </beans:beans>
\ No newline at end of file
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/views.xml b/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/views.xml
new file mode 100644 (file)
index 0000000..9e9701c
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+       xsi:schemaLocation="
+               http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd
+       ">
+
+       <bean id="org.argeo.slc.ui.gis.layersView" class="org.argeo.slc.ui.gis.views.LayersView"
+               scope="prototype">
+               <property name="dataStores" ref="dataStores" />
+       </bean>
+
+</beans>
index b482a4d7375856b8416baaeda8a16170344ab72c..eb40959831e9e5ac78b96a1cd8d6687d79d68d78 100644 (file)
@@ -4,18 +4,37 @@
 
    <extension
          point="org.eclipse.ui.views">
-      <category
-            name="GIS"
-            id="org.argeo.slc.client.gis">
-      </category>
       <view
-            name="Map"
+            name="Layers"
             icon="icons/sample.gif"
-            category="org.argeo.slc.client.gis"
             class="org.argeo.eclipse.spring.SpringExtensionFactory"
-            id="org.argeo.slc.client.gis.mapView">
+            id="org.argeo.slc.ui.gis.layersView">
       </view>
    </extension>
+       <extension
+         point="org.eclipse.ui.commands">
+               <command
+            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+            id="org.argeo.slc.ui.gis.loadLayersFromBackend"
+            name="loadLayersFromBackend ">
+       </command>
+    </extension>
+       <extension
+         point="org.eclipse.ui.menus">
+        <!-- Queries --> 
+               <menuContribution
+                allPopups="false"
+                locationURI="toolbar:org.argeo.slc.ui.gis.layersView">
+             <command
+                  commandId="org.argeo.slc.ui.gis.loadLayersFromBackend"
+                  disabledIcon="icons/sample.gif"
+                  icon="icons/sample.gif"
+                  label="Load Layers"
+                  style="push"
+                  tooltip="Load layers from backend">
+            </command>
+        </menuContribution>
+       </extension>
    <extension
          point="org.eclipse.ui.perspectiveExtensions">
       <perspectiveExtension
                ratio="0.5"
                relative="org.eclipse.ui.editorss"
                relationship="right"
-               id="org.argeo.slc.client.gis.mapView">
+               id="org.argeo.slc.ui.gis.mapView">
          </view>
       </perspectiveExtension>
    </extension>
    <extension
          point="org.eclipse.ui.perspectives">
       <perspective
-            class="org.argeo.slc.client.gis.GisPerspectiveFactory"
+            class="org.argeo.slc.ui.gis.GisPerspectiveFactory"
             id="org.argeo.slc.client.gis.perspective"
             name="GIS">
       </perspective>
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/ClientGisActivator.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/ClientGisActivator.java
new file mode 100644 (file)
index 0000000..3152ba1
--- /dev/null
@@ -0,0 +1,61 @@
+package org.argeo.slc.ui.gis;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class ClientGisActivator extends AbstractUIPlugin {
+
+       // The plug-in ID
+       public static final String PLUGIN_ID = "org.argeo.slc.client.gis"; //$NON-NLS-1$
+
+       // The shared instance
+       private static ClientGisActivator plugin;
+       
+       /**
+        * The constructor
+        */
+       public ClientGisActivator() {
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+        */
+       public void start(BundleContext context) throws Exception {
+               super.start(context);
+               plugin = this;
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+        */
+       public void stop(BundleContext context) throws Exception {
+               plugin = null;
+               super.stop(context);
+       }
+
+       /**
+        * Returns the shared instance
+        *
+        * @return the shared instance
+        */
+       public static ClientGisActivator getDefault() {
+               return plugin;
+       }
+
+       /**
+        * Returns an image descriptor for the image file at the given
+        * plug-in relative path
+        *
+        * @param path the path
+        * @return the image descriptor
+        */
+       public static ImageDescriptor getImageDescriptor(String path) {
+               return imageDescriptorFromPlugin(PLUGIN_ID, path);
+       }
+}
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/GisPerspectiveFactory.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/GisPerspectiveFactory.java
new file mode 100644 (file)
index 0000000..e49635c
--- /dev/null
@@ -0,0 +1,23 @@
+package org.argeo.slc.ui.gis;
+
+import org.eclipse.ui.IFolderLayout;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+public class GisPerspectiveFactory implements IPerspectiveFactory {
+
+       public void createInitialLayout(IPageLayout layout) {
+               String editorArea = layout.getEditorArea();
+               layout.setEditorAreaVisible(false);
+               layout.setFixed(false);
+
+               IFolderLayout topLeft = layout.createFolder("topLeft",
+                               IPageLayout.LEFT, 0.5f, editorArea);
+               topLeft.addView("org.argeo.slc.ui.gis.layersView");
+
+               IFolderLayout topRight = layout.createFolder("topRight",
+                               IPageLayout.RIGHT, 0.5f, editorArea);
+               topRight.addView("org.argeo.slc.ui.gis.mapView");
+       }
+
+}
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/MapViewer.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/MapViewer.java
new file mode 100644 (file)
index 0000000..99fa993
--- /dev/null
@@ -0,0 +1,45 @@
+package org.argeo.slc.ui.gis;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Control;
+
+public class MapViewer extends Viewer{
+
+       @Override
+       public Control getControl() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Object getInput() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public ISelection getSelection() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public void refresh() {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void setInput(Object input) {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void setSelection(ISelection selection, boolean reveal) {
+               // TODO Auto-generated method stub
+               
+       }
+
+}
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/commands/LoadLayersFromBackend.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/commands/LoadLayersFromBackend.java
new file mode 100644 (file)
index 0000000..15ea18b
--- /dev/null
@@ -0,0 +1,79 @@
+package org.argeo.slc.ui.gis.commands;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.geotools.Backend;
+import org.argeo.slc.geotools.DataDescriptor;
+import org.argeo.slc.geotools.data.FeatureSourceDataDescriptor;
+import org.argeo.slc.geotools.data.PostgisDataDescriptor;
+import org.argeo.slc.geotools.data.WorldImageDataDescriptor;
+import org.argeo.slc.ui.gis.views.AbstractMapView;
+import org.argeo.slc.ui.gis.views.LayersView;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.geotools.map.MapContext;
+import org.geotools.styling.RasterSymbolizer;
+import org.geotools.styling.Style;
+import org.geotools.styling.StyleBuilder;
+
+/** Open a JCR query editor. */
+public class LoadLayersFromBackend extends AbstractHandler {
+       private final static Log log = LogFactory
+                       .getLog(LoadLayersFromBackend.class);
+       private Backend backend;
+
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               AbstractMapView mapView = (AbstractMapView) HandlerUtil
+                               .getActiveWorkbenchWindow(event).getActivePage()
+                               .findView(AbstractMapView.ID);
+
+               MapContext mapContext = mapView.getMapContext();
+               mapContext.clearLayerList();
+               try {
+                       // load layers
+                       for (DataDescriptor dd : backend.getAvailableData(null)) {
+                               if (dd instanceof WorldImageDataDescriptor) {
+                                       StyleBuilder styleBuilder = new StyleBuilder();
+                                       RasterSymbolizer rs = styleBuilder.createRasterSymbolizer();
+                                       rs.setGeometryPropertyName("geom");
+                                       Style rasterStyle = styleBuilder.createStyle(rs);
+                                       try {
+                                               mapContext.addLayer(backend.loadGridCoverage(dd),
+                                                               rasterStyle);
+                                       } catch (Exception e) {
+                                               log.warn(e);
+                                       }
+
+                               } else if (dd instanceof FeatureSourceDataDescriptor) {
+                                       try {
+                                               mapContext
+                                                               .addLayer(backend.loadFeatureSource(dd), null);
+                                       } catch (Exception e) {
+                                               log.warn(e);
+                                       }
+                               } else if (dd instanceof PostgisDataDescriptor) {
+                                       // DataStore dataStore = backend.loadDataStore(dd);
+                                       for (DataDescriptor dd2 : backend.getAvailableData(dd))
+                                               mapContext.addLayer(backend.loadFeatureSource(dd2),
+                                                               null);
+                               }
+                       }
+
+                       LayersView view = (LayersView) HandlerUtil
+                                       .getActiveWorkbenchWindow(event).getActivePage()
+                                       .findView(LayersView.ID);
+                       view.setMapContext(mapContext);
+                       // view.refresh();
+               } catch (Exception e) {
+                       throw new ExecutionException("Cannot load layers from backend", e);
+               }
+               return null;
+       }
+
+       public void setBackend(Backend backend) {
+               this.backend = backend;
+       }
+
+}
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/views/AbstractMapView.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/views/AbstractMapView.java
new file mode 100644 (file)
index 0000000..df5c6c6
--- /dev/null
@@ -0,0 +1,34 @@
+package org.argeo.slc.ui.gis.views;
+
+import org.eclipse.ui.part.ViewPart;
+import org.geotools.map.MapContext;
+
+import com.vividsolutions.jts.geom.Coordinate;
+
+public abstract class AbstractMapView extends ViewPart {
+       public final static String ID = "org.argeo.slc.ui.gis.mapView";
+//     private final static Log log = LogFactory.getLog(AbstractMapView.class);
+
+//     private MapContext mapContext;
+
+//     protected abstract void createMapWidget(Composite parent,
+//                     MapContext mapContext);
+       
+       public abstract MapContext getMapContext();
+
+//     protected abstract void drawOverlayLocation(Point point, Boolean stale);
+
+       protected abstract void centerMap(Coordinate coordinate);
+
+//     public void createPartControl(Composite parent) {
+//             createMapWidget(parent, mapContext);
+//
+//             // center on position
+////           if (currentPosition != null)
+////                   centerMap(currentPosition.getLocation().getCoordinate());
+//
+//     }
+//     public void setMapContext(MapContext mapContext) {
+//             this.mapContext = mapContext;
+//     }
+}
\ No newline at end of file
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/views/LayersView.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/ui/gis/views/LayersView.java
new file mode 100644 (file)
index 0000000..0868c38
--- /dev/null
@@ -0,0 +1,165 @@
+package org.argeo.slc.ui.gis.views;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.slc.SlcException;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.part.ViewPart;
+import org.geotools.data.DataStore;
+import org.geotools.map.MapContext;
+import org.geotools.map.MapLayer;
+import org.opengis.feature.type.Name;
+
+public class LayersView extends ViewPart {
+       public final static String ID = "org.argeo.slc.ui.gis.layersView";
+
+       private final static Log log = LogFactory.getLog(LayersView.class);
+
+       private TreeViewer viewer;
+
+       private List<DataStore> dataStores;
+
+       @Override
+       public void createPartControl(Composite parent) {
+               viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+               viewer.setContentProvider(new MapContextContentProvider());
+               viewer.setLabelProvider(new MapContextLabelProvider());
+               viewer.setInput(getViewSite());
+       }
+
+       @Override
+       public void setFocus() {
+               viewer.getTree().setFocus();
+       }
+
+       public void setMapContext(MapContext mapContext) {
+               viewer.setInput(mapContext);
+       }
+
+       public void refresh() {
+               viewer.refresh();
+       }
+
+       public void setDataStores(List<DataStore> dataStores) {
+               this.dataStores = dataStores;
+       }
+
+       private class MapContextContentProvider implements ITreeContentProvider {
+
+               public void dispose() {
+               }
+
+               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+               }
+
+               public Object[] getElements(Object inputElement) {
+                       TreeParent dataStoresNode = new TreeParent("Data Stores");
+                       for (DataStore dataStore : dataStores)
+                               dataStoresNode.addChild(new DataStoreNode(dataStore));
+                       if (inputElement instanceof MapContext)
+                               return new Object[] {
+                                               new MapContextNode((MapContext) inputElement),
+                                               dataStoresNode };
+                       else if (inputElement instanceof IViewSite)
+                               return new Object[] { dataStoresNode };
+                       else
+                               return getChildren(inputElement);
+               }
+
+               public Object[] getChildren(Object element) {
+                       if (element instanceof MapContextNode) {
+                               MapContextNode mapContextNode = (MapContextNode) element;
+                               return mapContextNode.getMapContext().getLayers();
+                       } else if (element instanceof MapLayer) {
+                               MapLayer mapLayer = (MapLayer) element;
+
+                       } else if (element instanceof TreeParent) {
+                               return ((TreeParent) element).getChildren();
+                       }
+                       return new Object[0];
+               }
+
+               public Object getParent(Object element) {
+                       if (element instanceof TreeParent) {
+                               return ((TreeParent) element).getParent();
+                       }
+                       return null;
+               }
+
+               public boolean hasChildren(Object element) {
+                       if (element instanceof MapContextNode) {
+                               return true;
+                       } else if (element instanceof TreeParent) {
+                               return ((TreeParent) element).hasChildren();
+                       } else if (element instanceof MapLayer) {
+                               return false;
+                       }
+                       return false;
+               }
+
+       }
+
+       private class MapContextLabelProvider extends LabelProvider {
+
+               @Override
+               public String getText(Object element) {
+                       if (element instanceof MapLayer) {
+                               MapLayer mapLayer = (MapLayer) element;
+                               String title = mapLayer.getTitle();
+                               if (title == null || title.trim().equals(""))
+                                       title = mapLayer.toString();
+                               return title;
+                       }
+                       return super.getText(element);
+               }
+
+       }
+
+       private class MapContextNode extends TreeParent {
+               private MapContext mapContext;
+
+               public MapContextNode(MapContext mapContext) {
+                       super("Map Context");
+                       this.mapContext = mapContext;
+               }
+
+               public MapContext getMapContext() {
+                       return mapContext;
+               }
+
+       }
+
+       private class DataStoreNode extends TreeParent {
+               private DataStore dataStore;
+
+               public DataStoreNode(DataStore dataStore) {
+                       super(dataStore.getInfo().getTitle() != null ? dataStore.getInfo()
+                                       .getTitle() : dataStore.toString());
+                       this.dataStore = dataStore;
+                       try {
+                               for (Name name : dataStore.getNames()) {
+                                       if (log.isDebugEnabled())
+                                               log.debug("Name: " + name);
+                                       addChild(new TreeParent(name.toString()));
+                               }
+                       } catch (IOException e) {
+                               throw new SlcException("Cannot scan data store", e);
+                       }
+               }
+
+               public DataStore getDataStore() {
+                       return dataStore;
+               }
+
+       }
+}