Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Tables and Checkboxes
Tables and Checkboxes [message #333750] Wed, 31 December 2008 18:44 Go to next message
Andy is currently offline AndyFriend
Messages: 47
Registered: July 2009
Member
I have a table that I have created like the following:

Table table (myComposite, SWT.BORDER | SWT.MULTI);

// Make the columns
for (int i=0; i<6, i++){
TableColumn column = new TableColumn(table, SWT.NONE);
}

//Make the rows
for(int k=0; k<myArrayList.size(); k++){
new TableItem(table, SWT.NONE);
}

TableItem[] items = table.getItems();

for(int j=0; j<items.length; j++){
TableEditor editor = new TableEditor(table);
Button button = new Button(table, SWT.CHECK);
button.setText(myArrayList.get(j).toString());
button.pack();
editor.setEditor(button, items[j], 0);

editor = new TableEditor(table);
Button button2 = new Button(table, SWT.CHECK);
button2.setText(anotherArrayList.get(j).toString());
button2.pack();
editor.setEditor(button2, items[j], 1);

}

This displays how I would like it to display, basically a big 2 d array of
checkboxes. The issue that I am having is how do I go back into the table
to see what checkboxes have been checked and what ones haven't? I can't
seem to figure out how I would do that. To give it context, this grid is
going to display permissions for users and groups.

If there is a better way of creating a table or displaying a grid of
checkboxes and then managing their state please let me know. Thanks!

Andy
Re: Tables and Checkboxes [message #333755 is a reply to message #333750] Fri, 02 January 2009 11:55 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

You better use a TableViewer and emulated checkboxes because this
reduces the amount of memory and you have then backed up your states in
a model element.

Take a look at
http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls

Tom

Andy schrieb:
> I have a table that I have created like the following:
>
> Table table (myComposite, SWT.BORDER | SWT.MULTI);
>
> // Make the columns
> for (int i=0; i<6, i++){
> TableColumn column = new TableColumn(table, SWT.NONE);
> }
>
> //Make the rows
> for(int k=0; k<myArrayList.size(); k++){
> new TableItem(table, SWT.NONE);
> }
>
> TableItem[] items = table.getItems();
>
> for(int j=0; j<items.length; j++){
> TableEditor editor = new TableEditor(table);
> Button button = new Button(table, SWT.CHECK);
> button.setText(myArrayList.get(j).toString());
> button.pack();
> editor.setEditor(button, items[j], 0);
>
> editor = new TableEditor(table);
> Button button2 = new Button(table, SWT.CHECK);
> button2.setText(anotherArrayList.get(j).toString());
> button2.pack();
> editor.setEditor(button2, items[j], 1);
>
> }
>
> This displays how I would like it to display, basically a big 2 d array
> of checkboxes. The issue that I am having is how do I go back into the
> table to see what checkboxes have been checked and what ones haven't? I
> can't seem to figure out how I would do that. To give it context, this
> grid is going to display permissions for users and groups.
> If there is a better way of creating a table or displaying a grid of
> checkboxes and then managing their state please let me know. Thanks!
>
> Andy
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Tables and Checkboxes [message #333779 is a reply to message #333755] Mon, 05 January 2009 15:59 Go to previous messageGo to next message
Andy is currently offline AndyFriend
Messages: 47
Registered: July 2009
Member
Thanks for the info. I took a look at

http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls

I am still confused as to which option you are referred to as "emulated
checkboxes" because it seemed like all those articles had to do with
displaying items in a table and item visibility, not capturing the values
of the checkboxes. I can display all the items just fine with the current
code.

Was there an option out of the 5 on that page that covered this question?
I looked at them but didn't seem to find any.

Do you know of an example that displays multiple checkboxes in a table and
also has code to track the state of all of them? Thanks.

Andy


Tom Schindl wrote:

> Hi,

> You better use a TableViewer and emulated checkboxes because this
> reduces the amount of memory and you have then backed up your states in
> a model element.

> Take a look at
> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls

> Tom

> Andy schrieb:
>> I have a table that I have created like the following:
>>
>> Table table (myComposite, SWT.BORDER | SWT.MULTI);
>>
>> // Make the columns
>> for (int i=0; i<6, i++){
>> TableColumn column = new TableColumn(table, SWT.NONE);
>> }
>>
>> //Make the rows
>> for(int k=0; k<myArrayList.size(); k++){
>> new TableItem(table, SWT.NONE);
>> }
>>
>> TableItem[] items = table.getItems();
>>
>> for(int j=0; j<items.length; j++){
>> TableEditor editor = new TableEditor(table);
>> Button button = new Button(table, SWT.CHECK);
>> button.setText(myArrayList.get(j).toString());
>> button.pack();
>> editor.setEditor(button, items[j], 0);
>>
>> editor = new TableEditor(table);
>> Button button2 = new Button(table, SWT.CHECK);
>> button2.setText(anotherArrayList.get(j).toString());
>> button2.pack();
>> editor.setEditor(button2, items[j], 1);
>>
>> }
>>
>> This displays how I would like it to display, basically a big 2 d array
>> of checkboxes. The issue that I am having is how do I go back into the
>> table to see what checkboxes have been checked and what ones haven't? I
>> can't seem to figure out how I would do that. To give it context, this
>> grid is going to display permissions for users and groups.
>> If there is a better way of creating a table or displaying a grid of
>> checkboxes and then managing their state please let me know. Thanks!
>>
>> Andy
>>
Re: Tables and Checkboxes [message #333780 is a reply to message #333779] Mon, 05 January 2009 16:33 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Well if you take:
a) http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet056BooleanCellEditor.java?view=markup
and
b) http://tom-eclipse-dev.blogspot.com/2007/01/tableviewers-and -nativelooking.html

You are best of when checking out the code from the cvs-repository.

Tom

Andy schrieb:
> Thanks for the info. I took a look at
> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>
> I am still confused as to which option you are referred to as "emulated
> checkboxes" because it seemed like all those articles had to do with
> displaying items in a table and item visibility, not capturing the
> values of the checkboxes. I can display all the items just fine with
> the current code.
> Was there an option out of the 5 on that page that covered this
> question? I looked at them but didn't seem to find any.
>
> Do you know of an example that displays multiple checkboxes in a table
> and also has code to track the state of all of them? Thanks.
>
> Andy
>
>
> Tom Schindl wrote:
>
>> Hi,
>
>> You better use a TableViewer and emulated checkboxes because this
>> reduces the amount of memory and you have then backed up your states in
>> a model element.
>
>> Take a look at
>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>
>> Tom
>
>> Andy schrieb:
>>> I have a table that I have created like the following:
>>>
>>> Table table (myComposite, SWT.BORDER | SWT.MULTI);
>>>
>>> // Make the columns
>>> for (int i=0; i<6, i++){
>>> TableColumn column = new TableColumn(table, SWT.NONE);
>>> }
>>>
>>> //Make the rows
>>> for(int k=0; k<myArrayList.size(); k++){
>>> new TableItem(table, SWT.NONE);
>>> }
>>>
>>> TableItem[] items = table.getItems();
>>>
>>> for(int j=0; j<items.length; j++){
>>> TableEditor editor = new TableEditor(table);
>>> Button button = new Button(table, SWT.CHECK);
>>> button.setText(myArrayList.get(j).toString());
>>> button.pack();
>>> editor.setEditor(button, items[j], 0);
>>>
>>> editor = new TableEditor(table);
>>> Button button2 = new Button(table, SWT.CHECK);
>>> button2.setText(anotherArrayList.get(j).toString());
>>> button2.pack();
>>> editor.setEditor(button2, items[j], 1);
>>>
>>> }
>>>
>>> This displays how I would like it to display, basically a big 2 d array
>>> of checkboxes. The issue that I am having is how do I go back into the
>>> table to see what checkboxes have been checked and what ones haven't? I
>>> can't seem to figure out how I would do that. To give it context, this
>>> grid is going to display permissions for users and groups. If there
>>> is a better way of creating a table or displaying a grid of
>>> checkboxes and then managing their state please let me know. Thanks!
>>>
>>> Andy
>>>
>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Tables and Checkboxes [message #333783 is a reply to message #333780] Mon, 05 January 2009 20:45 Go to previous messageGo to next message
Andy is currently offline AndyFriend
Messages: 47
Registered: July 2009
Member
Thanks for the response.

Maybe I am doing something wrong or not asking a specific enough question,
but I still can't find any example as to how you go back and scan through
all the checkboxes. From what I can see these examples show how to
*display* the checkboxes. That isn't the problem as I can display them
without any issue. It seems like these examples are fixes to some kind of
bug in displaying a checkbox in a column other than the first one in a
table. I have no issue displaying the checkboxes in any column. All I
want to do is basically iterate over a 2 D array and check to see if a
particular checkbox (really a button) got checked or not.

I would like to do something like this:

TableItem[] updatedTableItems = table.getItems();

for(int k=0; k<updatedTableItems.length; k++){
for(int i=0; i<table.getColumnCount(); i++){

Button b = /* getButton at index [k][i] in the table */;

}
}

What would go in the /* */ area? table doesn't seem to give me methods
that I can feed a row and a column index to and pull out the Button stored
there. Thanks for your help.

Andy



Tom Schindl wrote:

> Well if you take:
>
a) http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet056BooleanCellEditor.java?view=markup
> and
>
b) http://tom-eclipse-dev.blogspot.com/2007/01/tableviewers-and -nativelooking.html

> You are best of when checking out the code from the cvs-repository.

> Tom

> Andy schrieb:
>> Thanks for the info. I took a look at
>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>
>> I am still confused as to which option you are referred to as "emulated
>> checkboxes" because it seemed like all those articles had to do with
>> displaying items in a table and item visibility, not capturing the
>> values of the checkboxes. I can display all the items just fine with
>> the current code.
>> Was there an option out of the 5 on that page that covered this
>> question? I looked at them but didn't seem to find any.
>>
>> Do you know of an example that displays multiple checkboxes in a table
>> and also has code to track the state of all of them? Thanks.
>>
>> Andy
>>
>>
>> Tom Schindl wrote:
>>
>>> Hi,
>>
>>> You better use a TableViewer and emulated checkboxes because this
>>> reduces the amount of memory and you have then backed up your states in
>>> a model element.
>>
>>> Take a look at
>>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>
>>> Tom
>>
>>> Andy schrieb:
>>>> I have a table that I have created like the following:
>>>>
>>>> Table table (myComposite, SWT.BORDER | SWT.MULTI);
>>>>
>>>> // Make the columns
>>>> for (int i=0; i<6, i++){
>>>> TableColumn column = new TableColumn(table, SWT.NONE);
>>>> }
>>>>
>>>> //Make the rows
>>>> for(int k=0; k<myArrayList.size(); k++){
>>>> new TableItem(table, SWT.NONE);
>>>> }
>>>>
>>>> TableItem[] items = table.getItems();
>>>>
>>>> for(int j=0; j<items.length; j++){
>>>> TableEditor editor = new TableEditor(table);
>>>> Button button = new Button(table, SWT.CHECK);
>>>> button.setText(myArrayList.get(j).toString());
>>>> button.pack();
>>>> editor.setEditor(button, items[j], 0);
>>>>
>>>> editor = new TableEditor(table);
>>>> Button button2 = new Button(table, SWT.CHECK);
>>>> button2.setText(anotherArrayList.get(j).toString());
>>>> button2.pack();
>>>> editor.setEditor(button2, items[j], 1);
>>>>
>>>> }
>>>>
>>>> This displays how I would like it to display, basically a big 2 d array
>>>> of checkboxes. The issue that I am having is how do I go back into the
>>>> table to see what checkboxes have been checked and what ones haven't? I
>>>> can't seem to figure out how I would do that. To give it context, this
>>>> grid is going to display permissions for users and groups. If there
>>>> is a better way of creating a table or displaying a grid of
>>>> checkboxes and then managing their state please let me know. Thanks!
>>>>
>>>> Andy
>>>>
>>
>>
>>
Re: Tables and Checkboxes [message #333788 is a reply to message #333783] Mon, 05 January 2009 22:08 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Andy,

What I'm trying to teach you is that you should use a Viewer with a
CellEditor a JFaceViewer is backed up by object-model.

Let's suppose you have a TableViewer like this:

-------------------------------------
|File | Read | Write | Execute |
-------------------------------------
| A.exe | x | x | x |
| A.html | x | x | |
-------------------------------------

As a model element you would have a class like this:

class File {
public String name;
public boolean read;
public boolean write;
public boolean execute;

public File(String name) {
this.name = name;
}
}

=> To show a table like the one above you need 2 instances

List<File> files = new ArrayList<File>();
files.add(new File("A.exe"));
files.add(new File("A.html"));

The CellEditor allows you to edit boolean values and magically update
the underlying model which means with a JFace-Viewer both your model
elements(=File-Attributes) and your view (=Cell-Values) are kept in sync
automatically with the benefit that you get sorting, fitering and
smoother scrolling for free. So with a viewer you don't need to go back
and scan the viewer because you simply look at your model element and
are done.

Tom


Andy schrieb:
>
> Thanks for the response.
> Maybe I am doing something wrong or not asking a specific enough
> question, but I still can't find any example as to how you go back and
> scan through all the checkboxes. From what I can see these examples
> show how to *display* the checkboxes. That isn't the problem as I can
> display them without any issue. It seems like these examples are fixes
> to some kind of bug in displaying a checkbox in a column other than the
> first one in a table. I have no issue displaying the checkboxes in any
> column. All I want to do is basically iterate over a 2 D array and
> check to see if a particular checkbox (really a button) got checked or not.
>
> I would like to do something like this:
>
> TableItem[] updatedTableItems = table.getItems();
> for(int k=0;
> k<updatedTableItems.length; k++){
> for(int i=0; i<table.getColumnCount(); i++){
> Button b = /* getButton at index [k][i] in the table */;
>
> }
> }
> What would go in the /* */ area? table doesn't seem to give me
> methods that I can feed a row and a column index to and pull out the
> Button stored there. Thanks for your help.
>
> Andy
>
>
>
> Tom Schindl wrote:
>
>> Well if you take:
>>
> a) http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet056BooleanCellEditor.java?view=markup
>
>> and
>>
> b) http://tom-eclipse-dev.blogspot.com/2007/01/tableviewers-and -nativelooking.html
>
>
>> You are best of when checking out the code from the cvs-repository.
>
>> Tom
>
>> Andy schrieb:
>>> Thanks for the info. I took a look at
>>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>>
>>> I am still confused as to which option you are referred to as "emulated
>>> checkboxes" because it seemed like all those articles had to do with
>>> displaying items in a table and item visibility, not capturing the
>>> values of the checkboxes. I can display all the items just fine with
>>> the current code. Was there an option out of the 5 on that page that
>>> covered this
>>> question? I looked at them but didn't seem to find any.
>>>
>>> Do you know of an example that displays multiple checkboxes in a table
>>> and also has code to track the state of all of them? Thanks.
>>>
>>> Andy
>>>
>>>
>>> Tom Schindl wrote:
>>>
>>>> Hi,
>>>
>>>> You better use a TableViewer and emulated checkboxes because this
>>>> reduces the amount of memory and you have then backed up your states in
>>>> a model element.
>>>
>>>> Take a look at
>>>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>>
>>>> Tom
>>>
>>>> Andy schrieb:
>>>>> I have a table that I have created like the following:
>>>>>
>>>>> Table table (myComposite, SWT.BORDER | SWT.MULTI);
>>>>>
>>>>> // Make the columns
>>>>> for (int i=0; i<6, i++){
>>>>> TableColumn column = new TableColumn(table, SWT.NONE);
>>>>> }
>>>>>
>>>>> //Make the rows
>>>>> for(int k=0; k<myArrayList.size(); k++){
>>>>> new TableItem(table, SWT.NONE);
>>>>> }
>>>>>
>>>>> TableItem[] items = table.getItems();
>>>>>
>>>>> for(int j=0; j<items.length; j++){
>>>>> TableEditor editor = new TableEditor(table);
>>>>> Button button = new Button(table, SWT.CHECK);
>>>>> button.setText(myArrayList.get(j).toString());
>>>>> button.pack();
>>>>> editor.setEditor(button, items[j], 0);
>>>>>
>>>>> editor = new TableEditor(table);
>>>>> Button button2 = new Button(table, SWT.CHECK);
>>>>> button2.setText(anotherArrayList.get(j).toString());
>>>>> button2.pack();
>>>>> editor.setEditor(button2, items[j], 1);
>>>>>
>>>>> }
>>>>>
>>>>> This displays how I would like it to display, basically a big 2 d
>>>>> array
>>>>> of checkboxes. The issue that I am having is how do I go back into
>>>>> the
>>>>> table to see what checkboxes have been checked and what ones
>>>>> haven't? I
>>>>> can't seem to figure out how I would do that. To give it context,
>>>>> this
>>>>> grid is going to display permissions for users and groups. If there
>>>>> is a better way of creating a table or displaying a grid of
>>>>> checkboxes and then managing their state please let me know. Thanks!
>>>>>
>>>>> Andy
>>>>>
>>>
>>>
>>>
>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Tables and Checkboxes [message #333801 is a reply to message #333788] Tue, 06 January 2009 15:46 Go to previous messageGo to next message
Andy is currently offline AndyFriend
Messages: 47
Registered: July 2009
Member
Tom,

Thanks for your patience in answering all my questions. The part that is
giving me trouble is I don't understand why if I can put the checkboxes
into the table directly, why I can't pull them back out directly. That
just seems odd to me based on the code I have below when it seems like I
should just need to do a one line method call to get the button based on
the position of the array.

It seems like I am forced into using several layers of abstraction, like
the Table plus

a LabelProvider,
a Viewer,
a Content Provider,
a BooleanCellEditor,
and possibly others.

I can find bits and pieces of examples that do something similar all over
the web, but none that are end to end examples that integrate all the
pieces together.

I gather that you are saying I should model each row of the table in an
object. No problem, I can do that. So if I was going to do that, would I
have a table which pointed to a viewer which would then hold that array of
files and then also hook the cell editor to the table? How would the cell
editor map to each boolean value in the file model?

Using the original table below as a start, if you have a simple example of
the java files that show the relationships I can take that and write an
article on it and post it so that others who run into this problem can use
it as a reference.

Sorry for me to be so clueless on the subject. Thanks,

Andy



Tom Schindl wrote:

> Hi Andy,

> What I'm trying to teach you is that you should use a Viewer with a
> CellEditor a JFaceViewer is backed up by object-model.

> Let's suppose you have a TableViewer like this:

> -------------------------------------
> |File | Read | Write | Execute |
> -------------------------------------
> | A.exe | x | x | x |
> | A.html | x | x | |
> -------------------------------------

> As a model element you would have a class like this:

> class File {
> public String name;
> public boolean read;
> public boolean write;
> public boolean execute;

> public File(String name) {
> this.name = name;
> }
> }

> => To show a table like the one above you need 2 instances

> List<File> files = new ArrayList<File>();
> files.add(new File("A.exe"));
> files.add(new File("A.html"));

> The CellEditor allows you to edit boolean values and magically update
> the underlying model which means with a JFace-Viewer both your model
> elements(=File-Attributes) and your view (=Cell-Values) are kept in sync
> automatically with the benefit that you get sorting, fitering and
> smoother scrolling for free. So with a viewer you don't need to go back
> and scan the viewer because you simply look at your model element and
> are done.

> Tom


> Andy schrieb:
>>
>> Thanks for the response.
>> Maybe I am doing something wrong or not asking a specific enough
>> question, but I still can't find any example as to how you go back and
>> scan through all the checkboxes. From what I can see these examples
>> show how to *display* the checkboxes. That isn't the problem as I can
>> display them without any issue. It seems like these examples are fixes
>> to some kind of bug in displaying a checkbox in a column other than the
>> first one in a table. I have no issue displaying the checkboxes in any
>> column. All I want to do is basically iterate over a 2 D array and
>> check to see if a particular checkbox (really a button) got checked or not.
>>
>> I would like to do something like this:
>>
>> TableItem[] updatedTableItems = table.getItems();
>> for(int k=0;
>> k<updatedTableItems.length; k++){
>> for(int i=0; i<table.getColumnCount(); i++){
>> Button b = /* getButton at index [k][i] in the table */;
>>
>> }
>> }
>> What would go in the /* */ area? table doesn't seem to give me
>> methods that I can feed a row and a column index to and pull out the
>> Button stored there. Thanks for your help.
>>
>> Andy
>>
>>
>>
>> Tom Schindl wrote:
>>
>>> Well if you take:
>>>
>>
a) http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet056BooleanCellEditor.java?view=markup
>>
>>> and
>>>
>>
b) http://tom-eclipse-dev.blogspot.com/2007/01/tableviewers-and -nativelooking.html
>>
>>
>>> You are best of when checking out the code from the cvs-repository.
>>
>>> Tom
>>
>>> Andy schrieb:
>>>> Thanks for the info. I took a look at
>>>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>>>
>>>> I am still confused as to which option you are referred to as "emulated
>>>> checkboxes" because it seemed like all those articles had to do with
>>>> displaying items in a table and item visibility, not capturing the
>>>> values of the checkboxes. I can display all the items just fine with
>>>> the current code. Was there an option out of the 5 on that page that
>>>> covered this
>>>> question? I looked at them but didn't seem to find any.
>>>>
>>>> Do you know of an example that displays multiple checkboxes in a table
>>>> and also has code to track the state of all of them? Thanks.
>>>>
>>>> Andy
>>>>
>>>>
>>>> Tom Schindl wrote:
>>>>
>>>>> Hi,
>>>>
>>>>> You better use a TableViewer and emulated checkboxes because this
>>>>> reduces the amount of memory and you have then backed up your states in
>>>>> a model element.
>>>>
>>>>> Take a look at
>>>>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>>>
>>>>> Tom
>>>>
>>>>> Andy schrieb:
>>>>>> I have a table that I have created like the following:
>>>>>>
>>>>>> Table table (myComposite, SWT.BORDER | SWT.MULTI);
>>>>>>
>>>>>> // Make the columns
>>>>>> for (int i=0; i<6, i++){
>>>>>> TableColumn column = new TableColumn(table, SWT.NONE);
>>>>>> }
>>>>>>
>>>>>> //Make the rows
>>>>>> for(int k=0; k<myArrayList.size(); k++){
>>>>>> new TableItem(table, SWT.NONE);
>>>>>> }
>>>>>>
>>>>>> TableItem[] items = table.getItems();
>>>>>>
>>>>>> for(int j=0; j<items.length; j++){
>>>>>> TableEditor editor = new TableEditor(table);
>>>>>> Button button = new Button(table, SWT.CHECK);
>>>>>> button.setText(myArrayList.get(j).toString());
>>>>>> button.pack();
>>>>>> editor.setEditor(button, items[j], 0);
>>>>>>
>>>>>> editor = new TableEditor(table);
>>>>>> Button button2 = new Button(table, SWT.CHECK);
>>>>>> button2.setText(anotherArrayList.get(j).toString());
>>>>>> button2.pack();
>>>>>> editor.setEditor(button2, items[j], 1);
>>>>>>
>>>>>> }
>>>>>>
>>>>>> This displays how I would like it to display, basically a big 2 d
>>>>>> array
>>>>>> of checkboxes. The issue that I am having is how do I go back into
>>>>>> the
>>>>>> table to see what checkboxes have been checked and what ones
>>>>>> haven't? I
>>>>>> can't seem to figure out how I would do that. To give it context,
>>>>>> this
>>>>>> grid is going to display permissions for users and groups. If there
>>>>>> is a better way of creating a table or displaying a grid of
>>>>>> checkboxes and then managing their state please let me know. Thanks!
>>>>>>
>>>>>> Andy
>>>>>>
>>>>
>>>>
>>>>
>>
>>
>>
Re: Tables and Checkboxes [message #333803 is a reply to message #333801] Tue, 06 January 2009 16:42 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Go and checkout https://bugs.eclipse.org/bugs/show_bug.cgi?id=260061 it
holds a code snippet which is exactly what you are looking for.

I didn't committed the code yet because I merged in contributions from
people who commented on my blog.

I'm not 100% satisfied because the cell-editor background is not
transparent and I've only tested on OS-X.

Tom

Andy schrieb:
> Tom,
>
> Thanks for your patience in answering all my questions. The part that
> is giving me trouble is I don't understand why if I can put the
> checkboxes into the table directly, why I can't pull them back out
> directly. That just seems odd to me based on the code I have below when
> it seems like I should just need to do a one line method call to get the
> button based on the position of the array.
> It seems like I am forced into using several layers of abstraction, like
> the Table plus
> a LabelProvider, a Viewer, a Content Provider, a BooleanCellEditor, and
> possibly others.
> I can find bits and pieces of examples that do something similar all
> over the web, but none that are end to end examples that integrate all
> the pieces together.
> I gather that you are saying I should model each row of the table in an
> object. No problem, I can do that. So if I was going to do that, would
> I have a table which pointed to a viewer which would then hold that
> array of files and then also hook the cell editor to the table? How
> would the cell editor map to each boolean value in the file model?
> Using the original table below as a start, if you have a simple example
> of the java files that show the relationships I can take that and write
> an article on it and post it so that others who run into this problem
> can use it as a reference.
>
> Sorry for me to be so clueless on the subject. Thanks,
>
> Andy
>
>
>
> Tom Schindl wrote:
>
>> Hi Andy,
>
>> What I'm trying to teach you is that you should use a Viewer with a
>> CellEditor a JFaceViewer is backed up by object-model.
>
>> Let's suppose you have a TableViewer like this:
>
>> -------------------------------------
>> |File | Read | Write | Execute |
>> -------------------------------------
>> | A.exe | x | x | x |
>> | A.html | x | x | |
>> -------------------------------------
>
>> As a model element you would have a class like this:
>
>> class File {
>> public String name;
>> public boolean read;
>> public boolean write;
>> public boolean execute;
>
>> public File(String name) {
>> this.name = name;
>> }
>> }
>
>> => To show a table like the one above you need 2 instances
>
>> List<File> files = new ArrayList<File>();
>> files.add(new File("A.exe"));
>> files.add(new File("A.html"));
>
>> The CellEditor allows you to edit boolean values and magically update
>> the underlying model which means with a JFace-Viewer both your model
>> elements(=File-Attributes) and your view (=Cell-Values) are kept in sync
>> automatically with the benefit that you get sorting, fitering and
>> smoother scrolling for free. So with a viewer you don't need to go back
>> and scan the viewer because you simply look at your model element and
>> are done.
>
>> Tom
>
>
>> Andy schrieb:
>>>
>>> Thanks for the response. Maybe I am doing something wrong or not
>>> asking a specific enough
>>> question, but I still can't find any example as to how you go back and
>>> scan through all the checkboxes. From what I can see these examples
>>> show how to *display* the checkboxes. That isn't the problem as I can
>>> display them without any issue. It seems like these examples are fixes
>>> to some kind of bug in displaying a checkbox in a column other than the
>>> first one in a table. I have no issue displaying the checkboxes in any
>>> column. All I want to do is basically iterate over a 2 D array and
>>> check to see if a particular checkbox (really a button) got checked
>>> or not.
>>>
>>> I would like to do something like this:
>>>
>>> TableItem[] updatedTableItems = table.getItems();
>>> for(int k=0;
>>> k<updatedTableItems.length; k++){
>>> for(int i=0; i<table.getColumnCount(); i++){
>>> Button b = /* getButton at index [k][i] in the table */;
>>>
>>> } } What
>>> would go in the /* */ area? table doesn't seem to give me
>>> methods that I can feed a row and a column index to and pull out the
>>> Button stored there. Thanks for your help.
>>>
>>> Andy
>>>
>>> Tom Schindl wrote:
>>>
>>>> Well if you take:
>>>>
>>>
> a) http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet056BooleanCellEditor.java?view=markup
>
>>>
>>>> and
>>>>
>>>
> b) http://tom-eclipse-dev.blogspot.com/2007/01/tableviewers-and -nativelooking.html
>
>>>
>>>
>>>> You are best of when checking out the code from the cvs-repository.
>>>
>>>> Tom
>>>
>>>> Andy schrieb:
>>>>> Thanks for the info. I took a look at
>>>>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>>>>
>>>>> I am still confused as to which option you are referred to as
>>>>> "emulated
>>>>> checkboxes" because it seemed like all those articles had to do with
>>>>> displaying items in a table and item visibility, not capturing the
>>>>> values of the checkboxes. I can display all the items just fine with
>>>>> the current code. Was there an option out of the 5 on that page that
>>>>> covered this
>>>>> question? I looked at them but didn't seem to find any.
>>>>>
>>>>> Do you know of an example that displays multiple checkboxes in a table
>>>>> and also has code to track the state of all of them? Thanks.
>>>>>
>>>>> Andy
>>>>>
>>>>>
>>>>> Tom Schindl wrote:
>>>>>
>>>>>> Hi,
>>>>>
>>>>>> You better use a TableViewer and emulated checkboxes because this
>>>>>> reduces the amount of memory and you have then backed up your
>>>>>> states in
>>>>>> a model element.
>>>>>
>>>>>> Take a look at
>>>>>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>>>>
>>>>>> Tom
>>>>>
>>>>>> Andy schrieb:
>>>>>>> I have a table that I have created like the following:
>>>>>>>
>>>>>>> Table table (myComposite, SWT.BORDER | SWT.MULTI);
>>>>>>>
>>>>>>> // Make the columns
>>>>>>> for (int i=0; i<6, i++){
>>>>>>> TableColumn column = new TableColumn(table, SWT.NONE);
>>>>>>> }
>>>>>>>
>>>>>>> //Make the rows
>>>>>>> for(int k=0; k<myArrayList.size(); k++){
>>>>>>> new TableItem(table, SWT.NONE);
>>>>>>> }
>>>>>>>
>>>>>>> TableItem[] items = table.getItems();
>>>>>>>
>>>>>>> for(int j=0; j<items.length; j++){
>>>>>>> TableEditor editor = new TableEditor(table);
>>>>>>> Button button = new Button(table, SWT.CHECK);
>>>>>>> button.setText(myArrayList.get(j).toString());
>>>>>>> button.pack();
>>>>>>> editor.setEditor(button, items[j], 0);
>>>>>>>
>>>>>>> editor = new TableEditor(table);
>>>>>>> Button button2 = new Button(table, SWT.CHECK);
>>>>>>> button2.setText(anotherArrayList.get(j).toString());
>>>>>>> button2.pack();
>>>>>>> editor.setEditor(button2, items[j], 1);
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> This displays how I would like it to display, basically a big 2 d
>>>>>>> array
>>>>>>> of checkboxes. The issue that I am having is how do I go back into
>>>>>>> the
>>>>>>> table to see what checkboxes have been checked and what ones
>>>>>>> haven't? I
>>>>>>> can't seem to figure out how I would do that. To give it context,
>>>>>>> this
>>>>>>> grid is going to display permissions for users and groups. If there
>>>>>>> is a better way of creating a table or displaying a grid of
>>>>>>> checkboxes and then managing their state please let me know.
>>>>>>> Thanks!
>>>>>>>
>>>>>>> Andy
>>>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>
>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Tables and Checkboxes [message #333822 is a reply to message #333803] Wed, 07 January 2009 16:23 Go to previous messageGo to next message
Andy is currently offline AndyFriend
Messages: 47
Registered: July 2009
Member
Tom,

I took a look at Snippet061FakedNativeCellEditor - thanks. One of the
things I have been trying to figure out is why does the example use a
treeviewer and not a tableviewer? I can't seem to find a tableviewer
anywhere yet the example obviously is in a table.

I see that the File Object is the model that holds all the files and their
properties. That definitely made the model concept more clear.

I changed the first column in the table to display a field in the File
mode, something simple like a filename, but I notice that I can only see
that when I click on it and instead see the tree information by default in
that column. Is there a way to disable that for the first column so that
I just see the filename?

Thanks,

Andy


Tom Schindl wrote:

> Hi,

> Go and checkout https://bugs.eclipse.org/bugs/show_bug.cgi?id=260061 it
> holds a code snippet which is exactly what you are looking for.

> I didn't committed the code yet because I merged in contributions from
> people who commented on my blog.

> I'm not 100% satisfied because the cell-editor background is not
> transparent and I've only tested on OS-X.

> Tom

> Andy schrieb:
>> Tom,
>>
>> Thanks for your patience in answering all my questions. The part that
>> is giving me trouble is I don't understand why if I can put the
>> checkboxes into the table directly, why I can't pull them back out
>> directly. That just seems odd to me based on the code I have below when
>> it seems like I should just need to do a one line method call to get the
>> button based on the position of the array.
>> It seems like I am forced into using several layers of abstraction, like
>> the Table plus
>> a LabelProvider, a Viewer, a Content Provider, a BooleanCellEditor, and
>> possibly others.
>> I can find bits and pieces of examples that do something similar all
>> over the web, but none that are end to end examples that integrate all
>> the pieces together.
>> I gather that you are saying I should model each row of the table in an
>> object. No problem, I can do that. So if I was going to do that, would
>> I have a table which pointed to a viewer which would then hold that
>> array of files and then also hook the cell editor to the table? How
>> would the cell editor map to each boolean value in the file model?
>> Using the original table below as a start, if you have a simple example
>> of the java files that show the relationships I can take that and write
>> an article on it and post it so that others who run into this problem
>> can use it as a reference.
>>
>> Sorry for me to be so clueless on the subject. Thanks,
>>
>> Andy
>>
>>
>>
>> Tom Schindl wrote:
>>
>>> Hi Andy,
>>
>>> What I'm trying to teach you is that you should use a Viewer with a
>>> CellEditor a JFaceViewer is backed up by object-model.
>>
>>> Let's suppose you have a TableViewer like this:
>>
>>> -------------------------------------
>>> |File | Read | Write | Execute |
>>> -------------------------------------
>>> | A.exe | x | x | x |
>>> | A.html | x | x | |
>>> -------------------------------------
>>
>>> As a model element you would have a class like this:
>>
>>> class File {
>>> public String name;
>>> public boolean read;
>>> public boolean write;
>>> public boolean execute;
>>
>>> public File(String name) {
>>> this.name = name;
>>> }
>>> }
>>
>>> => To show a table like the one above you need 2 instances
>>
>>> List<File> files = new ArrayList<File>();
>>> files.add(new File("A.exe"));
>>> files.add(new File("A.html"));
>>
>>> The CellEditor allows you to edit boolean values and magically update
>>> the underlying model which means with a JFace-Viewer both your model
>>> elements(=File-Attributes) and your view (=Cell-Values) are kept in sync
>>> automatically with the benefit that you get sorting, fitering and
>>> smoother scrolling for free. So with a viewer you don't need to go back
>>> and scan the viewer because you simply look at your model element and
>>> are done.
>>
>>> Tom
>>
>>
>>> Andy schrieb:
>>>>
>>>> Thanks for the response. Maybe I am doing something wrong or not
>>>> asking a specific enough
>>>> question, but I still can't find any example as to how you go back and
>>>> scan through all the checkboxes. From what I can see these examples
>>>> show how to *display* the checkboxes. That isn't the problem as I can
>>>> display them without any issue. It seems like these examples are fixes
>>>> to some kind of bug in displaying a checkbox in a column other than the
>>>> first one in a table. I have no issue displaying the checkboxes in any
>>>> column. All I want to do is basically iterate over a 2 D array and
>>>> check to see if a particular checkbox (really a button) got checked
>>>> or not.
>>>>
>>>> I would like to do something like this:
>>>>
>>>> TableItem[] updatedTableItems = table.getItems();
>>>> for(int k=0;
>>>> k<updatedTableItems.length; k++){
>>>> for(int i=0; i<table.getColumnCount(); i++){
>>>> Button b = /* getButton at index [k][i] in the table */;
>>>>
>>>> } } What
>>>> would go in the /* */ area? table doesn't seem to give me
>>>> methods that I can feed a row and a column index to and pull out the
>>>> Button stored there. Thanks for your help.
>>>>
>>>> Andy
>>>>
>>>> Tom Schindl wrote:
>>>>
>>>>> Well if you take:
>>>>>
>>>>
>>
a) http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet056BooleanCellEditor.java?view=markup
>>
>>>>
>>>>> and
>>>>>
>>>>
>>
b) http://tom-eclipse-dev.blogspot.com/2007/01/tableviewers-and -nativelooking.html
>>
>>>>
>>>>
>>>>> You are best of when checking out the code from the cvs-repository.
>>>>
>>>>> Tom
>>>>
>>>>> Andy schrieb:
>>>>>> Thanks for the info. I took a look at
>>>>>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>>>>>
>>>>>> I am still confused as to which option you are referred to as
>>>>>> "emulated
>>>>>> checkboxes" because it seemed like all those articles had to do with
>>>>>> displaying items in a table and item visibility, not capturing the
>>>>>> values of the checkboxes. I can display all the items just fine with
>>>>>> the current code. Was there an option out of the 5 on that page that
>>>>>> covered this
>>>>>> question? I looked at them but didn't seem to find any.
>>>>>>
>>>>>> Do you know of an example that displays multiple checkboxes in a table
>>>>>> and also has code to track the state of all of them? Thanks.
>>>>>>
>>>>>> Andy
>>>>>>
>>>>>>
>>>>>> Tom Schindl wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>
>>>>>>> You better use a TableViewer and emulated checkboxes because this
>>>>>>> reduces the amount of memory and you have then backed up your
>>>>>>> states in
>>>>>>> a model element.
>>>>>>
>>>>>>> Take a look at
>>>>>>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>>>>>
>>>>>>> Tom
>>>>>>
>>>>>>> Andy schrieb:
>>>>>>>> I have a table that I have created like the following:
>>>>>>>>
>>>>>>>> Table table (myComposite, SWT.BORDER | SWT.MULTI);
>>>>>>>>
>>>>>>>> // Make the columns
>>>>>>>> for (int i=0; i<6, i++){
>>>>>>>> TableColumn column = new TableColumn(table, SWT.NONE);
>>>>>>>> }
>>>>>>>>
>>>>>>>> //Make the rows
>>>>>>>> for(int k=0; k<myArrayList.size(); k++){
>>>>>>>> new TableItem(table, SWT.NONE);
>>>>>>>> }
>>>>>>>>
>>>>>>>> TableItem[] items = table.getItems();
>>>>>>>>
>>>>>>>> for(int j=0; j<items.length; j++){
>>>>>>>> TableEditor editor = new TableEditor(table);
>>>>>>>> Button button = new Button(table, SWT.CHECK);
>>>>>>>> button.setText(myArrayList.get(j).toString());
>>>>>>>> button.pack();
>>>>>>>> editor.setEditor(button, items[j], 0);
>>>>>>>>
>>>>>>>> editor = new TableEditor(table);
>>>>>>>> Button button2 = new Button(table, SWT.CHECK);
>>>>>>>> button2.setText(anotherArrayList.get(j).toString());
>>>>>>>> button2.pack();
>>>>>>>> editor.setEditor(button2, items[j], 1);
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>> This displays how I would like it to display, basically a big 2 d
>>>>>>>> array
>>>>>>>> of checkboxes. The issue that I am having is how do I go back into
>>>>>>>> the
>>>>>>>> table to see what checkboxes have been checked and what ones
>>>>>>>> haven't? I
>>>>>>>> can't seem to figure out how I would do that. To give it context,
>>>>>>>> this
>>>>>>>> grid is going to display permissions for users and groups. If there
>>>>>>>> is a better way of creating a table or displaying a grid of
>>>>>>>> checkboxes and then managing their state please let me know.
>>>>>>>> Thanks!
>>>>>>>>
>>>>>>>> Andy
>>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>>>
>>
>>
>>
>>
Re: Tables and Checkboxes [message #333824 is a reply to message #333822] Wed, 07 January 2009 16:45 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
s/Table/Tree and use an ordinary IStructuredContentProvider. The Snippet
uses a TreeViewer because I copied another Snippet to get started.

TreeViewer and TableViewer work 100% the same. I'm just working on some
fixes because OwnerDrawLabelProvider and FocusCellHighlighter seem to be
incorrect on Win32.

Tom

Andy schrieb:
> Tom,
>
> I took a look at Snippet061FakedNativeCellEditor - thanks. One of the
> things I have been trying to figure out is why does the example use a
> treeviewer and not a tableviewer? I can't seem to find a tableviewer
> anywhere yet the example obviously is in a table.
>
> I see that the File Object is the model that holds all the files and
> their properties. That definitely made the model concept more clear.
>
> I changed the first column in the table to display a field in the File
> mode, something simple like a filename, but I notice that I can only see
> that when I click on it and instead see the tree information by default
> in that column. Is there a way to disable that for the first column so
> that I just see the filename?
>
> Thanks,
>
> Andy
>
>
> Tom Schindl wrote:
>
>> Hi,
>
>> Go and checkout https://bugs.eclipse.org/bugs/show_bug.cgi?id=260061 it
>> holds a code snippet which is exactly what you are looking for.
>
>> I didn't committed the code yet because I merged in contributions from
>> people who commented on my blog.
>
>> I'm not 100% satisfied because the cell-editor background is not
>> transparent and I've only tested on OS-X.
>
>> Tom
>
>> Andy schrieb:
>>> Tom,
>>>
>>> Thanks for your patience in answering all my questions. The part that
>>> is giving me trouble is I don't understand why if I can put the
>>> checkboxes into the table directly, why I can't pull them back out
>>> directly. That just seems odd to me based on the code I have below when
>>> it seems like I should just need to do a one line method call to get the
>>> button based on the position of the array.
>>> It seems like I am forced into using several layers of abstraction, like
>>> the Table plus
>>> a LabelProvider, a Viewer, a Content Provider, a BooleanCellEditor, and
>>> possibly others. I can find bits and pieces of examples that do
>>> something similar all
>>> over the web, but none that are end to end examples that integrate all
>>> the pieces together. I gather that you are saying I should model each
>>> row of the table in an
>>> object. No problem, I can do that. So if I was going to do that, would
>>> I have a table which pointed to a viewer which would then hold that
>>> array of files and then also hook the cell editor to the table? How
>>> would the cell editor map to each boolean value in the file model?
>>> Using the original table below as a start, if you have a simple example
>>> of the java files that show the relationships I can take that and write
>>> an article on it and post it so that others who run into this problem
>>> can use it as a reference.
>>>
>>> Sorry for me to be so clueless on the subject. Thanks,
>>>
>>> Andy
>>>
>>>
>>>
>>> Tom Schindl wrote:
>>>
>>>> Hi Andy,
>>>
>>>> What I'm trying to teach you is that you should use a Viewer with a
>>>> CellEditor a JFaceViewer is backed up by object-model.
>>>
>>>> Let's suppose you have a TableViewer like this:
>>>
>>>> -------------------------------------
>>>> |File | Read | Write | Execute |
>>>> -------------------------------------
>>>> | A.exe | x | x | x |
>>>> | A.html | x | x | |
>>>> -------------------------------------
>>>
>>>> As a model element you would have a class like this:
>>>
>>>> class File {
>>>> public String name;
>>>> public boolean read;
>>>> public boolean write;
>>>> public boolean execute;
>>>
>>>> public File(String name) {
>>>> this.name = name;
>>>> }
>>>> }
>>>
>>>> => To show a table like the one above you need 2 instances
>>>
>>>> List<File> files = new ArrayList<File>();
>>>> files.add(new File("A.exe"));
>>>> files.add(new File("A.html"));
>>>
>>>> The CellEditor allows you to edit boolean values and magically update
>>>> the underlying model which means with a JFace-Viewer both your model
>>>> elements(=File-Attributes) and your view (=Cell-Values) are kept in
>>>> sync
>>>> automatically with the benefit that you get sorting, fitering and
>>>> smoother scrolling for free. So with a viewer you don't need to go back
>>>> and scan the viewer because you simply look at your model element and
>>>> are done.
>>>
>>>> Tom
>>>
>>>
>>>> Andy schrieb:
>>>>>
>>>>> Thanks for the response. Maybe I am doing something wrong or not
>>>>> asking a specific enough
>>>>> question, but I still can't find any example as to how you go back and
>>>>> scan through all the checkboxes. From what I can see these examples
>>>>> show how to *display* the checkboxes. That isn't the problem as I can
>>>>> display them without any issue. It seems like these examples are
>>>>> fixes
>>>>> to some kind of bug in displaying a checkbox in a column other than
>>>>> the
>>>>> first one in a table. I have no issue displaying the checkboxes in
>>>>> any
>>>>> column. All I want to do is basically iterate over a 2 D array and
>>>>> check to see if a particular checkbox (really a button) got checked
>>>>> or not.
>>>>>
>>>>> I would like to do something like this:
>>>>>
>>>>> TableItem[] updatedTableItems = table.getItems();
>>>>> for(int k=0;
>>>>> k<updatedTableItems.length; k++){
>>>>> for(int i=0; i<table.getColumnCount(); i++){
>>>>> Button b = /* getButton at index [k][i] in the table */;
>>>>>
>>>>> } } What
>>>>> would go in the /* */ area? table doesn't seem to give me
>>>>> methods that I can feed a row and a column index to and pull out the
>>>>> Button stored there. Thanks for your help.
>>>>>
>>>>> Andy
>>>>> Tom Schindl wrote:
>>>>>
>>>>>> Well if you take:
>>>>>>
>>>>>
>>>
> a) http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet056BooleanCellEditor.java?view=markup
>
>>>
>>>>>
>>>>>> and
>>>>>>
>>>>>
>>>
> b) http://tom-eclipse-dev.blogspot.com/2007/01/tableviewers-and -nativelooking.html
>
>>>
>>>>>
>>>>>
>>>>>> You are best of when checking out the code from the cvs-repository.
>>>>>
>>>>>> Tom
>>>>>
>>>>>> Andy schrieb:
>>>>>>> Thanks for the info. I took a look at
>>>>>>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>>>>>>
>>>>>>> I am still confused as to which option you are referred to as
>>>>>>> "emulated
>>>>>>> checkboxes" because it seemed like all those articles had to do with
>>>>>>> displaying items in a table and item visibility, not capturing the
>>>>>>> values of the checkboxes. I can display all the items just fine
>>>>>>> with
>>>>>>> the current code. Was there an option out of the 5 on that page that
>>>>>>> covered this
>>>>>>> question? I looked at them but didn't seem to find any.
>>>>>>>
>>>>>>> Do you know of an example that displays multiple checkboxes in a
>>>>>>> table
>>>>>>> and also has code to track the state of all of them? Thanks.
>>>>>>>
>>>>>>> Andy
>>>>>>>
>>>>>>>
>>>>>>> Tom Schindl wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>
>>>>>>>> You better use a TableViewer and emulated checkboxes because this
>>>>>>>> reduces the amount of memory and you have then backed up your
>>>>>>>> states in
>>>>>>>> a model element.
>>>>>>>
>>>>>>>> Take a look at
>>>>>>>> http://wiki.eclipse.org/Tables_And_Trees_And_NativeControls
>>>>>>>
>>>>>>>> Tom
>>>>>>>
>>>>>>>> Andy schrieb:
>>>>>>>>> I have a table that I have created like the following:
>>>>>>>>>
>>>>>>>>> Table table (myComposite, SWT.BORDER | SWT.MULTI);
>>>>>>>>>
>>>>>>>>> // Make the columns
>>>>>>>>> for (int i=0; i<6, i++){
>>>>>>>>> TableColumn column = new TableColumn(table, SWT.NONE);
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> //Make the rows
>>>>>>>>> for(int k=0; k<myArrayList.size(); k++){
>>>>>>>>> new TableItem(table, SWT.NONE);
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> TableItem[] items = table.getItems();
>>>>>>>>>
>>>>>>>>> for(int j=0; j<items.length; j++){
>>>>>>>>> TableEditor editor = new TableEditor(table);
>>>>>>>>> Button button = new Button(table, SWT.CHECK);
>>>>>>>>> button.setText(myArrayList.get(j).toString());
>>>>>>>>> button.pack();
>>>>>>>>> editor.setEditor(button, items[j], 0);
>>>>>>>>>
>>>>>>>>> editor = new TableEditor(table);
>>>>>>>>> Button button2 = new Button(table, SWT.CHECK);
>>>>>>>>> button2.setText(anotherArrayList.get(j).toString());
>>>>>>>>> button2.pack();
>>>>>>>>> editor.setEditor(button2, items[j], 1);
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> This displays how I would like it to display, basically a big 2 d
>>>>>>>>> array
>>>>>>>>> of checkboxes. The issue that I am having is how do I go back
>>>>>>>>> into
>>>>>>>>> the
>>>>>>>>> table to see what checkboxes have been checked and what ones
>>>>>>>>> haven't? I
>>>>>>>>> can't seem to figure out how I would do that. To give it context,
>>>>>>>>> this
>>>>>>>>> grid is going to display permissions for users and groups. If
>>>>>>>>> there
>>>>>>>>> is a better way of creating a table or displaying a grid of
>>>>>>>>> checkboxes and then managing their state please let me know.
>>>>>>>>> Thanks!
>>>>>>>>>
>>>>>>>>> Andy
>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>
>
>
>
Previous Topic:TextEditor (sourceViewer) in a view
Next Topic:(TableViewer) How to have all gui of celleditor be displayed all the time
Goto Forum:
  


Current Time: Wed Jul 17 15:20:18 GMT 2024

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

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

Back to the top