use of org.eclipse.ui.internal.StartupThreading.StartupRunnable in project eclipse.platform.ui by eclipse-platform.
the class WorkbenchAdvisor method openWindows.
/**
* Opens the workbench windows on startup. The default implementation tries to
* restore the previously saved workbench state using
* <code>IWorkbenchConfigurer.restoreWorkbenchState()</code>. If there was no
* previously saved state, or if the restore failed, then a first-time window is
* opened using <code>IWorkbenchConfigurer.openFirstTimeWindow</code>.
*
* @return <code>true</code> to proceed with workbench startup, or
* <code>false</code> to exit
*/
public boolean openWindows() {
final Display display = PlatformUI.getWorkbench().getDisplay();
final boolean[] result = new boolean[1];
// spawn another init thread. For API compatibility We guarantee this method is
// called from
// the UI thread but it could take enough time to disrupt progress reporting.
// spawn a new thread to do the grunt work of this initialization and spin the
// event loop
// ourselves just like it's done in Workbench.
final Throwable[] error = new Throwable[1];
Thread initThread = new Thread() {
@Override
public void run() {
try {
// declare us to be a startup thread so that our syncs will be executed
UISynchronizer.startupThread.set(Boolean.TRUE);
final IWorkbenchConfigurer[] myConfigurer = new IWorkbenchConfigurer[1];
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() throws Throwable {
myConfigurer[0] = getWorkbenchConfigurer();
}
});
IStatus status = myConfigurer[0].restoreState();
if (!status.isOK()) {
if (status.getCode() == IWorkbenchConfigurer.RESTORE_CODE_EXIT) {
result[0] = false;
return;
}
if (status.getCode() == IWorkbenchConfigurer.RESTORE_CODE_RESET) {
myConfigurer[0].openFirstTimeWindow();
}
}
result[0] = true;
} catch (Throwable e) {
error[0] = e;
} finally {
initDone = true;
Thread.yield();
try {
Thread.sleep(5);
} catch (InterruptedException e) {
// this is a no-op in this case.
}
display.wake();
}
}
};
initThread.start();
while (true) {
if (!display.readAndDispatch()) {
if (initDone)
break;
display.sleep();
}
}
// can only be a runtime or error
if (error[0] instanceof Error)
throw (Error) error[0];
else if (error[0] instanceof RuntimeException)
throw (RuntimeException) error[0];
return result[0];
}
use of org.eclipse.ui.internal.StartupThreading.StartupRunnable in project eclipse.platform.ui by eclipse-platform.
the class Workbench method doOpenFirstTimeWindow.
private void doOpenFirstTimeWindow() {
try {
final IAdaptable[] input = new IAdaptable[1];
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() throws Throwable {
input[0] = getDefaultPageInput();
}
});
openWorkbenchWindow(getDefaultPerspectiveId(), input[0]);
} catch (final WorkbenchException e) {
// Don't use the window's shell as the dialog parent,
// as the window is not open yet (bug 76724).
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() throws Throwable {
ErrorDialog.openError(null, WorkbenchMessages.Problems_Opening_Page, e.getMessage(), e.getStatus());
}
});
}
}
use of org.eclipse.ui.internal.StartupThreading.StartupRunnable in project eclipse.platform.ui by eclipse-platform.
the class Workbench method initializeFonts.
/*
* Initializes the workbench fonts with the stored values.
*/
private void initializeFonts() {
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
FontDefinition[] fontDefinitions = WorkbenchPlugin.getDefault().getThemeRegistry().getFonts();
ThemeElementHelper.populateRegistry(getThemeManager().getCurrentTheme(), fontDefinitions, PrefUtil.getInternalPreferenceStore());
final IPropertyChangeListener themeToPreferencesFontSynchronizer = event -> {
if (event.getNewValue() instanceof FontData[]) {
FontData[] fontData = (FontData[]) event.getNewValue();
PrefUtil.getInternalPreferenceStore().setValue(event.getProperty(), PreferenceConverter.getStoredRepresentation(fontData));
}
};
getThemeManager().getCurrentTheme().getFontRegistry().addListener(themeToPreferencesFontSynchronizer);
getThemeManager().addPropertyChangeListener(event -> {
if (IThemeManager.CHANGE_CURRENT_THEME.equals(event.getProperty())) {
Object oldValue = event.getOldValue();
if (oldValue != null && oldValue instanceof ITheme) {
((ITheme) oldValue).removePropertyChangeListener(themeToPreferencesFontSynchronizer);
}
Object newValue = event.getNewValue();
if (newValue != null && newValue instanceof ITheme) {
((ITheme) newValue).addPropertyChangeListener(themeToPreferencesFontSynchronizer);
}
}
});
}
});
}
use of org.eclipse.ui.internal.StartupThreading.StartupRunnable in project eclipse.platform.ui by eclipse-platform.
the class NavigationHistory method restoreState.
/**
* Restore the state of this history from the memento.
*/
void restoreState(IMemento memento) {
IMemento editorsMem = memento.getChild(IWorkbenchConstants.TAG_EDITORS);
IMemento[] items = memento.getChildren(IWorkbenchConstants.TAG_ITEM);
if (items.length == 0 || editorsMem == null) {
if (page.getActiveEditor() != null) {
markLocation(page.getActiveEditor());
}
return;
}
IMemento[] children = editorsMem.getChildren(IWorkbenchConstants.TAG_EDITOR);
NavigationHistoryEditorInfo[] editorsInfo = new NavigationHistoryEditorInfo[children.length];
for (int i = 0; i < editorsInfo.length; i++) {
editorsInfo[i] = new NavigationHistoryEditorInfo(children[i]);
editors.add(editorsInfo[i]);
}
for (int i = 0; i < items.length; i++) {
IMemento item = items[i];
int index = item.getInteger(IWorkbenchConstants.TAG_INDEX).intValue();
NavigationHistoryEditorInfo info = editorsInfo[index];
info.refCount++;
NavigationHistoryEntry entry = new NavigationHistoryEntry(info, page, null, null);
history.add(entry);
entry.restoreState(item);
if (item.getString(IWorkbenchConstants.TAG_ACTIVE) != null) {
activeEntry = i;
}
}
final NavigationHistoryEntry entry = getEntry(activeEntry);
if (entry != null && entry.editorInfo.editorInput != null) {
if (page.getActiveEditor() == page.findEditor(entry.editorInfo.editorInput)) {
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() throws Throwable {
gotoEntry(entry);
}
});
}
}
}
use of org.eclipse.ui.internal.StartupThreading.StartupRunnable in project eclipse.platform.ui by eclipse-platform.
the class Workbench method init.
/**
* Initializes the workbench now that the display is created.
*
* @return true if init succeeded.
*/
private boolean init() {
// setup debug mode if required.
if (WorkbenchPlugin.getDefault().isDebugging()) {
WorkbenchPlugin.DEBUG = true;
ModalContext.setDebugMode(true);
}
// Set up the JFace preference store
JFaceUtil.initializeJFacePreferences();
// TODO Correctly order service initialization
// there needs to be some serious consideration given to
// the services, and hooking them up in the correct order
// $NON-NLS-1$
e4Context.set("org.eclipse.core.runtime.Platform", Platform.class);
final EvaluationService evaluationService = new EvaluationService(e4Context);
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
serviceLocator.registerService(IEvaluationService.class, evaluationService);
}
});
initializeLazyServices();
// Initialize the activity support.
activityHelper = ActivityPersistanceHelper.getInstance();
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
WorkbenchImages.getImageRegistry();
}
});
initializeE4Services();
IIntroRegistry introRegistry = WorkbenchPlugin.getDefault().getIntroRegistry();
if (introRegistry.getIntroCount() > 0) {
IProduct product = Platform.getProduct();
if (product != null) {
introDescriptor = (IntroDescriptor) introRegistry.getIntroForProduct(product.getId());
}
}
initializeDefaultServices();
initializeFonts();
initializeApplicationColors();
// now that the workbench is sufficiently initialized, let the advisor
// have a turn.
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
advisor.internalBasicInitialize(getWorkbenchConfigurer());
}
});
// configure use of color icons in toolbars
boolean useColorIcons = PrefUtil.getInternalPreferenceStore().getBoolean(IPreferenceConstants.COLOR_ICONS);
ActionContributionItem.setUseColorIconsInToolbars(useColorIcons);
// initialize workbench single-click vs double-click behavior
initializeSingleClickOption();
initializeGlobalization();
initializeNLExtensions();
initializeWorkbenchImages();
// hook shortcut visualizer
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
new ShowKeysListener(Workbench.this, PrefUtil.getInternalPreferenceStore());
}
});
// attempt to restore a previous workbench state
try {
// $NON-NLS-1$
UIStats.start(UIStats.RESTORE_WORKBENCH, "Workbench");
final boolean[] bail = new boolean[1];
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() throws Throwable {
advisor.preStartup();
// TODO compat: open the windows here/instantiate the model
// TODO compat: instantiate the WW around the model
initializationDone = true;
if (isClosing() || !advisor.openWindows()) {
// if (isClosing()) {
bail[0] = true;
}
restoreWorkbenchState();
}
});
if (bail[0])
return false;
} finally {
// $NON-NLS-1$
UIStats.end(UIStats.RESTORE_WORKBENCH, this, "Workbench");
}
return true;
}
Aggregations