Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » tabletree cell
tabletree cell [message #369585] Mon, 05 May 2003 07:22 Go to next message
Eclipse UserFriend
Originally posted by: monicas.noida.hcltech.com

Hi,

I have a TreeTable. i want that when ever i right click on any cell then i
should be able to have a popup menu visible also i should be able to get
the item in that particular cell.
can u suggest something.

Thanks and Regards,
Monica
Re: tabletree cell [message #369598 is a reply to message #369585] Mon, 05 May 2003 10:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: veronika_irvine.oti.com

Setting a popup menu on a TableTree is fairly simple:

TableTree tree = new TableTree(shell, SWT.BORDER);
Table table = tree.getTable();
Menu menu = new Menu (shell, SWT.POP_UP);
MenuItem item = new MenuItem (menu, SWT.PUSH);
item.setText ("menu item");
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("hello");
}
});
table.setMenu(menu);

However, knowing what cell you are over is not. The problem is that the
popmenu can be activated by the keyboard (Shift F10 on Windows) or by the
mouse. If the menu is activated by the keyboard, it pops up wherever the
cursor is (which may not be over the TableTree at all). You could find out
where the cursor is and use that to find an item but it doesn't really work
because you move the cursor to select the menu item and loose your place:

MenuItem item = new MenuItem (menu, SWT.PUSH);
item.setText ("menu item");
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Point p = display.getCursorLocation();
p = table.toControl(p);
TableTreeItem item = tree.getItem(p);
if (item == null) return;
int count = table.getColumnCount();
for (int i = 0; i < count; i++) {
if (item.getBounds(i).contains(p)) {
System.out.println(item.getText(i));
break;
}
}
}
});

In 3.0, we have introduced the MenuDetect event. It is much better to use
this event rather than detecting a right mouse down event because different
platforms bring up menus on different events (e,g, Windows uses mouse up and
motif uses mouse down) and there are also keyboard accelerators to consider.
The MenuDetect event gives the x, y, coordinates of where the menu will
appear which you could use to locate a cell. It still has the problem that
when a keyboard accelerator is used, the x and y coordinates are just the
location of the cursor which could be anywhere and is therefore not very
useful to people with accessibility problems.

final TableTreeItem[] menuItem = new TableTreeItem[1];
final int[] menuItemColumn = new int[1];

final Menu menu = new Menu (shell, SWT.POP_UP);
MenuItem item = new MenuItem (menu, SWT.PUSH);
item.setText ("menu item");
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (menuItem[0] != null) {

System.out.println(menuItem[0].getText(menuItemColumn[0]));
}
}
});
table.addListener(SWT.MenuDetect, new Listener() {
public void handleEvent(org.eclipse.swt.widgets.Event event) {
menuItem[0] = null;
Point p = new Point(event.x, event.y);
p = table.toControl(p);
TableTreeItem item = tree.getItem(p);
if (item == null) return;
int count = table.getColumnCount();
for (int i = 0; i < count; i++) {
if (item.getBounds(i).contains(p)) {
menu.setLocation(event.x, event.y);
menu.setVisible(true);
menuItem[0] = item;
menuItemColumn[0] = i;
break;
}
}
}
});

"Monica" <monicas@noida.hcltech.com> wrote in message
news:b95hht$50k$1@rogue.oti.com...
> Hi,
>
> I have a TreeTable. i want that when ever i right click on any cell then i
> should be able to have a popup menu visible also i should be able to get
> the item in that particular cell.
> can u suggest something.
>
> Thanks and Regards,
> Monica
>
Re: tabletree cell [message #369622 is a reply to message #369598] Tue, 06 May 2003 01:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: monicas.noida.hcltech.com

Hi,

Thanks for the reply. but it isnt able to solve my problem.

Actually, i have a decoration on which i have a couple of things like a
menu bar, a tabletree.
it looks somethink like

------------------------------
|Menu1 |
-----------------------------|
| ------------------------ |
| | | | | |
| | | | | |
| | Table Tree | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| ------------------------ |
| |
------------------------------

Now, the objective is that whenever i click on any cell of the tabletree
then firstly i should be able to retrieve the value in that particular
cell and then depending on that retrieved value a pop up menu should be
displayed. this pop up menu has some menuitems which are enabled or
diabled depending on the value in the tabletree cell.
i think now i am able to tell the problem i am facing properly.

can u tell some way out to achieve the desired objective,

Thanks and Regards,
Monica

Veronika Irvine wrote:

> Setting a popup menu on a TableTree is fairly simple:

> TableTree tree = new TableTree(shell, SWT.BORDER);
> Table table = tree.getTable();
> Menu menu = new Menu (shell, SWT.POP_UP);
> MenuItem item = new MenuItem (menu, SWT.PUSH);
> item.setText ("menu item");
> item.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> System.out.println("hello");
> }
> });
> table.setMenu(menu);

