示例#1
0
        public static void CreateDialogControlsForCommand(Type commandType, ExolutioObject scopeObject, ProjectVersion projectVersion, StackPanel stackPanel, out List <Control> controls)
        {
            CommandDescriptor commandDescriptior = PublicCommandsHelper.GetCommandDescriptor(commandType);

            commandDescriptior.ScopeObject = scopeObject;
            controls = OperationParametersControlCreator.CreateControls
                           (commandDescriptior, projectVersion);

            int  tabOrder   = 0;
            bool foundFirst = false;

            foreach (Control control in controls)
            {
                if (control is ScopePropertyEditor)
                {
                    ((ScopePropertyEditor)control).Value = scopeObject;
                }
                if (!foundFirst && !(control is System.Windows.Controls.Label))
                {
                    control.Focus();
                    foundFirst = true;
                }
                control.TabIndex            = tabOrder++;
                control.HorizontalAlignment = HorizontalAlignment.Left;
                control.Margin = new Thickness(0, 0, 0, 5);
                if (control is System.Windows.Controls.Label)
                {
                    control.Margin = new Thickness(0, 5, 0, 5);
                }
                control.MinWidth = 180;
                stackPanel.Children.Add(control);
            }
        }
示例#2
0
        private void DoExecute()
        {
            CommandDescriptor commandDescriptor =
                PublicCommandsHelper.GetCommandDescriptor(ControllerCommandType);

            commandDescriptor.ClearParameterValues();
            OperationParametersControlCreator.ReadParameterValues(commandDescriptor, controls);
            foreach (ParameterDescriptor parameterDescriptor in commandDescriptor.Parameters)
            {
                if (parameterDescriptor.ParameterPropertyInfo == commandDescriptor.ScopeProperty)
                {
                    parameterDescriptor.ParameterValue = ((ExolutioObject)this.ScopeObject).ID;
                }
            }
            CreateControllerCommand();
            CommandSerializer.FillParameters(ControllerCommand, commandDescriptor);
            ControllerCommand.CanExecuteChanged -= OnControllerCommandCanExecuteChanged;
            if (!ControllerCommand.CanExecute())
            {
#if SILVERLIGHT
                ExolutioErrorMsgBox.Show("Command can not be executed", ControllerCommand.ErrorDescription);
#else
                ExolutioErrorMsgBox.Show("Command can not be executed", ControllerCommand.ErrorDescription);
#endif
            }
            else
            {
                if (ControllerCommand is StackedCommand)
                {
                    if (((StackedCommand)ControllerCommand).Controller == null)
                    {
                        ((StackedCommand)ControllerCommand).Controller = Current.Controller;
                    }
                }
                try
                {
                    ControllerCommand.Execute();
                }
                catch (ExolutioCommandException e)
                {
                    ExolutioErrorMsgBox.Show("Command " + e.Command.GetType().ToString() + " can not be executed", e.Command.ErrorDescription);
                }
            }
            ControllerCommand = null;
        }
示例#3
0
        public override void Execute(object parameter)
        {
            if (ScopeIsSelectedComponent && AcceptedSelectedComponentType != null && Current.ActiveDiagramView.IsSelectedComponentOfType(AcceptedSelectedComponentType))
            {
                ScopeObject = Current.ActiveDiagramView.GetSelectedComponents().First();
            }

            CommandDialogWindow w = null;

            dialogOpened = false;
            controls     = new List <Control>();

            #region substitute scope with diagram
            if (ScopeObject == null && Diagram != null)
            {
                CommandDescriptor commandDescriptor = PublicCommandsHelper.GetCommandDescriptor(ControllerCommandType);
                if (string.IsNullOrEmpty(ControllerCommandDescription))
                {
                    ControllerCommandDescription = commandDescriptor.CommandDescription;
                }
                commandDescriptor.ClearParameterValues();
                OperationParametersControlCreator.ReadParameterValues(commandDescriptor, controls);
                foreach (ParameterDescriptor parameterDescriptor in commandDescriptor.Parameters)
                {
                    if (parameterDescriptor.ParameterPropertyInfo == commandDescriptor.ScopeProperty)
                    {
                        if (parameterDescriptor.ComponentType != null &&
                            typeof(Diagram).IsAssignableFrom(parameterDescriptor.ComponentType))
                        {
                            ScopeObject = Diagram;
                        }

                        if (parameterDescriptor.ComponentType == typeof(PSMSchema) && Diagram is PSMDiagram)
                        {
                            ScopeObject = Diagram.Schema;
                        }
                    }
                }
            }
            #endregion

            if (OpenDialog)
            {
                w = new CommandDialogWindow();
                MenuHelper.CreateDialogControlsForCommand(ControllerCommandType, (ExolutioObject)ScopeObject, ProjectVersion, w.spParameters,
                                                          out controls);

                if (Diagram != null)
                {
                    foreach (Control control in controls)
                    {
                        ParameterControls.GuidLookup guidLookup = control as ParameterControls.GuidLookup;
                        if (guidLookup != null)
                        {
                            if (guidLookup.LookedUpType == typeof(PSMSchema) && Diagram is PSMDiagram)
                            {
                                guidLookup.SetSuggestedValue(Diagram.Schema);
                                guidLookup.Tag = "valueSuggested";
                                break;
                            }
                        }
                    }
                }

                w.lTitle.Content = ControllerCommandDescription;
                if (NoScope)
                {
                    w.lTarget.Content = " (global command) ";
                }
                else
                {
                    w.lTarget.Content = ScopeObject.ToString();
                }
            }

            bool dialogOk = !OpenDialog;

            if (!dialogOk)
            {
#if SILVERLIGHT
                //Current.MainWindow.FloatingWindowHost.Add(w);
                w.Closed += new EventHandler(w_Closed);
                w.Show();
#else
                w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                //w.ShowDialog();
                w.WindowStyle   = WindowStyle.ToolWindow;
                w.Topmost       = true;
                w.ShowInTaskbar = false;
                w.ShowActivated = true;
                Current.MainWindow.DisableCommands();
                w.Show();
                w.Closed += w_Closed;
#endif
                dialogOpened = true;
            }
            else
            {
                DoExecute();
            }

            //if (!OpenDialog || dialogOk)
            //{
            //    DoExecute();
            //}
        }