private void MogControl_PackageTreeView_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e)
		{
			// Encapsulate all of this in a try-catch, since we don't want to crash MOG
			try
			{
				if (!CheckLabelEdit(e))
				{
					return;
				}

				// Disable further label editing
				e.Node.TreeView.LabelEdit = false;

				// Find our parent package
				TreeNode package = FindPackage(e.Node);

				TreeNode parent = e.Node.Parent;

				string nodeText = e.Node.Text.ToLower();
				ArrayList packagePlatforms = GetPackageLabelEditPlatforms(e, ref nodeText);

				// Switch base on what our nodeText was before the user editted it
				switch (nodeText.ToLower())
				{
				case "newgroup":
					#region new-group
					if (package != null)
					{
						// Get the new edited label name
						//string groupName = e.Label;

						MOG_Filename packageAsset = new MOG_Filename(((Mog_BaseTag)package.Tag).FullFilename);

						string groupName = GetQualifiedGroupName(e, package);

						// If we have a duplicate, do not add it
						if (ValidateNodeIsNotDuplicate(e.Node.Parent, groupName) == true)
						{
							MOG_Prompt.PromptResponse("Duplicate Entry!", "The group, " + groupName + ", "
								+ "already exists!  Group not added.");
							e.Node.Remove();
							return;
						}

						// Add group to Database
						if (!AddGroupToDatabase(groupName, packageAsset))
						{
							// We need to clean up the unsuccessfull add to the database
							e.Node.Remove();

							// Show error
							MOG_Prompt.PromptMessage("Create group", "We were unable to add this group to the database. Aborting");
						}

						AttachValidatedTagToNewObjectOrGroup(package, e.Node, PackageNodeTypes.Group);
						// Go ahead and select our node
						e.Node.TreeView.SelectedNode = e.Node;
					}
					#endregion newgroup
					break;
				case "(newpackageobject)":
					#region new-package-object
					if (package != null)
					{
						// Get the new edited label name
						string objectName = e.Label;
						e.Node.Text = "(" + objectName + ")";

						// If we have a duplicate, do not add it
						if (ValidateNodeIsNotDuplicate(e.Node.Parent, e.Node.Text) == true)
						{
							MOG_Prompt.PromptResponse("Duplicate Entry!", "The object, (" + objectName + "), "
								+ "already exists!  Package object not added.");
							e.Node.Remove();
							return;
						}

						MOG_Filename packageAsset = new MOG_Filename(((Mog_BaseTag)package.Tag).FullFilename);

						string groupPath = GetQualifiedGroupName(e, package);

						// Add group to Database
						if (!AddGroupToDatabase(groupPath, packageAsset))
						{
							// We need to clean up the unsuccessfull add to the database
							e.Node.Remove();

							// Show error
							MOG_Prompt.PromptMessage("Create object", "We were unable to add this object to the database. Aborting");
						}
						else
						{
							e.CancelEdit = true;
							AttachValidatedTagToNewObjectOrGroup(package, e.Node, PackageNodeTypes.Object);
							// Go ahead and select our node
							e.Node.TreeView.SelectedNode = e.Node;
						}
					}
					#endregion new-package-object
					break;
				case "newpackage":
					#region new-package
					// Get the new package name
					string nodeFullname = MOG_Filename.JoinClassificationString(e.Node.FullPath, e.Label);

					// Construct a valid filename
					MOG_Filename[] packages = new MOG_Filename[packagePlatforms.Count];
					bool duplicateExists = false;
					string duplicates = "";
					for (int i = 0; i < packages.Length && i < packagePlatforms.Count; ++i)
					{
						MOG_Filename packageName = MOG_Filename.CreateAssetName(e.Node.Parent.FullPath, (string)packagePlatforms[i], e.Label);
						packages[i] = packageName;
						// If we have a duplicate package, store 
						if ((duplicateExists |= ValidateNodeIsNotDuplicate(e.Node.Parent, packageName.GetAssetName())) == true)
						{
							duplicates += packageName + "\r\n";
						}
					}

					// If we had duplicates, warn user and exit
					if (duplicateExists)
					{
						MOG_Prompt.PromptResponse("Duplicate Entry(ies) Detected!", "The following were already exist:\r\n\r\n"
							+ duplicates);
						e.Node.Remove();
						return;
					}

					// If we did not get a ValidPackageName (or the user decided to abort...)
					foreach (MOG_Filename packageName in packages)
					{
						if (!ValidatePackageExtension(e, packageName))
						{
							return;
						}
					}

					bool problemAdding = false;
					string packageErrorPrompt = "Did not complete package add for the following: \r\n";

					// Go backwards through our packages (so we can get the right platforms.
					for (int i = packages.Length - 1; i > -1; --i)
					{
						MOG_Filename packageName = packages[i];
						// Did we get a valid package name?
						if (packageName != null)
						{
							// Create the package
							MOG_Filename createdPackage = CreatePackageForPlatform(e, packageName, parent);

							// If the user cancelled some part of the process or we had an error...
							if (createdPackage == null)
							{
								// Remove the node
								packageErrorPrompt += "\t" + packageName + ".";
								problemAdding = true;
								break;
							}


							TreeNode newPackageNode;

							// For our first platform, we've already got a node, use it...
							if (i == 0)
							{
								e.Node.Text = createdPackage.GetAssetName();
								e.Label.ToString();
								newPackageNode = e.Node;
							}
							// For subsequent platforms, add a new node...
							else
							{
								newPackageNode = e.Node.Parent.Nodes.Add(createdPackage.GetAssetName());
							}

							// Now that we've got our initial information, add our tag
							newPackageNode.Tag = new Mog_BaseTag(newPackageNode, createdPackage.GetEncodedFilename(), this.FocusForAssetNodes, true);
							((Mog_BaseTag)newPackageNode.Tag).PackageNodeType = PackageNodeTypes.Package;
							((Mog_BaseTag)newPackageNode.Tag).PackageFullName = createdPackage.GetAssetFullName();
							SetImageIndices(newPackageNode, GetAssetFileImageIndex(createdPackage.GetEncodedFilename()));
						}
					}

					// If we had a problem, let the user know and remove our package
					if (problemAdding)
					{
						MOG_Prompt.PromptMessage("Unable to Add Package(s)",
							packageErrorPrompt);
						e.Node.Remove();
						foreach (MOG_Filename packageName in packages)
						{
							RemovePackage(packageName);
						}
					}
					else // Else, we were OK, so go ahead and select this node...
					{
						e.Node.TreeView.SelectedNode = e.Node;

						foreach (MOG_Filename packageName in packages)
						{
							// Add this package to the list of newly added packages
							this.CreatedPackages.Add(packageName);
						}

						// Fire the after package create event
						if (AfterPackageCreate != null)
						{
							AfterPackageCreate(this, EventArgs.Empty);
						}
					}
					#endregion new-package
					break;
				}
			}
			catch (Exception ex)
			{
				MOG_Report.ReportMessage("TreeNode Error!", "Error committing change to package, group, or package object label:\n" + ex.Message, ex.StackTrace, MOG.PROMPT.MOG_ALERT_LEVEL.ERROR);
				if (e.Node != null)
				{
					e.Node.Remove();
				}
			}
		}
