protected void onNew(Event event) { Shell shell = (Shell) XWT.findElementByName(event.widget, "Root"); Company company = (Company) XWT.getDataContext(shell); Person person = new Person(); person.setName("New Manager1"); person.getAddress().setCity("ShenZhen"); company.setManager(person); }
protected void handleButton(Event event) { Label message = (Label) XWT.findElementByName(event.widget, "Message"); if (message == null) { MessageDialog.openError( XWT.findShell(event.widget), "Test Name", "Label message is not found"); } else { MessageDialog.openInformation(XWT.findShell(event.widget), "Test Name", "Name works."); } }
public DomainCanvas(Composite parent, int style) { super(parent, style); setLayout(new FillLayout()); // load XWT String name = DomainCanvas.class.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX; try { URL url = DomainCanvas.class.getResource(name); Map<String, Object> options = new HashMap<String, Object>(); options.put(IXWTLoader.CLASS_PROPERTY, this); options.put(IXWTLoader.CONTAINER_PROPERTY, this); XWT.setLoadingContext(new DefaultLoadingContext(this.getClass().getClassLoader())); XWT.loadWithOptions(url, options); } catch (Throwable e) { throw new Error("Unable to load " + name, e); } }
public void registerEvent(IObservableValueListener manager, IProperty property) { Object host = manager.getHost(); IEventController controller = UserData.findEventController(host); if (controller == null) { controller = UserData.updateEventController(host); } IMetaclass metaclass = XWT.getMetaclass(host); EventProperty reaisedEventProperty = (EventProperty) property; String raisedName = reaisedEventProperty.getEvent().getName(); for (String name : getEventNames()) { if (name.equalsIgnoreCase(raisedName)) { continue; } String eventPropertyName = IEventConstants.getEventPropertyName(name); String eventName = IEventConstants.getEventName(name); IEvent event = metaclass.findEvent(eventName); IProperty eventProperty = metaclass.findProperty(eventPropertyName); try { controller.setEvent( event, UserData.getWidget(host), manager, eventProperty, IObservableValueListener.class.getDeclaredMethod( "changeValueHandle", Object.class, org.eclipse.swt.widgets.Event.class)); } catch (Exception e) { LoggerManager.log(e); return; } } }
public static DataContext getDataContext(Object widget) { if (widget == null) { return null; } try { Object dataContext = XWT.getDataContext(widget); Map<?, ?> resources = UserData.getResources(widget); if (resources == null) { return null; } if (dataContext != null && !resources.isEmpty()) { Set<?> entrySet = resources.entrySet(); for (Object object : entrySet) { Entry<?, ?> entry = (Entry<?, ?>) object; Object value = entry.getValue(); if (!dataContext.equals(value)) { continue; } Object key = entry.getKey(); return new DataContext(key.toString(), value); } } else { Set<?> entrySet = resources.entrySet(); for (Object object : entrySet) { Entry<?, ?> entry = (Entry<?, ?>) object; Object key = entry.getKey(); Object value = entry.getValue(); return new DataContext(key.toString(), value); } } } catch (Exception e) { e.printStackTrace(); } return null; }
public static void main(String[] args) { URL url = Table_Test3.class.getResource( Table_Test3.class.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX); try { XWT.open(url); } catch (Exception e) { e.printStackTrace(); } }
/** * this test must be at the last test since it modifies the XWT * * @throws Exception */ public void testSWT_Style_Default() throws Exception { URL url = Style.class.getResource(Style.class.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX); XWT.registerMetaclass(MyElement.class); runTest( url, new Runnable() { public void run() { Object object = XWT.findElementByName(root, "MyElement"); assertTrue(object instanceof MyElement); MyElement myElement = (MyElement) object; assertTrue(myElement.isMyStyle()); } }); }
public void fireEvent(IObservableValueListener manager, IProperty property) { Object host = manager.getHost(); IMetaclass metaclass = XWT.getMetaclass(host); EventProperty reaisedEventProperty = (EventProperty) property; String raisedName = reaisedEventProperty.getEvent().getName(); for (String name : getEventNames()) { if (name.equalsIgnoreCase(raisedName)) { continue; } String eventPropertyName = IEventConstants.getEventPropertyName(name); IProperty eventProperty = metaclass.findProperty(eventPropertyName); IObservableValue value = manager.getValue(eventProperty); if (value != null) { value.setValue(false); } } }
private static BindingInfo createBindingInfo( Object targetSource, String propertyName, XamlElement bindingNode) { BindingInfo bindingInfo = bindingCache.get(bindingNode); if (bindingInfo != null) { // TODO: To check if binding changed. return bindingInfo; } Observable target = ObservableUtil.getObservable(targetSource); Property targetProperty = target.getProperty(propertyName); String elementName = null; String modelPropertyName = null; String bindingMode = null; String updateTtrigger = null; String converter = null; XamlAttribute attribute = bindingNode.getAttribute(ELEMENT_NAME); if (attribute != null) { elementName = attribute.getValue(); } attribute = bindingNode.getAttribute(PATH); if (attribute != null) { modelPropertyName = attribute.getValue(); } attribute = bindingNode.getAttribute(MODE); if (attribute != null) { bindingMode = attribute.getValue(); } attribute = bindingNode.getAttribute(CONVERTER); if (attribute != null) { converter = attribute.getValue(); } attribute = bindingNode.getAttribute(UPDATE_SOURCE_TRIGGER); if (attribute != null) { updateTtrigger = attribute.getValue(); } Object modelSource; if (elementName != null) { modelSource = XWT.findElementByName(targetSource, elementName); } else { modelSource = getDataContext(targetSource); } IObservable model = ObservableUtil.getObservable(modelSource); if (model == null) { return null; } Property modelProperty = model.getProperty(modelPropertyName); bindingInfo = new BindingInfo(new BindingContext(target, targetProperty, model, modelProperty)); bindingInfo.setElementName(elementName); if (bindingMode != null) { bindingInfo.setBindingMode(BindingMode.valueOf(bindingMode)); } if (updateTtrigger != null) { bindingInfo.setTriggerMode(UpdateSourceTrigger.valueOf(updateTtrigger)); } bindingInfo.setConverter(converter); bindingInfo.setBindingNode(bindingNode); bindingCache.put(bindingNode, bindingInfo); return bindingInfo; }