[Pocket PC] Popup menu and table [message #450310] |
Thu, 10 February 2005 10:57 |
Eclipse User |
|
|
|
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();
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03227 seconds