Exemplo n.º 1
0
      public void applyMetadata(FaceletContext ctx, Object instance) {

        ValueExpression ve = attr.getValueExpression(ctx, type);
        UIComponent cc = (UIComponent) instance;
        assert (UIComponent.isCompositeComponent(cc));
        Map<String, Object> attrs = cc.getAttributes();
        BeanInfo componentMetadata = (BeanInfo) attrs.get(UIComponent.BEANINFO_KEY);
        BeanDescriptor desc = componentMetadata.getBeanDescriptor();
        Collection<String> attributesWithDeclaredDefaultValues =
            (Collection<String>) desc.getValue(RIConstants.ATTRS_WITH_DECLARED_DEFAULT_VALUES);
        if (null != attributesWithDeclaredDefaultValues
            && attributesWithDeclaredDefaultValues.contains(name)) {
          // It is necessary to remove the value from the attribute
          // map because the ELexpression transparancy doesn't know
          // about the value's existence.
          attrs.remove(name);
        }
        cc.setValueExpression(name, ve);
      }
  public static void main(String[] args) throws Exception {

    BeanInfo i = Introspector.getBeanInfo(C.class, Object.class);
    Checker.checkEq("description", i.getBeanDescriptor().getShortDescription(), "CHILD");

    PropertyDescriptor[] pds = i.getPropertyDescriptors();
    Checker.checkEq("number of properties", pds.length, 1);
    PropertyDescriptor p = pds[0];

    Checker.checkEq("property description", p.getShortDescription(), "CHILDPROPERTY");
    Checker.checkEq("isBound", p.isBound(), childFlag);
    Checker.checkEq("isExpert", p.isExpert(), childFlag);
    Checker.checkEq("isHidden", p.isHidden(), childFlag);
    Checker.checkEq("isPreferred", p.isPreferred(), childFlag);
    Checker.checkEq("required", p.getValue("required"), childFlag);
    Checker.checkEq("visualUpdate", p.getValue("visualUpdate"), childFlag);

    Checker.checkEnumEq(
        "enumerationValues",
        p.getValue("enumerationValues"),
        new Object[] {"BOTTOM", 3, "javax.swing.SwingConstants.BOTTOM"});
  }
Exemplo n.º 3
0
  /**
   * @see ViewHandler#retargetAttachedObjects(javax.faces.context.FacesContext,
   *     javax.faces.component.UIComponent, java.util.List)
   */
  @Override
  public void retargetAttachedObjects(
      FacesContext context, UIComponent topLevelComponent, List<AttachedObjectHandler> handlers) {

    BeanInfo componentBeanInfo =
        (BeanInfo) topLevelComponent.getAttributes().get(UIComponent.BEANINFO_KEY);
    // PENDING(edburns): log error message if componentBeanInfo is null;
    if (null == componentBeanInfo) {
      return;
    }
    BeanDescriptor componentDescriptor = componentBeanInfo.getBeanDescriptor();
    // There is an entry in targetList for each attached object in the
    // <composite:interface> section of the composite component.
    List<AttachedObjectTarget> targetList =
        (List<AttachedObjectTarget>)
            componentDescriptor.getValue(AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY);
    // Each entry in targetList will vend one or more UIComponent instances
    // that is to serve as the target of an attached object in the consuming
    // page.
    List<UIComponent> targetComponents = null;
    String forAttributeValue, curTargetName, handlerTagId, componentTagId;
    boolean foundMatch = false;

    // For each of the attached object handlers...
    for (AttachedObjectHandler curHandler : handlers) {
      // Get the name given to this attached object by the page author
      // in the consuming page.
      forAttributeValue = curHandler.getFor();
      // For each of the attached objects in the <composite:interface> section
      // of this composite component...
      foundMatch = false;
      for (AttachedObjectTarget curTarget : targetList) {
        if (foundMatch) {
          break;
        }
        // Get the name given to this attached object target by the
        // composite component author
        curTargetName = curTarget.getName();
        targetComponents = curTarget.getTargets(topLevelComponent);

        if (curHandler instanceof ActionSource2AttachedObjectHandler
            && curTarget instanceof ActionSource2AttachedObjectTarget) {
          if (forAttributeValue.equals(curTargetName)) {
            for (UIComponent curTargetComponent : targetComponents) {
              curHandler.applyAttachedObject(context, curTargetComponent);
              foundMatch = true;
            }
          }
        } else if (curHandler instanceof EditableValueHolderAttachedObjectHandler
            && curTarget instanceof EditableValueHolderAttachedObjectTarget) {
          if (forAttributeValue.equals(curTargetName)) {
            for (UIComponent curTargetComponent : targetComponents) {
              curHandler.applyAttachedObject(context, curTargetComponent);
              foundMatch = true;
            }
          }
        } else if (curHandler instanceof ValueHolderAttachedObjectHandler
            && curTarget instanceof ValueHolderAttachedObjectTarget) {
          if (forAttributeValue.equals(curTargetName)) {
            for (UIComponent curTargetComponent : targetComponents) {
              curHandler.applyAttachedObject(context, curTargetComponent);
              foundMatch = true;
            }
          }
        }
      }
    }
  }
 @Override
 public BeanDescriptor getBeanDescriptor() {
   return mRootBeanInfo.getBeanDescriptor();
 }
Exemplo n.º 5
0
 public BeanDescriptor getBeanDescriptor() {
   return delegate.getBeanDescriptor();
 }
Exemplo n.º 6
0
  /**
   * Standard constructor.
   *
   * @param type Type that you are going to be creating and editor for.
   * @param readOnly Set to true to create a read-only customizer.
   */
  public DynamicCustomizer(Class type, boolean readOnly) {
    super(new GridBagLayout());
    _readOnly = readOnly;
    _type = type;

    LabelFieldGBC gbc = new LabelFieldGBC();
    try {
      BeanInfo info = Introspector.getBeanInfo(type);
      // Set up pretty display stuff.
      setBorder(BorderFactory.createTitledBorder(info.getBeanDescriptor().getDisplayName()));
      setToolTipText(info.getBeanDescriptor().getShortDescription());

      // Get the properties and sort them.
      PropertyDescriptor[] props = info.getPropertyDescriptors();
      Arrays.sort(props, new PropertyComparator());
      for (int i = 0; i < props.length; i++) {
        // Ignore the "class" property, if it is provided.
        if (props[i].getName().equals("class")) continue;
        // Create a label for the field.
        JLabel label = new JLabel(props[i].getDisplayName() + ":");

        // Lookup the editor.
        PropertyEditor editor = getEditorForProperty(props[i]);

        // Add a listener to the editor so we know when to update
        // the bean's fields.
        editor.addPropertyChangeListener(_eListener);

        // XXX What we need to do right here is provide a component
        // that makes use of the "paintable" capability of the editor.
        Component comp = editor.getCustomEditor();
        if (comp == null) {
          comp = new JLabel("<No editor available.>");
          ((JLabel) comp).setBorder(BorderFactory.createEtchedBorder());
        }

        // See if it is a read-only property. If so, then just
        // display it.
        if (_readOnly || props[i].getWriteMethod() == null) {
          comp.setEnabled(false);
        }

        // Setup the accellerator key.
        label.setLabelFor(comp);
        label.setDisplayedMnemonic(label.getText().charAt(0));

        // Set the tool tip text, if any.
        String tip = props[i].getShortDescription();
        if (tip != null) {
          label.setToolTipText(tip);
          if (comp instanceof JComponent) {
            ((JComponent) comp).setToolTipText(tip);
          }
        }

        // Add the label and fields.
        add(label, gbc.forLabel());
        add(comp, gbc.forField());

        // Set the mappings between editor and property, etc. for
        // quick lookup later.
        _prop2Editor.put(props[i], editor);
        _editor2Prop.put(editor, props[i]);
      }
      // Filler...
      add(new JLabel(), gbc.forLastLabel());

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }