File: MySqlDataViewCommandHandler.cs

package info (click to toggle)
mysql-connector-net 6.4.3-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,160 kB
  • ctags: 8,552
  • sloc: cs: 63,689; xml: 7,505; sql: 345; makefile: 50; ansic: 40
file content (280 lines) | stat: -rw-r--r-- 11,334 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// Copyright  2008, 2010, Oracle and/or its affiliates. All rights reserved.
//
// MySQL Connector/NET is licensed under the terms of the GPLv2
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most 
// MySQL Connectors. There are special exceptions to the terms and 
// conditions of the GPLv2 as it is applied to this software, see the 
// FLOSS License Exception
// <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
//
// 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; version 2 of the License.
//
// 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, write to the Free Software Foundation, Inc., 
// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

/*
 * This file contains implementation of data view commands handler.
 */

using System;
using Microsoft.VisualStudio.Data;
using System.Diagnostics;
using Microsoft.VisualStudio.Shell.Interop;
using System.Windows.Forms;

namespace MySql.Data.VisualStudio
{
	/// <summary>
	/// Represents a custom data view command handler. 
	/// </summary>
	public class MySqlDataViewCommandHandler : DataViewCommandHandler
	{
//		private NodeIdMapper nodeMapper;

/*		private NodeIdMapper NodeMapper
		{
			get
			{
				if (nodeMapper == null)
					nodeMapper = new NodeIdMapper(DataViewHierarchyAccessor);
				return nodeMapper;
			}
		}*/

        /// <summary>
        /// This method supplies information about a command's status. At this point all 
        /// commands are supported and visible.
        /// </summary>
        /// <param name="itemIds">
        /// Array of identifiers for the items in the data view hierarchy on which this 
        /// command should be invoked.
        /// </param>
        /// <param name="command">
        /// The OleCommand object representing the command to invoke.
        /// </param>
        /// <param name="textType">
        /// The OleCommandTextType object instance for the specified command.
        /// </param>
        /// <param name="status">
        /// The OleCommandStatus object instance for the specified command.
        /// </param>
        /// <returns>
        /// Returns an OleCommandStatus object instance representing the status returned by the specified commands. /// 
        /// </returns>        
        public override OleCommandStatus GetCommandStatus(int[] itemIds, OleCommand command,
            OleCommandTextType textType, OleCommandStatus status)
        {
            if (command == null)
                throw new ArgumentNullException("command");
            if (status == null)
                throw new ArgumentNullException("status");

            OleCommandStatus result = new OleCommandStatus();

/*			string[] selTypes = DataViewHierarchyAccessor.GetChildSelectionTypes(itemIds[0]);
			string type = DataViewHierarchyAccessor.GetObjectType(itemIds[0]);
			string[] staticNodes = DataViewHierarchyAccessor.GetChildStaticNodeIds(itemIds[0]);
			string path = DataViewHierarchyAccessor.GetNodePath(itemIds[0]);
			object[] identifier = DataViewHierarchyAccessor.GetObjectIdentifier(itemIds[0]);

			object v1 = DataViewHierarchyAccessor.GetProperty(itemIds[0], (int)__VSHPROPID.VSHPROPID_IsHiddenItem);
			object v2 = DataViewHierarchyAccessor.GetProperty(itemIds[0], (int)__VSHPROPID.VSHPROPID_Parent);
*/

			//BaseNode node = NodeMapper[itemIds[0]];

            result.Enabled = true;
            result.Visible = true;
            result.Supported = true;
			return result;
/*            // Get command handler instance
            ICommand commandHandler = CommandFactory.Instance.CreateCommandHandler(command.GroupGuid, command.CommandId);
            if (commandHandler == null)
                return base.GetCommandStatus(itemIds, command, textType, status);
            result.Supported = true;

            // Determine visibility
            if (!commandHandler.GetIsVisible(Hierarchy, itemIds))
            {
                result.Visible = false;
                return result;
            }
            result.Visible = true;
            result.Enabled = true;

            // TODO: Find out why this doesn't work at all!
            // Localize text if possible
            string localizedText = commandHandler.GetText(Hierarchy, itemIds);
            if (!String.IsNullOrEmpty(localizedText))
                result.Text = localizedText;
            
            return result;*/
        }

