btSave.setActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OwnerClass oc = new OwnerClass(); oc.name = txtOwner.getText(); oc.employeeNr = txtEmployeeNr.getText(); myCC.addOwner(oc); } });
public void parse(XMLElement elem, String fieldName, JClassType type, final UiBinderWriter writer) throws UnableToCompleteException { String customTag = elem.consumeStringAttribute("tag", null); if (null != customTag) { OwnerField uiField = writer.getOwnerClass().getUiField(fieldName); if (uiField != null && uiField.isProvided()) { writer.die("UiField %s for FlowPanel cannot set tag when it is also provided.", fieldName); } writer.setFieldInitializerAsConstructor(fieldName, customTag); } }
OwnerField uiField = writer.getOwnerClass().getUiField(fieldName); if ((uiField == null) || (!uiField.isProvided())) { creator = writer.getOwnerClass().getUiFactoryMethod(type); if (creator == null) {
/** * Constructor. * * @param ownerType the type of the owner class * @param logger */ public OwnerClass(JClassType ownerType, MortalLogger logger, UiBinderContext context) throws UnableToCompleteException { this.logger = logger; this.ownerType = ownerType; this.context = context; findUiFields(ownerType); findUiFactories(ownerType); findUiHandlers(ownerType); }
/** * Evaluate whether all @UiField attributes are also defined in the template. * Dies if not. */ private void evaluateUiFields() throws UnableToCompleteException { if (designTime.isDesignTime()) { return; } for (OwnerField ownerField : getOwnerClass().getUiFields()) { String fieldName = ownerField.getName(); FieldWriter fieldWriter = fieldManager.lookup(fieldName); if (fieldWriter == null) { die("Template %s has no %s attribute for %s.%s#%s", templatePath, getUiFieldAttributeName(), uiOwnerType.getPackage().getName(), uiOwnerType.getName(), fieldName); } } }
continue; } else if (!enclosingType.getPackage().equals( writer.getOwnerClass().getOwnerType().getPackage())) {
for (JMethod method : ownerClass.getUiHandlers()) {
private void createResourceUiFactory(XMLElement elem, String resourceName, JClassType resourceType) throws UnableToCompleteException { FieldWriter fieldWriter; JMethod factoryMethod = writer.getOwnerClass().getUiFactoryMethod(resourceType); JClassType methodReturnType = factoryMethod.getReturnType().getErasedType() .isClassOrInterface(); if (!resourceType.getErasedType().equals(methodReturnType)) { writer.die(elem, "Type must match %s.", methodReturnType); } String initializer; if (writer.getDesignTime().isDesignTime()) { String typeName = factoryMethod.getReturnType().getQualifiedSourceName(); initializer = writer.getDesignTime().getProvidedFactory(typeName, factoryMethod.getName(), ""); } else { initializer = String.format("owner.%s()", factoryMethod.getName()); } fieldWriter = fieldManager.registerField( FieldWriterType.IMPORTED, resourceType, resourceName); fieldWriter.setInitializer(initializer); }
/** * Scans the owner class to find all methods annotated with @UiHandler, and * adds them to their respective fields. * * @param ownerType the type of the owner class */ private void findUiHandlers(JClassType ownerType) { JMethod[] methods = ownerType.getMethods(); for (JMethod method : methods) { if (method.isAnnotationPresent(UiHandler.class)) { uiHandlers.add(method); } } // Recurse to superclass JClassType superclass = ownerType.getSuperclass(); if (superclass != null) { findUiHandlers(superclass); } } }
/** * Scans the owner class to find all fields annotated with @UiField, and puts * them in {@link #uiFields} and {@link #uiFieldTypes}. * * @param ownerType the type of the owner class */ private void findUiFields(JClassType ownerType) throws UnableToCompleteException { JField[] fields = ownerType.getFields(); for (JField field : fields) { if (field.isAnnotationPresent(UiField.class)) { JClassType ownerFieldType = field.getType().isClassOrInterface(); if (ownerFieldType == null) { logger.die("Field type is not a class in field " + field.getName()); } OwnerField ownerField = new OwnerField(field, logger, context); String ownerFieldName = field.getName(); uiFields.put(ownerFieldName, ownerField); uiFieldTypes.put(ownerFieldType, ownerField); } } // Recurse to superclass JClassType superclass = ownerType.getSuperclass(); if (superclass != null) { findUiFields(superclass); } }
findUiFactories(superclass);
/** * Evaluate whether all @UiField attributes are also defined in the template. * Dies if not. */ private void evaluateUiFields() throws UnableToCompleteException { if (designTime.isDesignTime()) { return; } for (OwnerField ownerField : getOwnerClass().getUiFields()) { String fieldName = ownerField.getName(); FieldWriter fieldWriter = fieldManager.lookup(fieldName); if (fieldWriter == null) { die("Template %s has no %s attribute for %s.%s#%s", templatePath, getUiFieldAttributeName(), uiOwnerType.getPackage().getName(), uiOwnerType.getName(), fieldName); } } }
/** * Constructor. * * @param ownerType the type of the owner class * @param logger */ public OwnerClass(JClassType ownerType, MortalLogger logger, UiBinderContext context) throws UnableToCompleteException { this.logger = logger; this.ownerType = ownerType; this.context = context; findUiFields(ownerType); findUiFactories(ownerType); findUiHandlers(ownerType); }
continue; } else if (!enclosingType.getPackage().equals( writer.getOwnerClass().getOwnerType().getPackage())) {
for (JMethod method : ownerClass.getUiHandlers()) {
private void createResourceUiFactory(XMLElement elem, String resourceName, JClassType resourceType) throws UnableToCompleteException { FieldWriter fieldWriter; JMethod factoryMethod = writer.getOwnerClass().getUiFactoryMethod(resourceType); JClassType methodReturnType = factoryMethod.getReturnType().getErasedType() .isClassOrInterface(); if (!resourceType.getErasedType().equals(methodReturnType)) { writer.die(elem, "Type must match %s.", methodReturnType); } String initializer; if (writer.getDesignTime().isDesignTime()) { String typeName = factoryMethod.getReturnType().getQualifiedSourceName(); initializer = writer.getDesignTime().getProvidedFactory(typeName, factoryMethod.getName(), ""); } else { initializer = String.format("owner.%s()", factoryMethod.getName()); } fieldWriter = fieldManager.registerField( FieldWriterType.IMPORTED, resourceType, resourceName); fieldWriter.setInitializer(initializer); }
/** * Scans the owner class to find all methods annotated with @UiHandler, and * adds them to their respective fields. * * @param ownerType the type of the owner class */ private void findUiHandlers(JClassType ownerType) { JMethod[] methods = ownerType.getMethods(); for (JMethod method : methods) { if (method.isAnnotationPresent(UiHandler.class)) { uiHandlers.add(method); } } // Recurse to superclass JClassType superclass = ownerType.getSuperclass(); if (superclass != null) { findUiHandlers(superclass); } } }
/** * Scans the owner class to find all fields annotated with @UiField, and puts * them in {@link #uiFields} and {@link #uiFieldTypes}. * * @param ownerType the type of the owner class */ private void findUiFields(JClassType ownerType) throws UnableToCompleteException { JField[] fields = ownerType.getFields(); for (JField field : fields) { if (field.isAnnotationPresent(UiField.class)) { JClassType ownerFieldType = field.getType().isClassOrInterface(); if (ownerFieldType == null) { logger.die("Field type is not a class in field " + field.getName()); } OwnerField ownerField = new OwnerField(field, logger, context); String ownerFieldName = field.getName(); uiFields.put(ownerFieldName, ownerField); uiFieldTypes.put(ownerFieldType, ownerField); } } // Recurse to superclass JClassType superclass = ownerType.getSuperclass(); if (superclass != null) { findUiFields(superclass); } }
public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { if (writer.getOwnerClass().getUiField(fieldName).isProvided()) { return; } if (!writer.useLazyWidgetBuilders()) { writer.die("LazyPanel only works with UiBinder.useLazyWidgetBuilders enabled."); } XMLElement child = elem.consumeSingleChildElement(); if (!writer.isWidgetElement(child)) { writer.die(child, "Expecting only widgets in %s", elem); } FieldWriter childField = writer.parseElementToField(child); String lazyPanelClassPath = LazyPanel.class.getName(); String widgetClassPath = Widget.class.getName(); String code = String.format(INITIALIZER_FORMAT, lazyPanelClassPath, widgetClassPath, childField.getNextReference()); writer.setFieldInitializer(fieldName, code); } }