diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/Editors/Database/DatabaseEditor.Designer.cs b/CSharp/Libraries/UniversalEditor.UserInterface/Editors/Database/DatabaseEditor.Designer.cs new file mode 100644 index 00000000..b822bfaa --- /dev/null +++ b/CSharp/Libraries/UniversalEditor.UserInterface/Editors/Database/DatabaseEditor.Designer.cs @@ -0,0 +1,90 @@ +// +// DatabaseEditor.Designer.cs +// +// Author: +// Mike Becker +// +// Copyright (c) 2019 Mike Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Controls; +using MBS.Framework.UserInterface.Layouts; +using UniversalEditor.UserInterface; + +namespace UniversalEditor.Editors.Database +{ + partial class DatabaseEditor : Editor + { + private SplitContainer scExplorerContent = null; + private SplitContainer scContentResults = null; + private SyntaxTextBox txtQuery = null; + private TabContainer tbsResults = null; + private TabPage tabResultsResults = null; + private TabPage tabSpatialResults = null; + + private DefaultTreeModel tmResults = null; + private ListView lvResults = null; + + private DefaultTreeModel tmDatabase = null; + private ListView tvDatabase = null; + + private void InitializeComponent() + { + this.Layout = new BoxLayout(Orientation.Horizontal); + + this.tmDatabase = new DefaultTreeModel(new Type[] { typeof(string) }); + + this.tvDatabase = new ListView(); + this.tvDatabase.Columns.Add(new ListViewColumnText(this.tmDatabase.Columns[0], "Item")); + this.tvDatabase.Model = this.tmDatabase; + + this.scExplorerContent = new SplitContainer(); + this.scExplorerContent.Orientation = Orientation.Vertical; + this.scExplorerContent.Panel1.Layout = new BoxLayout(Orientation.Horizontal); + this.scExplorerContent.Panel1.Controls.Add(tvDatabase, new BoxLayout.Constraints(true, true)); + + this.scExplorerContent.Panel2.Layout = new BoxLayout(Orientation.Horizontal); + + this.scContentResults = new SplitContainer(); + this.scContentResults.Panel1.Layout = new BoxLayout(Orientation.Horizontal); + + this.txtQuery = new SyntaxTextBox(); + this.scContentResults.Panel1.Controls.Add(this.txtQuery, new BoxLayout.Constraints(true, true)); + + this.lvResults = new ListView(); + + this.tbsResults = new TabContainer(); + this.tabResultsResults = new TabPage(); + this.tabResultsResults.Text = "Results"; + this.tabResultsResults.Layout = new BoxLayout(Orientation.Vertical); + this.tabResultsResults.Controls.Add(this.lvResults, new BoxLayout.Constraints(true, true)); + this.tbsResults.TabPages.Add(this.tabResultsResults); + + this.tabSpatialResults = new TabPage(); + this.tabSpatialResults.Text = "Spatial Results"; + this.tbsResults.TabPages.Add(this.tabSpatialResults); + + this.scContentResults.Panel2.Layout = new BoxLayout(Orientation.Vertical); + this.scContentResults.Panel2.Controls.Add(this.tbsResults, new BoxLayout.Constraints(true, true)); + this.scContentResults.SplitterPosition = 128; + + this.scExplorerContent.Panel2.Controls.Add(this.scContentResults, new BoxLayout.Constraints(true, true)); + this.scExplorerContent.SplitterPosition = 128; + + this.Controls.Add(scExplorerContent, new BoxLayout.Constraints(true, true)); + } + } +} diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/Editors/Database/DatabaseEditor.cs b/CSharp/Libraries/UniversalEditor.UserInterface/Editors/Database/DatabaseEditor.cs new file mode 100644 index 00000000..39660c76 --- /dev/null +++ b/CSharp/Libraries/UniversalEditor.UserInterface/Editors/Database/DatabaseEditor.cs @@ -0,0 +1,117 @@ +// +// DatabaseEditor.cs +// +// Author: +// Mike Becker +// +// Copyright (c) 2019 Mike Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using System.Collections.Generic; +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Controls; +using UniversalEditor.ObjectModels.Database; +using UniversalEditor.UserInterface; + +namespace UniversalEditor.Editors.Database +{ + public partial class DatabaseEditor + { + public DatabaseEditor() + { + InitializeComponent(); + } + + private static EditorReference _er = null; + public override EditorReference MakeReference() + { + if (_er == null) + { + _er = base.MakeReference(); + _er.SupportedObjectModels.Add(typeof(DatabaseObjectModel)); + } + return _er; + } + + public override void UpdateSelections() + { + throw new NotImplementedException(); + } + + protected override EditorSelection CreateSelectionInternal(object content) + { + throw new NotImplementedException(); + } + + protected override void OnObjectModelChanged(EventArgs e) + { + base.OnObjectModelChanged(e); + + tmDatabase.Rows.Clear(); + + DatabaseObjectModel db = (ObjectModel as DatabaseObjectModel); + if (db == null) + return; + + TreeModelRow rowTables = new TreeModelRow(); + rowTables.RowColumns.Add(new TreeModelRowColumn(tmDatabase.Columns[0], String.Format("Tables ({0})", db.Tables.Count))); + + foreach (DatabaseTable table in db.Tables) + { + TreeModelRow rowTable = new TreeModelRow(); + rowTable.RowColumns.Add(new TreeModelRowColumn(tmDatabase.Columns[0], table.Name)); + + TreeModelRow rowColumns = new TreeModelRow(); + rowColumns.RowColumns.Add(new TreeModelRowColumn(tmDatabase.Columns[0], "Columns")); + foreach (DatabaseField field in table.Fields) + { + TreeModelRow rowColumn = new TreeModelRow(); + rowColumn.RowColumns.Add(new TreeModelRowColumn(tmDatabase.Columns[0], String.Format("{0} ({1})", field.Name, field.Value == null ? String.Empty : field.Value.GetType().Name))); + rowColumns.Rows.Add(rowColumn); + } + rowTable.Rows.Add(rowColumns); + + rowTables.Rows.Add(rowTable); + } + + if (db.Tables.Count > 0) + { + List list = new List(); + for (int i = 0; i < db.Tables[0].Fields.Count; i++) + { + list.Add(typeof(string)); + } + this.tmResults = new DefaultTreeModel(list.ToArray()); + for (int i = 0; i < db.Tables[0].Fields.Count; i++) + { + lvResults.Columns.Add(new ListViewColumnText(this.tmResults.Columns[i], db.Tables[0].Fields[i].Name)); + } + foreach (DatabaseRecord rec in db.Tables[0].Records) + { + TreeModelRow row = new TreeModelRow(); + for (int c = 0; c < rec.Fields.Count; c++) + { + row.RowColumns.Add(new TreeModelRowColumn(tmResults.Columns[c], rec.Fields[c].Value == null ? "NULL" : rec.Fields[c].Value.ToString())); + } + tmResults.Rows.Add(row); + } + lvResults.Model = tmResults; + this.txtQuery.Text = "SELECT * FROM '" + db.Tables[0].Name + "'"; + } + + tmDatabase.Rows.Add(rowTables); + } + } +} diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj b/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj index 9b9fb7a9..43690e0f 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj +++ b/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj @@ -127,6 +127,8 @@ + + @@ -179,6 +181,7 @@ +