Skip to content

Commit e285267

Browse files
committed
Enhanced InspectorTool to support writing attribute changes
1 parent 5786d8f commit e285267

File tree

2 files changed

+115
-76
lines changed

2 files changed

+115
-76
lines changed

Editing/InspectorTool/AttributeControl.xaml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@
3131
</UserControl.Resources>
3232
<Grid>
3333
<Border BorderBrush="{DynamicResource Esri_Gray125}" BorderThickness="2">
34-
<DockPanel LastChildFill="true" Margin="2">
35-
<TreeView x:Name="treeView" VerticalAlignment="Top" Width="Auto" DockPanel.Dock="Top" ItemsSource="{Binding SelectedMapFeatures}" SelectedItemChanged="treeView_SelectedItemChanged"
34+
<Grid Margin="2">
35+
<Grid.RowDefinitions>
36+
<RowDefinition Height="Auto"/>
37+
<RowDefinition Height="*"/>
38+
<RowDefinition Height="Auto"/>
39+
</Grid.RowDefinitions>
40+
<TreeView x:Name="treeView" Grid.Row="0" VerticalAlignment="Top" Width="Auto" DockPanel.Dock="Top" ItemsSource="{Binding SelectedMapFeatures}" SelectedItemChanged="treeView_SelectedItemChanged"
3641
Style="{DynamicResource {x:Type TreeView}}">
3742
<TreeView.ItemContainerStyle>
3843
<Style TargetType="{x:Type TreeViewItem}">
@@ -50,8 +55,14 @@
5055
</HierarchicalDataTemplate>
5156
</TreeView.ItemTemplate>
5257
</TreeView>
53-
<ContentPresenter Content="{Binding InspectorView}"></ContentPresenter>
54-
</DockPanel>
58+
<ContentPresenter Grid.Row="1" Content="{Binding InspectorView}"></ContentPresenter>
59+
<StackPanel Grid.Row="2" Orientation="Horizontal" Background="Transparent" Margin="0,6">
60+
<Button Margin="6,0,0,0" Content="Apply" Style="{DynamicResource Esri_Button}"
61+
IsEnabled="{Binding IsApplyEnabled}" Command="{Binding ApplyCommand}"/>
62+
<Button Margin="6,0,0,0" Content="Cancel" Style="{DynamicResource Esri_Button}"
63+
IsEnabled="{Binding IsCancelEnabled}" Command="{Binding CancelCommand}"/>
64+
</StackPanel>
65+
</Grid>
5566
</Border>
5667
</Grid>
5768
</UserControl>

Editing/InspectorTool/AttributeControlViewModel.cs

Lines changed: 100 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,91 +13,119 @@
1313
// limitations under the License.
1414

1515

16-
using System.Collections.Generic;
16+
using ArcGIS.Desktop.Editing.Attributes;
17+
using ArcGIS.Desktop.Framework;
1718
using ArcGIS.Desktop.Framework.Controls;
18-
using System.Xml.Linq;
19-
using System.Windows.Controls;
19+
using ArcGIS.Desktop.Framework.Threading.Tasks;
2020
using ArcGIS.Desktop.Mapping;
21-
using ArcGIS.Desktop.Editing.Attributes;
21+
using System.Collections.Generic;
22+
using System.Windows.Controls;
23+
using System.Windows.Input;
24+
using System.Xml.Linq;
2225

