Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Remove button from TableViewer Item
Remove button from TableViewer Item [message #325501] Wed, 20 February 2008 13:54 Go to next message
Oelerink is currently offline OelerinkFriend
Messages: 129
Registered: July 2009
Senior Member
Hello,

i have an TableViewer with Button on some cells. The following code
creates them for me.

for(int i =0; i<items.length;i++) {
TableItem item = items[i];
TableEditor editor = new TableEditor(table);
Button button = new Button(table, SWT.PUSH);
button.setText("add");
button.pack();
editor.minimumWidth = button.getSize().x;
editor.horizontalAlignment = SWT.LEFT;
editor.setEditor(button, item, Layer.getMaxColumn());
buttonListener BL = new buttonListener(i);
button.addSelectionListener(BL);
}

Now i change the number of columns in my view. Here i want to remove
these "old" buttons from the cells. How can i do this?
viewer.getTable.clearAll() removes only the text from the cells, but not
the buttons. And the javadoc from item and table doesn't really helped
me here.

Greetrings
Re: Remove button from TableViewer Item [message #325503 is a reply to message #325501] Wed, 20 February 2008 15:05 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You need to dispose the editor for the item. The best idea IMHO is to
install a dispose listener on the item and dispose the Editor if the
item is diposed.

Activating multiple editors will eat up your native handles you are
running into resource problems. That's why I normally suggest not to use
multiple editors at once but fake the button using an image which can be
reused. It by the way doesn't look good if your application runs on OS-X
because buttons there can not be made small than a certain size!

Tom

Jörg schrieb:
> Hello,
>
> i have an TableViewer with Button on some cells. The following code
> creates them for me.
>
> for(int i =0; i<items.length;i++) {
> TableItem item = items[i];
> TableEditor editor = new TableEditor(table);
> Button button = new Button(table, SWT.PUSH);
> button.setText("add");
> button.pack();
> editor.minimumWidth = button.getSize().x;
> editor.horizontalAlignment = SWT.LEFT;
> editor.setEditor(button, item, Layer.getMaxColumn());
> buttonListener BL = new buttonListener(i);
> button.addSelectionListener(BL);
> }
>
> Now i change the number of columns in my view. Here i want to remove
> these "old" buttons from the cells. How can i do this?
> viewer.getTable.clearAll() removes only the text from the cells, but not
> the buttons. And the javadoc from item and table doesn't really helped
> me here.
>
> Greetrings


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Remove button from TableViewer Item [message #325524 is a reply to message #325503] Thu, 21 February 2008 05:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: chinfo.michiganreview.org

This is a multi-part message in MIME format.
--------------070201090400040805010609
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit

Hello,

I'm having a similar problem, but disposing of the editor didn't seem to
do the trick. Any thoughts on what I'm missing?

In my case, I remove elements from the model, refresh the TableViewer,
get a reduced number of cell labels, but the original set of native
controls remain in the viewer.

I've copied the pertinent code below, and attached the full class
(adapted from the ExampleTableViewerWithNativeControls snippet).

Thanks in advance for your help.

-Christoph

------------------------------------------------

final TableEditor editor = new TableEditor(item.getParent());
Composite comp = new Composite(item.getParent(),SWT.NONE);
comp.setBackground(item.getParent().getBackground());
comp.setBackgroundMode(SWT.INHERIT_DEFAULT);
RowLayout l = new RowLayout();
l.marginHeight=0;
l.marginWidth=0;
l.marginTop=0;
l.marginBottom=0;
comp.setLayout(l);
Button button = new Button(comp, SWT.PUSH);

button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
System.out.println("Selection Event on: " + item);
}
});
button.setText("Push Me");
item.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
editor.dispose();
}
});

editor.grabHorizontal=true;
editor.setEditor(comp, item, 1);



