java.beans.BeanDescriptor#getShortDescription ( )源码实例Demo

下面列出了java.beans.BeanDescriptor#getShortDescription ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: SerialDataNode.java
/** Gets the short description of this feature. */
public String getShortDescription() {
    if (noBeanInfo) return super.getShortDescription();
    
    try {
        InstanceCookie ic = ic();
        if (ic == null) {
            // it must be unrecognized instance
            return getDataObject().getPrimaryFile().toString();
        }
        
        Class<?> clazz = ic.instanceClass();
        BeanDescriptor bd = Utilities.getBeanInfo(clazz).getBeanDescriptor();
        String desc = bd.getShortDescription();
        return (desc.equals(bd.getDisplayName()))? getDisplayName(): desc;
    } catch (Exception ex) {
        return super.getShortDescription();
    }
}
 
源代码2 项目: netbeans   文件: BeanNode.java
/** Performs initialization of the node
*/
private void initialization(boolean hasLookup) throws IntrospectionException {
    setIconBaseWithExtension(ICON_BASE);

    setSynchronizeName(true);

    // Find the first public superclass of the actual class.
    // Should not introspect on a private class, because then the method objects
    // used for the property descriptors will not be callable without an
    // IllegalAccessException, even if overriding a public method from a public superclass.
    Class<?> clazz = bean.getClass();

    while (!Modifier.isPublic(clazz.getModifiers()) && !hasExplicitBeanInfo(clazz)) {
        clazz = clazz.getSuperclass();

        if (clazz == null) {
            clazz = Object.class; // in case it was an interface
        }
    }

    beanInfo = Utilities.getBeanInfo(clazz);

    // resolving the name of this bean
    registerName();
    setNameSilently(getNameForBean());

    BeanDescriptor descriptor = beanInfo.getBeanDescriptor();
    String sd = descriptor.getShortDescription();

    if (!Utilities.compareObjects(sd, descriptor.getDisplayName())) {
        setShortDescription(sd);
    }

    // add propertyChangeListener
    EventSetDescriptor[] eventSetDescriptors = beanInfo.getEventSetDescriptors();
    int i;
    int k = eventSetDescriptors.length;
    Method method = null;

    for (i = 0; i < k; i++) {
        method = eventSetDescriptors[i].getAddListenerMethod();

        if (
            (method != null) && method.getName().equals("addPropertyChangeListener") && // NOI18N
                Modifier.isPublic(method.getModifiers())
        ) {
            break;
        }
    }

    if (i != k) {
        try {
            Object o = Beans.getInstanceOf(bean, method.getDeclaringClass());
            propertyChangeListener = new PropL();
            method.invoke(o, new Object[] { WeakListeners.propertyChange(propertyChangeListener, o) });
            removePCLMethod = eventSetDescriptors[i].getRemoveListenerMethod();
        } catch (Exception e) {
            // Warning, not info: likely to call e.g. getters or other things used
            // during startup of the bean, so it is not good to swallow errors here
            // (e.g. SharedClassObject.initialize throws RuntimeException -> it is
            // caught here and probably someone wants to know).
            Exceptions.attachMessage(e,
                                     "Trying to invoke " + method +
                                     " where introspected class is " +
                                     clazz.getName()); // NOI18N
            NodeOp.warning(e);
        }
    }

    createProperties(bean, beanInfo);

    for (Enumeration e = beanInfo.getBeanDescriptor().attributeNames(); e.hasMoreElements();) {
        String aname = (String) e.nextElement();
        setValue(aname, beanInfo.getBeanDescriptor().getValue(aname));
    }

    if (!hasLookup) {
        Node.Cookie instanceCookie = TMUtil.createInstanceCookie(bean);

        if (instanceCookie != null) {
            getCookieSet().add(instanceCookie);
        }
    }
}