|
|
Re: Send Events directly after application construction [message #1007130 is a reply to message #1007054] |
Mon, 04 February 2013 10:00   |
Eclipse User |
|
|
|
Hi Aljoscha
I like to use the Equinox Preferences to save UI state. In my part contribution class I inject the preference node and maybe some preferences to use for the logic. DI cares about creating a node for my part:
@Inject @Preference private IEclipsePreferences prefNode;
@Inject @Optional @Preference(value=PREF_SHOW_INAKTIV)
private Boolean showInactiv = null;
If you need to do a refresh in case a preference changes, you can let DI call a function instead of using a member variable:
@Inject
void inactivPrefChanged(@Optional @Preference(value=PREF_SHOW_INAKTIV) Boolean showInactiv) {
... do the refresh ...;
}
When something changes, I just set the preference and let DI care about the values.
final Button showInactivBtn = new Button(control.getComposite(), SWT.CHECK);
showInactivBtn .setText("Show inactive Elements");
showInactivBtn .setSelection(showInaktiv);
showInactivBtn .addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
prefNode.putBoolean(PREF_SHOW_INAKTIV, showInactivBtn.getSelection());
}
});
When the part gets dstroyed, I save the UI state on @PersistState. I.e. I save the column order and the column width of a JFace Viewer like this:
@PersistState
private void persistState() {
// Save the order of the columns
int[] columnOrder = viewer.getGrid().getColumnOrder();
String columnOrderString = Joiner.on(',').join(ArrayUtils.toObject(columnOrder));
prefNode.put(PREF_GRID_ORDER, columnOrderString);
// Save the width of every column using the EMF feature name as a key
for (GridColumn col : viewer.getGrid().getColumns()) {
EStructuralFeature feature = (EStructuralFeature) col.getData(DATA_COLUMN_FEATURE);
prefNode.putInt(feature.getName() + PREF_COLUMN_WIDTH_SUFFIX, col.getWidth());
}
// Cause Equinox the write the preferences to disc
try {
prefNode.flush();
} catch (BackingStoreException e) {
logger.error("Error while saving the preferences", e); //$NON-NLS-1$
}
}
[Edited after the Answer from Sopot below:]
An alternative to this approach could be to put your UI state into the persistedState of your MPart and let E4 save it in the application model for you. I haven't tried this approach, but it could look something like this:
@PostConstruct
void postConstruct(MPart part) {
String myStateValue = part.getPersistedState().get(MY_STATE_KEY);
}
@PersistState
void persistState(MPart part) {
part.getPersistedState ().put(MY_STATE_KEY, myStateValue);
}
Hope this helps!
Greetings
Christoph
[Updated on: Thu, 07 February 2013 03:22] by Moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05930 seconds