protected override void Initialize(bool initData) { base.Initialize(initData); if (initData) { _entireTableQueryController = new EntireTableQueryController(); _queryDesignerController = new QueryDesignerController(); _arbitrarySqlQueryController = new ArbitrarySqlQueryController(); _connectionStringList = new SelectableListNodeList(_staticConnectionStringList); var connectionString = _doc.ConnectionString; bool isConnectionStringValid = IsConnectionStringValid(ref connectionString); _connectionStringValidIndicator = new StringValidIndicator(connectionString, isConnectionStringValid); _tabItemList = new SelectableListNodeList(); _currentlySelectedController = _arbitrarySqlQueryController; // Decide which tab to show - if entireTableName at the end is not null, then show the entire table tab string entireTableName = null; if (!string.IsNullOrEmpty(SelectionStatement)) { var tokens = SelectionStatement.Split(new char[] { '\r', '\n', ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 4 && tokens[0].ToUpperInvariant() == "SELECT" && tokens[1].ToUpperInvariant() == "*" && tokens[2].ToUpperInvariant() == "FROM") { entireTableName = tokens[3]; _currentlySelectedController = _entireTableQueryController; } } else { _currentlySelectedController = _entireTableQueryController; } _entireTableQueryController.TableName = entireTableName; if (isConnectionStringValid) { _entireTableQueryController.ConnectionString = connectionString; } _tabItemList.Add(new SelectableListNode("Single table", _entireTableQueryController, object.ReferenceEquals(_entireTableQueryController, _currentlySelectedController))); // Query designer controller if (isConnectionStringValid) { _queryDesignerController.ConnectionString = connectionString; } _tabItemList.Add(new SelectableListNode("Query builder", _queryDesignerController, object.ReferenceEquals(_queryDesignerController, _currentlySelectedController))); // Arbitrary SQL controller if (isConnectionStringValid) { _arbitrarySqlQueryController.ConnectionString = connectionString; } _arbitrarySqlQueryController.SelectionStatement = SelectionStatement; _tabItemList.Add(new SelectableListNode("Arbitrary Sql statement", _arbitrarySqlQueryController, object.ReferenceEquals(_arbitrarySqlQueryController, _currentlySelectedController))); ConnectionString = connectionString; } if (null != _view) { _view.SetConnectionListSource(_connectionStringList, ConnectionString.OriginalConnectionString); _view.SetConnectionStatus(_connectionStringValidIndicator.IsConnectionStringValid); if (null == _entireTableQueryController.ViewObject) { Current.Gui.FindAndAttachControlTo(_entireTableQueryController); } if (null == _queryDesignerController.ViewObject) { Current.Gui.FindAndAttachControlTo(_queryDesignerController); } if (null == _arbitrarySqlQueryController.ViewObject) { Current.Gui.FindAndAttachControlTo(_arbitrarySqlQueryController); } _view.SetTabItemsSource(_tabItemList); } }
public override IEnumerable <ControllerAndSetNullMethod> GetSubControllers() { yield return(new ControllerAndSetNullMethod(_entireTableQueryController, () => _entireTableQueryController = null)); yield return(new ControllerAndSetNullMethod(_queryDesignerController, () => _queryDesignerController = null)); yield return(new ControllerAndSetNullMethod(_arbitrarySqlQueryController, () => _arbitrarySqlQueryController = null)); yield return(new ControllerAndSetNullMethod(null, () => _currentlySelectedController = null)); }