JideSplitButton with Action

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

JideSplitButton with Action

Postby Walter Laan » Thu Nov 19, 2009 6:31 am

Hi,
below I've a sub class of JideSplitButton with the following changes:

1) Use Action.LARGE_ICON_KEY when available since (I think) the split button is more a button than a menu (which uses small icon always)
2) Added support for a SPLIT_BUTTON_ENABLED action property

I think the first is OK to be committed to common JideSplitButton, as I don't think someone would use it in a menu (preferring a small icon)?
The second is a bit incomplete as there is also a setButtonSelected() but that is more a view property (whether the button or the menu part is selected) I think?

Code: Select all
public class CustomJideSplitButton extends JideSplitButton {

    public static final String SPLIT_BUTTON_ENABLED = "JideSplitButtonEnabled";

    public CustomJideSplitButton(Action action) {
        super(action);
    }

    @Override
    protected void configurePropertiesFromAction(Action action) {
        super.configurePropertiesFromAction(action);

        setButtonEnabled(isSplitButtonEnabled(action));
        doSetIconFromAction(action);
    }

    protected void doSetIconFromAction(Action action) {
        // setIconFromAction is package private in AbstractButton
        Icon icon = null;
        if (action != null) {
            icon = (Icon) action.getValue(Action.LARGE_ICON_KEY);
            if (icon == null) {
                icon = (Icon) action.getValue(Action.SMALL_ICON);
            }
        }
        setIcon(icon);
    }

    @Override
    protected void actionPropertyChanged(Action action, String propertyName) {
        super.actionPropertyChanged(action, propertyName);

        if(SPLIT_BUTTON_ENABLED.equals(propertyName)) {
            setButtonEnabled(isSplitButtonEnabled(action));
        }
        else if (propertyName == Action.SMALL_ICON) {
            // smallIconChanged is package private in AbstractButton
            if(action.getValue(Action.LARGE_ICON_KEY) == null) {
                doSetIconFromAction(action);
            }
        }
        else if (propertyName == Action.LARGE_ICON_KEY) {
            // largeIconChanged is package private in AbstractButton
            doSetIconFromAction(action);
        }
    }

    public static boolean isSplitButtonEnabled(Action action) {
        if(action == null) {
            return false;
        }
        else {
            Object value = action.getValue(SPLIT_BUTTON_ENABLED);
            if(value instanceof Boolean) {
                return ((Boolean) value).booleanValue();
            }
            else {
                return action.isEnabled();
            }
        }
    }
}
Walter Laan
 
Posts: 383
Joined: Mon May 01, 2006 12:13 am

Re: JideSplitButton with Action

Postby JIDE Support » Thu Nov 19, 2009 9:06 am

In general, people will use it as a button but there are indeed cases that it could be used as a menu which it acts like a JMenu on JPopupMenu except the menu item itself can be clicked. So we will keep the current design for now.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: JideSplitButton with Action

Postby JIDE Support » Thu Nov 19, 2009 2:28 pm

Thanks for code sharing. We will include your code in 2.8.1 since your design covers most of the cases for JideSplitButton and provides an overridable method for the customer to customize it further.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: JideSplitButton with Action

Postby JIDE Support » Fri Dec 04, 2009 3:25 pm

Just so you know, your code is included in 2.8.1 release.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 56 guests