Esempio n. 1
0
		///<summary>
	   /// This is the implementation of the method specified in the IPropertySetter Interface
		/// For now it is implemented in the rendering engine itself, but when it becomes
		/// too complex the IPropertySetter implementation will be isolated from
		/// this rendering class.
		///</summary>
		///<remarks>
		/// If part==null, the property will be retrieved fro the first matching part
		/// found starting from the top-part in first-order.
		///</remarks>
		public System.Object GetValue(Part part, Property prop)
		{
			if(part == null)
				part = Top;
			//search for the part, and get the widget
			Part p = part.SearchPart(prop.PartName);
			string className  = Voc.MapsOnCls(p.Class);
			Type classType = GuiAssembly.GetType(className);
			string getter = Voc.GetPropertyGetter(prop.Name, p.Class);

			System.Object targetObject = p.UiObject;
			PropertyInfo pInfo = null;
			int j = getter.IndexOf('.');
			while(j!=-1)
			{
				String parentType = getter.Substring(0,j);
				getter=getter.Substring(j+1,getter.Length-j-1);
				pInfo = classType.GetProperty(parentType);
				classType = pInfo.PropertyType;
				targetObject = pInfo.GetValue(targetObject, null);
				j = getter.IndexOf('.');
			}
			pInfo = classType.GetProperty(getter);

			//PropertyInfo pInfo = classType.GetProperty(getter);
			try
			{
				return pInfo.GetValue(targetObject, null);
			}
				catch(Exception e)
				{
					Console.WriteLine(e);
					//TODO TODO TODO
					return null;
				}
			
		}
Esempio n. 2
0
		///<summary>
		/// This is the implementation of the method specified in the IPropertySetter Interface
		/// For now it is implemented in the rendering engine itself, but when it becomes
		/// too complex the IPropertySetter implementation will be isolated from
		/// this rendering class.
		///</summary>
		///<remarks>
		/// If part==null, the property will be retrieved fro the first matching part
		/// found starting from the top-part in first-order.
		///</remarks>
		public System.Object GetValue(Part part, Property prop)
		{
			if(part == null)
				part = Top;
			//search for the part, and get the widget
			Part p = part.SearchPart(prop.PartName);
			string className  = Voc.MapsOnCls(p.Class);
			Type classType = GuiAssembly.GetType(className);
			string getter = Voc.GetPropertyGetter(prop.Name, p.Class);

			System.Object targetObject = p.UiObject;
			MemberInfo mInfo = null;
			int j = getter.IndexOf('.');
			while(j!=-1)
			{
				String parentType = getter.Substring(0,j);
				getter=getter.Substring(j+1,getter.Length-j-1);			
				mInfo = ResolveProperty(classType, parentType, out classType, ref targetObject);
				//targetObject = ((PropertyInfo)mInfo).GetValue(targetObject, null);
				j = getter.IndexOf('.');
			}
			
			try{ mInfo = ResolveProperty(classType, getter, out classType, ref targetObject); }
				catch(Exception e)
				{
					Console.WriteLine("Unable to query property \"{0}\" of part \"{1}\";", prop.Name, part.Identifier);
					Console.WriteLine("Please check your UIML document or the {0} vocabulary", Voc.VocabularyName);
				}
				
			return targetObject;
		}
