Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Save state when application closes
Save state when application closes [message #246362] Thu, 27 May 2004 16:35
Eclipse UserFriend
Originally posted by: christian.hauser.dvbern.ch

Hello everyone

How do I save the state of some GUI controls in my standalone JFace
application when the user closes the window by clicking on the X in the
upper right corner?

Here is an example of what I'm trying. I'd like to call saveSettings()
when the user wants to exit the application. However, it is impossible
to access the table widget (resulting in a NPE). This is possible with
plain SWT. Could anyone enlighten me, please?

public class ClosingJFace extends ApplicationWindow {

private Table table;

public ClosingJFace() {
super(null);
}

protected Control createContents(Composite parent) {
getShell().setText("MyApp");
getShell().addListener(SWT.Dispose, new Listener() {
public void handleEvent(Event event) {
System.out.println("Disposing Shell...");
saveSettings();
}
});
getShell().addListener(SWT.Close, new Listener() {
public void handleEvent(Event event) {
System.out.println("Closing Shell...");
//saveSettings();
}
});

Composite composite = new Composite(parent, SWT.NONE);
Table table = new Table(composite, SWT.MULTI | SWT.BORDER |
SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
String[] titles = {"Resource", "Folder", "Location"};
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(table, SWT.NULL);
column.setText(titles[i]);
}
int count = 50;
for (int i = 0; i < count; i++) {
TableItem item = new TableItem(table, SWT.NULL);
item.setText(0, "almost everywhere");
item.setText(1, "some.folder");
item.setText(2, "line " + i + " in nowhere");
}
for (int i = 0; i < titles.length; i++) {
table.getColumn(i).pack();
}
table.setSize(table.computeSize(SWT.DEFAULT, 150));

return composite;
}

public void saveSettings() {
DialogSettings settings = new DialogSettings("MyApp");
for (int i = 0; i < table.getColumnCount(); i++) {
settings.put(table.getColumn(i).getText() + ".ColumnWidth",
table.getColumn(i).getWidth());
System.out.println("setting " + i + " added...");
}
}

public static void main(String[] args) {
ClosingJFace app = new ClosingJFace();
app.setBlockOnOpen(true);
app.open();
Display.getCurrent().dispose();
}
}


Any hint on that is highly appreciated.

Regards,
Christian
Previous Topic:3.0M9 configuration error
Next Topic:intercept and modify typed key
Goto Forum:
  


Current Time: Wed Sep 18 17:15:48 GMT 2024

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

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

Back to the top