2326
namespace InspectorTool
2427
{
25-
internal class AttributeControlViewModel : EmbeddableControl
28+
internal class AttributeControlViewModel : EmbeddableControl
29+
{
30+
private EmbeddableControl _inspectorViewModel = null;
31+
private UserControl _inspectorView = null;
32+
private Dictionary<MapMember, List<long>> _selection = null;
33+
private static AttributeControlViewModel _dockpaneVM;
34+
private Inspector _featureInspector = null;
35+
36+
public AttributeControlViewModel(XElement options, bool canChangeOptions) : base(options, canChangeOptions)
2637
{
27-
private EmbeddableControl _inspectorViewModel = null;
28-
private UserControl _inspectorView = null;
29-
private Dictionary<MapMember, List<long>> _selection = null;
30-
private Inspector _featureInspector = null;
38+
_dockpaneVM = this;
3139

32-
public AttributeControlViewModel(XElement options, bool canChangeOptions) : base(options, canChangeOptions)
33-
{
34-
// create a new instance for the inspector
35-
_featureInspector = new Inspector();
36-
// create an embeddable control from the inspector class to display on the pane
37-
var icontrol = _featureInspector.CreateEmbeddableControl();
38-
39-
// get view and viewmodel from the inspector
40-
InspectorViewModel = icontrol.Item1;
41-
InspectorView = icontrol.Item2;
42-
}
40+
// create an inspector instance to support editing events
41+
_dockpaneVM.AttributeInspector = new Inspector();
42+
// create an embeddable control from the inspector class to display on the pane
43+
var icontrol = AttributeInspector.CreateEmbeddableControl();
4344

44-
/// <summary>
45-
/// Property containing an instance for the inspector.
46-
/// </summary>
47-
public Inspector AttributeInspector
48-
{
49-
get
50-
{
51-
return _featureInspector;
52-
}
53-
}
45+
// get view and viewmodel from the inspector
46+
InspectorViewModel = icontrol.Item1;
47+
InspectorView = icontrol.Item2;
5448

55-
/// <summary>
56-
/// Access to the view model of the inspector
57-
/// </summary>
58-
public EmbeddableControl InspectorViewModel
59-
{
60-
get { return _inspectorViewModel; }
61-
set
62-
{
63-
if (value != null)
64-
{
65-
_inspectorViewModel = value;
66-
_inspectorViewModel.OpenAsync();
67-
68-
}
69-
else if (_inspectorViewModel != null)
70-
{
71-
_inspectorViewModel.CloseAsync();
72-
_inspectorViewModel = value;
73-
}
74-
NotifyPropertyChanged(() => InspectorViewModel);
75-
}
76-
}
49+
// Listen for editing changes
50+
_dockpaneVM.AttributeInspector.PropertyChanged += InspectorViewModel_PropertyChanged;
51+
}
7752

78-
/// <summary>
79-
/// Dictionary holding the selected features in the map to populate the tree view for
80-
/// layers and respective selected features.
81-
/// </summary>
82-
public Dictionary<MapMember, List<long>> SelectedMapFeatures
53+
private void InspectorViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
54+
{
55+
// Did something change?
56+
if (e.PropertyName == "IsDirty")
57+
{
58+
// IsDirty has been updated, update the buttons (UI) accordingly
59+
_dockpaneVM.NotifyPropertyChanged(nameof(IsApplyEnabled));
60+
_dockpaneVM.NotifyPropertyChanged(nameof(IsCancelEnabled));
61+
}
62+
}
63+
64+
/// <summary>
65+
/// Property containing an instance for the inspector.
66+
/// </summary>
67+
internal Inspector AttributeInspector { get; private set; }
68+
69+
/// <summary>
70+
/// Access to the view model of the inspector
71+
/// </summary>
72+
public EmbeddableControl InspectorViewModel
73+
{
74+
get { return _inspectorViewModel; }
75+
set
76+
{
77+
if (value != null)
8378
{
84-
get
85-
{
86-
return _selection;
87-
}
88-
set
89-
{
90-
SetProperty(ref _selection, value, () => SelectedMapFeatures);
91-
}
92-
}
79+
_inspectorViewModel = value;
80+
_inspectorViewModel.OpenAsync();
9381

94-
/// <summary>
95-
/// Property for the inspector UI.
96-
/// </summary>
97-
public UserControl InspectorView
82+
}
83+
else if (_inspectorViewModel != null)
9884
{
99-
get { return _inspectorView; }
100-
set { SetProperty(ref _inspectorView, value, () => InspectorView); }
85+
_inspectorViewModel.CloseAsync();
86+
_inspectorViewModel = value;
10187
}
88+
NotifyPropertyChanged(() => InspectorViewModel);
89+
}
90+
}
91+
92+
/// <summary>
93+
/// Dictionary holding the selected features in the map to populate the tree view for
94+
/// layers and respective selected features.
95+
/// </summary>
96+
public Dictionary<MapMember, List<long>> SelectedMapFeatures
97+
{
98+
get => _selection;
99+
set => SetProperty(ref _selection, value);
102100
}
101+
102+
/// <summary>
103+
/// Property for the inspector UI.
104+
/// </summary>
105+
public UserControl InspectorView
106+
{
107+
get { return _inspectorView; }
108+
set { SetProperty(ref _inspectorView, value); }
109+
}
110+
public bool IsApplyEnabled => AttributeInspector?.IsDirty ?? false;
111+
public bool IsCancelEnabled => AttributeInspector?.IsDirty ?? false;
112+
113+
public ICommand CancelCommand
114+
{
115+
get => new RelayCommand(() => AttributeInspector?.Cancel());
116+
}
117+
118+
public ICommand ApplyCommand
119+
{
120+
get => new RelayCommand(() =>
121+
{
122+
QueuedTask.Run(() =>
123+
{
124+
//Apply the attribute changes.
125+
//Writing them back to the database in an Edit Operation.
126+
AttributeInspector?.Apply();
127+
});
128+
});
129+
}
130+
}
103131
}

0 commit comments

Comments
 (0)