Esempio n. 3
0
		///<summary>
		///Searches the parts that are used in the condition of Rule r. Events of a certain type emitted
		///by thow parts are connected to the condition of Rule r so it can be evaluated if such an event
		///occurs
		///</summary>
		///<param name="r">The rule with a condition and action</param>
		///<param name="p">A part where p itself or one of it subparts will emit events that are of interest
		///for the condition of Rule r</param>
		///<param name="gel">Links the renderer with the condition so appropriate queries can be executed by the condition.
		///It also allows the action to use the renderer afterwards to change properties in the user interface at runtime</param>

		protected void link(Rule r, Part p, CompactSWFEventLink sel)
		{
			IEnumerator eventsEnum = r.Condition.GetEvents().GetEnumerator();			
			while(eventsEnum.MoveNext())
			{
				Event e = (Event)eventsEnum.Current;
				Part thePart = p.SearchPart(e.PartName);
				if(thePart == null)
				{
					if(e.PartName == "")
						Console.WriteLine("Error in behavior specification: no part name given for {0}", e.Class);
					else
						Console.WriteLine("Error in behavior specification: {0} does not exist for event {0}", e.PartName, e.Class);
					return;
				}
				Control w = (Control)thePart.UiObject;

				string concreteEventName = m_renderer.Voc.MapsOnCls(e.Class);
				/* TODO: eventhandling is done with an ugly hack: 
				 * see the comments in the GTK# event handling classes for details.
				 */
				
					try
					{
						//Delegate handler = Delegate.CreateDelegate(typeof(EventHandler), sel, EXECUTE_METHOD);
						Delegate handler = new EventHandler(sel.Execute);
						string eventId = m_renderer.Voc.GetEventFor(thePart.Class,concreteEventName);

						//Sometimes eventId is a composed event:
						//it is an event of a property of widget w
						//so first load the property of w, and then link with
						//the event of this property
						//<property>.<event>
						
						Type theType = w.GetType();
						int j = eventId.IndexOf('.');
						System.Object targetObject = thePart.UiObject;
						while(j!=-1)
						{
							String parentType = eventId.Substring(0,j);
							eventId=eventId.Substring(j+1,eventId.Length-j-1);
							PropertyInfo pInfo = theType.GetProperty(parentType);
							theType = pInfo.PropertyType;
							targetObject = pInfo.GetValue(targetObject, null);
							j = eventId.IndexOf('.');
						}
						EventInfo eInfo = theType.GetEvent(eventId);
						//load the event info as provided by the mappings of Widget w
						eInfo.AddEventHandler(targetObject, handler);
					}
						catch(ArgumentException ae)
						{
							Console.WriteLine("Invalid argument: {0}", ae);
							//Console.WriteLine("Caused by: {0}", ae.ParamName);
						}
						catch(Exception be)
						{
							Console.WriteLine("Unexpected failure:");
							Console.WriteLine(be);
							Console.WriteLine("Please contact the uiml.net maintainer with the above output.");
						}
			}
		}
Esempio n. 4
0
		///<summary>
		///This is the implementation of the method specified in the IPropertySetter Interface
		///For now it is implemented in the rendering engine itself, but when it becomes
		///too complex the IPropertySetter implementation will be isolated from
		///this rendering class.
		///</summary>
		 ///<param name="part">The part on which prop will be applied</param>
		///<param name="prop">the property that will be applied</param>
		///<remarks>
		/// If part is null, the top part will be assumed
		///</remarks>
		public void ApplyProperty(Part part, Property prop)
		{
			if(part == null)
				part = m_top;
			Part p = part.SearchPart(prop.PartName);
			/*if(prop.Lazy) // not necessary because ApplyProperty will do it anyway!
				prop.Resolve(this);*/ 
			string className  = Voc.MapsOnCls(p.Class);
			Type classType = GuiAssembly.GetType(className);
			System.Object uiObj =  p.UiObject;
			ApplyProperty(ref uiObj, prop, p, classType);	
		}
Esempio n. 5
0
        private void LinkProperty(Property p, Part part)
        {
            // check if not already linked
            if (!PropertyLinked(p.Name, p.PartName))
            {
                m_propertyLinked[p.Name] = p.PartName;
                //Console.WriteLine("////////////// NOT LINKED: " + p.Name + " // " + p.PartName);

                Part thePart = part.SearchPart(p.PartName);
                if (thePart == null)
                {
                    if (p.PartName == "")
                        Console.WriteLine("Error in behavior specification: no part name given for {0}", p.PartClass);
                    else
                        Console.WriteLine("Error in behavior specification: {0} does not exist for event {0}", p.PartName, p.PartClass);
                    return;
                }
                Object w = (Object)thePart.UiObject;

                // register all events of this part => lots of overhead
                foreach (EventInfo ei in w.GetType().GetEvents())
                {
                    //Console.WriteLine("Adding event {0} to {1}", ei.Name, thePart.UiObject.GetType());
                    try
                    {
                        ei.AddEventHandler(thePart.UiObject, m_conditions.CreateHandlerWrapper(ei.Name, p.PartName));
                    }
                    catch (Exception ex) { }
                }
            }
        }
