Exemplo n.º 1
0
		/// <summary>
		/// Calling this method initializes the <see cref="T:Dataweb.NShape.Controllers.TemplateController" />.
		/// </summary>
		public void Initialize(Project project, Template template)
		{
			if (isInitializing) {
				Debug.Fail("Already initializing");
				return;
			}
			try {
				isInitializing = true;
				if (project == null) throw new ArgumentNullException("project");
				if (this.project != project) Project = project;

#if DEBUG_DIAGNOSTICS
				if (template != null)
					template.Tag = template.Name;
#endif

				// Check if there are shape types supporting templating
				bool templateSupportingShapeTypeFound = false;
				foreach (ShapeType shapeType in project.ShapeTypes) {
					if (shapeType.SupportsAutoTemplates) {
						templateSupportingShapeTypeFound = true;
						break;
					}
				}
				if (!templateSupportingShapeTypeFound)
					throw new NShapeException("No template supporting shape types found. Load a shape library first.");

				// Create a copy of the template
				if (template != null) {
					editMode = TemplateControllerEditMode.EditTemplate;
					originalTemplate = template;
					workTemplate = new Template(originalTemplate.Name, originalTemplate.Shape.Clone());
					workTemplate.CopyFrom(originalTemplate);
					workTemplate.Shape.DisplayService = this;
				}
				else {
					// Create a new Template
					editMode = TemplateControllerEditMode.CreateTemplate;
					originalTemplate = null;

					// As a shape is mandatory for every template, find a shape first
					Shape shape = FindFirstShapeOfType(typeof (IPlanarShape));
					if (shape == null) shape = FindFirstShapeOfType(typeof (Shape)); // if no planar shape was found, get the first one
					int templateCnt = 1;
					foreach (Template t in project.Repository.GetTemplates()) ++templateCnt;
					workTemplate = new Template(string.Format("Template {0}", templateCnt), shape);
					shape.DisplayService = this;
				}

				// Disable all controls if the user has not the appropriate access rights
				if (!project.SecurityManager.IsGranted(Permission.Templates)) {
					// ToDo: implement access right restrictions
				}

				InitShapeList();
				InitModelObjectList();
				isInitialized = true;

				if (Initializing != null) {
					TemplateControllerInitializingEventArgs eventArgs = new TemplateControllerInitializingEventArgs(editMode, template);
					Initializing(this, eventArgs);
				}
			}
			finally {
				isInitializing = false;
			}
		}
Exemplo n.º 2
0
        /// <summary>
        /// Calling this method initializes the <see cref="T:Dataweb.NShape.Controllers.TemplateController" />.
        /// </summary>
        public void Initialize(Project project, Template template)
        {
            if (isInitializing)
            {
                Debug.Fail("Already initializing");
                return;
            }
            try {
                isInitializing = true;
                if (project == null)
                {
                    throw new ArgumentNullException("project");
                }
                if (this.project != project)
                {
                    Project = project;
                }

#if DEBUG_DIAGNOSTICS
                if (template != null)
                {
                    template.Tag = template.Name;
                }
#endif

                // Check if there are shape types supporting templating
                bool templateSupportingShapeTypeFound = false;
                foreach (ShapeType shapeType in project.ShapeTypes)
                {
                    if (shapeType.SupportsAutoTemplates)
                    {
                        templateSupportingShapeTypeFound = true;
                        break;
                    }
                }
                if (!templateSupportingShapeTypeFound)
                {
                    throw new NShapeException("No template supporting shape types found. Load a shape library first.");
                }

                // Create a copy of the template
                if (template != null)
                {
                    editMode         = TemplateControllerEditMode.EditTemplate;
                    originalTemplate = template;
                    workTemplate     = new Template(originalTemplate.Name, originalTemplate.Shape.Clone());
                    workTemplate.CopyFrom(originalTemplate);
                    workTemplate.Shape.DisplayService = this;
                }
                else
                {
                    // Create a new Template
                    editMode         = TemplateControllerEditMode.CreateTemplate;
                    originalTemplate = null;

                    // As a shape is mandatory for every template, find a shape first
                    Shape shape = FindFirstShapeOfType(typeof(IPlanarShape));
                    if (shape == null)
                    {
                        shape = FindFirstShapeOfType(typeof(Shape));                                     // if no planar shape was found, get the first one
                    }
                    int templateCnt = 1;
                    foreach (Template t in project.Repository.GetTemplates())
                    {
                        ++templateCnt;
                    }
                    workTemplate         = new Template(string.Format("Template {0}", templateCnt), shape);
                    shape.DisplayService = this;
                }

                // Disable all controls if the user has not the appropriate access rights
                if (!project.SecurityManager.IsGranted(Permission.Templates))
                {
                    // ToDo: implement access right restrictions
                }

                InitShapeList();
                InitModelObjectList();
                isInitialized = true;

                if (Initializing != null)
                {
                    TemplateControllerInitializingEventArgs eventArgs = new TemplateControllerInitializingEventArgs(editMode, template);
                    Initializing(this, eventArgs);
                }
            }
            finally {
                isInitializing = false;
            }
        }
Exemplo n.º 3
0
		private void templateController_Initializing(object sender, TemplateControllerInitializingEventArgs e) {
			Initialize();
		}