Moving rows in SWT/Jface Table

D

derharri

Hello,

i have a problem i am not able to solve. Has someone an idea how to
move rows in an SWT Table? I want to change the order by user
ineraction but do not need to sort the entries.

The first way i would like to achieve is to move a selected row up or
down by buttonklick.
The second way would be to move table items by drag and drop.

Hints for solving that in pure SWT are as good as JFace hints.

Thank you for your help.

Harri E.


...i hope you excuse my very bad english.
 
C

crazzycloe

Are you using any kind of Content Provider?

If yes, I would do the following:
1. Write a class implementing Comparator and have an instance variable
inside for the row the user changed, by default it might be the first row in
the table. Your compare method will use this instance variable
2. Use an instance of this class when you create your Content Provider
3. When a user does something (click, drag, whatever you like), you set this
instance variable in the corresponding listener method

Mike
 
D

derharri

i am really sorry but i do not really understand how to do that.

Yes i use an Contentprovider:
- class ProcessListContentProvider implements
IStructuredContentProvider

An instance of this class is set as Contentprovider for my tableViewer:
- processListViewer.setContentProvider(new
ProcessListContentProvider());

I also create a Comparer class implementing java.util.Comparator
- public class HarriComparator implements Comparator {

/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object,
java.lang.Object)
*/
public int compare(Object anO1, Object anO2) {
// TODO Auto-generated method stub
System.out.println("Compare von HarriComparator aufgerufen");
return 0;
}
}

Where should i set this Comparator?
tableViewer.setComparer needs an IElementComparer!

Do i also need a sorter for my tableViewer to change a rows position?

Maybe i do understand what you meant if you have a little example?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top