示例#2
0
        private ArrayList ExcludeClassifications(ArrayList classificationList, string nodeClassification)
        {
            ArrayList excludedClassificationList = new ArrayList();

            // Check if we have any properties associated with this tree?
            if (MogPropertyList.Count > 0)
            {
                // Get the list of excluded classifications for this node classification
                ArrayList excludedClassifications = MOG_DBAssetAPI.GetClassificationChildren(nodeClassification, "", MogPropertyList, true);
                if (excludedClassifications != null)
                {
                    excludedClassificationList.AddRange(excludedClassifications);
                }

                // Not sure if this really is the best place for this logic but exclusions are hooked to the hip of inclusions...
                // Check if the specified property is the Inclusion property
                MOG_Property testProperty = MogPropertyList[0] as MOG_Property;
                if (testProperty != null)
                {
                    // Check if this is the 'FilterInclusion' property?
                    if (string.Compare("FilterInclusions", testProperty.mPropertyKey, true) == 0)
                    {
                        // Obtain the list of assets this filter is specifically excluded from
                        ArrayList exclusionPropertyList = new ArrayList();
                        exclusionPropertyList.Add(MOG.MOG_PropertyFactory.MOG_Classification_InfoProperties.New_FilterExclusions(testProperty.mPropertyValue));
                        // Get the list of excluded classifications for this node classification
                        ArrayList excludedCLassifications = MOG_DBAssetAPI.GetClassificationChildren(nodeClassification, "", exclusionPropertyList);
                        if (excludedCLassifications != null)
                        {
                            excludedClassificationList.AddRange(excludedCLassifications);
                        }
                    }
                }
            }

            // Check for any explicitly specified exclusions?
            if (ExclusionList.Length > 0)
            {
                foreach (string classification in classificationList)
                {
                    string testClassification = MOG_Filename.JoinClassificationString(nodeClassification, classification);
                    if (StringUtils.IsFiltered(testClassification, ExclusionList))
                    {
                        // Remove this asset from the list
                        excludedClassificationList.Add(classification);
                    }
                }
            }

            // Remove the identified classifications to be excluded
            foreach (string excludedClassification in excludedClassificationList)
            {
                // Check if this excludedclassification is listed in our list?
                foreach (string classification in classificationList)
                {
                    if (string.Compare(classification, excludedClassification, true) == 0)
                    {
                        // Remove this asset from the list
                        classificationList.Remove(classification);
                        break;
                    }
                }
            }

            return(classificationList);
        }