Tom Schindl wrote:
> You need to dispose the editor for the item. The best idea IMHO is to
> install a dispose listener on the item and dispose the Editor if the
> item is diposed.
>
> Activating multiple editors will eat up your native handles you are
> running into resource problems. That's why I normally suggest not to use
> multiple editors at once but fake the button using an image which can be
> reused. It by the way doesn't look good if your application runs on OS-X
> because buttons there can not be made small than a certain size!
>
> Tom
>
> J
Re: Remove button from TableViewer Item [message #325531 is a reply to message #325524] Thu, 21 February 2008 08:43 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
It seems that you also have to dipose the underlying control:

editor.getEditor().dispose();

Tom

Christoph Hoashi-Erhardt schrieb:
> Hello,
>
> I'm having a similar problem, but disposing of the editor didn't seem to
> do the trick. Any thoughts on what I'm missing?
>
> In my case, I remove elements from the model, refresh the TableViewer,
> get a reduced number of cell labels, but the original set of native
> controls remain in the viewer.
>
> I've copied the pertinent code below, and attached the full class
> (adapted from the ExampleTableViewerWithNativeControls snippet).
>
> Thanks in advance for your help.
>
> -Christoph
>
> ------------------------------------------------
>
> final TableEditor editor = new TableEditor(item.getParent());
> Composite comp = new Composite(item.getParent(),SWT.NONE);
>
> comp.setBackground(item.getParent().getBackground());
> comp.setBackgroundMode(SWT.INHERIT_DEFAULT);
> RowLayout l = new RowLayout();
> l.marginHeight=0;
> l.marginWidth=0;
> l.marginTop=0;
> l.marginBottom=0;
> comp.setLayout(l);
> Button button = new Button(comp, SWT.PUSH);
>
> button.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> System.out.println("Selection Event on: " + item);
> }
> });
> button.setText("Push Me");
> item.addDisposeListener(new DisposeListener() {
> public void widgetDisposed(DisposeEvent event) {
> editor.dispose();
> }
> });
>
> editor.grabHorizontal=true;
> editor.setEditor(comp, item, 1);
>
>
>
> Tom Schindl wrote:
>> You need to dispose the editor for the item. The best idea IMHO is to
>> install a dispose listener on the item and dispose the Editor if the
>> item is diposed.
>>
>> Activating multiple editors will eat up your native handles you are
>> running into resource problems. That's why I normally suggest not to
>> use multiple editors at once but fake the button using an image which
>> can be reused. It by the way doesn't look good if your application
>> runs on OS-X because buttons there can not be made small than a
>> certain size!
>>
>> Tom
>>
>> Jörg schrieb:
>>> Hello,
>>>
>>> i have an TableViewer with Button on some cells. The following code
>>> creates them for me.
>>>
>>> for(int i =0; i<items.length;i++) {
>>> TableItem item = items[i];
>>> TableEditor editor = new TableEditor(table);
>>> Button button = new Button(table, SWT.PUSH);
>>> button.setText("add");
>>> button.pack();
>>> editor.minimumWidth = button.getSize().x;
>>> editor.horizontalAlignment = SWT.LEFT;
>>> editor.setEditor(button, item, Layer.getMaxColumn());
>>> buttonListener BL = new buttonListener(i);
>>> button.addSelectionListener(BL);
>>> }
>>>
>>> Now i change the number of columns in my view. Here i want to remove
>>> these "old" buttons from the cells. How can i do this?
>>> viewer.getTable.clearAll() removes only the text from the cells, but
>>> not the buttons. And the javadoc from item and table doesn't really
>>> helped me here.
>>>
>>> Greetrings
>>
>>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Remove button from TableViewer Item [message #325535 is a reply to message #325531] Thu, 21 February 2008 10:21 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

I've updated the snippet to dispose the created editors when needed.

Tom

Tom Schindl schrieb:
> It seems that you also have to dipose the underlying control:
>
> editor.getEditor().dispose();
>
> Tom
>
> Christoph Hoashi-Erhardt schrieb:
>> Hello,
>>
>> I'm having a similar problem, but disposing of the editor didn't seem
>> to do the trick. Any thoughts on what I'm missing?
>>
>> In my case, I remove elements from the model, refresh the TableViewer,
>> get a reduced number of cell labels, but the original set of native
>> controls remain in the viewer.
>>
>> I've copied the pertinent code below, and attached the full class
>> (adapted from the ExampleTableViewerWithNativeControls snippet).
>>
>> Thanks in advance for your help.
>>
>> -Christoph
>>
>> ------------------------------------------------
>>
>> final TableEditor editor = new TableEditor(item.getParent());
>> Composite comp = new Composite(item.getParent(),SWT.NONE);
>>
>> comp.setBackground(item.getParent().getBackground());
>> comp.setBackgroundMode(SWT.INHERIT_DEFAULT);
>> RowLayout l = new RowLayout();
>> l.marginHeight=0;
>> l.marginWidth=0;
>> l.marginTop=0;
>> l.marginBottom=0;
>> comp.setLayout(l);
>> Button button = new Button(comp, SWT.PUSH);
>> button.addSelectionListener(new SelectionAdapter() {
>> public void widgetSelected(SelectionEvent event) {
>> System.out.println("Selection Event on: " + item);
>> }
>> });
>> button.setText("Push Me");
>> item.addDisposeListener(new DisposeListener() {
>> public void widgetDisposed(DisposeEvent event) {
>> editor.dispose();
>> }
>> });
>> editor.grabHorizontal=true;
>> editor.setEditor(comp, item, 1);
>>
>>
>>
>> Tom Schindl wrote:
>>> You need to dispose the editor for the item. The best idea IMHO is to
>>> install a dispose listener on the item and dispose the Editor if the
>>> item is diposed.
>>>
>>> Activating multiple editors will eat up your native handles you are
>>> running into resource problems. That's why I normally suggest not to
>>> use multiple editors at once but fake the button using an image which
>>> can be reused. It by the way doesn't look good if your application
>>> runs on OS-X because buttons there can not be made small than a
>>> certain size!
>>>
>>> Tom
>>>
>>> Jörg schrieb:
>>>> Hello,
>>>>
>>>> i have an TableViewer with Button on some cells. The following code
>>>> creates them for me.
>>>>
>>>> for(int i =0; i<items.length;i++) {
>>>> TableItem item = items[i];
>>>> TableEditor editor = new TableEditor(table);
>>>> Button button = new Button(table, SWT.PUSH);
>>>> button.setText("add");
>>>> button.pack();
>>>> editor.minimumWidth = button.getSize().x;
>>>> editor.horizontalAlignment = SWT.LEFT;
>>>> editor.setEditor(button, item, Layer.getMaxColumn());
>>>> buttonListener BL = new buttonListener(i);
>>>> button.addSelectionListener(BL);
>>>> }
>>>>
>>>> Now i change the number of columns in my view. Here i want to remove
>>>> these "old" buttons from the cells. How can i do this?
>>>> viewer.getTable.clearAll() removes only the text from the cells, but
>>>> not the buttons. And the javadoc from item and table doesn't really
>>>> helped me here.
>>>>
>>>> Greetrings
>>>
>>>
>>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Remove button from TableViewer Item [message #325537 is a reply to message #325503] Thu, 21 February 2008 10:56 Go to previous messageGo to next message
Oelerink is currently offline OelerinkFriend
Messages: 129
Registered: July 2009
Senior Member
I need only five editors at maximum maybe ten. So now i take those
editors in a array and set them to the new TableItem. Thanks for your
help again. It helps a lot :)

Tom Schindl schrieb:
> You need to dispose the editor for the item. The best idea IMHO is to
> install a dispose listener on the item and dispose the Editor if the
> item is diposed.
>
> Activating multiple editors will eat up your native handles you are
> running into resource problems. That's why I normally suggest not to use
> multiple editors at once but fake the button using an image which can be
> reused. It by the way doesn't look good if your application runs on OS-X
> because buttons there can not be made small than a certain size!
>
> Tom
>
> Jörg schrieb:
>> Hello,
>>
>> i have an TableViewer with Button on some cells. The following code
>> creates them for me.
>>
>> for(int i =0; i<items.length;i++) {
>> TableItem item = items[i];
>> TableEditor editor = new TableEditor(table);
>> Button button = new Button(table, SWT.PUSH);
>> button.setText("add");
>> button.pack();
>> editor.minimumWidth = button.getSize().x;
>> editor.horizontalAlignment = SWT.LEFT;
>> editor.setEditor(button, item, Layer.getMaxColumn());
>> buttonListener BL = new buttonListener(i);
>> button.addSelectionListener(BL);
>> }
>>
>> Now i change the number of columns in my view. Here i want to remove
>> these "old" buttons from the cells. How can i do this?
>> viewer.getTable.clearAll() removes only the text from the cells, but
>> not the buttons. And the javadoc from item and table doesn't really
>> helped me here.
>>
>> Greetrings
>
>
Re: Remove button from TableViewer Item [message #325563 is a reply to message #325535] Fri, 22 February 2008 03:48 Go to previous message
Christoph is currently offline ChristophFriend
Messages: 55
Registered: July 2009
Member
Thanks so much for your help.

-Christoph

Tom Schindl wrote:
> Hi,
>
> I've updated the snippet to dispose the created editors when needed.
>
> Tom
>
> Tom Schindl schrieb:
>> It seems that you also have to dipose the underlying control:
>>
>> editor.getEditor().dispose();
>>
>> Tom
>>
>> Christoph Hoashi-Erhardt schrieb:
>>> Hello,
>>>
>>> I'm having a similar problem, but disposing of the editor didn't seem
>>> to do the trick. Any thoughts on what I'm missing?
>>>
>>> In my case, I remove elements from the model, refresh the
>>> TableViewer, get a reduced number of cell labels, but the original
>>> set of native controls remain in the viewer.
>>>
>>> I've copied the pertinent code below, and attached the full class
>>> (adapted from the ExampleTableViewerWithNativeControls snippet).
>>>
>>> Thanks in advance for your help.
>>>
>>> -Christoph
>>>
>>> ------------------------------------------------
>>>
>>> final TableEditor editor = new TableEditor(item.getParent());
>>> Composite comp = new Composite(item.getParent(),SWT.NONE);
>>>
>>> comp.setBackground(item.getParent().getBackground());
>>> comp.setBackgroundMode(SWT.INHERIT_DEFAULT);
>>> RowLayout l = new RowLayout();
>>> l.marginHeight=0;
>>> l.marginWidth=0;
>>> l.marginTop=0;
>>> l.marginBottom=0;
>>> comp.setLayout(l);
>>> Button button = new Button(comp, SWT.PUSH);
>>> button.addSelectionListener(new SelectionAdapter() {
>>> public void widgetSelected(SelectionEvent event) {
>>> System.out.println("Selection Event on: " + item);
>>> }
>>> });
>>> button.setText("Push Me");
>>> item.addDisposeListener(new DisposeListener() {
>>> public void widgetDisposed(DisposeEvent event) {
>>> editor.dispose();
>>> }
>>> });
>>> editor.grabHorizontal=true;
>>> editor.setEditor(comp, item, 1);
>>>
>>>
>>>
>>> Tom Schindl wrote:
>>>> You need to dispose the editor for the item. The best idea IMHO is
>>>> to install a dispose listener on the item and dispose the Editor if
>>>> the item is diposed.
>>>>
>>>> Activating multiple editors will eat up your native handles you are
>>>> running into resource problems. That's why I normally suggest not to
>>>> use multiple editors at once but fake the button using an image
>>>> which can be reused. It by the way doesn't look good if your
>>>> application runs on OS-X because buttons there can not be made small
>>>> than a certain size!
>>>>
>>>> Tom
>>>>
>>>> Jörg schrieb:
>>>>> Hello,
>>>>>
>>>>> i have an TableViewer with Button on some cells. The following code
>>>>> creates them for me.
>>>>>
>>>>> for(int i =0; i<items.length;i++) {
>>>>> TableItem item = items[i];
>>>>> TableEditor editor = new TableEditor(table);
>>>>> Button button = new Button(table, SWT.PUSH);
>>>>> button.setText("add");
>>>>> button.pack();
>>>>> editor.minimumWidth = button.getSize().x;
>>>>> editor.horizontalAlignment = SWT.LEFT;
>>>>> editor.setEditor(button, item, Layer.getMaxColumn());
>>>>> buttonListener BL = new buttonListener(i);
>>>>> button.addSelectionListener(BL);
>>>>> }
>>>>>
>>>>> Now i change the number of columns in my view. Here i want to
>>>>> remove these "old" buttons from the cells. How can i do this?
>>>>> viewer.getTable.clearAll() removes only the text from the cells,
>>>>> but not the buttons. And the javadoc from item and table doesn't
>>>>> really helped me here.
>>>>>
>>>>> Greetrings
>>>>
>>>>
>>>
>>
>>
>
>
Previous Topic:Irregular expressions?
Next Topic:getting IResource objects for all files in an IResource directory
Goto Forum:
  


Current Time: Sat Nov 09 03:29:49 GMT 2024

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

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

Back to the top