|
|
Re: Send Events directly after application construction [message #1007130 is a reply to message #1007054] |
Mon, 04 February 2013 15:00 |
Christoph Keimel Messages: 482 Registered: December 2010 Location: Germany |
Senior Member |
|
|
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 08:22] Report message to a moderator
|
|
|
Re: Send Events directly after application construction [message #1007287 is a reply to message #1007130] |
Tue, 05 February 2013 11:34 |
Eclipse User |
|
|
|
I haven't read the whole thread in detail but it looks like MApplicationElement#getPersistedState is relevant here. Basically every model element (addon, MApplication, MPart etc.) extends MAE and it inherits this map like structure which is persisted across restarts. I'm sure Lars tutorials have something more detailed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Send Events directly after application construction [message #1017264 is a reply to message #1017261] |
Mon, 11 March 2013 11:24 |
Eclipse User |
|
|
|
Aljoscha, I haven't really understood what you're trying to accomplish, and why the normal E4 workbench save and restore mechanisms are insufficient? But rather of having your part contribution objects attempt to talk to each other, have them talk to a central service instead -- separating your business logic and your presentation logic.
Brian,
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05957 seconds