Example usage for javax.swing JMenuItem getListeners

List of usage examples for javax.swing JMenuItem getListeners

Introduction

In this page you can find the example usage for javax.swing JMenuItem getListeners.

Prototype

@SuppressWarnings("unchecked") 
public <T extends EventListener> T[] getListeners(Class<T> listenerType) 

Source Link

Document

Returns an array of all the objects currently registered as FooListeners upon this JComponent.

Usage

From source file:org.xulux.swing.widgets.Table.java

/**
 * Initializes the popupmenus of the table.
 *
 * @return if initialize update did some work
 *///from w ww.j  av a 2 s  .co m
protected boolean initializeUpdateButtons() {
    if (this.menu != null) {
        return false;
    }
    String buttons = getProperty("updatebuttons");
    if (buttons != null) {
        String updateAction = getProperty("updateaction");
        List list = new ArrayList();
        List strList = NyxCollectionUtils.getListFromCSV(buttons);
        Iterator it = strList.iterator();
        while (it.hasNext()) {
            String wName = (String) it.next();
            Widget widget = getPart().getWidget(wName);
            if (widget == null) {
                if (log.isWarnEnabled()) {
                    log.warn("Button " + wName + " does not exist, check your part xml");
                    continue;
                }
            }
            if (updateAction != null) {
                widget.setProperty("action", updateAction);
                widget.addNyxListener(new UpdateButtonsListener(this, widget));
            }
            list.add(widget);
        }
        menu = WidgetFactory.getPopupFromButtons(list, "Popup:" + getName());
        if (menu == null) {
            return false;
        }
        menu.setParent(this);
        menu.setPart(getPart());
        List children = menu.getChildWidgets();
        if (children != null) {
            for (Iterator cit = children.iterator(); cit.hasNext();) {
                Widget cw = (Widget) cit.next();
                // we must clear the prepostfieldlistener...
                JMenuItem jcomp = (JMenuItem) cw.getNativeWidget();
                EventListener[] evs = jcomp.getListeners(ActionListener.class);
                if (evs != null && evs.length > 0) {
                    jcomp.removeActionListener((ActionListener) evs[0]);
                }
                cw.addNyxListener(new UpdateButtonsListener(this, cw));
            }
        }
        addChildWidget(menu);
        table.addMouseListener(new PopupListener(this.menu, this));
        if (this.lockedTable != null) {
            this.lockedTable.addMouseListener(new PopupListener(this.menu, this));
        }
    }
    // we also add UpdateButtonsListener here..
    if (!childPopupsChecked) {
        childPopupsChecked = true;
        List list = getChildWidgets();
        if (list != null && list.size() > 0) {
            for (Iterator it = getChildWidgets().iterator(); it.hasNext();) {
                Widget cw = (Widget) it.next();
                if (cw instanceof MenuItem) {
                    hasChildPopups = true;
                    break;
                }
            }
        }
    }
    if (hasChildPopups && buttons != null) {
        // just add a seperator by default
        Widget item = WidgetFactory.getWidget("menuitem", "Separator:" + getName());
        item.setProperty("type", "separator");
        item.setParent(menu);
        menu.addChildWidget(item);
    }
    if (hasChildPopups) {
        if (menu == null) {
            menu = WidgetFactory.getWidget("popupmenu", "PopupMenu:" + getName());
        }
        if (getChildWidgets() != null) {
            for (Iterator it = getChildWidgets().iterator(); it.hasNext();) {
                Widget cw = (Widget) it.next();
                if (cw instanceof MenuItem) {
                    cw.addNyxListener(new UpdateButtonsListener(this, cw));
                    cw.setParent(menu);
                    menu.addChildWidget(cw);
                }
            }
        }
    }
    if (menu != null) {
        if (menu.getParent() == null) {
            menu.setParent(this);
        }
        menu.initialize();
    }
    return true;
}