The TimeZoneView
, created in Chapter 2, Creating views with SWT, presents a list of regions as tabs and allows the user to select a region of interest. When the view is closed and then re-opened, the previously selected tab is not remembered. This is the kind of nugget that could be persisted in a memento for later re-use. Perform the following steps:
To record what the last selected tab was when it is changed; add the variable
lastTabSelected
, which contains the last selected tab name, to theTimeZoneView
as follows:private transient String lastTabSelected;
At the end of
createPartControl(
)
, add a selection listener to the tab, such that any time the tab's selection is changed, the name of the tab is remembered:tabs.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if(e.item instanceof CTabItem) { lastTabSelected = ((CTabItem)e.item).getText(); } } });
When the workbench...