Home » Eclipse Projects » Nebula » How to add events to a cell in Grid
How to add events to a cell in Grid [message #17118] |
Mon, 27 November 2006 10:42 |
Eclipse User |
|
|
|
Originally posted by: swetha.atc.tcs.co.in
Hi
I have created a Grid with 3 columns and added 3 griditems in this way..
The first column being a text,2nd is a label and the third is text again...
GridEditor editor = new GridEditor (grid);
items[i].setText("something");
label = new Label (grid, SWT.BORDER);
label.setText(" ");
label.setBackground(Display.getCurrent().getSystemColor(13)) ;
label.pack ();
editor.minimumWidth = label.getSize ().x;
editor.horizontalAlignment = SWT.LEFT;
editor.setEditor (label, items[i], 1);
editor=new GridEditor(grid);
Text text1 = new Text (grid, SWT.NONE);
text1.setText("anything");
editor.grabHorizontal = true;
editor.setEditor(text1, items[i], 2);
The first GridItem contains 3 more subItems....added them in another for
loop as above..
Now I have 2 problems...
1.) When i expand the first GridItem ,I am able to see all the subItems in
all the 3 columns....and if I collapse the tree ,all these subItems are
hidden...
but if I resize the shell and do the same..its not working ....
I mean ,the items in the first column are hidden but those in the second
and 3rd are not.
2.)I want a dialog to open when i click on the label in the second column
...
I am not able to add listeners to the label..How can i do it???
Thanks in advance..
Swetha
|
|
|
Re: How to add events to a cell in Grid [message #17228 is a reply to message #17118] |
Mon, 27 November 2006 16:19 |
Chris Gross Messages: 253 Registered: July 2009 |
Senior Member |
|
|
Hi Swetha,
I'm afraid I don't quite understand what you are trying to say in #1.
Are you collapsing a tree and the items aren't disappearing? Or are you
collapsing a column group and the columns aren't disappearing? Can you
attach the full code?
Re 2.) You can add listeners to the label thats used in the editor.
There's no reason why you cannot.
Regards,
-Chris
Swetha wrote:
> Hi
>
> I have created a Grid with 3 columns and added 3 griditems in this way..
> The first column being a text,2nd is a label and the third is text again...
>
> GridEditor editor = new GridEditor (grid);
> items[i].setText("something");
> label = new Label (grid, SWT.BORDER);
> label.setText(" ");
> label.setBackground(Display.getCurrent().getSystemColor(13)) ;
> label.pack ();
> editor.minimumWidth = label.getSize ().x;
> editor.horizontalAlignment = SWT.LEFT;
> editor.setEditor (label, items[i], 1);
> editor=new GridEditor(grid);
> Text text1 = new Text (grid, SWT.NONE);
> text1.setText("anything");
> editor.grabHorizontal = true;
> editor.setEditor(text1, items[i], 2);
> The first GridItem contains 3 more subItems....added them in another for
> loop as above..
>
> Now I have 2 problems...
>
> 1.) When i expand the first GridItem ,I am able to see all the subItems
> in all the 3 columns....and if I collapse the tree ,all these subItems
> are hidden...
> but if I resize the shell and do the same..its not working ....
> I mean ,the items in the first column are hidden but those in the second
> and 3rd are not.
>
> 2.)I want a dialog to open when i click on the label in the second
> column ..
> I am not able to add listeners to the label..How can i do it???
>
>
> Thanks in advance..
> Swetha
>
>
>
|
|
|
Re: How to add events to a cell in Grid [message #18001 is a reply to message #17228] |
Wed, 29 November 2006 06:24 |
Eclipse User |
|
|
|
Originally posted by: swetha.atc.tcs.co.in
Hi
sorry for the delay...
Here is my complete code...
public class MyGrid
{
String col1[]={"First","Second","Third"};
String col3[]={"1st","2nd","3rd"};
int width[]={200,30,200};
GridColumn column = null;
GridItem item = null;
GridItem treeItems[] = null;
GridItem treeItem=null;
GridEditor gridEditor = null;
GridColumn[] columns;
GridItem items[]=null;
GridItem subItem=null;
GridItem subItemsArray[] = null;
Label label=null;
Grid grid ;
private ArrayList subItems=new ArrayList();
public void run()
{
Display display=new Display();
Shell shell=new Shell(display);
shell.setLayout(new FillLayout());
color = new Color(shell.getDisplay(), new RGB(0,0, 0));
createContents(shell);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected Control createContents(final Shell shell)
{
sash_form = new SashForm(shell, SWT.HORIZONTAL | SWT.NULL);
dlg = new ColorDialog(shell);
grid = new Grid(sash_form,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
grid.setLinesVisible(false);
grid.setCellSelectionEnabled(true);
createGrid(grid);
grid.setSize(300,300);
return sash_form;
}
public void createGrid(final Grid grid)
{
grid.setHeaderVisible(true);
for(int i=0;i<SIZE;i++)
{
column=new GridColumn(grid,SWT.NONE);
column.setTree(true);
column.setText("Column"+i);
column.setWidth(width[i]);
}
columns=grid.getColumns();
columns[1].setText(" ");
for(int i=0;i<SIZE;i++)
{
item=new GridItem(grid,SWT.NONE);
}
items=grid.getItems();
for(int i=0;i<SIZE;i++)
{
subItem=new GridItem(items[0],SWT.NONE);
}
subItemsArray=items[0].getItems();
for(int i=0;i<items.length;i++)
{
GridEditor editor = new GridEditor (grid);
items[i].setText(col1[i]);
label = new Label (grid, SWT.BORDER);
label.setText(" ");
label.setBackground(color);
label.pack ();
editor.minimumWidth = label.getSize ().x;
editor.horizontalAlignment = SWT.LEFT;
editor.setEditor (label, items[i], 1);
editor=new GridEditor(grid);
Text text1 = new Text (grid, SWT.NONE);
text1.setText(col3[i]);
editor.grabHorizontal = true;
editor.setEditor(text1, items[i], 2);
}
}
public static void main (String [] args)
{
new GridExample().run();
}
}
When i run this code...
1.)Expand the first gridItem,maximize the window and then collapse the
first griditem...
2.)Can u give sample code for adding events when a label in the above
grid is clicked...
Thanks
Swetha
|
|
|
Re: How to add events to a cell in Grid [message #18040 is a reply to message #18001] |
Wed, 29 November 2006 15:02 |
Chris Gross Messages: 253 Registered: July 2009 |
Senior Member |
|
|
Re 1.) It appears there is a bug in GridEditor. It does not update the
location of the editors when a tree item is expanded or collapsed. I've
entered a new bug for it. You can CC yourself to the bug to be updated
when its fixed.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=166206
If you have a small amount of tree items, you can manually workaround
this bug by listening for the expand/collapse event on the parent items
and calling GridEditor.layout().
Re 2.) Just add listeners to your label... like:
label.addListener(SWT.MouseDoubleClick, new Listener()
{
public void handleEvent(Event event)
{
System.out.println("double clicked");
}
});
-Chris
Swetha wrote:
> Hi
>
> sorry for the delay...
>
> Here is my complete code...
>
> public class MyGrid {
> String col1[]={"First","Second","Third"};
> String col3[]={"1st","2nd","3rd"};
> int width[]={200,30,200};
>
> GridColumn column = null;
> GridItem item = null;
> GridItem treeItems[] = null;
> GridItem treeItem=null;
> GridEditor gridEditor = null;
> GridColumn[] columns;
> GridItem items[]=null;
> GridItem subItem=null;
> GridItem subItemsArray[] = null;
> Label label=null;
> Grid grid ;
> private ArrayList subItems=new ArrayList();
> public void run()
> {
> Display display=new Display();
> Shell shell=new Shell(display);
> shell.setLayout(new FillLayout());
>
> color = new Color(shell.getDisplay(), new RGB(0,0, 0));
> createContents(shell);
> shell.pack();
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> }
>
>
> protected Control createContents(final Shell shell)
> {
> sash_form = new SashForm(shell, SWT.HORIZONTAL | SWT.NULL);
> dlg = new ColorDialog(shell);
> grid = new Grid(sash_form,SWT.BORDER | SWT.V_SCROLL |
> SWT.H_SCROLL);
> grid.setLinesVisible(false);
> grid.setCellSelectionEnabled(true);
> createGrid(grid);
> grid.setSize(300,300);
> return sash_form;
> }
>
> public void createGrid(final Grid grid)
> {
> grid.setHeaderVisible(true);
> for(int i=0;i<SIZE;i++)
> {
> column=new GridColumn(grid,SWT.NONE);
> column.setTree(true);
> column.setText("Column"+i);
> column.setWidth(width[i]);
> }
> columns=grid.getColumns();
> columns[1].setText(" ");
> for(int i=0;i<SIZE;i++)
> {
> item=new GridItem(grid,SWT.NONE);
> }
> items=grid.getItems();
>
> for(int i=0;i<SIZE;i++)
> {
> subItem=new GridItem(items[0],SWT.NONE);
> }
> subItemsArray=items[0].getItems();
>
> for(int i=0;i<items.length;i++)
> {
> GridEditor editor = new GridEditor (grid);
> items[i].setText(col1[i]);
>
> label = new Label (grid, SWT.BORDER);
> label.setText(" ");
> label.setBackground(color);
> label.pack ();
> editor.minimumWidth = label.getSize ().x;
> editor.horizontalAlignment = SWT.LEFT;
> editor.setEditor (label, items[i], 1);
> editor=new GridEditor(grid);
> Text text1 = new Text (grid, SWT.NONE);
> text1.setText(col3[i]);
> editor.grabHorizontal = true;
> editor.setEditor(text1, items[i], 2);
>
> }
>
> }
>
>
> public static void main (String [] args) {
>
> new GridExample().run();
> }
> }
> When i run this code...
>
> 1.)Expand the first gridItem,maximize the window and then collapse the
> first griditem...
>
> 2.)Can u give sample code for adding events when a label in the above
> grid is clicked...
>
> Thanks
> Swetha
|
|
|
Re: How to add events to a cell in Grid [message #569203 is a reply to message #17118] |
Mon, 27 November 2006 16:19 |
Chris Gross Messages: 471 Registered: July 2009 |
Senior Member |
|
|
Hi Swetha,
I'm afraid I don't quite understand what you are trying to say in #1.
Are you collapsing a tree and the items aren't disappearing? Or are you
collapsing a column group and the columns aren't disappearing? Can you
attach the full code?
Re 2.) You can add listeners to the label thats used in the editor.
There's no reason why you cannot.
Regards,
-Chris
Swetha wrote:
> Hi
>
> I have created a Grid with 3 columns and added 3 griditems in this way..
> The first column being a text,2nd is a label and the third is text again...
>
> GridEditor editor = new GridEditor (grid);
> items[i].setText("something");
> label = new Label (grid, SWT.BORDER);
> label.setText(" ");
> label.setBackground(Display.getCurrent().getSystemColor(13)) ;
> label.pack ();
> editor.minimumWidth = label.getSize ().x;
> editor.horizontalAlignment = SWT.LEFT;
> editor.setEditor (label, items[i], 1);
> editor=new GridEditor(grid);
> Text text1 = new Text (grid, SWT.NONE);
> text1.setText("anything");
> editor.grabHorizontal = true;
> editor.setEditor(text1, items[i], 2);
> The first GridItem contains 3 more subItems....added them in another for
> loop as above..
>
> Now I have 2 problems...
>
> 1.) When i expand the first GridItem ,I am able to see all the subItems
> in all the 3 columns....and if I collapse the tree ,all these subItems
> are hidden...
> but if I resize the shell and do the same..its not working ....
> I mean ,the items in the first column are hidden but those in the second
> and 3rd are not.
>
> 2.)I want a dialog to open when i click on the label in the second
> column ..
> I am not able to add listeners to the label..How can i do it???
>
>
> Thanks in advance..
> Swetha
>
>
>
|
|
|
Re: How to add events to a cell in Grid [message #569787 is a reply to message #17228] |
Wed, 29 November 2006 06:24 |
Swetha Messages: 68 Registered: July 2009 |
Member |
|
|
Hi
sorry for the delay...
Here is my complete code...
public class MyGrid
{
String col1[]={"First","Second","Third"};
String col3[]={"1st","2nd","3rd"};
int width[]={200,30,200};
GridColumn column = null;
GridItem item = null;
GridItem treeItems[] = null;
GridItem treeItem=null;
GridEditor gridEditor = null;
GridColumn[] columns;
GridItem items[]=null;
GridItem subItem=null;
GridItem subItemsArray[] = null;
Label label=null;
Grid grid ;
private ArrayList subItems=new ArrayList();
public void run()
{
Display display=new Display();
Shell shell=new Shell(display);
shell.setLayout(new FillLayout());
color = new Color(shell.getDisplay(), new RGB(0,0, 0));
createContents(shell);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected Control createContents(final Shell shell)
{
sash_form = new SashForm(shell, SWT.HORIZONTAL | SWT.NULL);
dlg = new ColorDialog(shell);
grid = new Grid(sash_form,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
grid.setLinesVisible(false);
grid.setCellSelectionEnabled(true);
createGrid(grid);
grid.setSize(300,300);
return sash_form;
}
public void createGrid(final Grid grid)
{
grid.setHeaderVisible(true);
for(int i=0;i<SIZE;i++)
{
column=new GridColumn(grid,SWT.NONE);
column.setTree(true);
column.setText("Column"+i);
column.setWidth(width[i]);
}
columns=grid.getColumns();
columns[1].setText(" ");
for(int i=0;i<SIZE;i++)
{
item=new GridItem(grid,SWT.NONE);
}
items=grid.getItems();
for(int i=0;i<SIZE;i++)
{
subItem=new GridItem(items[0],SWT.NONE);
}
subItemsArray=items[0].getItems();
for(int i=0;i<items.length;i++)
{
GridEditor editor = new GridEditor (grid);
items[i].setText(col1[i]);
label = new Label (grid, SWT.BORDER);
label.setText(" ");
label.setBackground(color);
label.pack ();
editor.minimumWidth = label.getSize ().x;
editor.horizontalAlignment = SWT.LEFT;
editor.setEditor (label, items[i], 1);
editor=new GridEditor(grid);
Text text1 = new Text (grid, SWT.NONE);
text1.setText(col3[i]);
editor.grabHorizontal = true;
editor.setEditor(text1, items[i], 2);
}
}
public static void main (String [] args)
{
new GridExample().run();
}
}
When i run this code...
1.)Expand the first gridItem,maximize the window and then collapse the
first griditem...
2.)Can u give sample code for adding events when a label in the above
grid is clicked...
Thanks
Swetha
|
|
|
Re: How to add events to a cell in Grid [message #569888 is a reply to message #18001] |
Wed, 29 November 2006 15:02 |
Chris Gross Messages: 471 Registered: July 2009 |
Senior Member |
|
|
Re 1.) It appears there is a bug in GridEditor. It does not update the
location of the editors when a tree item is expanded or collapsed. I've
entered a new bug for it. You can CC yourself to the bug to be updated
when its fixed.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=166206
If you have a small amount of tree items, you can manually workaround
this bug by listening for the expand/collapse event on the parent items
and calling GridEditor.layout().
Re 2.) Just add listeners to your label... like:
label.addListener(SWT.MouseDoubleClick, new Listener()
{
public void handleEvent(Event event)
{
System.out.println("double clicked");
}
});
-Chris
Swetha wrote:
> Hi
>
> sorry for the delay...
>
> Here is my complete code...
>
> public class MyGrid {
> String col1[]={"First","Second","Third"};
> String col3[]={"1st","2nd","3rd"};
> int width[]={200,30,200};
>
> GridColumn column = null;
> GridItem item = null;
> GridItem treeItems[] = null;
> GridItem treeItem=null;
> GridEditor gridEditor = null;
> GridColumn[] columns;
> GridItem items[]=null;
> GridItem subItem=null;
> GridItem subItemsArray[] = null;
> Label label=null;
> Grid grid ;
> private ArrayList subItems=new ArrayList();
> public void run()
> {
> Display display=new Display();
> Shell shell=new Shell(display);
> shell.setLayout(new FillLayout());
>
> color = new Color(shell.getDisplay(), new RGB(0,0, 0));
> createContents(shell);
> shell.pack();
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> }
>
>
> protected Control createContents(final Shell shell)
> {
> sash_form = new SashForm(shell, SWT.HORIZONTAL | SWT.NULL);
> dlg = new ColorDialog(shell);
> grid = new Grid(sash_form,SWT.BORDER | SWT.V_SCROLL |
> SWT.H_SCROLL);
> grid.setLinesVisible(false);
> grid.setCellSelectionEnabled(true);
> createGrid(grid);
> grid.setSize(300,300);
> return sash_form;
> }
>
> public void createGrid(final Grid grid)
> {
> grid.setHeaderVisible(true);
> for(int i=0;i<SIZE;i++)
> {
> column=new GridColumn(grid,SWT.NONE);
> column.setTree(true);
> column.setText("Column"+i);
> column.setWidth(width[i]);
> }
> columns=grid.getColumns();
> columns[1].setText(" ");
> for(int i=0;i<SIZE;i++)
> {
> item=new GridItem(grid,SWT.NONE);
> }
> items=grid.getItems();
>
> for(int i=0;i<SIZE;i++)
> {
> subItem=new GridItem(items[0],SWT.NONE);
> }
> subItemsArray=items[0].getItems();
>
> for(int i=0;i<items.length;i++)
> {
> GridEditor editor = new GridEditor (grid);
> items[i].setText(col1[i]);
>
> label = new Label (grid, SWT.BORDER);
> label.setText(" ");
> label.setBackground(color);
> label.pack ();
> editor.minimumWidth = label.getSize ().x;
> editor.horizontalAlignment = SWT.LEFT;
> editor.setEditor (label, items[i], 1);
> editor=new GridEditor(grid);
> Text text1 = new Text (grid, SWT.NONE);
> text1.setText(col3[i]);
> editor.grabHorizontal = true;
> editor.setEditor(text1, items[i], 2);
>
> }
>
> }
>
>
> public static void main (String [] args) {
>
> new GridExample().run();
> }
> }
> When i run this code...
>
> 1.)Expand the first gridItem,maximize the window and then collapse the
> first griditem...
>
> 2.)Can u give sample code for adding events when a label in the above
> grid is clicked...
>
> Thanks
> Swetha
|
|
|
Goto Forum:
Current Time: Fri Dec 13 17:26:44 GMT 2024
Powered by FUDForum. Page generated in 0.02251 seconds
|