下面列出了org.eclipse.ui.PlatformUI#isWorkbenchRunning ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void starting(Description d) {
name = d.getMethodName();
assertEmptyIndex();
IProject[] projects = IResourcesSetupUtil.root().getProjects();
if (projects.length != 0) {
Assert.assertEquals(1, projects.length);
Assert.assertEquals("RemoteSystemsTempFiles", projects[0].getName());
}
if (PlatformUI.isWorkbenchRunning()) {
final IIntroManager introManager = PlatformUI.getWorkbench().getIntroManager();
if (introManager.getIntro() != null) {
Display.getDefault().asyncExec(() -> introManager.closeIntro(introManager.getIntro()));
}
}
}
@Override
public void generatePom(int option) {
super.generatePom(option);
if (option == TalendProcessOptionConstants.GENERATE_IS_MAINJOB) {
try {
IRepositoryObject repositoryObject = new RepositoryObject(getProperty());
// Fix TESB-22660: Avoide to operate repo viewer before it open
if (PlatformUI.isWorkbenchRunning()) {
RepositorySeekerManager.getInstance().searchRepoViewNode(getProperty().getId(), false);
}
IRunnableWithProgress action = new JavaCamelJobScriptsExportWSAction(repositoryObject, getProperty().getVersion(),
"", false);
action.run(new NullProgressMonitor());
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
}
private void closeRelatedEditorIfOpened(final ICompilationUnit compilationUnit) throws PartInitException {
Optional<IWorkbenchPage> activePage = Optional.ofNullable(PlatformUI.getWorkbench().getActiveWorkbenchWindow())
.map(IWorkbenchWindow::getActivePage);
if (activePage.isPresent()) {
if (editorPart != null) {
if (PlatformUI.isWorkbenchRunning()) {
activePage.get().closeEditor(editorPart, false);
}
} else {
if (PlatformUI.isWorkbenchRunning()) {
for (final IEditorReference editorReference : activePage.get().getEditorReferences()) {
final IEditorInput editorInput = editorReference.getEditorInput();
if (compilationUnit.getResource()
.equals(EditorUtil.retrieveResourceFromEditorInput(editorInput))) {
activePage.get().closeEditors(new IEditorReference[] { editorReference }, false);
break;
}
}
}
}
}
}
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
if (Display.getCurrent() != null && PlatformUI.isWorkbenchRunning()) {
Bundle bundle = Platform.getBundle(PLUGIN_ID);
addImage(bundle, Icons.assist_item.name(), "icons/assist_item_16.png");
addImage(bundle, Icons.template_item.name(), "icons/template_item_16.png");
// for quick outline, add icons from YEdit
bundle = Platform.getBundle(org.dadacoalition.yedit.Activator.PLUGIN_ID);
addImage(bundle, Icons.outline_document.name(), "icons/outline_document.gif");
addImage(bundle, Icons.outline_mapping.name(), "icons/outline_mapping.gif");
addImage(bundle, Icons.outline_scalar.name(), "icons/outline_scalar.gif");
addImage(bundle, Icons.outline_mapping_scalar.name(), "icons/outline_mappingscalar.gif");
addImage(bundle, Icons.outline_sequence.name(), "icons/outline_sequence.png");
}
}
public boolean evaluate() {
if (!PlatformUI.isWorkbenchRunning()) {
return true;
}
final IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench == null) {
return true;
}
final Set<String> remaining = Sets.newHashSet(list);
Display.getDefault().syncExec(new Runnable() {
public void run() {
for (IWorkbenchWindow workbenchWindow : workbench.getWorkbenchWindows()) {
for (IWorkbenchPage workbenchPage : workbenchWindow.getPages()) {
for (IViewReference viewReference : workbenchPage.getViewReferences()) {
remaining.remove(viewReference.getId());
}
}
}
}
});
return remaining.isEmpty();
}
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
if (Display.getCurrent() != null && PlatformUI.isWorkbenchRunning()) {
Bundle bundle = Platform.getBundle(PLUGIN_ID);
// for quick outline, add icons from YEdit
bundle = Platform.getBundle(org.dadacoalition.yedit.Activator.PLUGIN_ID);
addImage(bundle, Icons.outline_document.name(), "icons/outline_document.gif");
addImage(bundle, Icons.outline_mapping.name(), "icons/outline_mapping.gif");
addImage(bundle, Icons.outline_scalar.name(), "icons/outline_scalar.gif");
addImage(bundle, Icons.outline_mapping_scalar.name(), "icons/outline_mappingscalar.gif");
addImage(bundle, Icons.outline_sequence.name(), "icons/outline_sequence.png");
}
}
@Override
public void generatePom(int option) {
super.generatePom(option);
if (option == TalendProcessOptionConstants.GENERATE_IS_MAINJOB
&& ComponentCategory.CATEGORY_4_CAMEL.getName().equals(getProcess().getComponentsType())) {
try {
IRepositoryObject repositoryObject = new RepositoryObject(getProperty());
// Fix TESB-22660: Avoide to operate repo viewer before it open
if (PlatformUI.isWorkbenchRunning()) {
RepositorySeekerManager.getInstance().searchRepoViewNode(getProperty().getId(), false);
}
IRunnableWithProgress action = new JavaCamelJobScriptsExportWSAction(repositoryObject, getProperty().getVersion(),
"", false);
action.run(new NullProgressMonitor());
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
}
protected ImageRegistry createImageRegistry() {
// If we are in the UI Thread use that
if (Display.getDefault() != null) {
return new ImageRegistry(Display.getDefault());
}
if (PlatformUI.isWorkbenchRunning()) {
return new ImageRegistry(PlatformUI.getWorkbench().getDisplay());
}
// Invalid thread access if it is not the UI Thread
// and the workbench is not created.
throw new SWTError(SWT.ERROR_THREAD_INVALID_ACCESS);
}
public static void popup(final String title, final String message) {
if (!PlatformUI.isWorkbenchRunning()) {
MyLog.log(Activator.class, Level.SEVERE, message);
} else {
ensureInDisplayThread(() -> {
MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title,
message);
});
}
}
public ITypeScriptConsole getInstallTypesConsole() {
if (!PlatformUI.isWorkbenchRunning()) {
return null;
}
InstallTypesConsole console = InstallTypesConsole.getConsole();
TypeScriptConsoleHelper.showConsole(console);
return console;
}
private void init() {
if (PlatformUI.isWorkbenchRunning()) {
IWorkbench workbench = JSDTTypeScriptUIPlugin.getDefault().getWorkbench();
if (workbench != null) {
IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
for (IWorkbenchWindow window : windows) {
windowOpened(window);
}
JSDTTypeScriptUIPlugin.getDefault().getWorkbench().addWindowListener(this);
}
}
}
public ITypeScriptConsole getConsole(IIDETypeScriptProject project) {
if (project.isServerDisposed()) {
return null;
}
if (!PlatformUI.isWorkbenchRunning()) {
return null;
}
TypeScriptConsole console = TypeScriptConsole.getOrCreateConsole(project);
TypeScriptConsoleHelper.showConsole(console);
return console;
}
public static Optional<IEditorPart> findOpenedEditor(Function<IEditorPart, Boolean> editorInstanceValidator) {
if (PlatformUI.isWorkbenchRunning()
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
return Arrays.asList(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences())
.stream()
.map(ref -> ref.getEditor(false))
.filter(editorInstanceValidator::apply)
.findFirst();
}
return Optional.empty();
}
/**
* Eine Log-Nachricht ausgeben.
*
* @param message
* die Nachricht
* @param level
* der level
*/
public void log(String message, int level){
if (out == null)
out = LoggerFactory.getLogger(Log.class);
synchronized (out) {
String type = "unknown"; //$NON-NLS-1$
if (level > 0 && level < Levels.length)
type = Levels[level];
switch (level) {
case NOTHING:
break;
case SYNCMARK:
out.info("SYNC: " + message);
break;
case FATALS: // slf4j does not know fatal. Use error instead
case ERRORS:
out.error(message);
break;
case WARNINGS:
out.error(message);
break;
case INFOS:
out.trace(message);
break;
case DEBUGMSG:
out.debug(message);
break;
default:
out.debug(message);
break;
}
if (level <= LogLevel) {
if (level <= alertLevel && PlatformUI.isWorkbenchRunning()) {
if (level != SYNCMARK) {
if (doAlert == null) {
doAlert = UiDesk.getTopShell();
}
lastError =
new StringBuilder().append(" |").append(type).append("| - ")
.append(prefix).append(": ").append(message).toString();
if (doAlert != null) {
UiDesk.asyncExec(new Runnable() {
public void run(){
MessageBox msg =
new MessageBox(doAlert, SWT.ICON_ERROR | SWT.OK);
msg.setMessage(lastError);
msg.open();
}
});
}
}
}
}
}
}
/**
* @return true if this xviewer is embedded in Eclipse workbench and it's running
*/
public static boolean isWorkbenchRunning() {
return PlatformUI.isWorkbenchRunning();
}
public boolean isIgnorinCommands() {
return !PlatformUI.isWorkbenchRunning() && DevelopmentCodeMarkers.TESTS_MODE;
}
public void configureLanguageSpecificURIEditorOpener(Binder binder) {
if (PlatformUI.isWorkbenchRunning()) {
binder.bind(IURIEditorOpener.class).annotatedWith(LanguageSpecific.class).to(DerivedMemberAwareEditorOpener.class);
binder.bind(IDerivedMemberAwareEditorOpener.class).to(DerivedMemberAwareEditorOpener.class);
}
}
protected boolean isWorkbenchRunning() {
return PlatformUI.isWorkbenchRunning();
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
IProject project = getSelectedProject(event);
if (PlatformUI.isWorkbenchRunning()) {
if (!PlatformUI.getWorkbench().saveAllEditors(true)) {
return null;
}
if (getWorkspace(event).isAutoBuilding()) {
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
}
}
Shell shell = HandlerUtil.getActiveShell(event);
if (project != null && !checkProjectErrors(project)) {
MessageDialog.openInformation(
shell,
Messages.getString("build.error.dialog.title"),
Messages.getString("build.error.dialog.message"));
return null;
}
if (!checkProject(shell, project)) {
return null;
}
IGoogleLoginService loginService = ServiceUtils.getService(event, IGoogleLoginService.class);
IGoogleApiFactory googleApiFactory = ServiceUtils.getService(event, IGoogleApiFactory.class);
DeployPreferencesDialog dialog =
newDeployPreferencesDialog(shell, project, loginService, googleApiFactory);
if (dialog.open() == Window.OK) {
launchDeployJob(project, dialog.getCredential());
}
// return value must be null, reserved for future use
return null;
} catch (CoreException | IOException | InterruptedException exception) {
throw new ExecutionException(
Messages.getString("deploy.failed.error.message"), exception); //$NON-NLS-1$
} catch (OperationCanceledException ex) {
/* ignore */
return null;
}
}
@Override
public void projectClosed(Repository repository, IProgressMonitor monitor) {
if (PlatformUI.isWorkbenchRunning()) {
stop();
}
}