        /// <summary>
        /// Executes a specified command, potentially based on parameters passed in 
        /// from the data view support XML.
        /// </summary>
        /// <param name="itemIds">
        /// Array of identifiers for the items in the data view hierarchy on which this 
        /// command should be invoked.
        /// </param>
        /// <param name="command">
        /// The OleCommand object representing the command to invoke.
        /// </param>
        /// <param name="executionOption">
        /// Any OleCommandExecutionOption object instance representing options on the 
        /// invoked command.
        /// NOT USED.
        /// </param>
        /// <param name="arguments">
        /// An object representing arguments to the command.
        /// NOT USED.
        /// </param>
        /// <returns>
        /// Returns an object instance representing the value returned by the specified 
        /// command, which is typically nothing. 
        /// </returns>
        public override object[] ExecuteCommand(int[] itemIds, OleCommand command,
            OleCommandExecutionOption executionOption, object arguments)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            if (!HandleStaticCommand(command.CommandId))
            {
                BaseNode node = MakeNewNode(itemIds[0]);
                node.ExecuteCommand(command.CommandId);
            }
			return null;
        }

        /// <summary>
        /// Handle any of the static commands
        /// </summary>
        /// <param name="commandId"></param>
        /// <returns></returns>
        private bool HandleStaticCommand(int commandId)
        {
            switch ((uint)commandId)
            {
                case PkgCmdIDList.cmdCreateTable:
                case PkgCmdIDList.cmdidGlobalCreateTable:
                    TableNode.CreateNew(DataViewHierarchyAccessor);
                    return true;
                case PkgCmdIDList.cmdCreateProcedure:
                case PkgCmdIDList.cmdidGlobalCreateProcedure:
                    StoredProcedureNode.CreateNew(DataViewHierarchyAccessor, false);
                    return true;
                case PkgCmdIDList.cmdCreateFunction:
                case PkgCmdIDList.cmdidGlobalCreateFunction:
                    StoredProcedureNode.CreateNew(DataViewHierarchyAccessor, true);
                    return true;
                case PkgCmdIDList.cmdCreateView:
                case PkgCmdIDList.cmdidGlobalCreateView:
                    ViewNode.CreateNew(DataViewHierarchyAccessor);
                    return true;
                case PkgCmdIDList.cmdCreateUDF:
                case PkgCmdIDList.cmdidGlobalCreateUDF:
                    UDFNode.CreateNew(DataViewHierarchyAccessor);
                    return true;
            }
            return false;
        }

        /// <summary>
        /// Executes a specified command, potentially based on parameters passed in 
        /// from the data view support XML.
        /// </summary>
        /// <param name="itemId">
        /// Identifier of hierarchy item for which command should be executed.
        /// </param>
        /// <param name="command">
        /// The OleCommand object representing the command to invoke.
        /// </param>
        /// <param name="executionOption">
        /// Any OleCommandExecutionOption object instance representing options on the 
        /// invoked command.
        /// NOT USED.
        /// </param>
        /// <param name="arguments">
        /// An object representing arguments to the command.
        /// NOT USED.
        /// </param>
        /// <returns>
        /// Returns an object instance representing the value returned by the specified 
        /// command, which is typically nothing. 
        /// </returns>
        public override object ExecuteCommand(int itemId, OleCommand command, OleCommandExecutionOption executionOption, object arguments)
        {
            return ExecuteCommand(new int[] { itemId }, command, executionOption, arguments);
        }

		private BaseNode MakeNewNode(int id)
		{
            string nodeId = DataViewHierarchyAccessor.GetNodeId(id);
			nodeId = nodeId.ToLowerInvariant();

			BaseNode newNode = null;
			switch (nodeId)
			{
				case "table":
					newNode = new TableNode(DataViewHierarchyAccessor, id);
					break;
				case "storedprocedure":
                    newNode = new StoredProcedureNode(DataViewHierarchyAccessor, id, false);
					break;
                case "storedfunction":
                    newNode = new StoredProcedureNode(DataViewHierarchyAccessor, id, true);
                    break;
                case "view":
					newNode = new ViewNode(DataViewHierarchyAccessor, id);
					break;
                case "udf":
                    newNode = new UDFNode(DataViewHierarchyAccessor, id);
                    break;
                case "trigger":
                    newNode = new TriggerNode(DataViewHierarchyAccessor, id);
                    break;
				default:
                    throw new NotSupportedException("Node type not supported");
			}
			Debug.Assert(newNode != null);
			return newNode;
		}

/*        #region Hierarchy accessor mediator
        /// <summary>
        /// Returns hierarchy accessor mediator instance. Create instance at the first call.
        /// </summary>
        protected ServerExplorerFacade Hierarchy
        {
            get
            {
                // Check if not created yet
                if (hierarchyRef == null)
                {
                    Debug.Assert(DataViewHierarchyAccessor != null, "Hierarchy accessor is not initialized!");
                    hierarchyRef = new ServerExplorerFacade(DataViewHierarchyAccessor);
                }
                // Here must be already created
                Debug.Assert(hierarchyRef != null, "Failed to initialize hierarchy accessor mediator!");
                return hierarchyRef;
            }
        }

        /// <summary>
        /// Used to store hierarchy accessor mediator instance
        /// </summary>
        private ServerExplorerFacade hierarchyRef; 
        #endregion*/
    }
}