use of org.eclipse.ui.application.ActionBarAdvisor in project eclipse.platform.ui by eclipse-platform.
the class WorkbenchSaveRestoreStateTest method testSaveRestoreActionBarState.
/**
* Test save/restore state lifecycle API for WorkbenchWindowAdvisor
*/
@Test
public void testSaveRestoreActionBarState() {
final String advisorStateData = Long.toString(System.currentTimeMillis());
// launch workbench and save some state data
WorkbenchAdvisorObserver wa = new WorkbenchAdvisorObserver(1) {
@Override
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
return new WorkbenchWindowAdvisor(configurer) {
@Override
public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer1) {
return new ActionBarAdvisor(configurer1) {
@Override
public IStatus saveState(IMemento memento) {
assertNotNull(memento);
memento.putString(ACTIONBAR_ADVISOR_STATE_KEY, advisorStateData);
return super.saveState(memento);
}
};
}
};
}
@Override
public void initialize(IWorkbenchConfigurer c) {
super.initialize(c);
c.setSaveAndRestore(true);
}
@Override
public void eventLoopIdle(Display d) {
workbenchConfig.getWorkbench().restart();
}
};
int code = PlatformUI.createAndRunWorkbench(display, wa);
assertEquals(PlatformUI.RETURN_RESTART, code);
assertFalse(display.isDisposed());
display.dispose();
assertTrue(display.isDisposed());
// restore the workbench and check for state data
display = PlatformUI.createDisplay();
WorkbenchAdvisorObserver wa2 = new WorkbenchAdvisorObserver(1) {
@Override
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
return new WorkbenchWindowAdvisor(configurer) {
@Override
public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer1) {
return new ActionBarAdvisor(configurer1) {
@Override
public IStatus restoreState(IMemento memento) {
assertNotNull(memento);
String stateData = memento.getString(ACTIONBAR_ADVISOR_STATE_KEY);
assertNotNull(stateData);
assertTrue(advisorStateData.equals(stateData));
return super.restoreState(memento);
}
};
}
};
}
@Override
public void initialize(IWorkbenchConfigurer c) {
super.initialize(c);
c.setSaveAndRestore(true);
}
};
int code2 = PlatformUI.createAndRunWorkbench(display, wa2);
assertEquals(PlatformUI.RETURN_OK, code2);
}
use of org.eclipse.ui.application.ActionBarAdvisor in project eclipse.platform.ui by eclipse-platform.
the class WorkbenchWindowConfigurerTest method testThreading.
// tests to ensure that all WorkbenchAdvisor API is called from the UI thread.
@Test
public void testThreading() {
final ArrayList<String> results = new ArrayList<>();
WorkbenchAdvisor advisor = new RCPTestWorkbenchAdvisor(1) {
@Override
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
return new WorkbenchWindowAdvisor(configurer) {
private void ensureThread() {
if (Display.getCurrent() != null) {
return;
}
Exception e = new Exception();
e.fillInStackTrace();
StackTraceElement element = e.getStackTrace()[1];
results.add(element.getClassName() + '.' + element.getMethodName());
}
@Override
public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
ensureThread();
return new ActionBarAdvisor(configurer) {
@Override
public void dispose() {
ensureThread();
super.dispose();
}
@Override
protected void disposeAction(IAction action) {
ensureThread();
super.disposeAction(action);
}
@Override
protected void disposeActions() {
ensureThread();
super.disposeActions();
}
@Override
public void fillActionBars(int flags) {
ensureThread();
super.fillActionBars(flags);
}
@Override
protected void fillCoolBar(ICoolBarManager coolBar) {
ensureThread();
super.fillCoolBar(coolBar);
}
@Override
protected void fillMenuBar(IMenuManager menuBar) {
ensureThread();
super.fillMenuBar(menuBar);
}
@Override
protected void fillStatusLine(IStatusLineManager statusLine) {
ensureThread();
super.fillStatusLine(statusLine);
}
@Override
protected IAction getAction(String id) {
ensureThread();
return super.getAction(id);
}
@Override
protected IActionBarConfigurer getActionBarConfigurer() {
ensureThread();
return super.getActionBarConfigurer();
}
@Override
public boolean isApplicationMenu(String menuId) {
ensureThread();
return super.isApplicationMenu(menuId);
}
@Override
protected void makeActions(IWorkbenchWindow window) {
ensureThread();
super.makeActions(window);
}
@Override
protected void register(IAction action) {
ensureThread();
super.register(action);
}
@Override
public IStatus restoreState(IMemento memento) {
ensureThread();
return super.restoreState(memento);
}
@Override
public IStatus saveState(IMemento memento) {
ensureThread();
return super.saveState(memento);
}
};
}
@Override
@SuppressWarnings("deprecation")
public Control createEmptyWindowContents(Composite parent) {
ensureThread();
return super.createEmptyWindowContents(parent);
}
@Override
@SuppressWarnings("deprecation")
public void createWindowContents(Shell shell) {
ensureThread();
super.createWindowContents(shell);
}
@Override
public void dispose() {
ensureThread();
super.dispose();
}
@Override
protected IWorkbenchWindowConfigurer getWindowConfigurer() {
ensureThread();
return super.getWindowConfigurer();
}
@Override
public void openIntro() {
ensureThread();
super.openIntro();
}
@Override
public void postWindowClose() {
ensureThread();
super.postWindowClose();
}
@Override
public void postWindowCreate() {
ensureThread();
super.postWindowCreate();
}
@Override
public void postWindowOpen() {
ensureThread();
super.postWindowOpen();
}
@Override
public void postWindowRestore() throws WorkbenchException {
ensureThread();
super.postWindowRestore();
}
@Override
public void preWindowOpen() {
ensureThread();
super.preWindowOpen();
}
@Override
public boolean preWindowShellClose() {
ensureThread();
return super.preWindowShellClose();
}
@Override
public IStatus restoreState(IMemento memento) {
ensureThread();
return super.restoreState(memento);
}
@Override
public IStatus saveState(IMemento memento) {
ensureThread();
return super.saveState(memento);
}
};
}
};
int code = PlatformUI.createAndRunWorkbench(display, advisor);
assertEquals(PlatformUI.RETURN_OK, code);
if (!results.isEmpty()) {
StringBuilder buffer = new StringBuilder("Window/action bar advisor methods called from non-UI threads:\n");
for (String string : results) {
buffer.append(string).append('\n');
}
fail(buffer.toString());
}
}
Aggregations