Esempio n. 1
0
		/// <ToBeCompleted></ToBeCompleted>
		public void CommitSetProperty() {
			AssertProjectExists();
			if (propertySetBuffer != null) {
				ICommand command = null;
				if (propertySetBuffer.Objects.Count != 0) {
					if (IsOfType(propertySetBuffer.ObjectType, typeof(Shape))) {
						command = new ShapePropertySetCommand(
							ConvertEnumerator<Shape>.Create(propertySetBuffer.Objects),
							propertySetBuffer.PropertyInfo,
							propertySetBuffer.OldValues,
							propertySetBuffer.NewValue);
					} else if (IsOfType(propertySetBuffer.ObjectType, typeof(IModelObject))) {
						command = new ModelObjectPropertySetCommand(
							ConvertEnumerator<IModelObject>.Create(propertySetBuffer.Objects),
							propertySetBuffer.PropertyInfo,
							propertySetBuffer.OldValues,
							propertySetBuffer.NewValue);
					} else if (IsOfType(propertySetBuffer.ObjectType, typeof(Diagram))) {
						command = new DiagramPropertySetCommand(
							ConvertEnumerator<Diagram>.Create(propertySetBuffer.Objects),
							propertySetBuffer.PropertyInfo,
							propertySetBuffer.OldValues,
							propertySetBuffer.NewValue);
					} else if (IsOfType(propertySetBuffer.ObjectType, typeof(Layer))) {
						Diagram diagram = null;
						foreach (Diagram d in project.Repository.GetDiagrams()) {
							foreach (Layer l in ConvertEnumerator<Layer>.Create(propertySetBuffer.Objects)) {
								if (d.Layers.Contains(l)) {
									diagram = d;
									break;
								}
								if (diagram != null) break;
							}
						}
						command = new LayerPropertySetCommand(
							diagram,
							ConvertEnumerator<Layer>.Create(propertySetBuffer.Objects),
							propertySetBuffer.PropertyInfo,
							propertySetBuffer.OldValues,
							propertySetBuffer.NewValue);
					} else if (IsOfType(propertySetBuffer.ObjectType, typeof(Design))) {
						command = new DesignPropertySetCommand(
							ConvertEnumerator<Design>.Create(propertySetBuffer.Objects),
							propertySetBuffer.PropertyInfo,
							propertySetBuffer.OldValues,
							propertySetBuffer.NewValue);
					} else if (IsOfType(propertySetBuffer.ObjectType, typeof(Style))) {
						Design design = null;
						if (project.Repository != null) {
							foreach (Design d in project.Repository.GetDesigns()) {
								foreach (Style s in ConvertEnumerator<Style>.Create(propertySetBuffer.Objects)) {
									if (d.ContainsStyle(s)) {
										design = d;
										break;
									}
								}
								if (design != null) break;
							}
						} else design = project.Design;
						if (design != null) {
							command = new StylePropertySetCommand(
								design,
								ConvertEnumerator<Style>.Create(propertySetBuffer.Objects),
								propertySetBuffer.PropertyInfo,
								propertySetBuffer.OldValues,
								propertySetBuffer.NewValue);
						}
					} else throw new NotSupportedException();
				}

				if (command != null) {
					if (!command.IsAllowed(Project.SecurityManager)) throw new NShapeSecurityException(command);
					if (updateRepository) Project.ExecuteCommand(command);
					else command.Execute();
					if (PropertyChanged != null) {
						int pageIndex;
						Hashtable selectedObjectsList;
						GetSelectedObjectList(propertySetBuffer.Objects, out pageIndex, out selectedObjectsList);
						if (pageIndex >= 0) {
							PropertyControllerPropertyChangedEventArgs e = new PropertyControllerPropertyChangedEventArgs(
								pageIndex,
								propertySetBuffer.Objects,
								propertySetBuffer.PropertyInfo,
								propertySetBuffer.OldValues,
								propertySetBuffer.NewValue);
							PropertyChanged(this, e);
						}
					}
				} else 
					CancelSetProperty();
			}
			propertySetBuffer = null;
		}