示例#3
0
        /// <summary>
        /// Shows Assets based on MOG_Property(s) assigned to PropertyList
        /// </summary>
        private void ExpandPropertyTreeDown(TreeNode node)
        {
            BeginUpdate();

            List <string> classificationsToAdd = GetSubClassifications(node);

            string thisClassification     = node.FullPath;
            string thisClassificationPath = MOG_ControllerLibrary.ConstructPathFromLibraryClassification(thisClassification);

            // Check for any local directories
            if (thisClassificationPath.Length > 0)
            {
                DirectoryInfo[] directories = DosUtils.DirectoryGetList(thisClassificationPath, "*.*");
                if (directories != null && directories.Length > 0)
                {
                    foreach (DirectoryInfo directory in directories)
                    {
                        // If we don't already have this classification, add it.
                        if (!classificationsToAdd.Contains(directory.Name))
                        {
                            classificationsToAdd.Add(directory.Name);
                        }
                    }
                }
            }

            // Sort our classifications alphabetically
            classificationsToAdd.Sort();

            // Foreach classification, add it
            foreach (string classification in classificationsToAdd)
            {
                string fullClassification = MOG_Filename.JoinClassificationString(node.FullPath, classification);

                // Only add library classifications
                if (MOG_Filename.IsParentClassificationString(fullClassification, MOG_Filename.GetProjectLibraryClassificationString()))
                {
                    TreeNode classificationNode = new TreeNode(classification);

                    // Is this a non-MOG folder?
                    if (!MOG_ControllerProject.IsValidClassification(fullClassification))
                    {
                        classificationNode.ForeColor = Color.LightGray;
                    }

                    // Assign the default node checked state
                    classificationNode.Checked = node.Checked;

                    classificationNode.Tag = new Mog_BaseTag(classificationNode, classification, RepositoryFocusLevel.Classification, false);
                    ((Mog_BaseTag)classificationNode.Tag).PackageNodeType = PackageNodeTypes.Class;
                    node.Nodes.Add(classificationNode);

                    classificationNode.Name = classificationNode.FullPath;
                    SetImageIndices(classificationNode, GetClassificationImageIndex(classificationNode.FullPath));

                    classificationNode.Nodes.Add(new TreeNode(Blank_Node_Text));
                }
            }

            EndUpdate();
        }