Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » ComboViewer dropdown list not updated with new data
ComboViewer dropdown list not updated with new data [message #756153] Fri, 11 November 2011 09:50 Go to next message
Mikael Petterson is currently offline Mikael PettersonFriend
Messages: 158
Registered: July 2009
Senior Member
Hi,

I am opening a new dialog form an existing Dialog. When I close the new dialog (NewActivityDialog) the comboViewer will not be updated with new data from activities. Why?

Any ideas what I am missing here?

br,

//mike

SelectionListener newListener = new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				// Open new Dialog to add activity.
				Shell activeShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
				NewActivityDialog dlg = new NewActivityDialog(activeShell, provider, ActivityDialog.this, resource);
				if (dlg.open() == Window.OK) {
					// refresh
					activities = provider.listMyActivities();
					// Select last added in arraylist
					comboViewer.getCombo().removeAll();
					comboViewer.add(activities.toArray(new String[activities.size()]));
					comboViewer.setSelection(new StructuredSelection(activities.size() - 1), true);
					comboViewer.refresh();
				} else
					return;

			}
		};
Re: ComboViewer dropdown list not updated with new data [message #756160 is a reply to message #756153] Fri, 11 November 2011 10:23 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 2011-11-11 10:50, Mikael Petterson wrote:
> Hi,
>
> I am opening a new dialog form an existing Dialog. When I close the new
> dialog (NewActivityDialog) the comboViewer will not be updated with new
> data from activities. Why?

What do you precisely mean with "will not be updated"?

> Any ideas what I am missing here?
> comboViewer.getCombo().removeAll();

You should always ensure that you invoke the *viewer* methods, why are
you not using setInput instead?

> comboViewer.add(activities.toArray(new String[activities.size()]));
> comboViewer.setSelection(new StructuredSelection(activities.size() - 1),
> true);

This cannot work: You are creating here a StructuredSelection object
that is initialized with an Integer Object with value activities.size()
- 1. You must assign a selection object that refers to the actual
object(s) within the viewer.

HTH & Greetings from Bremen,

Daniel Krügler
Re: ComboViewer dropdown list not updated with new data [message #756166 is a reply to message #756160] Fri, 11 November 2011 10:57 Go to previous messageGo to next message
Mikael Petterson is currently offline Mikael PettersonFriend
Messages: 158
Registered: July 2009
Senior Member
Daniel Krügler wrote on Fri, 11 November 2011 05:23
On 2011-11-11 10:50, Mikael Petterson wrote:
> Hi,
>
> I am opening a new dialog form an existing Dialog. When I close the new
> dialog (NewActivityDialog) the comboViewer will not be updated with new
> data from activities. Why?

What do you precisely mean with "will not be updated"?

When I call

ArrayList<String> activities = (ArrayList<String>)provider.listMyActivities();

after a new activity has been called the new activity is in the list.
But I cannot get it into the drop down list in ComboViewer.

> Any ideas what I am missing here?
> comboViewer.getCombo().removeAll();

You should always ensure that you invoke the *viewer* methods, why are
you not using setInput instead?

I got duplicates. But I will try it again.

> comboViewer.add(activities.toArray(new String[activities.size()]));
> comboViewer.setSelection(new StructuredSelection(activities.size() - 1),
> true);

This cannot work: You are creating here a StructuredSelection object
that is initialized with an Integer Object with value activities.size()
- 1. You must assign a selection object that refers to the actual
object(s) within the viewer.

No you are right Smile I did not see that.

But how do I do that when I have an arraylist?

br,

//mike

HTH & Greetings from Bremen,

Daniel Krügler

Re: ComboViewer dropdown list not updated with new data [message #756169 is a reply to message #756166] Fri, 11 November 2011 11:39 Go to previous message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 2011-11-11 11:57, Mikael Petterson wrote:
> Daniel Krügler wrote on Fri, 11 November 2011 05:23
>> On 2011-11-11 10:50, Mikael Petterson wrote:
>> > Hi,
>> >
>> > I am opening a new dialog form an existing Dialog. When I close the new
>> > dialog (NewActivityDialog) the comboViewer will not be updated with new
>> > data from activities. Why?
>>
>> What do you precisely mean with "will not be updated"?
>>
>> When I call
>> ArrayList<String> activities =
>> (ArrayList<String>)provider.listMyActivities();
>>
>> after a new activity has been called the new activity is in the list.
>> But I cannot get it into the drop down list in ComboViewer.

I can only assume, that you are using the Viewer API incorrectly, we
probably need to see a minimal, complete test case of what does not work.

>> > Any ideas what I am missing here?
>> > comboViewer.getCombo().removeAll();
>>
>> You should always ensure that you invoke the *viewer* methods, why are
>> you not using setInput instead?
>>
>> I got duplicates. But I will try it again.

I'm not sure about what you refer by "duplicates". If your input
contains "duplicates", those will be part of the presented viewer
content, because a viewer is not a set. If you call setInput, the old
input will be replaced by the new one, a refresh happens automagically,
so it is impossible that the viewer still contains parts of the previous
model.

Your description:

<quote>
This works fine as log as my activities are static but I my case I have
a method

String [] activities = getAllActivities();

Example:

First time it is executed:

e.g. activities will contain {"one","two","three"};

Second time it is executed ( new has been created):

e.g. activities will contain {"one","two","three","four"};

So it also contains the old ones.
</quote>

is not really helpful, because you don't show us, what
getAllActivities() returns at the first call and what it returns at the
second call. Your example does not really prove that the old ones are
still used. I would expect that the first call of getAllActivities()
returned {"one","two","three"} and that the second call returned
{"one","two","three","four"}, which would completely explain the outcome
of your experiment.

>> But how do I do that when I have an arraylist?

arraylist of what? If this is an ArrayList<String> and if each element
of this array refers to existing parts of the content, you can construct
an StructuredSelection object from this List.

HTH & Greetings from Bremen,

Daniel Krügler
Previous Topic:How to add new data to ComboViewer
Next Topic:EMF Adding to a collection with reflective API.
Goto Forum:
  


Current Time: Tue Apr 23 08:59:21 GMT 2024

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

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

Back to the top