示例#1
0
 /// <ToBeCompleted></ToBeCompleted>
 public TemplateControllerInitializingEventArgs(TemplateControllerEditMode editMode, Template template)
 {
     this.editMode = editMode;
     this.template = template;
 }
        /// <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;
            }
        }
示例#3
0
		/// <ToBeCompleted></ToBeCompleted>
		public TemplateControllerInitializingEventArgs(TemplateControllerEditMode editMode, Template template)
		{
			this.editMode = editMode;
			this.template = template;
		}
        /// <summary>
        /// Applies all changes made on the working template to the original template.
        /// </summary>
        public void ApplyChanges()
        {
            if (string.IsNullOrEmpty(workTemplate.Name)) throw new NShapeException("The template's name must not be empty.");
            if (TemplateWasChanged) {
                ICommand cmd = null;
                switch (editMode) {
                    case TemplateControllerEditMode.CreateTemplate:
                        cmd = new CreateTemplateCommand(workTemplate);
                        project.ExecuteCommand(cmd);
                        // after inserting the template into the cache, the template becomes the new
                        // originalTemplate and a new workTemplate has to be cloned.
                        // TemplateControllerEditMode is changed from Create to Edit so the user can continue editing the
                        // template until the template editor is closed
                        originalTemplate = workTemplate;
                        // ToDo: Set appropriate DisplayService
                        originalTemplate.Shape.DisplayService = null;
                        workTemplate = originalTemplate.Clone();
                        editMode = TemplateControllerEditMode.EditTemplate;
                        break;

                    case TemplateControllerEditMode.EditTemplate:
                        // set workTemplate.Shape's DisplayService to the original shape's DisplayService
                        // (typically the ToolSetController)
                        workTemplate.Shape.DisplayService = originalTemplate.Shape.DisplayService;
                        if (workTemplate.Shape.Type != originalTemplate.Shape.Type)
                            cmd = new ExchangeTemplateShapeCommand(originalTemplate, workTemplate);
                        else
                            cmd = new CopyTemplateFromTemplateCommand(originalTemplate, workTemplate);
                        project.ExecuteCommand(cmd);
                        break;

                    default: throw new NShapeUnsupportedValueException(typeof(TemplateControllerEditMode), editMode);
                }
                TemplateWasChanged = false;
                if (ApplyingChanges != null) ApplyingChanges(this, EventArgs.Empty);
            }
        }