Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Trouble with lots of data , Swt Tables and DataBinding
Trouble with lots of data , Swt Tables and DataBinding [message #331021] Thu, 21 August 2008 13:54 Go to next message
Eclipse UserFriend
Originally posted by: java14.cshg.com.br

Hi to everyone , I
[databinding] TreeViewer [message #331039 is a reply to message #331021] Thu, 21 August 2008 19:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: krzysztof.daniel.gmail.com

Hi there,

I am trying to learn databinding and I have run into following problem:
I have a tree displayed in a TreeViewer (with databinding):

Account
+- Folder

Now, Folder has messages, and I would like to show only the number of
messages in the Folder:
Account
+- Folder (4)

Then I populate messages in the background job and the Folder label is
*not* updated.

I use the code found somewhere in examples
(TreeStructureAdvisor/IObservableFactory).

How can I update the label of Folder when its observered message list
changes?

TIA
Chris
Re: [databinding] TreeViewer [message #331042 is a reply to message #331039] Thu, 21 August 2008 22:18 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
You need two things: the Folder object must fire some sort of change
event, and you need an observable capable of receiving those event
dispatches.

For your situation, I recommend extending ListeningLabelProvider. You
will have to implement the addListenerTo() and removeListenerFrom()
methods, and you will likely want to reimplement the updateLabel()
method as well.

class FolderLabelProvider extends ListeningLabelProvider {
public FolderLabelProvider(IObservableSet knownElements) {
super(knownElements);
}

// Must lazy init because addListenerTo is called by superconstructor
PropertyChangeListener listener;

protected void addListenerTo(Object o) {
if (listener == null) {
listener = new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent e) {
// If properties may be changed in another thread, you may
// have to wrap this method call in a Realm.asyncExec()
fireChangeEvent(Collections.singleton(e.getSource()));
}
}
}
((Folder)o).addPropertyChangeListener(listener);
}

protected void removeListenerFrom(Object o) {
if (listener != null) {
((Folder)o).removePropertyChangeListener(listener);
}
}

public void updateLabel(ViewerLabel label, Object element) {
Folder folder = (Folder) element;
String text = folder.getLabel();
if (folder.getUnreadItemCount() > 0)
text = text + " ("+folder.getUnreadItemCount()+")";
label.setText(text);
}
}

Matthew

> Hi there,
>
> I am trying to learn databinding and I have run into following problem:
> I have a tree displayed in a TreeViewer (with databinding):
>
> Account
> +- Folder
>
> Now, Folder has messages, and I would like to show only the number of
> messages in the Folder:
> Account
> +- Folder (4)
>
> Then I populate messages in the background job and the Folder label is
> *not* updated.
>
> I use the code found somewhere in examples
> (TreeStructureAdvisor/IObservableFactory).
>
> How can I update the label of Folder when its observered message list
> changes?
>
> TIA
> Chris
>
Re: [databinding] TreeViewer [message #331067 is a reply to message #331042] Fri, 22 August 2008 19:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: krzysztof.daniel.gmail.com

Thank you, thank you, thank you!
I was able to achieve the goal but I had to modify slightly your code,
basically because I had to support different objects (attached below).

The only sad thing is that you have access only to ViewerLabel and you
cannot use styled labels... any idea? should I open RFE?

Regards,
Chris


public class ServersLabelProvider extends ListeningLabelProvider {

public ServersLabelProvider(IObservableSet itemsThatNeedLabels) {
super(itemsThatNeedLabels);
}

public String prepareText(Object element) {
if (element instanceof ServerManager) {
return "Mail accounts";
}
if (element instanceof Server) {
return ((Server) element).getName();
}
if (element instanceof Folder) {
return ((Folder) element).getName() + " "
+ ((Folder) element).getMessages().size();
}
return null;
}

Adapter adapter;

@Override
protected void addListenerTo(Object next) {
if (adapter == null) {
if (next instanceof Folder) {
adapter = new Adapter() {

@Override
public Notifier getTarget() {
return null;
}

@Override
public boolean isAdapterForType(Object type) {
return true;
}

@Override
public void notifyChanged(final Notification notification) {
Display.getDefault().syncExec(new Runnable(){

@Override
public void run() {
fireChangeEvent(Collections.singleton(notification
.getNotifier()));
}

});

}

@Override
public void setTarget(Notifier newTarget) {

}

};
((Folder) next).eAdapters().add(adapter);
}
}
}

@Override
protected void removeListenerFrom(Object next) {
if (adapter != null && next instanceof Folder) {
((Folder) next).eAdapters().remove(adapter);
}
}

public void updateLabel(ViewerLabel label, Object element) {
label.setText(prepareText(element));
}

}


On Thu, 2008-08-21 at 15:18 -0700, Matthew Hall wrote:
> You need two things: the Folder object must fire some sort of change
> event, and you need an observable capable of receiving those event
> dispatches.
>
> For your situation, I recommend extending ListeningLabelProvider. You
> will have to implement the addListenerTo() and removeListenerFrom()
> methods, and you will likely want to reimplement the updateLabel()
> method as well.
>
> class FolderLabelProvider extends ListeningLabelProvider {
> public FolderLabelProvider(IObservableSet knownElements) {
> super(knownElements);
> }
>
> // Must lazy init because addListenerTo is called by superconstructor
> PropertyChangeListener listener;
>
> protected void addListenerTo(Object o) {
> if (listener == null) {
> listener = new PropertyChangeListener() {
> public void propertyChanged(PropertyChangeEvent e) {
> // If properties may be changed in another thread, you may
> // have to wrap this method call in a Realm.asyncExec()
> fireChangeEvent(Collections.singleton(e.getSource()));
> }
> }
> }
> ((Folder)o).addPropertyChangeListener(listener);
> }
>
> protected void removeListenerFrom(Object o) {
> if (listener != null) {
> ((Folder)o).removePropertyChangeListener(listener);
> }
> }
>
> public void updateLabel(ViewerLabel label, Object element) {
> Folder folder = (Folder) element;
> String text = folder.getLabel();
> if (folder.getUnreadItemCount() > 0)
> text = text + " ("+folder.getUnreadItemCount()+")";
> label.setText(text);
> }
> }
>
> Matthew
>
> > Hi there,
> >
> > I am trying to learn databinding and I have run into following problem:
> > I have a tree displayed in a TreeViewer (with databinding):
> >
> > Account
> > +- Folder
> >
> > Now, Folder has messages, and I would like to show only the number of
> > messages in the Folder:
> > Account
> > +- Folder (4)
> >
> > Then I populate messages in the background job and the Folder label is
> > *not* updated.
> >
> > I use the code found somewhere in examples
> > (TreeStructureAdvisor/IObservableFactory).
> >
> > How can I update the label of Folder when its observered message list
> > changes?
> >
> > TIA
> > Chris
> >
Re: Trouble with lots of data , Swt Tables and DataBinding [message #331078 is a reply to message #331021] Sat, 23 August 2008 11:23 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
could you provide a test-case and add a snippet for us to reproduce the
faulty behaviour? Then please file a bug and attach me to it tom.schindl
(at)bestsolution.at.

Tom

Nelson Fernando schrieb:
> Hi to everyone , IŽm having some trouble when using databing into SWT tables
> .
>
> The binding works , but I have a large amount of data ( 600 rows , each with
> 25 colums ) , the table takes 1 hole minute to get ready for presentation
> .
> Then I started looking for a solution and end up up the virtual table , but
> it didnŽt change a thing it still took a lot of time to load the table .
> But when I removed the databinding of the table and inserted the itens by
> hand ( one by one ) using tableItens , it was faster than a split second .
>
> Is this a know issue in table databinding ? Is there another solution ? Did
> I post this in the right forum ?
>
> thanks in advance
>
>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Previous Topic:Writing to the Eclipse Log
Next Topic:Obtaining an IResource from a fully qualified class name
Goto Forum:
  


Current Time: Fri Dec 27 16:29:21 GMT 2024

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

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

Back to the top