> However, knowing what cell you are over is not. The problem is that the
> popmenu can be activated by the keyboard (Shift F10 on Windows) or by the
> mouse. If the menu is activated by the keyboard, it pops up wherever the
> cursor is (which may not be over the TableTree at all). You could find out
> where the cursor is and use that to find an item but it doesn't really work
> because you move the cursor to select the menu item and loose your place:

> MenuItem item = new MenuItem (menu, SWT.PUSH);
> item.setText ("menu item");
> item.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> Point p = display.getCursorLocation();
> p = table.toControl(p);
> TableTreeItem item = tree.getItem(p);
> if (item == null) return;
> int count = table.getColumnCount();
> for (int i = 0; i < count; i++) {
> if (item.getBounds(i).contains(p)) {
> System.out.println(item.getText(i));
> break;
> }
> }
> }
> });

> In 3.0, we have introduced the MenuDetect event. It is much better to use
> this event rather than detecting a right mouse down event because different
> platforms bring up menus on different events (e,g, Windows uses mouse up and
> motif uses mouse down) and there are also keyboard accelerators to consider.
> The MenuDetect event gives the x, y, coordinates of where the menu will
> appear which you could use to locate a cell. It still has the problem that
> when a keyboard accelerator is used, the x and y coordinates are just the
> location of the cursor which could be anywhere and is therefore not very
> useful to people with accessibility problems.

> final TableTreeItem[] menuItem = new TableTreeItem[1];
> final int[] menuItemColumn = new int[1];

> final Menu menu = new Menu (shell, SWT.POP_UP);
> MenuItem item = new MenuItem (menu, SWT.PUSH);
> item.setText ("menu item");
> item.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> if (menuItem[0] != null) {

> System.out.println(menuItem[0].getText(menuItemColumn[0]));
> }
> }
> });
> table.addListener(SWT.MenuDetect, new Listener() {
> public void handleEvent(org.eclipse.swt.widgets.Event event) {
> menuItem[0] = null;
> Point p = new Point(event.x, event.y);
> p = table.toControl(p);
> TableTreeItem item = tree.getItem(p);
> if (item == null) return;
> int count = table.getColumnCount();
> for (int i = 0; i < count; i++) {
> if (item.getBounds(i).contains(p)) {
> menu.setLocation(event.x, event.y);
> menu.setVisible(true);
> menuItem[0] = item;
> menuItemColumn[0] = i;
> break;
> }
> }
> }
> });

