/// <summary>Implements ICustomSerializedDomainModel.ShouldSerializeDomainClass</summary>
		protected bool ShouldSerializeDomainClass(Store store, DomainClassInfo classInfo)
		{
			Dictionary<DomainClassInfo, object> omissions = this.myCustomSerializationOmissions;
			if (omissions == null)
			{
				omissions = BarkerERShapeDomainModel.BuildCustomSerializationOmissions(store);
				this.myCustomSerializationOmissions = omissions;
			}
			return !omissions.ContainsKey(classInfo);
		}
Exemplo n.º 2
0
        protected override void DoValidate(string objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            if (string.IsNullOrEmpty(objectToValidate))
            {
                return;
            }

            ModelElement mel = currentTarget as ModelElement;

            if (mel == null ||
                (!(mel is XsdMessage) && !(mel is XsdElementFault)))
            {
                return;
            }

            XmlSchemaElementMoniker elementUri = new XmlSchemaElementMoniker(objectToValidate);

            // It's a primite type
            if (string.IsNullOrEmpty(elementUri.ElementName))
            {
                return;
            }

            string fileName = Path.GetFileName(elementUri.XmlSchemaPath);
            string fullPath = GetXsdFullPath(mel, elementUri.XmlSchemaPath);


            string melName = string.Empty;

            DomainClassInfo.TryGetName(mel, out melName);

            if (string.IsNullOrEmpty(fullPath))
            {
                this.LogValidationResult(validationResults, string.Format(CultureInfo.CurrentUICulture, this.invalidFilePathMessage, melName, fileName, schemaDirectory), currentTarget, key);
                return;
            }

            XmlSchemaTypeGenerator generator = new XmlSchemaTypeGenerator(IsXmlSerializer(mel));

            CodeCompileUnit unit = null;

            try
            {
                unit = generator.GenerateCodeCompileUnit(fullPath);
            }
            catch (InvalidDataContractException exception)
            {
                this.LogValidationResult(validationResults, exception.Message, currentTarget, key);
                return;
            }
            catch (InvalidSerializerException serializationException)
            {
                if (!IsXmlSerializer(mel))
                {
                    this.LogValidationResult(validationResults,
                                             string.Format(CultureInfo.CurrentUICulture,
                                                           this.notCompliantWithDataContractSerializerMessage + ". " + serializationException.Message,
                                                           fileName), currentTarget, key);
                    return;
                }
            }

            foreach (CodeNamespace ns in unit.Namespaces)
            {
                foreach (CodeTypeDeclaration codeType in ns.Types)
                {
                    if (codeType.Name.Equals(elementUri.ElementName, StringComparison.Ordinal))
                    {
                        return;
                    }
                }
            }

            this.LogValidationResult(validationResults, string.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, melName, elementUri.ElementName, fileName), currentTarget, key);
        }
		bool ICustomSerializedDomainModel.ShouldSerializeDomainClass(Store store, DomainClassInfo classInfo)
		{
			return this.ShouldSerializeDomainClass(store, classInfo);
		}