Esempio n. 6
0
        private void LinkEvent(Object ie, Part part)
        {
            Event e = (Event)ie;
            Part thePart = part.SearchPart(e.PartName);

            if (e.Class == "init")
            {
                // special case: init event
                string fullEventName = m_renderer.Voc.MapsOnCls(e.Class);
                string typeName = fullEventName.Substring(0, fullEventName.LastIndexOf('.'));
                string eventName = fullEventName.Substring(fullEventName.LastIndexOf('.') + 1);

                // get the top part
                Part top = m_renderer.Top;

                // get the current rendered instances
                IRenderedInstance instance = m_renderer.TopWindow;
                Type type = instance.GetType();

                /*Type type = null;
                foreach (Assembly a in ExternalLibraries.Instance.Assemblies)
                {
                    try
                    {
                        type = a.GetType(typeName, true);
                        break;
                    }
                    catch
                    {
                    }
                }

                if (type == null)
                {
                    Console.WriteLine("Error in behavior specification: init event cannot be linked. Please check your vocabulary (e.g. the maps-to attribute of the 'init' d-class).");
                    return;
                }*/

                EventInfo init = type.GetEvent(eventName);
                // now create a correct handler
                EventHandler handler = delegate(object sender, EventArgs args)
                {
                    // add the top part as the part-name
                    m_conditions.Execute(instance, args, "init", top.Identifier);
                };

                // add the handler to the event
                init.AddEventHandler(instance, handler);

                // tada!
                return;

                /*// get the connected object                
                IEnumerator enumObjects = ExternalObjects.Instance.LoadedObjects;
                while (enumObjects.MoveNext())
                {
                    object obj = enumObjects.Current;
                    Type objType = obj.GetType();
                    if (objType.Equals(type) || objType.IsSubclassOf(type))
                    {
                        // found it
                        // now create a correct handler
                        EventHandler handler = delegate(object sender, EventArgs args) 
                        { 
                            // add the top part as the part-name
                            m_conditions.Execute(obj, args, "init", "top");
                        };

                        // add the handler to the event
                        init.AddEventHandler(obj, handler);

                        // tada!
                        return;
                    }
                }*/
            }

            if (thePart == null)
            {
                if (e.PartName == "")
                    Console.WriteLine("Error in behavior specification: no part name given for {0}", e.Class);
                else
                    Console.WriteLine("Error in behavior specification: {0} does not exist for event {0}", e.PartName, e.Class);
                return;
            }
            Object w = (Object)thePart.UiObject;

            string concreteEventName = m_renderer.Voc.MapsOnCls(e.Class);
            /* TODO: eventhandling is done with an ugly hack: 
             * see the comments in the GTK# event handling classes for details.
             */

            string eventId = m_renderer.Voc.GetEventFor(thePart.Class, concreteEventName);

            EventHandler wrapper = m_conditions.CreateHandlerWrapper(ConditionManager.GetEventName(concreteEventName), e.PartName);

            //Sometimes eventId is a composed event:
            //it is an event of a property of widget w
            //so first load the property of w, and then link with
            //the event of this property
            //<property>.<event>

            Type theType = w.GetType();
            int j = eventId.IndexOf('.');
            System.Object targetObject = thePart.UiObject;
            while (j != -1)
            {
                String parentType = eventId.Substring(0, j);
                eventId = eventId.Substring(j + 1, eventId.Length - j - 1);
                PropertyInfo pInfo = theType.GetProperty(parentType);
                theType = pInfo.PropertyType;
                targetObject = pInfo.GetValue(targetObject, null);
                j = eventId.IndexOf('.');
            }
            EventInfo eInfo = theType.GetEvent(eventId);
            //load the event info as provided by the mappings of Widget w
            eInfo.AddEventHandler(targetObject, wrapper);
        }