> "Monica" <monicas@noida.hcltech.com> wrote in message
> news:b95hht$50k$1@rogue.oti.com...
> > Hi,
> >
> > I have a TreeTable. i want that when ever i right click on any cell then i
> > should be able to have a popup menu visible also i should be able to get
> > the item in that particular cell.
> > can u suggest something.
> >
> > Thanks and Regards,
> > Monica
> >
Re: tabletree cell [message #369636 is a reply to message #369622] Tue, 06 May 2003 09:19 Go to previous message
Eclipse UserFriend
Originally posted by: veronika_irvine.oti.com

The mouse event has x and y coordinates. You can use this to identify the
cell you clicked on:

Point p = new Point(mouseEvent.x, mouseEvent.y);
TableTreeItem item = tree.getItem(p);
if (item == null) return;
int count = table.getColumnCount();
for (int i = 0; i < count; i++) {
if (item.getBounds(i).contains(p)) {
System.out.println("Cell contains "+item.getText(i));
break;
}
}

Note that by relying on a mouse click you have made your application
inaccessible to users who can not use a mouse.


"Monica" <monicas@noida.hcltech.com> wrote in message
news:b97hk8$h4f$1@rogue.oti.com...
> Hi,
>
> Thanks for the reply. but it isnt able to solve my problem.
>
> Actually, i have a decoration on which i have a couple of things like a
> menu bar, a tabletree.
> it looks somethink like
>
> ------------------------------
> |Menu1 |
> -----------------------------|
> | ------------------------ |
> | | | | | |
> | | | | | |
> | | Table Tree | |
> | | | | | |
> | | | | | |
> | | | | | |
> | | | | | |
> | ------------------------ |
> | |
> ------------------------------
>
> Now, the objective is that whenever i click on any cell of the tabletree
> then firstly i should be able to retrieve the value in that particular
> cell and then depending on that retrieved value a pop up menu should be
> displayed. this pop up menu has some menuitems which are enabled or
> diabled depending on the value in the tabletree cell.
> i think now i am able to tell the problem i am facing properly.
>
> can u tell some way out to achieve the desired objective,
>
> Thanks and Regards,
> Monica
>
> Veronika Irvine wrote:
>
> > Setting a popup menu on a TableTree is fairly simple:
>
> > TableTree tree = new TableTree(shell, SWT.BORDER);
> > Table table = tree.getTable();
> > Menu menu = new Menu (shell, SWT.POP_UP);
> > MenuItem item = new MenuItem (menu, SWT.PUSH);
> > item.setText ("menu item");
> > item.addSelectionListener(new SelectionAdapter() {
> > public void widgetSelected(SelectionEvent e) {
> > System.out.println("hello");
> > }
> > });
> > table.setMenu(menu);
>
> > However, knowing what cell you are over is not. The problem is that the
> > popmenu can be activated by the keyboard (Shift F10 on Windows) or by
the
> > mouse. If the menu is activated by the keyboard, it pops up wherever
the
> > cursor is (which may not be over the TableTree at all). You could find
out
> > where the cursor is and use that to find an item but it doesn't really
work
> > because you move the cursor to select the menu item and loose your
place:
>
> > MenuItem item = new MenuItem (menu, SWT.PUSH);
> > item.setText ("menu item");
> > item.addSelectionListener(new SelectionAdapter() {
> > public void widgetSelected(SelectionEvent e) {
> > Point p = display.getCursorLocation();
> > p = table.toControl(p);
> > TableTreeItem item = tree.getItem(p);
> > if (item == null) return;
> > int count = table.getColumnCount();
> > for (int i = 0; i < count; i++) {
> > if (item.getBounds(i).contains(p)) {
> > System.out.println(item.getText(i));
> > break;
> > }
> > }
> > }
> > });
>
> > In 3.0, we have introduced the MenuDetect event. It is much better to
use
> > this event rather than detecting a right mouse down event because
different
> > platforms bring up menus on different events (e,g, Windows uses mouse up
and
> > motif uses mouse down) and there are also keyboard accelerators to
consider.
> > The MenuDetect event gives the x, y, coordinates of where the menu will
> > appear which you could use to locate a cell. It still has the problem
that
> > when a keyboard accelerator is used, the x and y coordinates are just
the
> > location of the cursor which could be anywhere and is therefore not very
> > useful to people with accessibility problems.
>
> > final TableTreeItem[] menuItem = new TableTreeItem[1];
> > final int[] menuItemColumn = new int[1];
>
> > final Menu menu = new Menu (shell, SWT.POP_UP);
> > MenuItem item = new MenuItem (menu, SWT.PUSH);
> > item.setText ("menu item");
> > item.addSelectionListener(new SelectionAdapter() {
> > public void widgetSelected(SelectionEvent e) {
> > if (menuItem[0] != null) {
>
> > System.out.println(menuItem[0].getText(menuItemColumn[0]));
> > }
> > }
> > });
> > table.addListener(SWT.MenuDetect, new Listener() {
> > public void handleEvent(org.eclipse.swt.widgets.Event event) {
> > menuItem[0] = null;
> > Point p = new Point(event.x, event.y);
> > p = table.toControl(p);
> > TableTreeItem item = tree.getItem(p);
> > if (item == null) return;
> > int count = table.getColumnCount();
> > for (int i = 0; i < count; i++) {
> > if (item.getBounds(i).contains(p)) {
> > menu.setLocation(event.x, event.y);
> > menu.setVisible(true);
> > menuItem[0] = item;
> > menuItemColumn[0] = i;
> > break;
> > }
> > }
> > }
> > });
>
> > "Monica" <monicas@noida.hcltech.com> wrote in message
> > news:b95hht$50k$1@rogue.oti.com...
> > > Hi,
> > >
> > > I have a TreeTable. i want that when ever i right click on any cell
then i
> > > should be able to have a popup menu visible also i should be able to
get
> > > the item in that particular cell.
> > > can u suggest something.
> > >
> > > Thanks and Regards,
> > > Monica
> > >
>
>
>
>
>
Previous Topic:problem compiling SWT example
Next Topic:Change cursor while drag and drop
Goto Forum:
  


Current Time: Fri Oct 31 06:50:05 EDT 2025

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

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

Back to the top