private Type SelectTypeReference(ISyntaxNode context, Type scopeType, Visual control) { // get scope provider IScopeProvider scopeProvider = SyntaxTreeManager.GetScopeProvider(scopeType); if (scopeProvider == null) { return(scopeType); } // scope provider is not registered // get references in the scope IEnumerable <Type> scope = scopeProvider.Scope(context, scopeType); if (scope == null || scope.Count() == 0) { return(scopeType); } // scope provider found nothing // build Type selection tree TreeNodeViewModel viewModel = SyntaxNodeExtensions.BuildTypeSelectionTree(scope); // open dialog window PopupWindow dialog = new PopupWindow(control, viewModel); _ = dialog.ShowDialog(); if (dialog.Result == null) { return(null); } // user made no choice // return selected reference return(dialog.Result.NodePayload as Type); }
private IAssemblyConcept SelectAssemblyReference(ISyntaxNode concept, string propertyName, Visual control) { // get scope provider IScopeProvider scopeProvider = SyntaxTreeManager.GetScopeProvider(concept.GetType()); if (scopeProvider == null) { return(null); } // get references in the scope IEnumerable <ISyntaxNode> scope = scopeProvider.Scope(concept, propertyName); if (scope == null || scope.Count() == 0) { return(null); } // build tree view TreeNodeViewModel viewModel = SyntaxNodeExtensions.BuildAssemblySelectorTree(scope); // open dialog window PopupWindow dialog = new PopupWindow(control, viewModel); _ = dialog.ShowDialog(); if (dialog.Result == null) { return(null); } // return selected reference return(dialog.Result.NodePayload as IAssemblyConcept); }
protected override void OnMouseDown(object parameter) { if (!(parameter is MouseButtonEventArgs args)) { return; } if (args.ChangedButton == MouseButton.Right) { return; } args.Handled = true; // TODO: move this code to SyntaxTreeManager PropertyInfo property = Owner.SyntaxNode.GetPropertyInfo(PropertyBinding); Type optionType = SyntaxTreeManager.GetPropertyType(property); ISyntaxNode concept = SyntaxTreeManager.CreateConcept(optionType, Owner.SyntaxNode, PropertyBinding); ConceptNodeViewModel node = SyntaxTreeController.Current.CreateSyntaxNode(Owner, concept); node.PropertyBinding = PropertyBinding; NodePosition position = Owner.GetPosition(this); Owner.Lines[position.Line].Nodes.RemoveAt(position.Position + 1); // remove concept view model from layout Owner.Lines[position.Line].Nodes.RemoveAt(position.Position); // remove this concept option command Owner.Lines[position.Line].Nodes.Add(node); // add newly created concept node }
public void Initialize(IShell shell) { Shell = shell ?? throw new ArgumentNullException(nameof(shell)); SyntaxTreeManager.RegisterScopeProvider(typeof(LanguageConcept), new AssemblyScopeProvider()); SyntaxTreeController.Current.RegisterConceptLayout(typeof(ScriptConcept), new ScriptConceptLayout()); SyntaxTreeController.Current.RegisterConceptLayout(typeof(LanguageConcept), new LanguageConceptLayout()); Shell.AddMenuItem(new MenuItemViewModel() { MenuItemIcon = new BitmapImage(new Uri(EDIT_WINDOW)), MenuItemHeader = "Add test script", MenuItemCommand = new RelayCommand(CreateCodeEditor), MenuItemPayload = this }); Shell.AddMenuItem(new MenuItemViewModel() { MenuItemIcon = new BitmapImage(new Uri(OPEN_SCRIPT)), MenuItemHeader = "Open script file", MenuItemCommand = new RelayCommand(OpenScript), MenuItemPayload = this }); Shell.AddMenuItem(new MenuItemViewModel() { MenuItemIcon = new BitmapImage(new Uri(SAVE_SCRIPT)), MenuItemHeader = "Save current script", MenuItemCommand = new RelayCommand(SaveScript), MenuItemPayload = this }); }
private void CreateRepetableOption(Type optionType, ISyntaxNode parent, string propertyName) { // TODO: move this code to SyntaxTreeManager ISyntaxNode model = SyntaxTreeManager.CreateRepeatableConcept(optionType, parent, propertyName); ConceptNodeViewModel node = SyntaxTreeController.Current.CreateSyntaxNode(Owner, model); Owner.Add(node); }
private void RegisterDatabaseAssemblies() { DatabaseScopeProvider databaseProvider = new DatabaseScopeProvider(); SyntaxTreeManager.RegisterScopeProvider(typeof(UseDatabaseConcept), databaseProvider); //foreach (string directory in Directory.GetDirectories()) foreach (string file in Directory.GetFiles(DatabasesCatalog, "*.dll")) { Assembly assembly = Assembly.LoadFrom(file); databaseProvider.RegisterDatabase(assembly); } }
public void Initialize(IShell shell) { Shell = shell ?? throw new ArgumentNullException(nameof(shell)); RegisterDatabaseAssemblies(); SyntaxTreeManager.RegisterScopeProvider(typeof(EntityConcept), new EntityScopeProvider()); try { // TODO: move to the base abstract module class ! RegisterConceptLayouts(); } catch (Exception ex) { // TODO: log error !!! MessageBox.Show("Failed to load DDL module:" + Environment.NewLine + Environment.NewLine + ex.Message, ONE_C_SHARP, MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
private ISyntaxNode SelectSyntaxNodeReference(Type childConcept, ISyntaxNode parentConcept, string propertyName, Visual control) { // get scope provider IScopeProvider scopeProvider = SyntaxTreeManager.GetScopeProvider(childConcept); if (scopeProvider == null) { return(null); // TODO: if selector is for language concepts which are not yet nodes of the syntax tree !!! // Create ConceptViewModel and ConceptModel // SyntaxTreeController.Current.CreateSyntaxNode(this, new childConcept()); } // get references in the scope IEnumerable <ISyntaxNode> scope = scopeProvider.Scope(parentConcept, propertyName); if (scope == null || scope.Count() == 0) { return(null); } // build tree view TreeNodeViewModel viewModel = SyntaxNodeExtensions.BuildReferenceSelectorTree(scope); // open dialog window PopupWindow dialog = new PopupWindow(control, viewModel); _ = dialog.ShowDialog(); if (dialog.Result == null) { return(null); } // return selected reference return(dialog.Result.NodePayload as ISyntaxNode); }
private void RegisterScopeProviders() { SyntaxTreeManager.RegisterScopeProvider(typeof(VariableConcept), new VariableScopeProvider()); SyntaxTreeManager.RegisterScopeProvider(typeof(ParameterConcept), new ParameterScopeProvider()); SyntaxTreeManager.RegisterScopeProvider(typeof(ColumnConcept), new ColumnReferenceScopeProvider()); }
protected override void OnMouseDown(object parameter) { if (!(parameter is MouseButtonEventArgs args)) { return; } if (args.ChangedButton == MouseButton.Right) { return; } args.Handled = true; Visual control = args.Source as Visual; if (IsTemporallyVisible) { base.OnMouseDown(parameter); return; } // get parent concept node var ancestor = this.Ancestor <ConceptNodeViewModel>(); if (ancestor == null) { return; } // check if property is referencing assembly - special case ! if (ancestor.SyntaxNode.IsAssemblyReference(PropertyBinding)) { IAssemblyConcept assemblyConcept = SelectAssemblyReference(ancestor.SyntaxNode, PropertyBinding, control); if (assemblyConcept == null) { return; } SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, assemblyConcept.Assembly); SyntaxNode = ancestor.SyntaxNode; OnPropertyChanged(nameof(Presentation)); return; } // get hosting script concept ScriptConcept script; if (ancestor.SyntaxNode is ScriptConcept) { script = (ScriptConcept)ancestor.SyntaxNode; } else { script = ancestor.SyntaxNode.Ancestor <ScriptConcept>() as ScriptConcept; } // get type constraints of the property TypeConstraint constraints = SyntaxTreeManager.GetTypeConstraints(script?.Languages, ancestor.SyntaxNode, PropertyBinding); // build tree view TreeNodeViewModel viewModel = SyntaxNodeSelector.BuildSelectorTree(constraints); // open dialog window PopupWindow dialog = new PopupWindow(control, viewModel); _ = dialog.ShowDialog(); if (dialog.Result == null) { return; } Type selectedType = dialog.Result.NodePayload as Type; if (selectedType == null) { return; } // set binded property of the model by selected reference PropertyInfo property = ancestor.SyntaxNode.GetPropertyInfo(PropertyBinding); if (SyntaxTreeManager.GetPropertyType(property) == typeof(Type)) { selectedType = SelectTypeReference(ancestor.SyntaxNode, selectedType, control); SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, selectedType); SyntaxNodeType = selectedType; } else if (selectedType.IsEnum) { object enumValue = SelectEnumerationValue(selectedType, control); if (enumValue == null) { return; } SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, enumValue); } else { ISyntaxNode reference; if (selectedType.IsSubclassOf(typeof(DataType))) { reference = (ISyntaxNode)Activator.CreateInstance(selectedType); } else { // use dialog and scope provider to find reference to the node in the syntax tree reference = SelectSyntaxNodeReference(selectedType, ancestor.SyntaxNode, PropertyBinding, control); if (reference == null) { return; } } SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, reference); SyntaxNode = reference; } // reset view model's state OnPropertyChanged(nameof(Presentation)); }
protected override void OnMouseDown(object parameter) { if (!(parameter is MouseButtonEventArgs args)) { return; } if (args.ChangedButton == MouseButton.Right) { return; } args.Handled = true; var concept = this.Ancestor <ConceptNodeViewModel>(); if (concept == null) { return; } if (concept.SyntaxNode == null) { return; } ScriptConcept script; if (concept.SyntaxNode is ScriptConcept) { script = (ScriptConcept)concept.SyntaxNode; } else { script = concept.SyntaxNode.Ancestor <ScriptConcept>() as ScriptConcept; } string propertyName = Owner.PropertyBinding; TypeConstraint constraints = SyntaxTreeManager.GetTypeConstraints(script?.Languages, concept.SyntaxNode, propertyName); // if selection is obvious then just create the node ... if (constraints.Concepts.Count == 1 && constraints.DataTypes.Count == 0) { CreateRepetableOption(constraints.Concepts[0], concept.SyntaxNode, propertyName); return; } if (constraints.DataTypes.Count == 1 && constraints.Concepts.Count == 0) { CreateRepetableOption(constraints.DataTypes[0], concept.SyntaxNode, propertyName); return; } // build tree view TreeNodeViewModel viewModel = SyntaxNodeSelector.BuildSelectorTree(constraints); // open dialog window Visual control = args.Source as Visual; PopupWindow dialog = new PopupWindow(control, viewModel); _ = dialog.ShowDialog(); if (dialog.Result == null) { return; } // get result Type selectedType = dialog.Result.NodePayload as Type; if (selectedType == null) { return; } // create concept option, its view model and add it to syntax tree CreateRepetableOption(selectedType, concept.SyntaxNode, propertyName); }