Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Table with SWT.CHECK style
Table with SWT.CHECK style [message #450717] Wed, 16 February 2005 19:22 Go to next message
Ross is currently offline RossFriend
Messages: 4
Registered: July 2009
Junior Member
Hi,

I am working with the Table and TableViewer classes to display records to a
user. I passed the SWT.CHECK to the constructor to get the checkbox in the
first column of the table. My question is how do I gain access to the
checkbox widget. I need access to the check box to be able to enable/disable
this check box depending on the data in the table. How would I go about
doing this?

Thanks,

Ross Camara
Re: Table with SWT.CHECK style [message #450723 is a reply to message #450717] Thu, 17 February 2005 00:49 Go to previous messageGo to next message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
Hi,

I use the below and it works like a charm...

int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.CHECK;

checkTableViewer = CheckboxTableViewer.newCheckList(parentComposite, style);

The above gives me a check table viewer.

Now install check event on the table viewer

checkTableViewer.addCheckStateListener(new ICheckStateListener()
{
public void checkStateChanged(CheckStateChangedEvent e)
{
onCheckStateChanged(e);
}
});

Here is how to implement on onCheckStateChanged(...)

public void onCheckStateChanged(CheckStateChangedEvent e)
{
// The source is simply our checkbox table viewer
CheckboxTableViewer source =
(CheckboxTableViewer)e.getSource();

// Get the element that just got checked/unchecked
MyElementData data = (MyElementData)e.getElement();

// Your 'MyElementData' class should have a flag as a data
// member that toggles its state whether being turned on/off.
// Assuming you have the methods 'MyElementData.setFlag()' and
// 'MyElementData.getFlag()', which returns a boolean.

// Here is how to make sure it's checked for viewer!
if (MyElementData.getFlag() == false)
MyElementData.setFlag(true);
else MyElementData.setFlag(false);

// The above if...else is the same as this--a toggle:
// MyElementData.setFlag(!MyElementData.getFlag());

// Tell the viewer to check it!
source.setChecked(data, MyElementData.getFlag());

// Also, you can get all the checked elements by doing this:
// Object[] checkedItems = source.getCheckedElements().
// The elements are your model data, i.e., MyElementData.
// Eclipse lets you use set the check state via your model
// data! That's cool, because you won't have to worry about
// what the index into rows, etc! This is true OO programming!


}

Ross Camara wrote:

> Hi,
>
> I am working with the Table and TableViewer classes to display records to a
> user. I passed the SWT.CHECK to the constructor to get the checkbox in the
> first column of the table. My question is how do I gain access to the
> checkbox widget. I need access to the check box to be able to enable/disable
> this check box depending on the data in the table. How would I go about
> doing this?
>
> Thanks,
>
> Ross Camara
>
>
Re: Table with SWT.CHECK style [message #450740 is a reply to message #450723] Thu, 17 February 2005 14:31 Go to previous messageGo to next message
Ross is currently offline RossFriend
Messages: 4
Registered: July 2009
Junior Member
Thanks. I definetly missed the CheckboxTableViewer class. I've been
experimenting with it and for some reason when i set the grayed state to
true on a node only the check in the checkbox is grayed. The checkbox itself
does not apear 'grayed out'. Does anyone know if this is intentional or a
bug? In either case does anyone know how make that checkbox apear disabled?

Ross

"AL" <unbonnevie@yahoo.com> wrote in message
news:cv0pd9$pba$1@www.eclipse.org...
> Hi,
>
> I use the below and it works like a charm...
>
> int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
> SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.CHECK;
>
> checkTableViewer = CheckboxTableViewer.newCheckList(parentComposite,
style);
>
> The above gives me a check table viewer.
>
> Now install check event on the table viewer
>
> checkTableViewer.addCheckStateListener(new ICheckStateListener()
> {
> public void checkStateChanged(CheckStateChangedEvent e)
> {
> onCheckStateChanged(e);
> }
> });
>
> Here is how to implement on onCheckStateChanged(...)
>
> public void onCheckStateChanged(CheckStateChangedEvent e)
> {
> // The source is simply our checkbox table viewer
> CheckboxTableViewer source =
> (CheckboxTableViewer)e.getSource();
>
> // Get the element that just got checked/unchecked
> MyElementData data = (MyElementData)e.getElement();
>
> // Your 'MyElementData' class should have a flag as a data
> // member that toggles its state whether being turned on/off.
> // Assuming you have the methods 'MyElementData.setFlag()' and
> // 'MyElementData.getFlag()', which returns a boolean.
>
> // Here is how to make sure it's checked for viewer!
> if (MyElementData.getFlag() == false)
> MyElementData.setFlag(true);
> else MyElementData.setFlag(false);
>
> // The above if...else is the same as this--a toggle:
> // MyElementData.setFlag(!MyElementData.getFlag());
>
> // Tell the viewer to check it!
> source.setChecked(data, MyElementData.getFlag());
>
> // Also, you can get all the checked elements by doing this:
> // Object[] checkedItems = source.getCheckedElements().
> // The elements are your model data, i.e., MyElementData.
> // Eclipse lets you use set the check state via your model
> // data! That's cool, because you won't have to worry about
> // what the index into rows, etc! This is true OO programming!
>
>
> }
>
> Ross Camara wrote:
>
> > Hi,
> >
> > I am working with the Table and TableViewer classes to display records
to a
> > user. I passed the SWT.CHECK to the constructor to get the checkbox in
the
> > first column of the table. My question is how do I gain access to the
> > checkbox widget. I need access to the check box to be able to
enable/disable
> > this check box depending on the data in the table. How would I go about
> > doing this?
> >
> > Thanks,
> >
> > Ross Camara
> >
> >
>
Re: Table with SWT.CHECK style [message #450761 is a reply to message #450740] Thu, 17 February 2005 18:58 Go to previous messageGo to next message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
I believe you can use your own image for the checkbox. So, based on
your graying out it, you can set the image to the grayed out checkbox.

One example of using one's own images for the checkbox is the JDT's
string externalizer. Open a Java file in the JDT with some hardcoded
strings. Then right-click on the file and choose "Source->Externalize
String".

Hope this helps.

Ross Camara wrote:

> Thanks. I definetly missed the CheckboxTableViewer class. I've been
> experimenting with it and for some reason when i set the grayed state to
> true on a node only the check in the checkbox is grayed. The checkbox itself
> does not apear 'grayed out'. Does anyone know if this is intentional or a
> bug? In either case does anyone know how make that checkbox apear disabled?
>
> Ross
>
> "AL" <unbonnevie@yahoo.com> wrote in message
> news:cv0pd9$pba$1@www.eclipse.org...
>
>>Hi,
>>
>>I use the below and it works like a charm...
>>
>>int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
>> SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.CHECK;
>>
>>checkTableViewer = CheckboxTableViewer.newCheckList(parentComposite,
>
> style);
>
>>The above gives me a check table viewer.
>>
>>Now install check event on the table viewer
>>
>>checkTableViewer.addCheckStateListener(new ICheckStateListener()
>>{
>> public void checkStateChanged(CheckStateChangedEvent e)
>> {
>> onCheckStateChanged(e);
>> }
>>});
>>
>>Here is how to implement on onCheckStateChanged(...)
>>
>>public void onCheckStateChanged(CheckStateChangedEvent e)
>>{
>> // The source is simply our checkbox table viewer
>> CheckboxTableViewer source =
>> (CheckboxTableViewer)e.getSource();
>>
>> // Get the element that just got checked/unchecked
>> MyElementData data = (MyElementData)e.getElement();
>>
>> // Your 'MyElementData' class should have a flag as a data
>> // member that toggles its state whether being turned on/off.
>> // Assuming you have the methods 'MyElementData.setFlag()' and
>> // 'MyElementData.getFlag()', which returns a boolean.
>>
>> // Here is how to make sure it's checked for viewer!
>> if (MyElementData.getFlag() == false)
>> MyElementData.setFlag(true);
>> else MyElementData.setFlag(false);
>>
>> // The above if...else is the same as this--a toggle:
>> // MyElementData.setFlag(!MyElementData.getFlag());
>>
>> // Tell the viewer to check it!
>> source.setChecked(data, MyElementData.getFlag());
>>
>> // Also, you can get all the checked elements by doing this:
>> // Object[] checkedItems = source.getCheckedElements().
>> // The elements are your model data, i.e., MyElementData.
>> // Eclipse lets you use set the check state via your model
>> // data! That's cool, because you won't have to worry about
>> // what the index into rows, etc! This is true OO programming!
>>
>>
>>}
>>
>>Ross Camara wrote:
>>
>>
>>>Hi,
>>>
>>>I am working with the Table and TableViewer classes to display records
>
> to a
>
>>>user. I passed the SWT.CHECK to the constructor to get the checkbox in
>
> the
>
>>>first column of the table. My question is how do I gain access to the
>>>checkbox widget. I need access to the check box to be able to
>
> enable/disable
>
>>>this check box depending on the data in the table. How would I go about
>>>doing this?
>>>
>>>Thanks,
>>>
>>>Ross Camara
>>>
>>>
>>
>
>
Re: Table with SWT.CHECK style [message #450763 is a reply to message #450761] Thu, 17 February 2005 20:05 Go to previous messageGo to next message
Ross is currently offline RossFriend
Messages: 4
Registered: July 2009
Junior Member
Thanks that does help. Do you know where the source for the JDT externalize
string wizard is?


Ross

"AL" <unbonnevie@yahoo.com> wrote in message
news:cv2p7c$gvs$1@www.eclipse.org...
> I believe you can use your own image for the checkbox. So, based on
> your graying out it, you can set the image to the grayed out checkbox.
>
> One example of using one's own images for the checkbox is the JDT's
> string externalizer. Open a Java file in the JDT with some hardcoded
> strings. Then right-click on the file and choose "Source->Externalize
> String".
>
> Hope this helps.
>
> Ross Camara wrote:
>
> > Thanks. I definetly missed the CheckboxTableViewer class. I've been
> > experimenting with it and for some reason when i set the grayed state to
> > true on a node only the check in the checkbox is grayed. The checkbox
itself
> > does not apear 'grayed out'. Does anyone know if this is intentional or
a
> > bug? In either case does anyone know how make that checkbox apear
disabled?
> >
> > Ross
> >
> > "AL" <unbonnevie@yahoo.com> wrote in message
> > news:cv0pd9$pba$1@www.eclipse.org...
> >
> >>Hi,
> >>
> >>I use the below and it works like a charm...
> >>
> >>int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
> >> SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.CHECK;
> >>
> >>checkTableViewer = CheckboxTableViewer.newCheckList(parentComposite,
> >
> > style);
> >
> >>The above gives me a check table viewer.
> >>
> >>Now install check event on the table viewer
> >>
> >>checkTableViewer.addCheckStateListener(new ICheckStateListener()
> >>{
> >> public void checkStateChanged(CheckStateChangedEvent e)
> >> {
> >> onCheckStateChanged(e);
> >> }
> >>});
> >>
> >>Here is how to implement on onCheckStateChanged(...)
> >>
> >>public void onCheckStateChanged(CheckStateChangedEvent e)
> >>{
> >> // The source is simply our checkbox table viewer
> >> CheckboxTableViewer source =
> >> (CheckboxTableViewer)e.getSource();
> >>
> >> // Get the element that just got checked/unchecked
> >> MyElementData data = (MyElementData)e.getElement();
> >>
> >> // Your 'MyElementData' class should have a flag as a data
> >> // member that toggles its state whether being turned on/off.
> >> // Assuming you have the methods 'MyElementData.setFlag()' and
> >> // 'MyElementData.getFlag()', which returns a boolean.
> >>
> >> // Here is how to make sure it's checked for viewer!
> >> if (MyElementData.getFlag() == false)
> >> MyElementData.setFlag(true);
> >> else MyElementData.setFlag(false);
> >>
> >> // The above if...else is the same as this--a toggle:
> >> // MyElementData.setFlag(!MyElementData.getFlag());
> >>
> >> // Tell the viewer to check it!
> >> source.setChecked(data, MyElementData.getFlag());
> >>
> >> // Also, you can get all the checked elements by doing this:
> >> // Object[] checkedItems = source.getCheckedElements().
> >> // The elements are your model data, i.e., MyElementData.
> >> // Eclipse lets you use set the check state via your model
> >> // data! That's cool, because you won't have to worry about
> >> // what the index into rows, etc! This is true OO programming!
> >>
> >>
> >>}
> >>
> >>Ross Camara wrote:
> >>
> >>
> >>>Hi,
> >>>
> >>>I am working with the Table and TableViewer classes to display records
> >
> > to a
> >
> >>>user. I passed the SWT.CHECK to the constructor to get the checkbox in
> >
> > the
> >
> >>>first column of the table. My question is how do I gain access to the
> >>>checkbox widget. I need access to the check box to be able to
> >
> > enable/disable
> >
> >>>this check box depending on the data in the table. How would I go about
> >>>doing this?
> >>>
> >>>Thanks,
> >>>
> >>>Ross Camara
> >>>
> >>>
> >>
> >
> >
>
Re: Table with SWT.CHECK style [message #450764 is a reply to message #450763] Thu, 17 February 2005 20:37 Go to previous message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
It's in
<eclipse_root_install_dir> \plugins\org.eclipse.jdt.source_3.0.0\src\org.eclipse.jdt.ui _3.0.0\org\eclipse\jdt\internal\ui\refactoring\nls

The file is ExternalizeWizardPage.java...I am not sure if you are doing
pure SWT or JFace. The above stuff is pretty much JFace.

Hope that helps.


Ross Camara wrote:

> Thanks that does help. Do you know where the source for the JDT externalize
> string wizard is?
>
>
> Ross
>
> "AL" <unbonnevie@yahoo.com> wrote in message
> news:cv2p7c$gvs$1@www.eclipse.org...
>
>>I believe you can use your own image for the checkbox. So, based on
>>your graying out it, you can set the image to the grayed out checkbox.
>>
>>One example of using one's own images for the checkbox is the JDT's
>>string externalizer. Open a Java file in the JDT with some hardcoded
>>strings. Then right-click on the file and choose "Source->Externalize
>>String".
>>
>>Hope this helps.
>>
>>Ross Camara wrote:
>>
>>
>>>Thanks. I definetly missed the CheckboxTableViewer class. I've been
>>>experimenting with it and for some reason when i set the grayed state to
>>>true on a node only the check in the checkbox is grayed. The checkbox
>
> itself
>
>>>does not apear 'grayed out'. Does anyone know if this is intentional or
>
> a
>
>>>bug? In either case does anyone know how make that checkbox apear
>
> disabled?
>
>>>Ross
>>>
>>>"AL" <unbonnevie@yahoo.com> wrote in message
>>>news:cv0pd9$pba$1@www.eclipse.org...
>>>
>>>
>>>>Hi,
>>>>
>>>>I use the below and it works like a charm...
>>>>
>>>>int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
>>>> SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.CHECK;
>>>>
>>>>checkTableViewer = CheckboxTableViewer.newCheckList(parentComposite,
>>>
>>>style);
>>>
>>>
>>>>The above gives me a check table viewer.
>>>>
>>>>Now install check event on the table viewer
>>>>
>>>>checkTableViewer.addCheckStateListener(new ICheckStateListener()
>>>>{
>>>> public void checkStateChanged(CheckStateChangedEvent e)
>>>> {
>>>> onCheckStateChanged(e);
>>>> }
>>>>});
>>>>
>>>>Here is how to implement on onCheckStateChanged(...)
>>>>
>>>>public void onCheckStateChanged(CheckStateChangedEvent e)
>>>>{
>>>> // The source is simply our checkbox table viewer
>>>> CheckboxTableViewer source =
>>>> (CheckboxTableViewer)e.getSource();
>>>>
>>>> // Get the element that just got checked/unchecked
>>>> MyElementData data = (MyElementData)e.getElement();
>>>>
>>>> // Your 'MyElementData' class should have a flag as a data
>>>> // member that toggles its state whether being turned on/off.
>>>> // Assuming you have the methods 'MyElementData.setFlag()' and
>>>> // 'MyElementData.getFlag()', which returns a boolean.
>>>>
>>>> // Here is how to make sure it's checked for viewer!
>>>> if (MyElementData.getFlag() == false)
>>>> MyElementData.setFlag(true);
>>>> else MyElementData.setFlag(false);
>>>>
>>>> // The above if...else is the same as this--a toggle:
>>>> // MyElementData.setFlag(!MyElementData.getFlag());
>>>>
>>>> // Tell the viewer to check it!
>>>> source.setChecked(data, MyElementData.getFlag());
>>>>
>>>> // Also, you can get all the checked elements by doing this:
>>>> // Object[] checkedItems = source.getCheckedElements().
>>>> // The elements are your model data, i.e., MyElementData.
>>>> // Eclipse lets you use set the check state via your model
>>>> // data! That's cool, because you won't have to worry about
>>>> // what the index into rows, etc! This is true OO programming!
>>>>
>>>>
>>>>}
>>>>
>>>>Ross Camara wrote:
>>>>
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>I am working with the Table and TableViewer classes to display records
>>>
>>>to a
>>>
>>>
>>>>>user. I passed the SWT.CHECK to the constructor to get the checkbox in
>>>
>>>the
>>>
>>>
>>>>>first column of the table. My question is how do I gain access to the
>>>>>checkbox widget. I need access to the check box to be able to
>>>
>>>enable/disable
>>>
>>>
>>>>>this check box depending on the data in the table. How would I go about
>>>>>doing this?
>>>>>
>>>>>Thanks,
>>>>>
>>>>>Ross Camara
>>>>>
>>>>>
>>>>
>>>
>
>
Previous Topic:Slider and Infinite Loop
Next Topic:Korean characters in text files?
Goto Forum:
  


Current Time: Thu Apr 25 22:58:12 GMT 2024

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

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

Back to the top