From 1cdb2b94ac24cb156b54f06566a3650163cd0c0b Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Tue, 18 Jan 2022 17:15:22 -0800 Subject: [PATCH] table designer - support indexes and write operations (#1363) * support indexes * column properties --- .../Localization/sr.cs | 88 +++ .../Localization/sr.resx | 32 ++ .../Localization/sr.strings | 8 + .../Localization/sr.xlf | 40 ++ .../TableDesigner/Constants.cs | 18 + .../Contracts/TableDesignerView.cs | 2 + .../Contracts/ViewModel/IndexViewModel.cs | 32 ++ .../Contracts/ViewModel/TableViewModel.cs | 2 + .../TableDesigner/TableDesignerService.cs | 504 +++++++++++++++--- 9 files changed, 646 insertions(+), 80 deletions(-) create mode 100644 src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/IndexViewModel.cs diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs index 684f4cea..9a1930d8 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs @@ -8581,6 +8581,70 @@ namespace Microsoft.SqlTools.ServiceLayer } } + public static string IndexIsEnabledPropertyDescription + { + get + { + return Keys.GetString(Keys.IndexIsEnabledPropertyDescription); + } + } + + public static string IndexIsClusteredPropertyDescription + { + get + { + return Keys.GetString(Keys.IndexIsClusteredPropertyDescription); + } + } + + public static string TableDesignerIndexIsClusteredPropertyTitle + { + get + { + return Keys.GetString(Keys.TableDesignerIndexIsClusteredPropertyTitle); + } + } + + public static string IndexIsUniquePropertyDescription + { + get + { + return Keys.GetString(Keys.IndexIsUniquePropertyDescription); + } + } + + public static string TableDesignerIsUniquePropertyTitle + { + get + { + return Keys.GetString(Keys.TableDesignerIsUniquePropertyTitle); + } + } + + public static string IndexColumnIsAscendingPropertyDescription + { + get + { + return Keys.GetString(Keys.IndexColumnIsAscendingPropertyDescription); + } + } + + public static string IndexColumnIsAscendingPropertyTitle + { + get + { + return Keys.GetString(Keys.IndexColumnIsAscendingPropertyTitle); + } + } + + public static string TableDesignerColumnsDisplayValueTitle + { + get + { + return Keys.GetString(Keys.TableDesignerColumnsDisplayValueTitle); + } + } + public static string ConnectionServiceListDbErrorNotConnected(string uri) { return Keys.GetString(Keys.ConnectionServiceListDbErrorNotConnected, uri); @@ -12268,6 +12332,30 @@ namespace Microsoft.SqlTools.ServiceLayer public const string CheckConstraintIsEnabledDescription = "CheckConstraintIsEnabledDescription"; + public const string IndexIsEnabledPropertyDescription = "IndexIsEnabledPropertyDescription"; + + + public const string IndexIsClusteredPropertyDescription = "IndexIsClusteredPropertyDescription"; + + + public const string TableDesignerIndexIsClusteredPropertyTitle = "TableDesignerIndexIsClusteredPropertyTitle"; + + + public const string IndexIsUniquePropertyDescription = "IndexIsUniquePropertyDescription"; + + + public const string TableDesignerIsUniquePropertyTitle = "TableDesignerIsUniquePropertyTitle"; + + + public const string IndexColumnIsAscendingPropertyDescription = "IndexColumnIsAscendingPropertyDescription"; + + + public const string IndexColumnIsAscendingPropertyTitle = "IndexColumnIsAscendingPropertyTitle"; + + + public const string TableDesignerColumnsDisplayValueTitle = "TableDesignerColumnsDisplayValueTitle"; + + private Keys() { } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx index 74435378..2fd413c8 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx @@ -4689,4 +4689,36 @@ Specifies whether the check constraint is Enabled + + Specifies whether the index is enabled + + + + Whether the index is clustered, only one clustered index is allowed in a table. + + + + Is Clustered + + + + Whether the data entered into this index must be unique. + + + + Is Unique + + + + Specifies the sort order of the column. + + + + Is Ascending + + + + Columns + + diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings index 60d6183d..26bd5b34 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings @@ -2243,3 +2243,11 @@ SqlForeignKeyAction_SetNull = Set Null SqlForeignKeyAction_SetDefault = Set Default UnKnownSqlForeignKeyAction(string name) = '{0}' is not a supported SqlForeignKeyAction. CheckConstraintIsEnabledDescription = Specifies whether the check constraint is Enabled +IndexIsEnabledPropertyDescription = Specifies whether the index is enabled +IndexIsClusteredPropertyDescription = Whether the index is clustered, only one clustered index is allowed in a table. +TableDesignerIndexIsClusteredPropertyTitle = Is Clustered +IndexIsUniquePropertyDescription = Whether the data entered into this index must be unique. +TableDesignerIsUniquePropertyTitle = Is Unique +IndexColumnIsAscendingPropertyDescription = Specifies the sort order of the column. +IndexColumnIsAscendingPropertyTitle = Is Ascending +TableDesignerColumnsDisplayValueTitle = Columns diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf index e20d0667..b59b58af 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf @@ -5702,6 +5702,46 @@ . Parameters: 0 - underlyingType (string), 1 - columnName (string) + + Specifies whether the index is enabled + Specifies whether the index is enabled + + + + Whether the index is clustered, only one clustered index is allowed in a table. + Whether the index is clustered, only one clustered index is allowed in a table. + + + + Is Clustered + Is Clustered + + + + Whether the data entered into this index must be unique. + Whether the data entered into this index must be unique. + + + + Is Unique + Is Unique + + + + Specifies the sort order of the column. + Specifies the sort order of the column. + + + + Is Ascending + Is Ascending + + + + Columns + Columns + + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs index eba038b5..dd43b83d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs @@ -12,6 +12,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner public const string Description = "description"; public const string Columns = "columns"; public const string ForeignKeys = "foreignKeys"; + public const string CheckConstraints = "checkConstraints"; + public const string Indexes = "indexes"; } public static class TableColumnPropertyNames @@ -52,4 +54,20 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner public const string PrimaryKeyColumn = "primaryKeyColumn"; public const string ForeignKeyColumn = "foreignKeyColumn"; } + + public static class IndexPropertyNames + { + public const string Name = "name"; + public const string Enabled = "enabled"; + public const string IsUnique = "isUnique"; + public const string IsClustered = "isClustered"; + public const string Columns = "columns"; + public const string ColumnsDisplayValue = "columnsDisplayValue"; + } + + public static class IndexColumnSpecificationPropertyNames + { + public const string Column = "column"; + public const string Ascending = "ascending"; + } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs index 52b2c551..89495abe 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs @@ -17,6 +17,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts public BuiltinTableOptions ColumnTableOptions { get; set; } = new BuiltinTableOptions(); public BuiltinTableOptions ForeignKeyTableOptions { get; set; } = new BuiltinTableOptions(); public BuiltinTableOptions CheckConstraintTableOptions { get; set; } = new BuiltinTableOptions(); + public BuiltinTableOptions IndexTableOptions { get; set; } = new BuiltinTableOptions(); + public BuiltinTableOptions IndexColumnSpecificationTableOptions { get; set; } = new BuiltinTableOptions(); } public class BuiltinTableOptions diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/IndexViewModel.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/IndexViewModel.cs new file mode 100644 index 00000000..bee2300e --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/IndexViewModel.cs @@ -0,0 +1,32 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Newtonsoft.Json; + +namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts +{ + /// + /// The view model of index. + /// + public class IndexViewModel : ObjectViewModelBase + { + public CheckBoxProperties Enabled { get; set; } = new CheckBoxProperties(); + + public CheckBoxProperties IsClustered { get; set; } = new CheckBoxProperties(); + + public CheckBoxProperties IsUnique { get; set; } = new CheckBoxProperties(); + + public InputBoxProperties ColumnsDisplayValue { get; set; } = new InputBoxProperties(); + + public TableComponentProperties Columns { get; set; } = new TableComponentProperties(); + } + + public class IndexedColumnSpecification + { + public DropdownProperties Column { get; set; } = new DropdownProperties(); + + public CheckBoxProperties Ascending { get; set; } = new CheckBoxProperties(); + } +} \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableViewModel.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableViewModel.cs index 61271f39..2f167879 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableViewModel.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableViewModel.cs @@ -22,6 +22,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts public TableComponentProperties CheckConstraints { get; set; } = new TableComponentProperties(); + public TableComponentProperties Indexes { get; set; } = new TableComponentProperties(); + public InputBoxProperties Script { get; set; } = new InputBoxProperties(); } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs index 7a43f410..7e8fed72 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs @@ -176,13 +176,49 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner case TablePropertyNames.Columns: table.Columns.AddNew(); break; + case TablePropertyNames.CheckConstraints: + table.CheckConstraints.AddNew(); + break; + case TablePropertyNames.ForeignKeys: + table.ForeignKeys.AddNew(); + break; + case TablePropertyNames.Indexes: + table.Indexes.AddNew(); + break; default: break; } } - else + else if (path.Length == 3) { - // TODO: Handle the add item request on second level properties, e.g. Adding a column to an index + var propertyNameL1 = path[0] as string; + var indexL1 = Convert.ToInt32(path[1]); + var propertyNameL2 = path[2] as string; + switch (propertyNameL1) + { + case TablePropertyNames.ForeignKeys: + switch (propertyNameL2) + { + case ForeignKeyPropertyNames.ColumnMapping: + // TODO: handle add item to foreign key's column mapping + break; + default: + break; + } + break; + case TablePropertyNames.Indexes: + switch (propertyNameL2) + { + case IndexPropertyNames.Columns: + // TODO: handle add item to index's column specification + break; + default: + break; + } + break; + default: + break; + } } } @@ -194,53 +230,48 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner if (path.Length == 2) { var propertyName = path[0] as string; + var objIndex = Convert.ToInt32(path[1]); switch (propertyName) { case TablePropertyNames.Columns: - table.Columns.RemoveAt(Convert.ToInt32(path[1])); + table.Columns.RemoveAt(objIndex); + break; + case TablePropertyNames.CheckConstraints: + table.CheckConstraints.RemoveAt(objIndex); + break; + case TablePropertyNames.ForeignKeys: + table.ForeignKeys.RemoveAt(objIndex); + break; + case TablePropertyNames.Indexes: + table.Indexes.RemoveAt(objIndex); break; default: break; } } - else + else if (path.Length == 4) { - // TODO: Handle the add item request on second level properties, e.g. Adding a column to an index - } - } - - private void HandleUpdateItemRequest(ProcessTableDesignerEditRequestParams requestParams) - { - var table = this.GetTableDesigner(requestParams.TableInfo).TableViewModel; - var path = requestParams.TableChangeInfo.Path; - - if (path.Length == 3) - { - var propertyName = path[0] as string; - switch (propertyName) + var propertyNameL1 = path[0] as string; + var indexL1 = Convert.ToInt32(path[1]); + var propertyNameL2 = path[2] as string; + var indexL2 = Convert.ToInt32(path[3]); + switch (propertyNameL1) { - case TablePropertyNames.Columns: - var colIndex = Convert.ToInt32(path[1]); - var colPropertyName = path[2] as string; - switch (colPropertyName) + case TablePropertyNames.ForeignKeys: + switch (propertyNameL2) { - case TableColumnPropertyNames.Name: - table.Columns.Items[colIndex].Name = requestParams.TableChangeInfo.Value as string; + case ForeignKeyPropertyNames.ColumnMapping: + // TODO: handle remove item from foreign key's column mapping break; - case TableColumnPropertyNames.Length: - table.Columns.Items[colIndex].Length = requestParams.TableChangeInfo.Value as string; + default: break; - case TableColumnPropertyNames.AllowNulls: - table.Columns.Items[colIndex].IsNullable = (bool)requestParams.TableChangeInfo.Value; - break; - case TableColumnPropertyNames.Precision: - table.Columns.Items[colIndex].Precision = Int32.Parse(requestParams.TableChangeInfo.Value as string); - break; - case TableColumnPropertyNames.Scale: - table.Columns.Items[colIndex].Scale = Int32.Parse(requestParams.TableChangeInfo.Value as string); - break; - case TableColumnPropertyNames.Type: - table.Columns.Items[colIndex].DataType = requestParams.TableChangeInfo.Value as string; + } + break; + case TablePropertyNames.Indexes: + switch (propertyNameL2) + { + case IndexPropertyNames.Columns: + // TODO: handle remove item from index's column specification break; default: break; @@ -252,6 +283,216 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner } } + private void HandleUpdateItemRequest(ProcessTableDesignerEditRequestParams requestParams) + { + var table = this.GetTableDesigner(requestParams.TableInfo).TableViewModel; + var path = requestParams.TableChangeInfo.Path; + var newValue = requestParams.TableChangeInfo.Value; + if (path.Length == 1) + { + var propertyName = path[0] as string; + switch (propertyName) + { + case TablePropertyNames.Description: + table.Description = GetStringValue(newValue); + break; + case TablePropertyNames.Name: + table.Name = GetStringValue(newValue); + break; + case TablePropertyNames.Schema: + table.Schema = GetStringValue(newValue); + break; + default: + break; + } + } + else if (path.Length == 3) + { + var propertyNameL1 = path[0] as string; + var indexL1 = Convert.ToInt32(path[1]); + var propertyNameL2 = path[2] as string; + switch (propertyNameL1) + { + case TablePropertyNames.Columns: + var column = table.Columns.Items[indexL1]; + switch (propertyNameL2) + { + case TableColumnPropertyNames.AllowNulls: + column.IsNullable = GetBooleanValue(newValue); + break; + case TableColumnPropertyNames.DefaultValue: + column.DefaultValue = GetStringValue(newValue); + break; + case TableColumnPropertyNames.IdentityIncrement: + column.IdentityIncrement = GetInt32Value(newValue); + break; + case TableColumnPropertyNames.IdentitySeed: + column.IdentitySeed = GetInt32Value(newValue); + break; + case TableColumnPropertyNames.IsIdentity: + column.IsIdentity = GetBooleanValue(newValue); + break; + case TableColumnPropertyNames.IsPrimaryKey: + column.IsPrimaryKey = GetBooleanValue(newValue); + break; + case TableColumnPropertyNames.Length: + column.Length = GetStringValue(newValue); + break; + case TableColumnPropertyNames.Name: + column.Name = GetStringValue(newValue); + break; + case TableColumnPropertyNames.Precision: + column.Precision = GetInt32Value(newValue); + break; + case TableColumnPropertyNames.Scale: + column.Scale = GetInt32Value(newValue); + break; + case TableColumnPropertyNames.Type: + column.DataType = GetStringValue(newValue); + break; + default: + break; + } + break; + case TablePropertyNames.CheckConstraints: + var checkConstraint = table.CheckConstraints.Items[indexL1]; + switch (propertyNameL2) + { + case CheckConstraintPropertyNames.Name: + checkConstraint.Name = GetStringValue(newValue); + break; + case CheckConstraintPropertyNames.Enabled: + checkConstraint.Enabled = GetBooleanValue(newValue); + break; + case CheckConstraintPropertyNames.Expression: + checkConstraint.Expression = GetStringValue(newValue); + break; + default: + break; + } + break; + case TablePropertyNames.ForeignKeys: + var foreignKey = table.ForeignKeys.Items[indexL1]; + switch (propertyNameL2) + { + case ForeignKeyPropertyNames.Enabled: + foreignKey.Enabled = GetBooleanValue(newValue); + break; + case ForeignKeyPropertyNames.IsNotForReplication: + foreignKey.IsNotForReplication = GetBooleanValue(newValue); + break; + case ForeignKeyPropertyNames.Name: + foreignKey.Name = GetStringValue(newValue); + break; + case ForeignKeyPropertyNames.OnDeleteAction: + foreignKey.OnDeleteAction = SqlForeignKeyActionUtil.GetValue(GetStringValue(newValue)); + break; + case ForeignKeyPropertyNames.OnUpdateAction: + foreignKey.OnUpdateAction = SqlForeignKeyActionUtil.GetValue(GetStringValue(newValue)); + break; + case ForeignKeyPropertyNames.PrimaryKeyTable: + foreignKey.PrimaryKeyTable = GetStringValue(newValue); + break; + default: + break; + } + break; + case TablePropertyNames.Indexes: + var sqlIndex = table.Indexes.Items[indexL1]; + switch (propertyNameL2) + { + case IndexPropertyNames.Enabled: + sqlIndex.Enabled = GetBooleanValue(newValue); + break; + case IndexPropertyNames.IsClustered: + sqlIndex.IsClustered = GetBooleanValue(newValue); + break; + case IndexPropertyNames.IsUnique: + sqlIndex.IsUnique = GetBooleanValue(newValue); + break; + case IndexPropertyNames.Name: + sqlIndex.Name = GetStringValue(newValue); + break; + default: + break; + } + break; + default: + break; + } + } + else if (path.Length == 5) + { + var propertyNameL1 = path[0] as string; + var indexL1 = Convert.ToInt32(path[1]); + var propertyNameL2 = path[2] as string; + var indexL2 = Convert.ToInt32(path[3]); + var propertyNameL3 = path[4] as string; + switch (propertyNameL1) + { + case TablePropertyNames.ForeignKeys: + // TODO: handle foreign key collection property update + // changes need to be made in DACFX to support it. + switch (propertyNameL2) + { + case ForeignKeyPropertyNames.ColumnMapping: + switch (propertyNameL3) + { + case ForeignKeyColumnMappingPropertyNames.ForeignKeyColumn: + break; + case ForeignKeyColumnMappingPropertyNames.PrimaryKeyColumn: + break; + default: + break; + } + break; + default: + break; + } + break; + case TablePropertyNames.Indexes: + var sqlIndex = table.Indexes.Items[indexL1]; + switch (propertyNameL2) + { + case IndexPropertyNames.Columns: + var columnSpec = sqlIndex.Columns[indexL2]; + switch (propertyNameL3) + { + case IndexColumnSpecificationPropertyNames.Column: + columnSpec.Column = GetStringValue(newValue); + break; + case IndexColumnSpecificationPropertyNames.Ascending: + columnSpec.isAscending = GetBooleanValue(newValue); + break; + default: + break; + } + break; + default: + break; + } + break; + default: + break; + } + } + } + + private int GetInt32Value(object value) + { + return Int32.Parse(value as string); + } + + private string GetStringValue(object value) + { + return value as string; + } + + private bool GetBooleanValue(object value) + { + return (bool)value; + } + private TableViewModel GetTableViewModel(TableInfo tableInfo) { var tableDesigner = this.GetTableDesigner(tableInfo); @@ -324,6 +565,25 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner tableViewModel.CheckConstraints.Data.Add(constraint); } + foreach (var index in table.Indexes.Items) + { + var indexVM = new IndexViewModel(); + indexVM.Name.Value = index.Name; + indexVM.IsClustered.Checked = index.IsClustered; + indexVM.Enabled.Checked = index.Enabled; + indexVM.IsUnique.Checked = index.IsUnique; + foreach (var columnSpec in index.Columns) + { + var columnSpecVM = new IndexedColumnSpecification(); + columnSpecVM.Ascending.Checked = columnSpec.isAscending; + columnSpecVM.Column.Value = columnSpec.Column; + columnSpecVM.Column.Values = table.Columns.Items.Select(c => c.Name).ToList(); + indexVM.Columns.Data.Add(columnSpecVM); + } + indexVM.ColumnsDisplayValue.Value = index.ColumnsDisplayValue; + indexVM.ColumnsDisplayValue.Enabled = false; + tableViewModel.Indexes.Data.Add(indexVM); + } tableViewModel.Script.Enabled = false; tableViewModel.Script.Value = tableDesigner.Script; // TODO: set other properties of the table @@ -333,64 +593,84 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner private TableDesignerView GetDesignerViewInfo(TableInfo tableInfo) { var view = new TableDesignerView(); + this.SetColumnsViewInfo(view); + this.SetForeignKeysViewInfo(view); + this.SetCheckConstraintsViewInfo(view); + this.SetIndexesViewInfo(view); + return view; + } + + private void SetColumnsViewInfo(TableDesignerView view) + { view.ColumnTableOptions.AdditionalProperties.AddRange(new DesignerDataPropertyInfo[] { new DesignerDataPropertyInfo() - { - PropertyName = TableColumnPropertyNames.IsIdentity, - Description = SR.TableColumnIsIdentityPropertyDescription, - Group = SR.TableColumnIdentityGroupName, - ComponentType = DesignerComponentType.Checkbox, - ComponentProperties = new CheckBoxProperties() { - Title = SR.TableColumnIsIdentityPropertyTitle - } - }, new DesignerDataPropertyInfo() - { - PropertyName = TableColumnPropertyNames.IdentitySeed, - Description = SR.TableColumnIdentitySeedPropertyDescription, - Group = SR.TableColumnIdentityGroupName, - ComponentType = DesignerComponentType.Input, - ComponentProperties = new InputBoxProperties() + PropertyName = TableColumnPropertyNames.IsIdentity, + Description = SR.TableColumnIsIdentityPropertyDescription, + Group = SR.TableColumnIdentityGroupName, + ComponentType = DesignerComponentType.Checkbox, + ComponentProperties = new CheckBoxProperties() + { + Title = SR.TableColumnIsIdentityPropertyTitle + } + }, + new DesignerDataPropertyInfo() { - Title = SR.TableColumnIdentitySeedPropertyTitle - } - },new DesignerDataPropertyInfo() - { - PropertyName = TableColumnPropertyNames.IdentityIncrement, - Description = SR.TableColumnIdentityIncrementPropertyDescription, - Group = SR.TableColumnIdentityGroupName, - ComponentType = DesignerComponentType.Input, - ComponentProperties = new InputBoxProperties() + PropertyName = TableColumnPropertyNames.IdentitySeed, + Description = SR.TableColumnIdentitySeedPropertyDescription, + Group = SR.TableColumnIdentityGroupName, + ComponentType = DesignerComponentType.Input, + ComponentProperties = new InputBoxProperties() + { + Title = SR.TableColumnIdentitySeedPropertyTitle + } + }, + new DesignerDataPropertyInfo() { - Title = SR.TableColumnIdentityIncrementPropertyTitle + PropertyName = TableColumnPropertyNames.IdentityIncrement, + Description = SR.TableColumnIdentityIncrementPropertyDescription, + Group = SR.TableColumnIdentityGroupName, + ComponentType = DesignerComponentType.Input, + ComponentProperties = new InputBoxProperties() + { + Title = SR.TableColumnIdentityIncrementPropertyTitle + } } - }}); + }); view.ColumnTableOptions.canAddRows = true; view.ColumnTableOptions.canRemoveRows = true; + } + private void SetForeignKeysViewInfo(TableDesignerView view) + { view.ForeignKeyTableOptions.AdditionalProperties.AddRange(new DesignerDataPropertyInfo[] { - new DesignerDataPropertyInfo() - { - PropertyName = ForeignKeyPropertyNames.Enabled, - Description = SR.ForeignKeyIsEnabledDescription, - ComponentType = DesignerComponentType.Checkbox, - ComponentProperties = new CheckBoxProperties() + new DesignerDataPropertyInfo() { - Title = SR.TableDesignerIsEnabledPropertyTitle - } - }, - new DesignerDataPropertyInfo() - { - PropertyName = ForeignKeyPropertyNames.IsNotForReplication, - Description = SR.ForeignKeyIsNotForReplicationDescription, - ComponentType = DesignerComponentType.Checkbox, - ComponentProperties = new CheckBoxProperties() + PropertyName = ForeignKeyPropertyNames.Enabled, + Description = SR.ForeignKeyIsEnabledDescription, + ComponentType = DesignerComponentType.Checkbox, + ComponentProperties = new CheckBoxProperties() + { + Title = SR.TableDesignerIsEnabledPropertyTitle + } + }, + new DesignerDataPropertyInfo() { - Title = SR.ForeignKeyIsNotForReplicationTitle + PropertyName = ForeignKeyPropertyNames.IsNotForReplication, + Description = SR.ForeignKeyIsNotForReplicationDescription, + ComponentType = DesignerComponentType.Checkbox, + ComponentProperties = new CheckBoxProperties() + { + Title = SR.ForeignKeyIsNotForReplicationTitle + } } - }}); + }); view.ForeignKeyTableOptions.canAddRows = true; view.ForeignKeyTableOptions.canRemoveRows = true; + } + + private void SetCheckConstraintsViewInfo(TableDesignerView view) + { view.CheckConstraintTableOptions.AdditionalProperties.Add( new DesignerDataPropertyInfo() { @@ -404,7 +684,71 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner }); view.CheckConstraintTableOptions.canAddRows = true; view.CheckConstraintTableOptions.canRemoveRows = true; - return view; + } + + private void SetIndexesViewInfo(TableDesignerView view) + { + view.IndexTableOptions.AdditionalProperties.AddRange(new DesignerDataPropertyInfo[] { + new DesignerDataPropertyInfo() + { + PropertyName = IndexPropertyNames.ColumnsDisplayValue, + ShowInPropertiesView = false, + ComponentType = DesignerComponentType.Input, + ComponentProperties = new InputBoxProperties() + { + Title = SR.TableDesignerColumnsDisplayValueTitle, + Width = 200 + } + }, + new DesignerDataPropertyInfo() + { + PropertyName = IndexPropertyNames.Enabled, + Description = SR.IndexIsEnabledPropertyDescription, + ComponentType = DesignerComponentType.Checkbox, + ComponentProperties = new CheckBoxProperties() + { + Title = SR.TableDesignerIsEnabledPropertyTitle + } + }, + new DesignerDataPropertyInfo() + { + PropertyName = IndexPropertyNames.IsClustered, + Description = SR.IndexIsClusteredPropertyDescription, + ComponentType = DesignerComponentType.Checkbox, + ComponentProperties = new CheckBoxProperties() + { + Title = SR.TableDesignerIndexIsClusteredPropertyTitle + } + }, + new DesignerDataPropertyInfo() + { + PropertyName = IndexPropertyNames.IsUnique, + Description = SR.IndexIsUniquePropertyDescription, + ComponentType = DesignerComponentType.Checkbox, + ComponentProperties = new CheckBoxProperties() + { + Title = SR.TableDesignerIsUniquePropertyTitle + } + } + }); + view.IndexTableOptions.PropertiesToDisplay = new List() { IndexPropertyNames.Name, IndexPropertyNames.ColumnsDisplayValue, IndexPropertyNames.IsClustered, IndexPropertyNames.IsUnique }; + view.IndexTableOptions.canAddRows = true; + view.IndexTableOptions.canRemoveRows = true; + + view.IndexColumnSpecificationTableOptions.AdditionalProperties.Add( + new DesignerDataPropertyInfo() + { + PropertyName = IndexColumnSpecificationPropertyNames.Ascending, + Description = SR.IndexColumnIsAscendingPropertyDescription, + ComponentType = DesignerComponentType.Checkbox, + ComponentProperties = new CheckBoxProperties() + { + Title = SR.IndexColumnIsAscendingPropertyTitle + } + }); + view.IndexColumnSpecificationTableOptions.PropertiesToDisplay.AddRange(new string[] { IndexColumnSpecificationPropertyNames.Column, IndexColumnSpecificationPropertyNames.Ascending }); + view.IndexColumnSpecificationTableOptions.canAddRows = true; + view.IndexColumnSpecificationTableOptions.canRemoveRows = true; } private Dac.TableDesigner GetTableDesigner(TableInfo tableInfo)