Esempio n. 2
0
        /// <ToBeCompleted></ToBeCompleted>
        public void CommitSetProperty()
        {
            AssertProjectExists();
            if (propertySetBuffer != null)
            {
                ICommand command = null;
                if (propertySetBuffer.Objects.Count != 0)
                {
                    if (IsOfType(propertySetBuffer.ObjectType, typeof(Shape)))
                    {
                        command = new ShapePropertySetCommand(
                            ConvertEnumerator <Shape> .Create(propertySetBuffer.Objects),
                            propertySetBuffer.PropertyInfo,
                            propertySetBuffer.OldValues,
                            propertySetBuffer.NewValue);
                    }
                    else if (IsOfType(propertySetBuffer.ObjectType, typeof(IModelObject)))
                    {
                        command = new ModelObjectPropertySetCommand(
                            ConvertEnumerator <IModelObject> .Create(propertySetBuffer.Objects),
                            propertySetBuffer.PropertyInfo,
                            propertySetBuffer.OldValues,
                            propertySetBuffer.NewValue);
                    }
                    else if (IsOfType(propertySetBuffer.ObjectType, typeof(Diagram)))
                    {
                        command = new DiagramPropertySetCommand(
                            ConvertEnumerator <Diagram> .Create(propertySetBuffer.Objects),
                            propertySetBuffer.PropertyInfo,
                            propertySetBuffer.OldValues,
                            propertySetBuffer.NewValue);
                    }
                    else if (IsOfType(propertySetBuffer.ObjectType, typeof(Layer)))
                    {
                        Diagram diagram = null;
                        foreach (Diagram d in project.Repository.GetDiagrams())
                        {
                            foreach (Layer l in ConvertEnumerator <Layer> .Create(propertySetBuffer.Objects))
                            {
                                if (d.Layers.Contains(l))
                                {
                                    diagram = d;
                                    break;
                                }
                                if (diagram != null)
                                {
                                    break;
                                }
                            }
                        }
                        command = new LayerPropertySetCommand(
                            diagram,
                            ConvertEnumerator <Layer> .Create(propertySetBuffer.Objects),
                            propertySetBuffer.PropertyInfo,
                            propertySetBuffer.OldValues,
                            propertySetBuffer.NewValue);
                    }
                    else if (IsOfType(propertySetBuffer.ObjectType, typeof(Design)))
                    {
                        command = new DesignPropertySetCommand(
                            ConvertEnumerator <Design> .Create(propertySetBuffer.Objects),
                            propertySetBuffer.PropertyInfo,
                            propertySetBuffer.OldValues,
                            propertySetBuffer.NewValue);
                    }
                    else if (IsOfType(propertySetBuffer.ObjectType, typeof(Style)))
                    {
                        Design design = null;
                        if (project.Repository != null)
                        {
                            foreach (Design d in project.Repository.GetDesigns())
                            {
                                foreach (Style s in ConvertEnumerator <Style> .Create(propertySetBuffer.Objects))
                                {
                                    if (d.ContainsStyle(s))
                                    {
                                        design = d;
                                        break;
                                    }
                                }
                                if (design != null)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            design = project.Design;
                        }
                        if (design != null)
                        {
                            command = new StylePropertySetCommand(
                                design,
                                ConvertEnumerator <Style> .Create(propertySetBuffer.Objects),
                                propertySetBuffer.PropertyInfo,
                                propertySetBuffer.OldValues,
                                propertySetBuffer.NewValue);
                        }
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }

                if (command != null)
                {
                    // Check if command execution is allowed
                    Exception exc = command.CheckAllowed(Project.SecurityManager);
                    if (exc != null)
                    {
                        throw exc;
                    }
                    //
                    if (updateRepository)
                    {
                        Project.ExecuteCommand(command);
                    }
                    else
                    {
                        command.Execute();
                    }
                    if (PropertyChanged != null)
                    {
                        int       pageIndex;
                        Hashtable selectedObjectsList;
                        GetSelectedObjectList(propertySetBuffer.Objects, out pageIndex, out selectedObjectsList);
                        if (pageIndex >= 0)
                        {
                            PropertyControllerPropertyChangedEventArgs e = new PropertyControllerPropertyChangedEventArgs(
                                pageIndex,
                                propertySetBuffer.Objects,
                                propertySetBuffer.PropertyInfo,
                                propertySetBuffer.OldValues,
                                propertySetBuffer.NewValue);
                            PropertyChanged(this, e);
                        }
                    }
                }
                else
                {
                    CancelSetProperty();
                }
            }
            propertySetBuffer = null;
        }