You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Edvin Syse <ed...@sysedata.no> on 2011/06/15 21:30:37 UTC

No ListIterator in tabs

When I delete a domain object in my app, I check a tab pane to see if it 
contains any tabs that edits the deleted object and close them. I find 
myself writing code like this (Page is the domain object in this example):

// Delete the page from RDBMS
deletePage(page);

// Put tabs to remove in another list to avoid 
ConcurrentModificationException
List<Component> remove = new ArrayList<Component>();

// Search for tabs to remove
for (Component tab : tabs.getTabs()) {
     if (tab instanceof DomainObjectHolder) {
         DomainObjectHolder holder = (DomainObjectHolder) tab;
         if (page.equals(holder.getDomainObject()))
             remove.add(tab);
     }
}

// Remove the tabs
for (Component tab : remove)
     tabs.getTabs().remove(tab);

If tabs.getTabs() could give me a ListIterator, this would be a lot 
smoother, by maybe there is another Pivot way of doing this?

-- Edvin


Re: No ListIterator in tabs

Posted by Edvin Syse <ed...@sysedata.no>.
Den 15.06.2011 22:23, skrev Greg Brown:
> OK. Well, the reason that this isn't supported is simply development effort. Nested collections like TabPane's TabSequence fire events. In order to support remove(), we'd need to write a custom iterator for each nested sequence, so that it would fire events appropriately. And it is not as simple as just having the iterator's remove() method remove the element from the backing collection, because that would generate a ConcurrentModificationException. So, we sidestepped the issue by making the iterators for nested sequences read only.
>
> Given this, your approach of copying the items you want to remove is probably the best solution.

No problem, I'll just make a utility method :)

-- Edvin

Re: No ListIterator in tabs

Posted by Greg Brown <gk...@verizon.net>.
OK. Well, the reason that this isn't supported is simply development effort. Nested collections like TabPane's TabSequence fire events. In order to support remove(), we'd need to write a custom iterator for each nested sequence, so that it would fire events appropriately. And it is not as simple as just having the iterator's remove() method remove the element from the backing collection, because that would generate a ConcurrentModificationException. So, we sidestepped the issue by making the iterators for nested sequences read only.

Given this, your approach of copying the items you want to remove is probably the best solution.

G

On Jun 15, 2011, at 4:14 PM, Edvin Syse wrote:

> Den 15.06.2011 21:58, skrev Greg Brown:
>> Correct me if I am wrong, but I don't think you need a ListIterator for this - I think you just want an iterator that supports remove(). Is that right?
> 
> That's correct. Commonly, ListIterators do that, but you are right - I have no need for the ListIterator itself :)


Re: No ListIterator in tabs

Posted by Edvin Syse <ed...@sysedata.no>.
Den 15.06.2011 21:58, skrev Greg Brown:
> Correct me if I am wrong, but I don't think you need a ListIterator for this - I think you just want an iterator that supports remove(). Is that right?

That's correct. Commonly, ListIterators do that, but you are right - I 
have no need for the ListIterator itself :)

Re: No ListIterator in tabs

Posted by Greg Brown <gk...@verizon.net>.
Correct me if I am wrong, but I don't think you need a ListIterator for this - I think you just want an iterator that supports remove(). Is that right?

On Jun 15, 2011, at 3:30 PM, Edvin Syse wrote:

> When I delete a domain object in my app, I check a tab pane to see if it contains any tabs that edits the deleted object and close them. I find myself writing code like this (Page is the domain object in this example):
> 
> // Delete the page from RDBMS
> deletePage(page);
> 
> // Put tabs to remove in another list to avoid ConcurrentModificationException
> List<Component> remove = new ArrayList<Component>();
> 
> // Search for tabs to remove
> for (Component tab : tabs.getTabs()) {
>    if (tab instanceof DomainObjectHolder) {
>        DomainObjectHolder holder = (DomainObjectHolder) tab;
>        if (page.equals(holder.getDomainObject()))
>            remove.add(tab);
>    }
> }
> 
> // Remove the tabs
> for (Component tab : remove)
>    tabs.getTabs().remove(tab);
> 
> If tabs.getTabs() could give me a ListIterator, this would be a lot smoother, by maybe there is another Pivot way of doing this?
> 
> -- Edvin
> 


Re: No ListIterator in tabs

Posted by Chris Bartlett <cb...@gmail.com>.
Perhaps knocking up a some reusable utility methods along these lines would
be enough?

public static ListIterator<T> getListIterator(Sequence<T> sequence) {...}
 public static Iterator<T> getIterator(Sequence<T> sequence) {...}
public static Iterable<T> getIterable(Sequence<T> sequence) {...}

I'm not aware of anything like this within Pivot, but may be wrong.

Chris

On 16 June 2011 02:30, Edvin Syse <ed...@sysedata.no> wrote:

> When I delete a domain object in my app, I check a tab pane to see if it
> contains any tabs that edits the deleted object and close them. I find
> myself writing code like this (Page is the domain object in this example):
>
> // Delete the page from RDBMS
> deletePage(page);
>
> // Put tabs to remove in another list to avoid
> ConcurrentModificationException
> List<Component> remove = new ArrayList<Component>();
>
> // Search for tabs to remove
> for (Component tab : tabs.getTabs()) {
>    if (tab instanceof DomainObjectHolder) {
>        DomainObjectHolder holder = (DomainObjectHolder) tab;
>        if (page.equals(holder.getDomainObject()))
>            remove.add(tab);
>    }
> }
>
> // Remove the tabs
> for (Component tab : remove)
>    tabs.getTabs().remove(tab);
>
> If tabs.getTabs() could give me a ListIterator, this would be a lot
> smoother, by maybe there is another Pivot way of doing this?
>
> -- Edvin
>
>