The Artima Developer Community
Sponsored Link

Agile Buzz Forum
How To Build A GUI With Pollock - Multiple and Single Selection

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
How To Build A GUI With Pollock - Multiple and Single Selection Posted: Mar 13, 2004 6:20 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: How To Build A GUI With Pollock - Multiple and Single Selection
Feed Title: Pollock
Feed URL: http://www.cincomsmalltalk.com/rssBlog/pollock-rss.xml
Feed Description: Pollock - the next VW GUI
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Pollock

Advertisement

Last time I said we would show how to allow multiple selection of protocols, and show all of the methods associated with them in the list of methods. Before I show you the one line of code that enables that, we have to talk about one set of the features of all enumeration panes.

Which right there brings up the question: "What Do I Mean By 'Enumeration Panes'?" In Pollock, any pane that has a list/collection like object as it's model is considered an enumeration pane. In Pollock, these are ListBox, TreeView and Grid. In actual fact, all of these panes are subclassed from an abstract class named "EnumerationPane."

All of these panes have many things in common. They can have scrollbars, they have search as you type lookup and other things. In our case, we're focusing on the fact that all of these panes have both a single-select and multi-select mode. When you are selecting things from one of these panes in single select mode, you can use one of the following methods to get the current selection:

  • selection - <Answers the current object that is selected, or nil if no object is selected>
  • selectionIndex - <Answers the current linear selection index that is selected, or 0 if no object is selected>

When you are selecting things from one of these panes in multi-select mode, you can use one of the following methods to get a collection of the current selections

  • selections - <Answers a collection of the objects that are selected, in the order they were selected, or an empty collection if no object is selected>
  • selectionIndexs - <Answers a collection of the current linear selection indexes, in the order they were selected that is selected, or an empty collection if no object is selected>

Here is were Pollock goes one step further... Both sets of these methods are available and meaningful in the "other" mode.

  • In Single Select mode, the following is true:
    • selections - <Answers a collection of the selected object, or an empty collection if no object is selected>
    • selectionIndexs - <Answers a collection of the current linear selection indexes, or an empty collection if no object is selected>
  • In Multi-Select mode, the following is true:
    • selection - <Answers a the last item selected, or nil if no object is selected>
    • selectionIndex - <Answers the linear selection index of the last item selected, or an empty collection if no object is selected>

Why does Pollock bother to do this? Because you can dynamically, at runtime, change the mode of an enumeration pane from multi to single select or visa versa.

In our case, we don't need to change the mode dynamically, but, we do want to turn it to multi-select for the protocol list box. All enumeration panes are single select by default when they are created. Here's the code changes the modes:

	anEnumerationPane beMultiSelect.

-+-+-+-+

	anEnumerationPane beSingleSelect.

Now all we have to do is change two methods in our ClassHierarchyBrowser. First, we need to change our createInterface to add the line to change the protocol list box to be multi-select:

	.....
	pane := ListBox new.
	pane beMultiSelect.
	pane frame: (FractionalFrame fractionTop: 0 right: 0.66 bottom: 0.5 left: 0.33).
	.....

Then we want to (but don't actually have to) change our use of #selection to #selections in our #fillMethodList method, as well as use a different lookup method for the selectors. While we're at it, we'll add code to sort the selectors:

fillMethodList
	(self paneAt: #TreeView1) selection ifNotNil: 
		[:classValue | 
		| selections |
		selections := (self paneAt: #ListBox1) selections asSortedCollection.
		selections notEmpty ifTrue: 
			[(self paneAt: #ListBox2) list: (classValue organization listAtCategoriesNamed: selections)]]

The above is published as version 1.9 in the Package named "PollockBlog" on the Cincom public repository.

Let's open the result and see

	ClassHierarchyBrowser open.

I told you it was E-Z! Now, you'll notice you can do multiple select in the protocol list. Clicking on one protocol and then another changes the methods. Ctrl clicking adds or removes a protocol to the selections. Shift clicking adds all items from the first selection to the current mouse point. And all the keyboard selection and navigation works as you would expect... including Ctrl-A to select all protocols

That was simple. Our Class Hierarchy Browser is pretty nice, but, it would be nicer if we could resize the panes. So, next time, we'll show you how to add ResizingSplitters to our browser, so we can resize the panes.


And So It Goes
Sames

Read: How To Build A GUI With Pollock - Multiple and Single Selection

Topic: Compelled to say something stupid Previous Topic   Next Topic Topic: Software Development and attitudes

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use