Search in sources :

Example 6 with FeatureDescriptor

use of java.beans.FeatureDescriptor in project Activiti by Activiti.

the class ResourceBundleELResolver method getFeatureDescriptors.

/**
	 * If the base object is a ResourceBundle, returns an Iterator containing the set of keys
	 * available in the ResourceBundle. Otherwise, returns null. The Iterator returned must contain
	 * zero or more instances of java.beans.FeatureDescriptor. Each info object contains information
	 * about a key in the ResourceBundle, and is initialized as follows:
	 * <ul>
	 * <li>displayName - The String key name</li>
	 * <li>name - Same as displayName property</li>
	 * <li>shortDescription - Empty string</li>
	 * <li>expert - false</li>
	 * <li>hidden - false</li>
	 * <li>preferred - true</li>
	 * </ul>
	 * In addition, the following named attributes must be set in the returned FeatureDescriptors:
	 * <ul>
	 * <li>{@link ELResolver#TYPE} - String.class.</li>
	 * <li>{@link ELResolver#RESOLVABLE_AT_DESIGN_TIME} - true</li>
	 * </ul>
	 * 
	 * @param context
	 *            The context of this evaluation.
	 * @param base
	 *            The bundle to analyze. Only bases of type ResourceBundle are handled by this
	 *            resolver.
	 * @return An Iterator containing zero or more (possibly infinitely more) FeatureDescriptor
	 *         objects, each representing a key in this bundle, or null if the base object is not a
	 *         ResourceBundle.
	 */
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
    if (isResolvable(base)) {
        final Enumeration<String> keys = ((ResourceBundle) base).getKeys();
        return new Iterator<FeatureDescriptor>() {

            public boolean hasNext() {
                return keys.hasMoreElements();
            }

            public FeatureDescriptor next() {
                FeatureDescriptor feature = new FeatureDescriptor();
                feature.setDisplayName(keys.nextElement());
                feature.setName(feature.getDisplayName());
                feature.setShortDescription("");
                feature.setExpert(true);
                feature.setHidden(false);
                feature.setPreferred(true);
                feature.setValue(TYPE, String.class);
                feature.setValue(RESOLVABLE_AT_DESIGN_TIME, true);
                return feature;
            }

            public void remove() {
                throw new UnsupportedOperationException("Cannot remove");
            }
        };
    }
    return null;
}
Also used : FeatureDescriptor(java.beans.FeatureDescriptor) Iterator(java.util.Iterator) ResourceBundle(java.util.ResourceBundle)

Example 7 with FeatureDescriptor

use of java.beans.FeatureDescriptor in project ACS by ACS-Community.

the class ButtonEditor method handleButtonClick.

/**
     * method called when the user clicks on the JButton.
     * By default, this implementation does a setValue(Boolean.True)
     * on the Bean property associated with the Button.
     * 
     * Override this if you need to do something else when the button is
     * clicked...
     * 
     * @param evt the ActionEvent generated by the JButton
     */
