Index: src/DeltaShell/DeltaShell.Plugins.SharpMapGis.Gui/SharpMapGisGuiPlugin.cs
===================================================================
diff -u -r18f9b18cab9da0c768badb3084415e993a5414ee -r5fc71a385897af92ccb092f2f969b5709afab85a
--- src/DeltaShell/DeltaShell.Plugins.SharpMapGis.Gui/SharpMapGisGuiPlugin.cs (.../SharpMapGisGuiPlugin.cs) (revision 18f9b18cab9da0c768badb3084415e993a5414ee)
+++ src/DeltaShell/DeltaShell.Plugins.SharpMapGis.Gui/SharpMapGisGuiPlugin.cs (.../SharpMapGisGuiPlugin.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a)
@@ -33,45 +33,58 @@
[Extension(typeof(IPlugin))]
public class SharpMapGisGuiPlugin : GuiPlugin
{
- private bool isActive;
private static IGui gui;
- private static SharpMapGisGuiPlugin instance;
private static MapLegendView mapLegendView;
private static IGisGuiService gisGuiService;
+ private bool isActive;
private IRibbonCommandHandler ribbonCommandHandler;
-
public SharpMapGisGuiPlugin()
{
- instance = this;
+ Instance = this;
gisGuiService = new GisGuiService(this);
}
public override string Name
{
- get { return "GIS (UI)"; }
+ get
+ {
+ return "GIS (UI)";
+ }
}
public override string DisplayName
{
- get { return "SharpMap GIS Plugin (UI)"; }
+ get
+ {
+ return "SharpMap GIS Plugin (UI)";
+ }
}
public override string Description
{
- get { return SharpMapGis.Properties.Resources.SharpMapGisApplicationPlugin_Description; }
+ get
+ {
+ return SharpMapGis.Properties.Resources.SharpMapGisApplicationPlugin_Description;
+ }
}
public override string Version
{
- get { return GetType().Assembly.GetName().Version.ToString(); }
+ get
+ {
+ return GetType().Assembly.GetName().Version.ToString();
+ }
}
public override bool IsActive
{
- get { return isActive; }
+ get
+ {
+ return isActive;
+ }
}
public override IRibbonCommandHandler RibbonCommandHandler
@@ -89,26 +102,132 @@
public override IGui Gui
{
- get { return gui; }
- set { gui = value; }
+ get
+ {
+ return gui;
+ }
+ set
+ {
+ gui = value;
+ }
}
- public static SharpMapGisGuiPlugin Instance
- {
- get { return instance; }
- }
+ public static SharpMapGisGuiPlugin Instance { get; private set; }
public IGisGuiService GisGuiService
{
- get { return gisGuiService; }
- set { gisGuiService = value; }
+ get
+ {
+ return gisGuiService;
+ }
+ set
+ {
+ gisGuiService = value;
+ }
}
public MapLegendView MapLegendView
{
- get { return mapLegendView; }
+ get
+ {
+ return mapLegendView;
+ }
}
+ ///
+ /// Creates a object for
+ /// a IEnumerable of TFeature that is present part of a TFeatureContainer
+ ///
+ ///
+ /// Model - boundaries
+ ///
+ /// var viewInfo = CreateAttributeTableViewInfo]]>(m => m.Boundaries, () => Gui)
+ ///
+ ///
+ /// Type of the sub features
+ /// Type of the feature container
+ /// Function for getting the IEnumerable of from
+ /// Function for getting an
+ public static ViewInfo, ILayer, VectorLayerAttributeTableView> CreateAttributeTableViewInfo(Func> getCollection, Func getGui)
+ {
+ return new ViewInfo, ILayer, VectorLayerAttributeTableView>
+ {
+ Description = "Attribute Table",
+ GetViewName = (v, o) => o.Name,
+ AdditionalDataCheck = o =>
+ {
+ var container = getGui().Application.Project.Items.OfType().FirstOrDefault(fc => Equals(o, getCollection(fc)));
+ return container != null;
+ },
+ GetViewData = o =>
+ {
+ var centralMap = getGui().DocumentViews.OfType()
+ .FirstOrDefault(v => v.MapView.GetLayerForData(o) != null);
+ return centralMap == null ? null : centralMap.MapView.GetLayerForData(o);
+ },
+ CompositeViewType = typeof(ProjectItemMapView),
+ GetCompositeViewData = o => getGui().Application.Project.Items.OfType().FirstOrDefault(fc =>
+ {
+ if (fc is TFeatureContainer)
+ {
+ return Equals(o, getCollection((TFeatureContainer) fc));
+ }
+
+ return false;
+ }),
+ AfterCreate = (v, o) =>
+ {
+ var centralMap = getGui().DocumentViews.OfType()
+ .FirstOrDefault(vi => vi.MapView.GetLayerForData(o) != null);
+ if (centralMap == null)
+ {
+ return;
+ }
+
+ v.DeleteSelectedFeatures = () => centralMap.MapView.MapControl.DeleteTool.DeleteSelection();
+ v.OpenViewMethod = ob => getGui().CommandHandler.OpenView(ob);
+ v.ZoomToFeature = feature => centralMap.MapView.EnsureVisible(feature);
+ v.CanAddDeleteAttributes = false;
+ }
+ };
+ }
+
+ public void InitializeMapLegend()
+ {
+ if ((mapLegendView == null) || (mapLegendView.IsDisposed))
+ {
+ mapLegendView = new MapLegendView(gui)
+ {
+ OnOpenLayerAttributeTable = layer =>
+ {
+ var mapView = GetFocusedMapView();
+ if (mapView == null)
+ {
+ return;
+ }
+
+ var layerData = mapView.GetDataForLayer != null
+ ? mapView.GetDataForLayer(layer)
+ : null;
+
+ if (!Gui.DocumentViewsResolver.OpenViewForData(layerData, typeof(ILayerEditorView)) && layer is VectorLayer)
+ {
+ mapView.OpenLayerAttributeTable(layer, o => gui.CommandHandler.OpenView(o));
+ }
+ },
+ Text = Properties.Resources.SharpMapGisPluginGui_InitializeMapLegend_Map_Contents
+ };
+ }
+
+ // TODO: subscribe to mapLegendView.TreeView.SelectionChanged! and update Gui.Selection if necessary
+
+ if (gui.ToolWindowViews != null)
+ {
+ gui.ToolWindowViews.Add(mapLegendView, ViewLocation.Left | ViewLocation.Bottom);
+ gui.ToolWindowViews.ActiveView = mapLegendView;
+ }
+ }
+
public override void Activate()
{
InitializeMapLegend();
@@ -156,7 +275,7 @@
}
gui = null;
- instance = null;
+ Instance = null;
mapLegendView = null;
gisGuiService = null;
}
@@ -166,7 +285,10 @@
UpdateMapLegendView();
var mapView = GetFocusedMapView(view);
- if (mapView == null) return;
+ if (mapView == null)
+ {
+ return;
+ }
mapView.MapControl.SelectedFeaturesChanged -= MapControlSelectedFeaturesChanged;
mapView.MapControl.MouseDoubleClick -= mapView_MouseDoubleClick;
@@ -180,64 +302,72 @@
public override IEnumerable GetViewInfoObjects()
{
- yield return new ViewInfo