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
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,
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
--- /dev/null
+<?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>
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
--- /dev/null
+<?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>
<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>
--- /dev/null
+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);
+ }
+}
--- /dev/null
+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");
+ }
+
+}
--- /dev/null
+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
+
+ }
+
+}
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+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
--- /dev/null
+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;
+ }
+
+ }
+}