Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach Actions to SourceListItems #22

Open
GoogleCodeExporter opened this issue Mar 13, 2015 · 13 comments
Open

Attach Actions to SourceListItems #22

GoogleCodeExporter opened this issue Mar 13, 2015 · 13 comments

Comments

@GoogleCodeExporter
Copy link

What would be really, really nice, would be if I could add an instance of
javax.swing.Action to a SourceListItem. Or something similar.

Original issue reported on code.google.com by steve.mc...@gmail.com on 30 Oct 2008 at 7:57

@GoogleCodeExporter
Copy link
Author

What is it you want to do in the ActionListener? 

Maybe it would make more sense to introduce a SourceListViewController if your 
trying to toggle views based on 
what item is selected.

This would keep the SourceList class free of particular usage patterns.

Original comment by kenneth....@gmail.com on 31 Oct 2008 at 2:52

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

Original comment by kenneth....@gmail.com on 17 Jan 2009 at 1:18

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Enabling SourceItems (potentially SourceListCategories too) to be configured 
via an
Action will increase code reuse. A SourceListClickListener may delegate to an 
item's
action to handle the click event for instance.

Original comment by aalmi...@gmail.com on 9 Jun 2009 at 5:31

@GoogleCodeExporter
Copy link
Author

Thanks for the feedback Andres. Can you show me what you want your Groovy 
syntax to look like? That'll give 
me a better idea of your use case.

Original comment by kenneth....@gmail.com on 9 Jun 2009 at 10:24

@GoogleCodeExporter
Copy link
Author

Sure, this is what I have in mind

class DefaultSourceListClickListener implements SourceListClickListener {
  void sourceListItemClicked(SourceListItem item, Button button, int clickCount) {
    Action action = item.getAction()
    if( action && item.enabled ) {
      ActionEvent evt = ...
      action.actionPerformed(evt)
    }
  }

  void sourceListCategoryClicked(SourceListCategory category, Button button, int
clickCount) {
    ... // similar impl as above
  }
}

actions {
  action(id: "checkEmailAction",
    smallIcon: imageIcon("/icons/email.png"),
    closure: controller.checkEmail)
}

sourceList(id: "sl") {
  sourceListCategory("Mail") {
    sourceListItem(checkEmailAction, text: "John Doe")
    sourceListItem(checkEmailAction, text: "Jane Doe")
  }
}
sl.addSourceListClickListener(new DefaultSourceClicklistener())

Both items will inherit the same icon and actionListener, 
DefaultSourceClicklistener
makes sure to delegate to the appropriate action if it exists and if it is 
enabled. I
believe items/categories are always enabled, does it make sense to disable them?
(don't know if Apple HIGs define this behavior).

Original comment by aalmi...@gmail.com on 9 Jun 2009 at 5:41

@GoogleCodeExporter
Copy link
Author

Thanks Andres. Would it be better if I just called the action for you when an 
item was selected?

Original comment by kenneth....@gmail.com on 10 Jun 2009 at 12:29

@GoogleCodeExporter
Copy link
Author

That would take care of the click event if a DefaultSourceClickListener is 
registered
upon SourceList creation. My concern is also about the looks of an 
Item/Category, as
if you update an action's properties so must the configured Item/Category.

I'm not sure if Item/Category support updating their text/icon after they are
created. In any case we can prototype this on MacwidgetsBuilder without 
affecting
Macwidgets directly, thanks to Groovy's metaprogramming facilities :-)

Original comment by aalmi...@gmail.com on 10 Jun 2009 at 6:43

@GoogleCodeExporter
Copy link
Author

Issue 5 has been merged into this issue.

Original comment by kenneth....@gmail.com on 3 Dec 2009 at 9:00

@GoogleCodeExporter
Copy link
Author

Is this issue ever going to be resolved? What is the use of the sourcelist if 
you cant apply actionevents to it?

Original comment by JakeTyo on 5 Jun 2010 at 10:17

@GoogleCodeExporter
Copy link
Author

You can react to selection events using a SourceListSelectionListener:

http://exploding-
pixels.com/google_code/javadoc_0.9.5/com/explodingpixels/macwidgets/SourceListSe
lectionListener.html

Original comment by kenneth....@gmail.com on 5 Jun 2010 at 10:55

@GoogleCodeExporter
Copy link
Author

Thanks for the quick response! I tried adding it with minimal success. Can you 
look at this snippet and tell me what Im doing wrong?

// Source List
            SourceListModel model = new SourceListModel();

            // Source List Category
            SourceListCategory category = new SourceListCategory("Views");
            model.addCategory(category);

                    // Create Source List Items
                    SourceListItem codeViewItem = new SourceListItem("Code View", new ImageIcon(FrameController.class.getResource("assets/TreeIcons/codeView.png")));
                    SourceListItem debuggerItem = new SourceListItem("Debugger", new ImageIcon(FrameController.class.getResource("assets/TreeIcons/debuggerView.png")));
                    SourceListItem profilerItem = new SourceListItem("Profiler", new ImageIcon(FrameController.class.getResource("assets/TreeIcons/profilerView.png")));

                    // Add Source List Items
                    model.addItemToCategory(codeViewItem, category);
                    model.addItemToCategory(debuggerItem, category);
                    model.addItemToCategory(profilerItem, category);

            // Add Source List Categorys
            SourceList sourceList = new SourceList(model);

            // Set Selected Source List Item
            sourceList.setSelectedItem(codeViewItem);

            // Create Source List Listener
            new SourceListSelectionListener() {
                    public void sourceListItemSelected(SourceListItem sli) {
                        System.err.println(sli);
                    }
            };

Original comment by JakeTyo on 6 Jun 2010 at 5:03

@GoogleCodeExporter
Copy link
Author

You need to install the SourceListSelectionListener you created on your 
SourceList:

http://exploding-
pixels.com/google_code/javadoc_0.9.5/com/explodingpixels/macwidgets/SourceList.h
tml#addSourceListSelecti
onListener(com.explodingpixels.macwidgets.SourceListSelectionListener)

Original comment by kenneth....@gmail.com on 6 Jun 2010 at 3:06

@GoogleCodeExporter
Copy link
Author

It works! Thanks a bunch!

Original comment by JakeTyo on 6 Jun 2010 at 7:04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant