Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » IStructuredSelection thoughts
IStructuredSelection thoughts [message #536586] Fri, 28 May 2010 19:43 Go to next message
Miles Parker is currently offline Miles ParkerFriend
Messages: 1341
Registered: July 2009
Senior Member
In the "always wondered" department..

1. Why doesn't IStructuredSelection implement Iterable? It would make a very common pattern a lot more usable.

2. Is there a reason that it wouldn't make sense for IStructuredSelection along with ISelection, etc.. be moved into ..core in the same way that say CommandEvent was? It sure would be nice to be able to re-use the same code for non-ui stuff.
Re: IStructuredSelection thoughts [message #536593 is a reply to message #536586] Fri, 28 May 2010 19:57 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 28.05.10 21:43, schrieb Miles Parker:
> In the "always wondered" department..
>
> 1. Why doesn't IStructuredSelection implement Iterable? It would make a
> very common pattern a lot more usable.

.... because it is Java 1.5 and things like JFace/SWT are not allowed to
use this.

>
> 2. Is there a reason that it wouldn't make sense for
> IStructuredSelection along with ISelection, etc.. be moved into ..core
> in the same way that say CommandEvent was? It sure would be nice to be
> able to re-use the same code for non-ui stuff.
Re: IStructuredSelection thoughts [message #536596 is a reply to message #536593] Fri, 28 May 2010 20:10 Go to previous messageGo to next message
Miles Parker is currently offline Miles ParkerFriend
Messages: 1341
Registered: July 2009
Senior Member
Tom Schindl wrote on Fri, 28 May 2010 15:57
Am 28.05.10 21:43, schrieb Miles Parker:
> In the "always wondered" department..
>
> 1. Why doesn't IStructuredSelection implement Iterable? It would make a
> very common pattern a lot more usable.

.... because it is Java 1.5 and things like JFace/SWT are not allowed to
use this.



Yeah, I'd forgotten that Iterable was a 1.5 / generics construct.
Re: IStructuredSelection thoughts [message #536751 is a reply to message #536596] Sun, 30 May 2010 17:17 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
Personally i think iteratable is use less...

especially in java 1.5 u have foreach ,which makes itteratable useless...

give me one instance where iteratable is useful or without it work can not be done...
i think it just over complicates things(collections)...


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: IStructuredSelection thoughts [message #536755 is a reply to message #536751] Sun, 30 May 2010 17:48 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 30.05.10 19:17, schrieb vijay:
> Personally i think iteratable is use less...
>
> especially in java 1.5 u have foreach ,which makes itteratable useless...

This is wrong! You can use foreach ONLY if it is a Array or the
collection implements Iterable!

>
> give me one instance where iteratable is useful or without it work can
> not be done... i think it just over complicates things(collections)...

I guess you are mixing up Iterator and Iterable!

Tom
Re: IStructuredSelection thoughts [message #536757 is a reply to message #536755] Sun, 30 May 2010 18:16 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
Quote:
I guess you are mixing up Iterator and Iterable!


???

how does it matter. to use iterable u ask for a iterator by iterator method....

and ultimately it comes down to iterator..

any way IStructuredSelection has toList Method which is iterable....




---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: IStructuredSelection thoughts [message #536758 is a reply to message #536757] Sun, 30 May 2010 18:32 Go to previous messageGo to next message
Miles Parker is currently offline Miles ParkerFriend
Messages: 1341
Registered: July 2009
Senior Member
vijay wrote on Sun, 30 May 2010 14:16

any way IStructuredSelection has toList Method which is iterable....



And requires iterating across the whole selection to get the list, preventing which is the a main point of using an iterator pattern in the first place!
Re: IStructuredSelection thoughts [message #536759 is a reply to message #536758] Sun, 30 May 2010 18:39 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
by implementing iteratable u just have to implement a method iterator()...

which is already there,what difference will it make...???


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: IStructuredSelection thoughts [message #536760 is a reply to message #536759] Sun, 30 May 2010 18:42 Go to previous messageGo to next message
Miles Parker is currently offline Miles ParkerFriend
Messages: 1341
Registered: July 2009
Senior Member
vijay wrote on Sun, 30 May 2010 14:39
by implementing iteratable u just have to implement a method iterator()...

which is already there,what difference will it make...???


Because you can't use it in a for (Object o: list) construct..
Re: IStructuredSelection thoughts [message #536761 is a reply to message #536760] Sun, 30 May 2010 18:49 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
pls see code for StructuredSelection.iterator method

/* (non-Javadoc)
     * Method declared in IStructuredSelection.
     */
    public Iterator iterator() {
        return Arrays.asList(elements == null ? new Object[0] : elements)
                .iterator();
    }


there is no way out of
Quote:
And requires iterating across the whole selection to get the list, preventing which is the a main point of using an iterator pattern in the first place!


if u want a iterable u have to iterate thru the whole selection to construct a iteratable...

"It is inevitable, Mr Anderson"
Razz



---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: IStructuredSelection thoughts [message #536762 is a reply to message #536761] Sun, 30 May 2010 18:57 Go to previous messageGo to next message
Miles Parker is currently offline Miles ParkerFriend
Messages: 1341
Registered: July 2009
Senior Member
vijay wrote on Sun, 30 May 2010 14:49

if u want a iterable u have to iterate thru the whole selection to construct a iteratable...



OK, I think you're seriously misunderstanding how collections work. You might want to take a look java.util.HashMap.
Re: IStructuredSelection thoughts [message #536764 is a reply to message #536762] Sun, 30 May 2010 19:09 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
but slection dont come as maps,

they can only come as an array or list right....

hashmap has "hash" in it,it uses buckets to store values according to hash values,hence it does not require to iterate thru the whole thing(in some cases)...

list does not use a hash value....


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: IStructuredSelection thoughts [message #536765 is a reply to message #536764] Sun, 30 May 2010 19:24 Go to previous messageGo to next message
Miles Parker is currently offline Miles ParkerFriend
Messages: 1341
Registered: July 2009
Senior Member
vijay wrote on Sun, 30 May 2010 15:09

list does not use a hash value....


Right, ok, I think I see where our failure to communicate is. Smile Yes, that's true for the default implementation of StrcuturedSelection, but according to the contract for IStructuredSelection there is no reason for that to be the case. Take for example an update for a UI that is very large or slow updating. You might not want to pull that entire result down at once -- think for example of the case where you're displaying a large database query result and you only want to grab the results for the next page when the user scrolls down to it
Re: IStructuredSelection thoughts [message #536770 is a reply to message #536765] Sun, 30 May 2010 19:39 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
hmmm...

ok do u want to show results in table on request...
(VirtualTables would be the answer)

Or

u want structured selection to behave lazily ....
i think that would not be possible,cuz tableviewer asks the table for selected items and it gets the item.data to construct the selection...
so nothing can be done here lazily(may be sombody has ideas)


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: IStructuredSelection thoughts [message #536774 is a reply to message #536770] Sun, 30 May 2010 20:39 Go to previous messageGo to next message
Miles Parker is currently offline Miles ParkerFriend
Messages: 1341
Registered: July 2009
Senior Member
vijay wrote on Sun, 30 May 2010 15:39

u want structured selection to behave lazily ....



Well again, you need to think in abstract terms. As a user of IStructuredSelection I don't and shouldn't need to know what specific uses it's going to be put to. You may not be using the structured selection in the context of the a JFace viewer, right? The whole point of having an interface is that you can create different implementations of it. And when designing a framework you are always trying to make the interface as non-contraining as possible. So in the case of using a structured selection, I'm going to avoid making it into a list AOTBE because my assumption is going to be that that there cold be a reason that the interface is defined the way it is, i.e. not with random access.
Re: IStructuredSelection thoughts [message #536778 is a reply to message #536757] Sun, 30 May 2010 21:22 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You can only use stuff which implements Iterable in a for-loop so todays
code:
-------8<-------
for( Object o: selection.toList() )
-------8<-------

could be written

-------8<-------
for( Object o: selection )
-------8<-------

And as outline by Miles you could pass it to all API methods who expect
to get an Iterable-Interface.

Tom

Am 30.05.10 20:16, schrieb vijay:
> Quote:
>> I guess you are mixing up Iterator and Iterable!
>
>
> ???
>
> how does it matter. to use iterable u ask for a iterator by iterator
> method....
>
> and ultimately it comes down to iterator..
>
> any way IStructuredSelection has toList Method which is iterable....
>
>
>
Previous Topic:Why having a single thread for display is so important?
Next Topic:Help simulating mouse click in SWT browser?
Goto Forum:
  


Current Time: Thu Apr 18 20:10:13 GMT 2024

Powered by FUDForum. Page generated in 0.02570 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top