public override void Init(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, DisplayableProperty <TKey, ReadableTuple <TKey> > dp) { _tab = tab; _configuration = (CustomTableInitializer)tab.Settings.AttributeList[1].AttachedObject; _configuration.AttributeTable = tab.Settings.AttributeList[1]; _tab.Settings.NewItemAddedFunction += item => item.SetRawValue(_configuration.AttributeTable, new Dictionary <int, ReadableTuple <int> >()); SdeDatabase gdb = _tab.ProjectDatabase; _table.Commands.CommandUndo += _commandChanged; _table.Commands.CommandRedo += _commandChanged; _table.Commands.CommandExecuted += _commandChanged; _table.Commands.ModifiedStateChanged += _visualUpdate; gdb.Commands.CommandUndo += _commandChanged2; gdb.Commands.CommandRedo += _commandChanged2; gdb.Commands.CommandExecuted += _commandChanged2; Grid grid = new Grid(); grid.SetValue(Grid.RowProperty, _row); grid.SetValue(Grid.ColumnProperty, 0); grid.SetValue(Grid.ColumnSpanProperty, 1); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(-1, GridUnitType.Auto) }); grid.RowDefinitions.Add(new RowDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); _lv = new RangeListView(); _lv.SetValue(TextSearch.TextPathProperty, "ID"); _lv.SetValue(WpfUtils.IsGridSortableProperty, true); _lv.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled); _lv.SetValue(Grid.RowProperty, 1); _lv.Width = 334; _lv.FocusVisualStyle = null; _lv.Margin = new Thickness(3); _lv.BorderThickness = new Thickness(1); _lv.HorizontalAlignment = HorizontalAlignment.Left; _lv.SelectionChanged += _lv_SelectionChanged; SdeEditor.Instance.ProjectDatabase.Reloaded += _database_Reloaded; OnInitListView(); _lv.PreviewMouseDown += delegate { _lv.Focus(); Keyboard.Focus(_lv); }; _lv.ContextMenu = new ContextMenu(); _configuration.ListView = _lv; dp.AddResetField(_lv); dp.AddUpdateAction(_updateTable); _dp = new DisplayableProperty <TKey, ReadableTuple <TKey> >(); _dp.IsDico = true; _dp.DicoConfiguration = _configuration; grid.Children.Add(_lv); OnDeplayTable(); _tab.PropertiesGrid.Children.Add(grid); _dp.Deploy(_tab, null, true); DbSearchPanel dbSearchPanel = new DbSearchPanel(); dbSearchPanel._border1.BorderThickness = new Thickness(1); dbSearchPanel.Margin = new Thickness(3, 0, 3, 0); grid.Children.Add(dbSearchPanel); Settings = new GTabSettings <TKey, ReadableTuple <TKey> >(ServerDbs.MobGroups, tab.DbComponent); var attributes = _configuration.SubTableAttributeList.Take(_configuration.MaxElementsToCopy).Where(p => !p.IsSkippable).ToList(); if (!attributes.Any(p => p.IsDisplayAttribute)) { var att = _configuration.SubTableAttributeList.Attributes.FirstOrDefault(p => p.IsDisplayAttribute); if (att != null) { attributes.Insert(1, att); } } if (attributes.Count % 2 != 0) { attributes.Add(null); } Settings.AttributeList = _configuration.SubTableAttributeList; Settings.DbData = _configuration.ServerDb; Settings.AttId = attributes[0]; Settings.AttDisplay = attributes[1]; SearchEngine = Settings.SearchEngine; SearchEngine.SetAttributes(); SearchEngine.SetSettings(attributes[0], true); SearchEngine.SetSettings(attributes[1], true); SearchEngine.SetAttributes(attributes); SearchEngine.Init(dbSearchPanel, _lv, () => { var dico = _getSelectedGroups(); if (dico == null) { return(new List <ReadableTuple <TKey> >()); } return(dico.Values.Cast <ReadableTuple <TKey> >().ToList()); }); ApplicationShortcut.Link(ApplicationShortcut.Cut, Cut, _lv); foreach (var update in _dp.Updates) { Tuple <DbAttribute, FrameworkElement> x = update; if (x.Item1.DataType == typeof(bool)) { CheckBox element = (CheckBox)x.Item2; _dp.AddUpdateAction(new Action <ReadableTuple <TKey> >(item => element.Dispatch(p => Debug.Ignore(() => p.IsChecked = item.GetValue <bool>(x.Item1))))); element.Checked += delegate { _dp.ApplyDicoCommand(_tab, _lv, (ReadableTuple <TKey>)_tab.List.SelectedItem, _configuration.AttributeTable, (ReadableTuple <TKey>)_lv.SelectedItem, x.Item1, true); }; element.Unchecked += delegate { _dp.ApplyDicoCommand(_tab, _lv, (ReadableTuple <TKey>)_tab.List.SelectedItem, _configuration.AttributeTable, (ReadableTuple <TKey>)_lv.SelectedItem, x.Item1, false); }; } else if ( x.Item1.DataType == typeof(string) || x.Item1.DataType == typeof(int)) { // This will convert integers to strings, but the database engine // is smart enough to auto-convert them to integers afterwards. TextBox element = (TextBox)x.Item2; _dp.AddUpdateAction(new Action <ReadableTuple <TKey> >(item => element.Dispatch( delegate { try { string val = item.GetValue <string>(x.Item1); if (val == element.Text) { return; } element.Text = item.GetValue <string>(x.Item1); element.UndoLimit = 0; element.UndoLimit = int.MaxValue; } catch { } }))); element.TextChanged += delegate { _dp.ApplyDicoCommand(_tab, _lv, (ReadableTuple <TKey>)_tab.List.SelectedItem, _configuration.AttributeTable, (ReadableTuple <TKey>)_lv.SelectedItem, x.Item1, element.Text); }; } } foreach (var property in _dp.FormattedProperties) { //property.Initialize() property.Init(tab, _dp); } }
public SelectFromDialog(Table<int, ReadableTuple<int>> table, ServerDbs db, string text) : base("Select item in [" + db.Filename + "]", "cde.ico", SizeToContent.Manual, ResizeMode.CanResize) { InitializeComponent(); Extensions.SetMinimalSize(this); _unclickableBorder.Init(_cbSubMenu); DbAttribute attId = table.AttributeList.PrimaryAttribute; DbAttribute attDisplay = table.AttributeList.Attributes.FirstOrDefault(p => p.IsDisplayAttribute) ?? table.AttributeList.Attributes[1]; Extensions.GenerateListViewTemplate(_listView, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.GeneralColumnInfo {Header = attId.DisplayName, DisplayExpression = "[" + attId.Index + "]", SearchGetAccessor = attId.AttributeName, FixedWidth = 60, TextAlignment = TextAlignment.Right, ToolTipBinding = "[" + attId.Index + "]"}, new ListViewDataTemplateHelper.RangeColumnInfo {Header = attDisplay.DisplayName, DisplayExpression = "[" + attDisplay.Index + "]", SearchGetAccessor = attDisplay.AttributeName, IsFill = true, ToolTipBinding = "[" + attDisplay.Index + "]", MinWidth = 100, TextWrapping = TextWrapping.Wrap } }, new DatabaseItemSorter(table.AttributeList), new string[] { "Deleted", "Red", "Modified", "Green", "Added", "Blue", "Normal", "Black" }); //_listView.ItemsSource = new ObservableCollection<ReadableTuple<int>>(table.FastItems); GTabSettings<int, ReadableTuple<int>> gTabSettings = new GTabSettings<int, ReadableTuple<int>>(db, null); gTabSettings.AttributeList = table.AttributeList; gTabSettings.AttId = attId; gTabSettings.AttDisplay = attDisplay; GSearchEngine<int, ReadableTuple<int>> gSearchEngine = new GSearchEngine<int, ReadableTuple<int>>(db, gTabSettings); var attributes = new DbAttribute[] { attId, attDisplay }.Concat(table.AttributeList.Attributes.Skip(2).Where(p => p.IsSearchable != null)).ToList(); if (attributes.Count % 2 != 0) { attributes.Add(null); } gSearchEngine.SetAttributes(attributes); gSearchEngine.SetSettings(attId, true); gSearchEngine.SetSettings(attDisplay, true); gSearchEngine.Init(_gridSearchContent, _searchTextBox, _listView, table); _searchTextBox.GotFocus += new RoutedEventHandler(_searchTextBox_GotFocus); _searchTextBox.LostFocus += new RoutedEventHandler(_searchTextBox_LostFocus); _buttonOpenSubMenu.Click += new RoutedEventHandler(_buttonOpenSubMenu_Click); _listView.MouseDoubleClick += new MouseButtonEventHandler(_listView_MouseDoubleClick); Loaded += delegate { gSearchEngine.Filter(this); }; bool first = true; gSearchEngine.FilterFinished += delegate { if (!first) return; try { int ival; if (Int32.TryParse(text, out ival)) { _listView.Dispatch(delegate { _listView.SelectedItem = table.TryGetTuple(ival); TokeiLibrary.WPF.Extensions.ScrollToCenterOfView(_listView, _listView.SelectedItem); }); } } finally { first = false; } }; }
public SelectFromDialog(Table <int, ReadableTuple <int> > table, ServerDbs db, string text) : base("Select item in [" + db.Filename + "]", "cde.ico", SizeToContent.Manual, ResizeMode.CanResize) { InitializeComponent(); Extensions.SetMinimalSize(this); DbAttribute attId = table.AttributeList.PrimaryAttribute; DbAttribute attDisplay = table.AttributeList.Attributes.FirstOrDefault(p => p.IsDisplayAttribute) ?? table.AttributeList.Attributes[1]; ListViewDataTemplateHelper.GenerateListViewTemplateNew(_listView, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.GeneralColumnInfo { Header = attId.DisplayName, DisplayExpression = "[" + attId.Index + "]", SearchGetAccessor = attId.AttributeName, FixedWidth = 60, TextAlignment = TextAlignment.Right, ToolTipBinding = "[" + attId.Index + "]" }, new ListViewDataTemplateHelper.RangeColumnInfo { Header = attDisplay.DisplayName, DisplayExpression = "[" + attDisplay.Index + "]", SearchGetAccessor = attDisplay.AttributeName, IsFill = true, ToolTipBinding = "[" + attDisplay.Index + "]", MinWidth = 100, TextWrapping = TextWrapping.Wrap } }, new DatabaseItemSorter(table.AttributeList), new string[] { "Deleted", "{DynamicResource CellBrushRemoved}", "Modified", "{DynamicResource CellBrushModified}", "Added", "{DynamicResource CellBrushAdded}", "Normal", "{DynamicResource TextForeground}" }); //_listView.ItemsSource = new ObservableCollection<ReadableTuple<int>>(table.FastItems); GTabSettings <int, ReadableTuple <int> > gTabSettings = new GTabSettings <int, ReadableTuple <int> >(db, null); gTabSettings.AttributeList = table.AttributeList; gTabSettings.AttId = attId; gTabSettings.AttDisplay = attDisplay; GSearchEngine <int, ReadableTuple <int> > gSearchEngine = new GSearchEngine <int, ReadableTuple <int> >(db, gTabSettings); var attributes = new DbAttribute[] { attId, attDisplay }.Concat(table.AttributeList.Attributes.Skip(2).Where(p => p.IsSearchable != null)).ToList(); if (attributes.Count % 2 != 0) { attributes.Add(null); } gSearchEngine.SetAttributes(attributes); gSearchEngine.SetSettings(attId, true); gSearchEngine.SetSettings(attDisplay, true); gSearchEngine.Init(_dbSearchPanel, _listView, table); _listView.MouseDoubleClick += new MouseButtonEventHandler(_listView_MouseDoubleClick); Loaded += delegate { gSearchEngine.Filter(this); }; bool first = true; gSearchEngine.FilterFinished += delegate { if (!first) { return; } try { int ival; if (Int32.TryParse(text, out ival)) { _listView.Dispatch(delegate { _listView.SelectedItem = table.TryGetTuple(ival); TokeiLibrary.WPF.Extensions.ScrollToCenterOfView(_listView, _listView.SelectedItem); }); } } finally { first = false; } }; Loaded += delegate { _dbSearchPanel._searchTextBox.Focus(); _dbSearchPanel._searchTextBox.SelectAll(); }; }