Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Add a new data to ComboViewer
Add a new data to ComboViewer [message #736835] Fri, 14 October 2011 11:23 Go to next message
Mikael Petterson is currently offline Mikael PettersonFriend
Messages: 158
Registered: July 2009
Senior Member
Hi,

I got a great tip here about using ComboViewer.

This is my scenario:

- I have a list of activities ( retrieved using Activity.refreshActivities() ).
I present them in the ComboViewer.
- Then a new activity is created and I get all the activities again ( Activity.refreshActivities()).

I use the following code to present them:
Activity[] activities = Activity.refreshActivities(viewName, provider);
					comboViewer.setInput(activities);
					comboViewer.refresh();

But I need to set the newly added activity as selected.

How can I do that?

br,

//mike
Re: Add a new data to ComboViewer [message #736857 is a reply to message #736835] Fri, 14 October 2011 11:56 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-10-14 13:23, Mikael Petterson wrote:
> Hi,
>
> I got a great tip here about using ComboViewer.
>
> This is my scenario:
>
> - I have a list of activities ( retrieved using
> Activity.refreshActivities() ).
> I present them in the ComboViewer.
> - Then a new activity is created and I get all the activities again (
> Activity.refreshActivities()).
>
> I use the following code to present them:
>
> Activity[] activities = Activity.refreshActivities(viewName, provider);
> comboViewer.setInput(activities);
> comboViewer.refresh();
>
> But I need to set the newly added activity as selected.
>
> How can I do that?

Have you tried the StructuredViewer API function setSelection?

HTH & Greetings from Bremen,

Daniel Krügler
Re: Add a new data to ComboViewer [message #739485 is a reply to message #736857] Mon, 17 October 2011 14:24 Go to previous message
Mikael Petterson is currently offline Mikael PettersonFriend
Messages: 158
Registered: July 2009
Senior Member
Hi,

I have now made a sort on date of my Activity using
final Comparator<Activity> DATE_ORDER = new Comparator<Activity>() {
			public int compare(Activity a1, Activity a2) {
				return a2.getDate().compareTo(a1.getDate());
			}
		};

		Collections.sort(activities, DATE_ORDER);


Then in my comboviewer I have the following:

                Activity.refreshActivities();
                Activity[] activities = Activity.getActivitiesAsArray();
               
		comboViewer = createComboViewer(shell, Activity.getActivitiesAsArray());
                comboViewer.setInput(activities);
		// if we have activity set as selected otherwise let sorter in list
		// decide which to set.new
		// StructuredSelection(comboViewer.getSelection()
		//First element in array is last created.
		comboViewer.setSelection(new StructuredSelection(activities[0]));
		comboViewer.refresh();


I use this code above in several places and it results in a duplication of activities since a refreshActivities() gives all activities.
How can I avoid this.

br,

//mike

Previous Topic:[DataBinding] ComputedList and ConcurrentModification problems
Next Topic:2 different Celleditors
Goto Forum:
  


Current Time: Fri Apr 19 10:19:10 GMT 2024

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

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

Back to the top