protected void handleButtonClick(ActionEvent evt) {
    FeatureDescriptor fd = propertyEnv.getFeatureDescriptor();
    // this.setValue() does not propagate until the Bean.
    if (fd instanceof Node.Property) {
        try {
            ((Node.Property) fd).setValue(Boolean.TRUE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // nevertheless call this.setValue() to be coherent
    setValue(Boolean.TRUE);
}
Also used : FeatureDescriptor(java.beans.FeatureDescriptor)

Example 8 with FeatureDescriptor

use of java.beans.FeatureDescriptor in project tomcat by apache.

the class ScopedAttributeELResolver method getFeatureDescriptors.

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
    PageContext ctxt = (PageContext) context.getContext(JspContext.class);
    List<FeatureDescriptor> list = new ArrayList<>();
    Enumeration<String> e;
    Object value;
    String name;
    e = ctxt.getAttributeNamesInScope(PageContext.PAGE_SCOPE);
    while (e.hasMoreElements()) {
        name = e.nextElement();
        value = ctxt.getAttribute(name, PageContext.PAGE_SCOPE);
        FeatureDescriptor descriptor = new FeatureDescriptor();
        descriptor.setName(name);
        descriptor.setDisplayName(name);
        descriptor.setExpert(false);
        descriptor.setHidden(false);
        descriptor.setPreferred(true);
        descriptor.setShortDescription("page scoped attribute");
        descriptor.setValue("type", value.getClass());
        descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
        list.add(descriptor);
    }
    e = ctxt.getAttributeNamesInScope(PageContext.REQUEST_SCOPE);
    while (e.hasMoreElements()) {
        name = e.nextElement();
        value = ctxt.getAttribute(name, PageContext.REQUEST_SCOPE);
        FeatureDescriptor descriptor = new FeatureDescriptor();
        descriptor.setName(name);
        descriptor.setDisplayName(name);
        descriptor.setExpert(false);
        descriptor.setHidden(false);
        descriptor.setPreferred(true);
        descriptor.setShortDescription("request scope attribute");
        descriptor.setValue("type", value.getClass());
        descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
        list.add(descriptor);
    }
    if (ctxt.getSession() != null) {
        e = ctxt.getAttributeNamesInScope(PageContext.SESSION_SCOPE);
        while (e.hasMoreElements()) {
            name = e.nextElement();
            value = ctxt.getAttribute(name, PageContext.SESSION_SCOPE);
            FeatureDescriptor descriptor = new FeatureDescriptor();
            descriptor.setName(name);
            descriptor.setDisplayName(name);
            descriptor.setExpert(false);
            descriptor.setHidden(false);
            descriptor.setPreferred(true);
            descriptor.setShortDescription("session scoped attribute");
            descriptor.setValue("type", value.getClass());
            descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
            list.add(descriptor);
        }
    }
    e = ctxt.getAttributeNamesInScope(PageContext.APPLICATION_SCOPE);
    while (e.hasMoreElements()) {
        name = e.nextElement();
        value = ctxt.getAttribute(name, PageContext.APPLICATION_SCOPE);
        FeatureDescriptor descriptor = new FeatureDescriptor();
        descriptor.setName(name);
        descriptor.setDisplayName(name);
        descriptor.setExpert(false);
        descriptor.setHidden(false);
        descriptor.setPreferred(true);
        descriptor.setShortDescription("application scoped attribute");
        descriptor.setValue("type", value.getClass());
        descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
        list.add(descriptor);
    }
    return list.iterator();
}
Also used : JspContext(javax.servlet.jsp.JspContext) FeatureDescriptor(java.beans.FeatureDescriptor) ArrayList(java.util.ArrayList) PageContext(javax.servlet.jsp.PageContext)

Example 9 with FeatureDescriptor

use of java.beans.FeatureDescriptor in project tomcat by apache.

the class ResourceBundleELResolver method getFeatureDescriptors.

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
    if (base instanceof ResourceBundle) {
        List<FeatureDescriptor> feats = new ArrayList<>();
        Enumeration<String> e = ((ResourceBundle) base).getKeys();
        FeatureDescriptor feat;
        String key;
        while (e.hasMoreElements()) {
            key = e.nextElement();
            feat = new FeatureDescriptor();
            feat.setDisplayName(key);
            feat.setShortDescription("");
            feat.setExpert(false);
            feat.setHidden(false);
            feat.setName(key);
            feat.setPreferred(true);
            feat.setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
            feat.setValue(TYPE, String.class);
            feats.add(feat);
        }
        return feats.iterator();
    }
    return null;
}
Also used : FeatureDescriptor(java.beans.FeatureDescriptor) ArrayList(java.util.ArrayList) ResourceBundle(java.util.ResourceBundle)

Example 10 with FeatureDescriptor

use of java.beans.FeatureDescriptor in project tomcat by apache.

the class TestResourceBundleELResolver method testGetFeatureDescriptors02.

/**
     * Tests that a valid FeatureDescriptors are returned.
     */
@Test
public void testGetFeatureDescriptors02() {
    ResourceBundleELResolver resolver = new ResourceBundleELResolver();
    ELContext context = new StandardELContext(ELManager.getExpressionFactory());
    ResourceBundle resourceBundle = new TesterResourceBundle(new Object[][] { { "key", "value" } });
    Iterator<FeatureDescriptor> result = resolver.getFeatureDescriptors(context, resourceBundle);
    while (result.hasNext()) {
        FeatureDescriptor featureDescriptor = result.next();
        Assert.assertEquals("key", featureDescriptor.getDisplayName());
        Assert.assertEquals("key", featureDescriptor.getName());
        Assert.assertEquals("", featureDescriptor.getShortDescription());
        Assert.assertFalse(featureDescriptor.isExpert());
        Assert.assertFalse(featureDescriptor.isHidden());
        Assert.assertTrue(featureDescriptor.isPreferred());
        Assert.assertEquals(String.class, featureDescriptor.getValue(ELResolver.TYPE));
        Assert.assertEquals(Boolean.TRUE, featureDescriptor.getValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME));
    }
}
Also used : FeatureDescriptor(java.beans.FeatureDescriptor) ResourceBundle(java.util.ResourceBundle) ListResourceBundle(java.util.ListResourceBundle) Test(org.junit.Test)

Aggregations

FeatureDescriptor (java.beans.FeatureDescriptor)15 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 PropertyDescriptor (java.beans.PropertyDescriptor)3 ResourceBundle (java.util.ResourceBundle)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 BeanDescriptor (java.beans.BeanDescriptor)1 EventSetDescriptor (java.beans.EventSetDescriptor)1 IndexedPropertyChangeEvent (java.beans.IndexedPropertyChangeEvent)1 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)1 IntrospectionException (java.beans.IntrospectionException)1 MethodDescriptor (java.beans.MethodDescriptor)1 ParameterDescriptor (java.beans.ParameterDescriptor)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1