public static IList <Element> Parse(string expression) { //TODO we may want to chache the expressions for better performance ParseContext context = new ParseContext(expression); while (context.TokenPosition < expression.Length) { string c = context.Expression.Substring(context.TokenPosition, 1); if (WhiteSpaceRegExp.IsMatch(c)) { context.TokenPosition++; continue; } if (ElementGrouping.Parse(context)) { continue; } else if (ElementTernaryOperator.Parse(context)) { continue; } else if (ElementOperator.Parse(context)) { continue; } else if (ElementLiteral.Parse(context)) { continue; } else if (ElementVariable.Parse(context)) { continue; } else if (ElementSelector.Parse(context)) { continue; } else { throw new ELException("Invalid character at position" + context.TokenPosition); } } Element.ValidateTokenOrder(context, TokenType.End); if (context.BpOrder.Count != 0) { throw new ELException("Not all parentesis or brakets were closed or ? with out :"); } while (context.Stack.Count > 0) { context.Ouput.Push(context.Stack.Pop()); } //reverse order List <Element> result = new List <Element>(context.Ouput); result.Reverse(); return(result); }
protected override ITree GetTree(ITypeDescriptorContext context, object value) { ElementGrouping instance = (ElementGrouping)EditorUtility.ResolveContextInstance(context.Instance, false); // false indicates this should not be called in multiselect mode. ITree tree = new VirtualTree(); tree.Root = new GroupingTypesBranch(instance); return(tree); }
public GroupingTypesBranch(ElementGrouping grouping) { myContextGrouping = grouping; Store store = grouping.Store; ReadOnlyCollection <DomainClassInfo> groupTypes = store.DomainDataDirectory.GetDomainClass(ElementGroupingType.DomainClassId).AllDescendants; int groupTypeCount = groupTypes.Count; if (groupTypeCount != 0) { int concreteGroupTypeCount = 0; for (int i = 0; i < groupTypeCount; ++i) { if (!groupTypes[i].ImplementationClass.IsAbstract) { ++concreteGroupTypeCount; } } if (concreteGroupTypeCount != 0) { LinkedElementCollection <ElementGroupingType> currentTypeInstances = grouping.GroupingTypeCollection; int currentTypeInstanceCount = currentTypeInstances.Count; GroupingTypeData[] typeData = new GroupingTypeData[concreteGroupTypeCount]; int nextTypeData = 0; for (int i = 0; i < groupTypeCount; ++i) { DomainClassInfo groupType = groupTypes[i]; if (!groupType.ImplementationClass.IsAbstract) { ElementGroupingType matchingTypeInstance = null; for (int j = 0; j < currentTypeInstanceCount; ++j) { ElementGroupingType testInstance = currentTypeInstances[j]; if (testInstance.GetDomainClass() == groupType) { matchingTypeInstance = testInstance; } } typeData[nextTypeData] = new GroupingTypeData(matchingTypeInstance, groupType); ++nextTypeData; } } if (concreteGroupTypeCount > 1) { Array.Sort <GroupingTypeData>( typeData, delegate(GroupingTypeData left, GroupingTypeData right) { return(string.Compare(left.DisplayName, right.DisplayName, StringComparison.CurrentCultureIgnoreCase)); }); } myGroupTypeData = typeData; myGlyphProvider = SurveyGroupingTypeGlyph.GetStoreInstance(store); } } }
/// <summary> /// Apply changes based on the selection state /// </summary> public void ApplyChanges() { GroupingTypeData[] types = myGroupTypeData; if (types != null) { int typeCount = types.Length; bool hasChanges = false; for (int i = 0; i < typeCount; ++i) { GroupingTypeSelectionState selectionState = types[i].SelectionState; if ((0 == (selectionState & GroupingTypeSelectionState.InitiallySelected)) != (0 == (selectionState & GroupingTypeSelectionState.CurrentlySelected))) { hasChanges = true; break; } } if (hasChanges) { ElementGrouping grouping = myContextGrouping; Store store = grouping.Store; using (Transaction t = store.TransactionManager.BeginTransaction(ResourceStrings.ElementGroupingTypesPropertyDescriptorTransactionName)) { for (int i = 0; i < typeCount; ++i) { GroupingTypeData type = types[i]; GroupingTypeSelectionState selectionState = type.SelectionState; bool typeAdded; if ((typeAdded = (0 == (selectionState & GroupingTypeSelectionState.InitiallySelected))) != (0 == (selectionState & GroupingTypeSelectionState.CurrentlySelected))) { if (typeAdded) { ((ElementGroupingType)store.ElementFactory.CreateElement(type.GroupingTypeClassInfo)).Grouping = grouping; } else { type.GroupingTypeInstance.Delete(); } } } t.Commit(); } } } }