use of java.beans.EventSetDescriptor in project intellij-community by JetBrains.
the class CreateListenerAction method prepareActionGroup.
private DefaultActionGroup prepareActionGroup(final List<RadComponent> selection) {
final DefaultActionGroup actionGroup = new DefaultActionGroup();
final EventSetDescriptor[] eventSetDescriptors;
try {
BeanInfo beanInfo = Introspector.getBeanInfo(selection.get(0).getComponentClass());
eventSetDescriptors = beanInfo.getEventSetDescriptors();
} catch (IntrospectionException e) {
LOG.error(e);
return null;
}
EventSetDescriptor[] sortedDescriptors = new EventSetDescriptor[eventSetDescriptors.length];
System.arraycopy(eventSetDescriptors, 0, sortedDescriptors, 0, eventSetDescriptors.length);
Arrays.sort(sortedDescriptors, (o1, o2) -> o1.getListenerType().getName().compareTo(o2.getListenerType().getName()));
for (EventSetDescriptor descriptor : sortedDescriptors) {
actionGroup.add(new MyCreateListenerAction(selection, descriptor));
}
return actionGroup;
}
use of java.beans.EventSetDescriptor in project ACS by ACS-Community.
the class IntrospectionBasedNodeUpdater method findPropertyChangeListenerMethods.
//
// -- PRIVATE METHODS -----------------------------------------------
//
private void findPropertyChangeListenerMethods() {
// add propertyChangeListener
EventSetDescriptor[] eventSetDescriptors = _beanInfo.getEventSetDescriptors();
for (int i = 0; i < eventSetDescriptors.length; i++) {
Method method = eventSetDescriptors[i].getAddListenerMethod();
if (method != null && method.getName().equals("addPropertyChangeListener") && Modifier.isPublic(method.getModifiers())) {
// set descriptor. In such a case, do not try to add a listener.
try {
_propertyChangeListener = new PropertyChangeListenerImpl();
method.invoke(_bean, new Object[] { _propertyChangeListener });
_hasRegisteredListener = true;
} 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).
GPManager.notify(GPManager.ERROR, e);
// [PENDING] deal with the error to notify
}
_removePropertyChangeListenerMethod = eventSetDescriptors[i].getRemoveListenerMethod();
break;
}
}
}
use of java.beans.EventSetDescriptor in project jdk8u_jdk by JetBrains.
the class Test6311051 method main.
public static void main(String[] args) throws IntrospectionException, NoSuchMethodException {
EventSetDescriptor esd = new EventSetDescriptor("foo", FooListener.class, new Method[] { FooListener.class.getMethod("fooHappened", EventObject.class), FooListener.class.getMethod("moreFooHappened", EventObject.class, Object.class), FooListener.class.getMethod("lessFooHappened") }, Bean.class.getMethod("addFooListener", FooListener.class), Bean.class.getMethod("removeFooListener", FooListener.class));
System.gc();
for (Method method : esd.getListenerMethods()) {
System.out.println(method);
}
}
use of java.beans.EventSetDescriptor in project yamcs-studio by yamcs.
the class DefaultWidgetIntrospector method getBeanInfo.
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
Introspector.flushFromCaches(beanClass);
BeanInfo bi = Introspector.getBeanInfo(beanClass);
BeanDescriptor bd = bi.getBeanDescriptor();
MethodDescriptor[] mds = bi.getMethodDescriptors();
EventSetDescriptor[] esds = bi.getEventSetDescriptors();
PropertyDescriptor[] pds = bi.getPropertyDescriptors();
List<PropertyDescriptor> filteredPDList = new ArrayList<PropertyDescriptor>();
List<String> nonPropList = Arrays.asList(getNonProperties());
for (PropertyDescriptor pd : pds) {
if (!nonPropList.contains(pd.getName()) && pd.getWriteMethod() != null && pd.getReadMethod() != null)
filteredPDList.add(pd);
}
int defaultEvent = bi.getDefaultEventIndex();
int defaultProperty = bi.getDefaultPropertyIndex();
return new GenericBeanInfo(bd, esds, defaultEvent, filteredPDList.toArray(new PropertyDescriptor[filteredPDList.size()]), defaultProperty, mds, null);
}
use of java.beans.EventSetDescriptor in project opennms by OpenNMS.
the class BeanInfoManager method initialize.
// -------------------------------------
/**
* Initializes by mapping property names to BeanInfoProperties
*/
void initialize(Logger pLogger) throws ELException {
try {
mBeanInfo = Introspector.getBeanInfo(mBeanClass);
mPropertyByName = new HashMap();
mIndexedPropertyByName = new HashMap();
PropertyDescriptor[] pds = mBeanInfo.getPropertyDescriptors();
for (int i = 0; pds != null && i < pds.length; i++) {
// Treat as both an indexed property and a normal property
PropertyDescriptor pd = pds[i];
if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
Method readMethod = getPublicMethod(ipd.getIndexedReadMethod());
Method writeMethod = getPublicMethod(ipd.getIndexedWriteMethod());
BeanInfoIndexedProperty property = new BeanInfoIndexedProperty(readMethod, writeMethod, ipd);
mIndexedPropertyByName.put(ipd.getName(), property);
}
Method readMethod = getPublicMethod(pd.getReadMethod());
Method writeMethod = getPublicMethod(pd.getWriteMethod());
BeanInfoProperty property = new BeanInfoProperty(readMethod, writeMethod, pd);
mPropertyByName.put(pd.getName(), property);
}
mEventSetByName = new HashMap();
EventSetDescriptor[] esds = mBeanInfo.getEventSetDescriptors();
for (int i = 0; esds != null && i < esds.length; i++) {
EventSetDescriptor esd = esds[i];
mEventSetByName.put(esd.getName(), esd);
}
} catch (IntrospectionException exc) {
if (pLogger.isLoggingWarning()) {
pLogger.logWarning(Constants.EXCEPTION_GETTING_BEANINFO, exc, mBeanClass.getName());
}
}
}
Aggregations