Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » [Pocket PC] Popup menu and table
[Pocket PC] Popup menu and table [message #450310] Thu, 10 February 2005 10:57 Go to next message
Eclipse UserFriend
Originally posted by: fr.wedekind2-LA.yahoo.com

Hi,

I have an problem on ppc with a table and a popup menu.

The problem is the popup menuitem 'Pay' which should only enabled if the
person has open payments.
I discovered that the following method on Pocket PC will invoke only once
menuPopup.addListener(SWT.Show, new Listener() {
public void handleEvent(Event event) {
and then the popup menu is always the same.

Or more in detail:
- start programm ==> popup menu on john or frank ==> the 'pay' item is
now for all persons disabled
- start programm ==> popup menu on bill ==> the 'pay' item is now for
all persons enabled

Is this a bug or pocket pc behaviour and exists an workaround for this?

I have Windows Mobile 2003, Second edition - Version 4.21.1088 (Build
14260.2.0.5) and SWT 3.0.1 for PPC. On PC the snippet works right.

Will this SWT version influence in the eRCP project?

Many thanks,
Frank




package test;

import java.util.*;

import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class TablePopupSnippet {
private Person person;
protected Shell shell;
private Table table;

public TablePopupSnippet() {
// model
Vector persons = new Vector();
persons.add(new Person("John", 2, false));
persons.add(new Person("Bill", 5, true));
persons.add(new Person("Frank", 1, false));
// ui
Display display = new Display();
shell = new Shell(display, SWT.CLOSE | SWT.RESIZE);
shell.setText("Table popup");
shell.setLayout(new FillLayout());
table = new Table(shell, SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
showDetails();
}
});
new TableColumn(table, SWT.CENTER).setText("Name");
new TableColumn(table, SWT.CENTER).setText("Orders");
new TableColumn(table, SWT.CENTER).setText("Open payments");

final Menu menuPopup = new Menu(table);

MenuItem itemShow = new MenuItem(menuPopup, SWT.CASCADE);
itemShow.setText("Show person details");
itemShow.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
showDetails();
}
});

new MenuItem(menuPopup, SWT.SEPARATOR);

final MenuItem itemPay = new MenuItem(menuPopup, SWT.CASCADE);
itemPay.setText("Pay");
itemPay.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
box.setText("Info");
box.setMessage("You should pay your bill.");
box.open();
}
});

menuPopup.addListener(SWT.Show, new Listener() {
public void handleEvent(Event event) {
Person person = getPerson();
System.out.println(
"Person: " + person.getName() + ", open payments: " +
person.isOpenPayment());
itemPay.setEnabled(person.isOpenPayment());
}
});

table.setMenu(menuPopup);

for (int i = 0; i < persons.size(); i++) {
person = (Person) persons.get(i);
TableItem item = new TableItem(table, SWT.NONE);
item.setData(person);
item.setText(0, person.getName());
item.setText(1, String.valueOf(person.getOrders()));
item.setText(2, String.valueOf(person.isOpenPayment()));
}

for (int i = 0; i < table.getColumnCount(); i++) {
table.getColumn(i).pack();
}

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

private void showDetails() {
Person person = getPerson();
MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
box.setText("Info");
box.setMessage(
"Person: " + person.getName() + ", open payments: " +
person.isOpenPayment());
box.open();
}

private Person getPerson() {
TableItem[] tableItems = table.getSelection();
TableItem tableItem = tableItems[0];
return (Person) tableItem.getData();
}

class Person {
String name;
int orders;
boolean openPayment;

public Person(String name, int orders, boolean openPayment) {
this.name = name;
this.orders = orders;
this.openPayment = openPayment;
}

public String getName() {
return name;
}

public boolean isOpenPayment() {
return openPayment;
}

public int getOrders() {
return orders;
}
}

public static void main(String[] args) {
new TablePopupSnippet();
}
}
Re: [Pocket PC] Popup menu and table [message #450417 is a reply to message #450310] Fri, 11 February 2005 15:09 Go to previous messageGo to next message
Christophe Cornu is currently offline Christophe CornuFriend
Messages: 304
Registered: July 2009
Senior Member
Hi Frank:

I opened a bug report. Check out the workaround at:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=84997#c1

Thanks for the snippet. It's worth a thousand words :-)

Chris
Re: [Pocket PC] Popup menu and table [message #450452 is a reply to message #450417] Sun, 13 February 2005 08:17 Go to previous message
Eclipse UserFriend
Originally posted by: fr.wedekind2-LA.yahoo.com

Christophe Cornu wrote:
> Hi Frank:
>
> I opened a bug report. Check out the workaround at:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=84997#c1
>
> Thanks for the snippet. It's worth a thousand words :-)
>
> Chris
>
>

Hi Chris,

Thank you very much for the great code snippet which solves my problem!
Do you also see my other code snippet in 'SWT menu button on PPC'
(2005.02.10.) for my other PPC problem?

Regards, Frank
Previous Topic:Tray under KDE
Next Topic:Snippet98 with ScrolledComposite (dynamically removing and adding children of a Composite)?
Goto Forum:
  


Current Time: Wed Sep 18 19:37:04 GMT 2024

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

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

Back to the top