Exemplo n.º 4
0
        /// <summary>See <see cref="TypeConverter.ConvertTo(ITypeDescriptorContext,CultureInfo,Object,Type)"/>.</summary>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            ModelElement element;
            string       name;

            if (destinationType == typeof(string) && (element = value as ModelElement) != null && DomainClassInfo.TryGetName(element, out name))
            {
                return(name);
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
 /// <summary>Implements ICustomSerializedDomainModel.ShouldSerializeDomainClass</summary>
 protected bool ShouldSerializeDomainClass(Store store, DomainClassInfo classInfo)
 {
     return(true);
 }
        /// <summary>
        /// Initialization routine.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            this.domainClassInfo = this.Store.DomainDataDirectory.FindDomainClass(this.ModelElementType);

            if (this.domainClassInfo != null)
            {
                this.ViewModelStore.EventManager.GetEvent<ModelElementAddedEvent>().Subscribe(this.domainClassInfo, OnElementAdded);
                this.ViewModelStore.EventManager.GetEvent<ModelElementDeletedEvent>().Subscribe(this.domainClassInfo, OnElementDeleted);
            }

            if (this.ModelData.CurrentModelContext.RootElement != null)
                InitSpecificVMs();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="rInfo"></param>
 /// <param name="cInfo"></param>
 public ContextMenuCreationHelper(DomainRoleInfo rInfo, DomainClassInfo cInfo)
 {
     RoleInfo       = rInfo;
     RolePlayerInfo = cInfo;
 }
Exemplo n.º 8
0
                private bool ActivateError(ModelElement selectedElement, ModelError error, DomainClassInfo domainClass)
                {
                    ORMModelErrorActivator activator;

                    if (myActivators.TryGetValue(domainClass.ImplementationClass, out activator))
                    {
                        if (activator((IORMToolServices)myStore, selectedElement, error))
                        {
                            return(true);
                        }
                    }
                    // See if anything on a base type can handle it. This maximizes the chances of finding a handler.
                    // UNDONE: Do we want both the 'registerDerivedTypes' parameter on RegisterErrorActivator and this recursion?
                    domainClass = domainClass.BaseDomainClass;
                    if (domainClass != null)
                    {
                        return(ActivateError(selectedElement, error, domainClass));
                    }
                    return(false);
                }
        private void LoadCategories()
        {
            ModelErrorDisplayFilter filter = myModel.ModelErrorDisplayFilter;

            DomainDataDirectory dataDirectory = myModel.Store.DomainDataDirectory;
            DomainClassInfo     baseType      = dataDirectory.GetDomainClass(typeof(ModelErrorCategory));
            ReadOnlyCollection <DomainClassInfo> categoryDescendants = baseType.AllDescendants;

            int numCategories = categoryDescendants.Count;

            Category[] categories = new Category[numCategories + 1];
            categories[numCategories] = new Category(null, false);
            for (int i = 0; i < numCategories; ++i)
            {
                DomainClassInfo info         = categoryDescendants[i];
                Type            categoryType = info.ImplementationClass;
                categories[i] = new Category(info, filter != null && filter.IsCategoryExcluded(categoryType));
            }

            // Presort the categories list
            Category.Sort(categories);

            baseType = dataDirectory.GetDomainClass(typeof(ModelError));
            ReadOnlyCollection <DomainClassInfo> errorDescendants = baseType.AllDescendants;
            int errorDescendantCount = errorDescendants.Count;
            int includedErrorCount   = 0;

            for (int i = 0; i < errorDescendantCount; ++i)
            {
                if (!errorDescendants[i].ImplementationClass.IsAbstract)
                {
                    ++includedErrorCount;
                }
            }

            Error[] errors             = new Error[includedErrorCount];
            int     includedErrorIndex = -1;

            for (int i = 0; i < errorDescendantCount; ++i)
            {
                DomainClassInfo info  = errorDescendants[i];
                Type            error = info.ImplementationClass;
                if (!error.IsAbstract)
                {
                    ++includedErrorIndex;
                    errors[includedErrorIndex] = new Error(
                        info,
                        Category.IndexOf(categories, ResolveErrorCategory(error)),
                        filter != null && filter.IsErrorExcluded(error));
                }
            }

            // Sort the errors with a primary sort on the presorted category index
            Array.Sort(errors,
                       delegate(Error error1, Error error2)
            {
                int retVal         = 0;
                int categoryIndex1 = error1.CategoryIndex;
                int categoryIndex2 = error2.CategoryIndex;
                if (categoryIndex1 < categoryIndex2)
                {
                    retVal = -1;
                }
                else if (categoryIndex1 > categoryIndex2)
                {
                    retVal = 1;
                }
                else
                {
                    retVal = string.Compare(error1.DisplayName, error2.DisplayName, StringComparison.CurrentCultureIgnoreCase);
                }
                return(retVal);
            });

            // Walk the errors and bind the categories to the errors
            int currentCategoryStartErrorIndex = -1;
            int lastCategoryIndex = -1;

            for (int i = 0; i < includedErrorCount; ++i)
            {
                int currentIndex = errors[i].CategoryIndex;
                if (currentIndex != lastCategoryIndex)
                {
                    if (lastCategoryIndex == -1)
                    {
                        lastCategoryIndex = currentIndex;
                        currentCategoryStartErrorIndex = i;
                    }
                    else
                    {
                        categories[lastCategoryIndex].BindErrorRange(currentCategoryStartErrorIndex, i - 1);
                        currentCategoryStartErrorIndex = i;
                        lastCategoryIndex = currentIndex;
                    }
                }
            }
            if (lastCategoryIndex != -1)
            {
                categories[lastCategoryIndex].BindErrorRange(currentCategoryStartErrorIndex, includedErrorCount - 1);
            }
            myCategories = categories;
            myErrors     = errors;
        }
Exemplo n.º 10
0
            /// <summary>
            /// Binarizes the unary <see cref="FactType"/> specified by <paramref name="unaryFactType"/>, defaulting
            /// to using open-world assumption. The caller is responsible for making sure <paramref name="unaryFactType"/>
            /// is in fact a unary fact type.
            /// </summary>
            public static void BinarizeUnary(FactType unaryFactType, INotifyElementAdded notifyAdded)
            {
                Partition partition = unaryFactType.Partition;
                Store     store     = partition.Store;
                IHasAlternateOwner <FactType>      toAlternateOwner;
                IAlternateElementOwner <FactType>  alternateFactTypeOwner = (null == (toAlternateOwner = unaryFactType as IHasAlternateOwner <FactType>)) ? null : toAlternateOwner.AlternateOwner;
                LinkedElementCollection <RoleBase> roleCollection         = unaryFactType.RoleCollection;

                Debug.Assert(roleCollection.Count == 1, "Unaries should only have one role.");

                Role   unaryRole = (Role)roleCollection[0];
                string implicitBooleanValueTypeName = GetImplicitBooleanValueTypeName(unaryRole);

                // UNDONE: We are using open-world assumption now
                // Setup the mandatory constraint (for closed-world assumption)
                //MandatoryConstraint mandatoryConstraint = MandatoryConstraint.CreateSimpleMandatoryConstraint(unaryRole);
                //mandatoryConstraint.Model = unaryFactType.Model;
                //if (notifyAdded != null)
                //{
                //    notifyAdded.ElementAdded(mandatoryConstraint, true);
                //}

                // Setup the uniqueness constraint (to make the newly binarized FactType valid)
                if (unaryRole.SingleRoleAlethicUniquenessConstraint == null)
                {
                    UniquenessConstraint uniquenessConstraint = UniquenessConstraint.CreateInternalUniquenessConstraint(unaryFactType);
                    uniquenessConstraint.RoleCollection.Add(unaryRole);
                    if (notifyAdded != null)
                    {
                        notifyAdded.ElementAdded(uniquenessConstraint, true);
                    }
                }

                // Setup the boolean role (to make the FactType a binary)
                Role implicitBooleanRole = new Role(partition, null);

                implicitBooleanRole.Name = unaryRole.Name;

                // Setup the boolean value type (because the boolean role needs a role player)

                IAlternateElementOwner <ObjectType> alternateObjectTypeOwner = null;
                DomainClassInfo alternateCtor =
                    (null != alternateFactTypeOwner &&
                     null != (alternateObjectTypeOwner = alternateFactTypeOwner as IAlternateElementOwner <ObjectType>)) ?
                    alternateObjectTypeOwner.GetOwnedElementClassInfo(typeof(ObjectType)) :
                    null;
                PropertyAssignment implicitBooleanProperty  = new PropertyAssignment(ObjectType.IsImplicitBooleanValueDomainPropertyId, true);
                ObjectType         implicitBooleanValueType = (alternateCtor != null) ?
                                                              (ObjectType)partition.ElementFactory.CreateElement(alternateCtor, implicitBooleanProperty) :
                                                              new ObjectType(partition, implicitBooleanProperty);
                Dictionary <object, object> contextInfo = store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo;
                object duplicateNamesKey         = ORMModel.AllowDuplicateNamesKey;
                bool   removeDuplicateNamesKey   = false;
                object duplicateSignaturesKey    = ORMModel.BlockDuplicateReadingSignaturesKey;
                bool   addDuplicateSignaturesKey = false;

                try
                {
                    if (!contextInfo.ContainsKey(duplicateNamesKey))
                    {
                        contextInfo[duplicateNamesKey] = null;
                        removeDuplicateNamesKey        = true;
                    }
                    if (contextInfo.ContainsKey(duplicateSignaturesKey))
                    {
                        contextInfo[duplicateSignaturesKey] = null;
                        addDuplicateSignaturesKey           = true;
                    }
                    implicitBooleanValueType.Name = implicitBooleanValueTypeName;
                    if (alternateCtor != null)
                    {
                        ((IHasAlternateOwner <ObjectType>)implicitBooleanValueType).AlternateOwner = alternateObjectTypeOwner;
                    }
                    else
                    {
                        implicitBooleanValueType.Model = unaryFactType.ResolvedModel;
                    }
                    if (notifyAdded != null)
                    {
                        notifyAdded.ElementAdded(implicitBooleanValueType, true);
                    }
                }
                finally
                {
                    if (removeDuplicateNamesKey)
                    {
                        contextInfo.Remove(duplicateNamesKey);
                    }
                    if (addDuplicateSignaturesKey)
                    {
                        contextInfo[duplicateSignaturesKey] = null;
                    }
                }
                implicitBooleanValueType.DataType = store.ElementDirectory.FindElements <TrueOrFalseLogicalDataType>(false)[0];

                // Set value constraint on implicit boolean ValueType for open-world assumption
                ValueTypeValueConstraint implicitBooleanValueConstraint = implicitBooleanValueType.ValueConstraint
                                                                              = new ValueTypeValueConstraint(partition, null);

                // Add the true-only ValueRange to the value constraint for open-world assumption
                implicitBooleanValueConstraint.ValueRangeCollection.Add(new ValueRange(partition,
                                                                                       new PropertyAssignment(ValueRange.MinValueDomainPropertyId, bool.TrueString),
                                                                                       new PropertyAssignment(ValueRange.MaxValueDomainPropertyId, bool.TrueString)));

                // Make the boolean value type the role player for the implicit boolean role
                implicitBooleanRole.RolePlayer = implicitBooleanValueType;

                // Add the boolean role to the FactType
                roleCollection.Add(implicitBooleanRole);
                if (notifyAdded != null)
                {
                    notifyAdded.ElementAdded(implicitBooleanRole, true);
                }
            }
Exemplo n.º 11
0
        public ElementLink Connect(ModelElement source, ModelElement target)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            // TODO bei fehler mit base in svn vergleichen ;)
            if (source != rememberedSourceShape || target != rememberedTargetShape)
            {
                Debug.Fail("Cannot create Connection for other then the rememberd ones.");
                throw new InvalidOperationException();
            }

            if (CanAcceptSourceAndTarget(source, target))
            {
                if (source is SOURCE_ELEMENT)
                {
                    if (target is TARGET_ELEMENT)
                    {
                        SOURCE_ELEMENT sourceAccepted = (SOURCE_ELEMENT)source;
                        TARGET_ELEMENT targetAccepted = (TARGET_ELEMENT)target;

                        ElementLink result;
                        if (rememberedSourceEntry.IsRegularShape)
                        {
                            result = CreateElementLink(sourceAccepted,
                                                       SelectedCompartmentPartType.None,
                                                       null,
                                                       targetAccepted,
                                                       rememberedTargetEntry.Type,
                                                       rememberedTargetEntry.Element as TARGET_COMPARTMENT_ENTRY);
                        }
                        else if (rememberedTargetEntry.IsRegularShape)
                        {
                            result = CreateElementLink(sourceAccepted,
                                                       rememberedSourceEntry.Type,
                                                       rememberedSourceEntry.Element as SOURCE_COMPARTMENT_ENTRY,
                                                       targetAccepted,
                                                       SelectedCompartmentPartType.None,
                                                       null);
                        }
                        else
                        {
                            result = CreateElementLink(sourceAccepted,
                                                       rememberedSourceEntry.Type,
                                                       rememberedSourceEntry.Element as SOURCE_COMPARTMENT_ENTRY,
                                                       targetAccepted,
                                                       rememberedTargetEntry.Type,
                                                       rememberedTargetEntry.Element as TARGET_COMPARTMENT_ENTRY);
                        }

                        if (DomainClassInfo.HasNameProperty(result))
                        {
                            DomainClassInfo.SetUniqueName(result);
                        }

                        rememberedSourceEntry = null;
                        rememberedTargetEntry = null;
                        rememberedSourceShape = null;
                        rememberedTargetShape = null;

                        return(result);
                    }
                }
            }
            Debug.Fail("Having agreed that the connection can be accepted we should never fail to make one.");
            throw new InvalidOperationException();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Search a specific model element by using the given search criteria.
        /// </summary>
        /// <param name="modelElement">Model element to be searched.</param>
        /// <param name="criteria">Search criteria to use.</param>
        /// <param name="searchText">Text to search.</param>
        /// <param name="options">Search options.</param>
        /// <returns>Search result list if any found. Empty list otherwise.</returns>
        public virtual List <SearchResult> Search(ModelElement modelElement, SearchCriteriaEnum criteria, string searchText, SearchOptions options)
        {
            List <SearchResult> results = new List <SearchResult>();
            DomainClassInfo     info    = modelElement.GetDomainClass();
            Type modelElementType       = modelElement.GetType();

            #region properties
            if (criteria == SearchCriteriaEnum.Name ||
                criteria == SearchCriteriaEnum.NameAndType ||
                criteria == SearchCriteriaEnum.All ||
                criteria == SearchCriteriaEnum.Properties ||
                criteria == SearchCriteriaEnum.PropertiesWithoutName)
            {
                foreach (DomainPropertyInfo propertyInfo in info.AllDomainProperties)
                {
                    if (propertyInfo == info.NameDomainProperty &&
                        criteria != SearchCriteriaEnum.Name &&
                        criteria != SearchCriteriaEnum.NameAndType &&
                        criteria != SearchCriteriaEnum.Properties &&
                        criteria != SearchCriteriaEnum.All)
                    {
                        continue;
                    }
                    else if (propertyInfo != info.NameDomainProperty &&
                             criteria != SearchCriteriaEnum.All &&
                             criteria != SearchCriteriaEnum.Properties &&
                             criteria != SearchCriteriaEnum.PropertiesWithoutName)
                    {
                        continue;
                    }

                    object nameValue = GetPropertyValue(modelElement, modelElementType, propertyInfo.Name);
                    if (nameValue == null && System.String.IsNullOrEmpty(searchText))
                    {
                        SearchResult searchResult = new SearchResult();
                        searchResult.IsSuccessFull = true;
                        searchResult.Source        = modelElement;
                        searchResult.Reason        = "Property " + propertyInfo.Name + " is 'null'";

                        results.Add(searchResult);
                    }
                    else if (nameValue != null && !System.String.IsNullOrEmpty(searchText))
                    {
                        if (Contains(nameValue.ToString(), searchText, options))
                        {
                            SearchResult searchResult = new SearchResult();
                            searchResult.IsSuccessFull = true;
                            searchResult.Source        = modelElement;
                            searchResult.Reason        = "Property " + propertyInfo.Name + " contains '" + searchText + "'";

                            results.Add(searchResult);
                        }
                    }
                }
            }
            #endregion

            #region roles
            if (criteria == SearchCriteriaEnum.Roles ||
                criteria == SearchCriteriaEnum.All)
            {
                foreach (DomainRoleInfo roleInfo in info.AllDomainRolesPlayed)
                {
                    if (!roleInfo.IsSource)
                    {
                        continue;
                    }

                    DomainRelationshipInfo relInfo = roleInfo.DomainRelationship;
                    if (!IsLinkIncludedInDomainTree(modelElement.Store as DomainModelStore, relInfo.Id))
                    {
                        continue;
                    }

                    ReadOnlyCollection <ElementLink> links = DomainRoleInfo.GetElementLinks <ElementLink>(modelElement, roleInfo.Id);
                    if (links.Count == 0 && String.IsNullOrEmpty(searchText))
                    {
                        SearchResult searchResult = new SearchResult();
                        searchResult.IsSuccessFull = true;
                        searchResult.Source        = modelElement;
                        searchResult.Reason        = "Role " + roleInfo.PropertyName + " is empty";

                        results.Add(searchResult);
                    }

                    foreach (ElementLink link in links)
                    {
                        ModelElement m = DomainRoleInfo.GetTargetRolePlayer(link);
                        if (m == null && System.String.IsNullOrEmpty(searchText))
                        {
                            SearchResult searchResult = new SearchResult();
                            searchResult.IsSuccessFull = true;
                            searchResult.Source        = modelElement;
                            searchResult.Reason        = "Role " + roleInfo.PropertyName + " is null";

                            results.Add(searchResult);
                        }
                        else if (m != null && !System.String.IsNullOrEmpty(searchText))
                        {
                            if (Contains((m as IDomainModelOwnable).DomainElementFullName, searchText, options))
                            {
                                SearchResult searchResult = new SearchResult();
                                searchResult.IsSuccessFull = true;
                                searchResult.Source        = modelElement;
                                searchResult.Reason        = "Role " + roleInfo.PropertyName + " contains '" + searchText + "' in the Full Name property on referenced element " + (m as IDomainModelOwnable).DomainElementFullName;

                                results.Add(searchResult);
                            }
                        }
                    }
                }
            }
            #endregion

            #region type
            if (criteria == SearchCriteriaEnum.Type ||
                criteria == SearchCriteriaEnum.NameAndType ||
                criteria == SearchCriteriaEnum.All)
            {
                if (Contains((modelElement as IDomainModelOwnable).DomainElementType, searchText, options) ||
                    Contains((modelElement as IDomainModelOwnable).DomainElementTypeDisplayName, searchText, options))
                {
                    SearchResult searchResult = new SearchResult();
                    searchResult.IsSuccessFull = true;
                    searchResult.Source        = modelElement;
                    searchResult.Reason        = "Type '" + searchText + "' found";

                    results.Add(searchResult);
                }
            }
            #endregion

            return(results);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="rInfo"></param>
 /// <param name="cInfo"></param>
 public ContextMenuCreationHelper(DomainRoleInfo rInfo, DomainClassInfo cInfo)
 {
     RoleInfo = rInfo;
     RolePlayerInfo = cInfo;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Get the index of a <see cref="DomainClassInfo"/> that is a descendent of the
 /// <see cref="DomainClassInfo"/> for <see cref="ElementGroupingType"/>
 /// </summary>
 public int GetGroupingTypeIndex(DomainClassInfo groupingTypeClassInfo)
 {
     return(Array.IndexOf <Type>(myGroupingTypes, groupingTypeClassInfo.ImplementationClass));
 }
Exemplo n.º 15
0
				public ClassDetailBranch(DomainClassInfo baseDomainClass, DomainClassInfo instanceDomainClass)
				{
					myDomainClasses = new DomainClassInfo[] { baseDomainClass, instanceDomainClass };
				}
Exemplo n.º 16
0
        private void ContextMenuOpening(object sender, EventArgs e)
        {
            MultiDiagramContextMenuStrip contextMenu = ContextMenuStrip;
            ToolStripItemCollection      menuItems   = contextMenu.Items;
            Diagram diagram         = contextMenu.SelectedDiagram;
            bool    haveSelectedTab = diagram != null;

            foreach (ToolStripItem item in menuItems)
            {
                if (item.Tag == ContextMenuItemNeedsSelectedTab)
                {
                    item.Enabled = haveSelectedTab;
                }
            }

            Partition partition = this.DocData.Store.DefaultPartition;

            //Disable/Enable New Diagram Tabs stuff wow
            ToolStripDropDownItem   newPageMenuItem = (ToolStripDropDownItem)menuItems[ResourceStrings.DiagramCommandNewPage];
            ToolStripItemCollection items           = newPageMenuItem.DropDownItems;
            int itemCount = items.Count;

            for (int i = 0; i < itemCount; i++)
            {
                object[]        itemInfo    = (object[])items[i].Tag;
                DomainClassInfo diagramInfo = (DomainClassInfo)itemInfo[1];
                ReadOnlyCollection <ModelElement> modelElements = partition.ElementDirectory.FindElements(diagramInfo);
                DiagramMenuDisplayAttribute       attribute     = (DiagramMenuDisplayAttribute)itemInfo[0];
                if (modelElements.Count > 0 & (attribute.DiagramOption & DiagramMenuDisplayOptions.AllowMultiple) == 0)
                {
                    //DISABLE NEW
                    items[i].Enabled = false;
                }
                else
                {
                    //ENABLE NEW
                    items[i].Enabled = true;
                }
            }

            // Disable page reordering if there is only one page
            string reorderKey = ResourceStrings.DiagramCommandReorderPages;

            if (menuItems.ContainsKey(reorderKey))
            {
                menuItems[reorderKey].Enabled = HasMultiplePages;
            }


            //If a diagram tab is selected
            if (diagram != null)
            {
                //Retrieve all existing diagrams of the same type as the one selected
                ReadOnlyCollection <ModelElement> modelElements = partition.ElementDirectory.FindElements(diagram.GetDomainClass(), true);
                DomainClassInfo diagramInfo = diagram.GetDomainClass();

                //Grab the attribute of the diagram type selected
                object[] attributes = diagramInfo.ImplementationClass.GetCustomAttributes(typeof(DiagramMenuDisplayAttribute), false);
                if (attributes.Length > 0)
                {
                    DiagramMenuDisplayAttribute attribute = (DiagramMenuDisplayAttribute)attributes[0];
                    //If required but you only have 1 then disable delete
                    if ((attribute.DiagramOption & DiagramMenuDisplayOptions.Required) != 0 && modelElements.Count <= 1)
                    {
                        //DISABLE DELETE
                        ToolStripMenuItem deletePageMenuItem = (ToolStripMenuItem)menuItems[ResourceStrings.DiagramCommandDeletePage];
                        deletePageMenuItem.Enabled = false;
                    }
                    else
                    {
                        //ALLOW DELETE
                        ToolStripMenuItem deletePageMenuItem = (ToolStripMenuItem)menuItems[ResourceStrings.DiagramCommandDeletePage];
                        deletePageMenuItem.Enabled = true;
                    }

                    if ((attribute.DiagramOption & DiagramMenuDisplayOptions.BlockRename) != 0)
                    {
                        //DISABLE RENAME
                        ToolStripMenuItem renamePageMenuItem = (ToolStripMenuItem)menuItems[ResourceStrings.DiagramCommandRenamePage];
                        renamePageMenuItem.Enabled = false;
                    }
                    else
                    {
                        //ALLOW RENAME
                        ToolStripMenuItem renamePageMenuItem = (ToolStripMenuItem)menuItems[ResourceStrings.DiagramCommandRenamePage];
                        renamePageMenuItem.Enabled = true;
                    }
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// See <see cref="ModelingDocView.LoadView"/>.
        /// </summary>
        protected override bool LoadView()
        {
            if (base.LoadView())
            {
                ORMDesignerDocData document = (ORMDesignerDocData)this.DocData;
                #region Setup context menu
                ContextMenuStrip contextMenu = base.ContextMenuStrip = new MultiDiagramContextMenuStrip();
                contextMenu.ShowImageMargin = false;
                contextMenu.Opening        += ContextMenuOpening;
                ToolStripMenuItem newPageMenuItem    = new ToolStripMenuItem(ResourceStrings.DiagramCommandNewPage);
                ToolStripMenuItem deletePageMenuItem = new ToolStripMenuItem(ResourceStrings.DiagramCommandDeletePage);
                ToolStripMenuItem renamePageMenuItem = new ToolStripMenuItem(ResourceStrings.DiagramCommandRenamePage);
                newPageMenuItem.DropDown = new ToolStripDropDown();
                ToolStripItemCollection items = newPageMenuItem.DropDownItems;

                ReadOnlyCollection <DomainClassInfo> diagrams = document.Store.DomainDataDirectory.FindDomainClass(Diagram.DomainClassId).AllDescendants;
                int diagramCount = diagrams.Count;
                for (int i = 0; i < diagramCount; ++i)
                {
                    DomainClassInfo diagramInfo = diagrams[i];
                    object[]        attributes  = diagramInfo.ImplementationClass.GetCustomAttributes(typeof(DiagramMenuDisplayAttribute), false);
                    if (attributes.Length > 0)
                    {
                        DiagramMenuDisplayAttribute attribute = (DiagramMenuDisplayAttribute)attributes[0];
                        Image  image = attribute.TabImage;
                        string name  = attribute.DisplayName;
                        if (string.IsNullOrEmpty(name))
                        {
                            name = diagramInfo.DisplayName;
                        }
                        if (image != null)
                        {
                            base.RegisterImageForDiagramType(diagramInfo.ImplementationClass, image);
                        }
                        ToolStripMenuItem newDiagramMenuItem = new ToolStripMenuItem(name, image, ContextMenuNewPageClick);
                        newDiagramMenuItem.Tag = new object[] { attribute, diagramInfo };
                        items.Add(newDiagramMenuItem);
                    }
                }
                newPageMenuItem.Name = ResourceStrings.DiagramCommandNewPage;
                newPageMenuItem.DropDown.ImageScalingSize = DiagramImageSize;

                deletePageMenuItem.Name   = ResourceStrings.DiagramCommandDeletePage;
                deletePageMenuItem.Click += ContextMenuDeletePageClick;
                deletePageMenuItem.Tag    = ContextMenuItemNeedsSelectedTab;

                renamePageMenuItem.Name   = ResourceStrings.DiagramCommandRenamePage;
                renamePageMenuItem.Click += ContextMenuRenamePageClick;
                renamePageMenuItem.Tag    = ContextMenuItemNeedsSelectedTab;

                if (null != Store.FindDomainModel(DiagramDisplayDomainModel.DomainModelId))
                {
                    ToolStripMenuItem reorderPagesMenuItem = new ToolStripMenuItem(ResourceStrings.DiagramCommandReorderPages);
                    reorderPagesMenuItem.Name   = ResourceStrings.DiagramCommandReorderPages;
                    reorderPagesMenuItem.Click += ContextMenuPageOrderClick;

                    contextMenu.Items.AddRange(new ToolStripItem[] { newPageMenuItem, reorderPagesMenuItem, new ToolStripSeparator(), deletePageMenuItem, renamePageMenuItem });
                }
                else
                {
                    contextMenu.Items.AddRange(new ToolStripItem[] { newPageMenuItem, new ToolStripSeparator(), deletePageMenuItem, renamePageMenuItem });
                }
                #endregion                 // Setup context menu

                Store store = document.Store;
                // Add our existing diagrams. If we have the diagram display model extension turned on
                // for this designer, then we will always have an ordered set of diagrams at this point.
                if (null != (store.FindDomainModel(DiagramDisplayDomainModel.DomainModelId)))
                {
                    ReadOnlyCollection <DiagramDisplay> diagramDisplayElements = store.ElementDirectory.FindElements <DiagramDisplay>(false);
                    if (diagramDisplayElements.Count != 0)
                    {
                        IList <DiagramDisplayHasDiagramOrder> existingDiagramLinks = DiagramDisplayHasDiagramOrder.GetLinksToOrderedDiagramCollection(diagramDisplayElements[0]);
                        int existingDiagramsCount = existingDiagramLinks.Count;
                        if (existingDiagramsCount != 0)
                        {
                            Partition defaultPartition = store.DefaultPartition;
                            for (int i = 0; i < existingDiagramsCount; ++i)
                            {
                                DiagramDisplayHasDiagramOrder link = existingDiagramLinks[i];
                                Diagram existingDiagram            = link.Diagram;
                                if (existingDiagram.Partition == defaultPartition)
                                {
                                    // The fixup listeners guarantee that there is exactly one active diagram,
                                    // so we can safely trust the property to get an active diagram
                                    base.AddDiagram(existingDiagram, link.IsActiveDiagram);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Add our existing diagrams
                    ReadOnlyCollection <Diagram> existingDiagrams = store.ElementDirectory.FindElements <Diagram>(true);
                    int existingDiagramsCount = existingDiagrams.Count;
                    if (existingDiagramsCount != 0)
                    {
                        bool      seenDiagram      = false;
                        Partition defaultPartition = store.DefaultPartition;
                        for (int i = 0; i < existingDiagramsCount; ++i)
                        {
                            Diagram existingDiagram = existingDiagrams[i];
                            if (existingDiagram.Partition == defaultPartition)
                            {
                                // Make the first diagram be selected
                                base.AddDiagram(existingDiagram, !seenDiagram);
                                seenDiagram = true;
                            }
                        }
                    }
                }

                // Make sure we get a closing notification so we can clear the
                // selected components
                document.DocumentClosing += new EventHandler(DocumentClosing);
                return(true);
            }
            return(false);
        }
Exemplo n.º 18
0
        public override bool ModelCanMerge(CopyPaste.ModelProtoElement protoElement, CopyPaste.ModelProtoGroup protoGroup)
        {
            if (protoElement != null)
            {
                DomainClassInfo elementDomainInfo = this.Partition.DomainDataDirectory.GetDomainClass(protoElement.DomainClassId);
                if (elementDomainInfo.IsDerivedFrom(global::Tum.PDE.LanguageDSL.DomainClass.DomainClassId))
                {
                    if (protoGroup.Operation == ModelProtoGroupOperation.Move)
                    {
                        foreach (global::Tum.PDE.LanguageDSL.LibraryModelContextHasClasses link in DomainRoleInfo.GetElementLinks <global::Tum.PDE.LanguageDSL.LibraryModelContextHasClasses>(this, global::Tum.PDE.LanguageDSL.LibraryModelContextHasClasses.LibraryModelContextDomainRoleId))
                        {
                            if (link.DomainClass.Id == protoElement.ElementId)
                            {
                                return(false);
                            }
                        }
                    }
                    return(true);
                }
                else if (elementDomainInfo.IsDerivedFrom(global::Tum.PDE.LanguageDSL.DomainRelationship.DomainClassId))
                {
                    if (protoGroup.Operation == ModelProtoGroupOperation.Move)
                    {
                        foreach (global::Tum.PDE.LanguageDSL.LibraryModelContextHasRelationships link in DomainRoleInfo.GetElementLinks <global::Tum.PDE.LanguageDSL.LibraryModelContextHasRelationships>(this, global::Tum.PDE.LanguageDSL.LibraryModelContextHasRelationships.LibraryModelContextDomainRoleId))
                        {
                            if (link.DomainRelationship.Id == protoElement.ElementId)
                            {
                                return(false);
                            }
                        }
                    }

                    // see if source and target domain classes are copied here
                    List <ModelProtoElement> elements = protoGroup.GetEmbeddedElements(this.Partition, protoElement);
                    for (int i = 0; i < elements.Count; i++)
                    {
                        if (elements[i].Name == "DomainRole")
                        {
                            List <ModelProtoLink> links = protoGroup.GetReferenceLinks(this.Partition, elements[i]);
                            foreach (ModelProtoLink link in links)
                            {
                                if (link.Name == "DomainRoleReferencesRolePlayer")
                                {
                                    ModelProtoRolePlayer rP = link.GetTargetRolePlayer(this.Partition);
                                    // see if the target element is beeing copied or is already in the model
                                    if (!protoGroup.HasProtoElementFor(rP.RolePlayerId, this.Partition))
                                    {
                                        ModelElement m = this.Store.ElementDirectory.FindElement(rP.RolePlayerId);
                                        if (m == null)
                                        {
                                            if (!this.MetaModel.HasElement(rP.ElementName))
                                            {
                                                return(false);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Updates the displayed dependencies based on filter information.
        /// </summary>
        public virtual void UpdateBasedOnFilter(GraphicalDependenciesFilterItem filterItem)
        {
            this.Store.UndoManager.UndoState = UndoState.DisabledNoFlush;
            using (Transaction t = this.Store.TransactionManager.BeginTransaction("", true))
            {
                if (filterItem.IsFiltered)
                {
                    // remove elements
                    for (int i = 0; i < this.Diagram.SourceDependencyShapes.Count; i++)
                    {
                        if (this.Diagram.SourceDependencyShapes[i].RelationshipTypeId == filterItem.RelationshipType &&
                            this.Diagram.SourceDependencyShapes[i].RelationshipTypeId != Guid.Empty)
                        {
                            RemoveHostShape(this.Diagram.SourceDependencyShapes[i]);
                            break;
                        }

                        if (this.Diagram.SourceDependencyShapes[i].CustomInfo == filterItem.CustomFilterInformation &&
                            !String.IsNullOrEmpty(this.Diagram.SourceDependencyShapes[i].CustomInfo))
                        {
                            RemoveHostShape(this.Diagram.SourceDependencyShapes[i]);
                            break;
                        }
                    }

                    for (int i = 0; i < this.Diagram.TargetDependencyShapes.Count; i++)
                    {
                        if (this.Diagram.TargetDependencyShapes[i].RelationshipTypeId == filterItem.RelationshipType &&
                            this.Diagram.TargetDependencyShapes[i].RelationshipTypeId != Guid.Empty)
                        {
                            RemoveHostShape(this.Diagram.TargetDependencyShapes[i]);
                            break;
                        }

                        if (this.Diagram.TargetDependencyShapes[i].CustomInfo == filterItem.CustomFilterInformation &&
                            !String.IsNullOrEmpty(this.Diagram.TargetDependencyShapes[i].CustomInfo))
                        {
                            RemoveHostShape(this.Diagram.TargetDependencyShapes[i]);
                            break;
                        }
                    }
                    UpdateLayout();
                }
                else
                {
                    // add elements
                    GraphicalDependencyShape hostShape = null;
                    bool bSource = true;

                    DomainClassInfo elementInfo            = this.MainElement.GetDomainClass();
                    ReadOnlyCollection <ElementLink> links = DomainRoleInfo.GetAllElementLinks(this.MainElement);
                    foreach (ElementLink link in links)
                    {
                        DomainRelationshipInfo info = link.GetDomainRelationship();
                        if (info.Id == filterItem.RelationshipType)
                        {
                            if (DomainRoleInfo.GetSourceRolePlayer(link) != this.MainElement)
                            {
                                bSource = false;
                            }

                            if (hostShape == null)
                            {
                                hostShape = CreateHostShape(link, info);

                                if (bSource)
                                {
                                    this.Diagram.TargetDependencyShapes.Add(hostShape);
                                }
                                else
                                {
                                    this.Diagram.SourceDependencyShapes.Add(hostShape);
                                }
                            }

                            if (bSource)
                            {
                                hostShape.AddNestedChild(CreateChildShape(link, true));
                            }
                            else
                            {
                                hostShape.AddNestedChild(CreateChildShape(link, false));
                            }
                        }
                    }

                    UpdateLayout();

                    if (hostShape != null)
                    {
                        UpdateLink(hostShape, !bSource);
                    }
                }

                t.Commit();
            }
            this.Store.UndoManager.UndoState = UndoState.Enabled;
        }
Exemplo n.º 20
0
 private void SetNameConsumerValue(string value)
 {
     myConsumerDomainClass = ObjectModel.NameConsumer.TranslateFromConsumerIdentifier(Store, value);
 }
Exemplo n.º 21
0
                        public GroupingTypeData(ElementGroupingType groupingTypeInstance, DomainClassInfo groupingTypeClassInfo)
                        {
                            GroupingTypeInstance  = groupingTypeInstance;
                            GroupingTypeClassInfo = groupingTypeClassInfo;
                            Type groupingTypeClass = groupingTypeClassInfo.ImplementationClass;

                            DisplayName    = DomainTypeDescriptor.GetDisplayName(groupingTypeClass);
                            Description    = DomainTypeDescriptor.GetDescription(groupingTypeClass);
                            SelectionState = (groupingTypeInstance != null) ? (GroupingTypeSelectionState.InitiallySelected | GroupingTypeSelectionState.CurrentlySelected) : 0;
                        }
Exemplo n.º 22
0
 private void SetNameUsageValue(string value)
 {
     myUsageDomainClass = ObjectModel.NameUsage.TranslateFromNameUsageIdentifier(Store, value);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Add or remove the provided handler
 /// </summary>
 /// <typeparam name="TEventArgs">The type of the handler</typeparam>
 /// <param name="domainClass">The domainClass to add</param>
 /// <param name="domainProperty">The domainProperty to add</param>
 /// <param name="handler">The event to add or remove</param>
 /// <param name="addHandler">true to add an event listener, false to remove one</param>
 /// <returns>Returns non-null if the wrapper needs to be added or removed</returns>
 private Delegate AddOrRemove <TEventArgs>(DomainClassInfo domainClass, DomainPropertyInfo domainProperty, EventHandler <TEventArgs> handler, bool addHandler) where TEventArgs : ModelingEventArgs
 {
     return(AddOrRemove <TEventArgs>(new TypeAndDomainObjectKey(typeof(TEventArgs), domainClass, domainProperty), handler, addHandler));
 }
Exemplo n.º 24
0
 /// <summary>See <see cref="IEqualityComparer.Equals"/>.</summary>
 bool IEqualityComparer.Equals(object x, object y)
 {
     if (x == y)
     {
         return(true);
     }
     else if (x == null || y == null)
     {
         return(false);
     }
     else
     {
         return(myStringComparer.Equals(DomainClassInfo.GetName((TModelElement)x), DomainClassInfo.GetName((TModelElement)y)));
     }
 }
Exemplo n.º 25
0
 bool ICustomSerializedDomainModel.ShouldSerializeDomainClass(Store store, DomainClassInfo classInfo)
 {
     return(this.ShouldSerializeDomainClass(store, classInfo));
 }
		/// <summary>Implements ICustomSerializedDomainModel.ShouldSerializeDomainClass</summary>
		protected bool ShouldSerializeDomainClass(Store store, DomainClassInfo classInfo)
		{
			return true;
		}
Exemplo n.º 27
0
			public Category(DomainClassInfo classInfo, bool excluded)
			{
				if (classInfo != null)
				{
					myType = classInfo.ImplementationClass;
					myDisplayName = classInfo.DisplayName;
				}
				else
				{
					myType = null;
					myDisplayName = ResourceStrings.ModelErrorUncategorized;
				}
				myIsExcluded = excluded;
				myWasExcluded = excluded;
				myFirstError = -1;
				myLastError = -1;
			}
Exemplo n.º 28
0
			public Error(DomainClassInfo classInfo, int categoryIndex, bool excluded)
			{
				myType = classInfo.ImplementationClass;
				myCategoryIndex = categoryIndex;
				myDisplayName = classInfo.DisplayName;

				myIsExcluded = excluded;
				myWasExcluded = excluded;
			}
Exemplo n.º 29
0
 private static HashSet<DomainRoleInfo> GetAllEmbeddingRoles(DomainClassInfo classInfo)
 {
     HashSet<DomainRoleInfo> embeddedItemRoles = new HashSet<DomainRoleInfo>();
     ReadOnlyCollection<DomainRoleInfo> rolesPlayed = classInfo.AllDomainRolesPlayed;
     foreach (DomainRoleInfo roleInfo in rolesPlayed)
     {
         if (roleInfo.IsEmbedding)
         {
             embeddedItemRoles.Add(roleInfo);
         }
     }
     return embeddedItemRoles;
 }
Exemplo n.º 30
0
        /// <summary>
        /// This guarantees that we have an instance for every possible Name Generator type.
        /// </summary>
        private void FullyPopulateRefinements()
        {
            LinkedElementCollection <NameGenerator> currentChildren = RefinedByGeneratorCollection;
            DomainClassInfo contextDomainClass = GetDomainClass();
            ReadOnlyCollection <DomainClassInfo> requiredDescendantsCollection = contextDomainClass.LocalDescendants;
            int requiredDescendantsCount = requiredDescendantsCollection.Count;

            Type[] requiredUsageTypes = GetSupportedNameUsageTypes();
            int    requiredUsageCount = requiredUsageTypes.Length;

            if (requiredDescendantsCount != 0 || requiredUsageCount != 0)
            {
                DomainClassInfo[] requiredDescendants = new DomainClassInfo[requiredDescendantsCount];
                requiredDescendantsCollection.CopyTo(requiredDescendants, 0);
                int missingDescendantsCount = requiredDescendantsCount;
                int missingUsageCount       = requiredUsageCount;
                foreach (NameGenerator currentChild in currentChildren)
                {
                    if (missingDescendantsCount != 0)
                    {
                        int index = Array.IndexOf <DomainClassInfo>(requiredDescendants, currentChild.GetDomainClass());
                        if (index != -1)
                        {
                            requiredDescendants[index] = null;
                        }
                    }
                    Type nameUsage = currentChild.NameUsageType;
                    if (nameUsage == null)
                    {
                        currentChild.FullyPopulateRefinements();
                    }
                    else if (missingUsageCount != 0)
                    {
                        int index = Array.IndexOf <Type>(requiredUsageTypes, nameUsage);
                        if (index != -1)
                        {
                            requiredUsageTypes[index] = null;
                        }
                    }
                }
                if (missingDescendantsCount != 0)
                {
                    for (int i = 0; i < requiredDescendantsCount; ++i)
                    {
                        DomainClassInfo classInfo = requiredDescendants[i];
                        if (classInfo != null)
                        {
                            CreateRefinement(classInfo, null).FullyPopulateRefinements();;
                        }
                    }
                }
                if (missingUsageCount != 0)
                {
                    for (int i = 0; i < requiredUsageCount; ++i)
                    {
                        Type usageType = requiredUsageTypes[i];
                        if (usageType != null)
                        {
                            CreateRefinement(contextDomainClass, usageType);
                        }
                    }
                }
            }
        }