Java Code Examples for org.eclipse.ui.PlatformUI#isWorkbenchRunning()

The following examples show how to use org.eclipse.ui.PlatformUI#isWorkbenchRunning() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RunContainerProcessor.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example 2
Source File: Activator.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
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");
    }
}
 
Example 3
Source File: TestedN4JSWorkspace.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@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()));
		}
	}
}
 
Example 4
Source File: BundleJavaProcessor.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example 5
Source File: SourceFileStore.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
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;
                    }
                }
            }
        }
    }
}
 
Example 6
Source File: ShowViewScanner.java    From workspacemechanic with Eclipse Public License 1.0 6 votes vote down vote up
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();
}
 
Example 7
Source File: Activator.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
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");
    }
}
 
Example 8
Source File: JSDTEditorTracker.java    From typescript.java with MIT License 5 votes vote down vote up
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);
		}
	}
}
 
Example 9
Source File: EditorFinder.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 10
Source File: TypeScriptUIPlugin.java    From typescript.java with MIT License 5 votes vote down vote up
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;
}
 
Example 11
Source File: TypeScriptUIPlugin.java    From typescript.java with MIT License 5 votes vote down vote up
public ITypeScriptConsole getInstallTypesConsole() {
	if (!PlatformUI.isWorkbenchRunning()) {
		return null;
	}
	InstallTypesConsole console = InstallTypesConsole.getConsole();
	TypeScriptConsoleHelper.showConsole(console);
	return console;
}
 
Example 12
Source File: MyLib.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
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);
});
    }
}
 
Example 13
Source File: DefinitionResourceProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 14
Source File: Log.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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();
							}
						});
						
					}
				}
			}
		}
	}
}
 
Example 15
Source File: AbstractContentAssistFragmentTestLangUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
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);
	}
}
 
Example 16
Source File: BonitaStudioApplication.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected boolean isWorkbenchRunning() {
    return PlatformUI.isWorkbenchRunning();
}
 
Example 17
Source File: ToolsConsole.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public boolean isIgnorinCommands() {
	return !PlatformUI.isWorkbenchRunning() && DevelopmentCodeMarkers.TESTS_MODE;
}
 
Example 18
Source File: DeployCommandHandler.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
@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;
  }
}
 
Example 19
Source File: UIDesignerServerManager.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void projectClosed(Repository repository, IProgressMonitor monitor) {
    if (PlatformUI.isWorkbenchRunning()) {
        stop();
    }
}
 
Example 20
Source File: XViewerDisplay.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @return true if this xviewer is embedded in Eclipse workbench and it's running
 */
public static boolean isWorkbenchRunning() {
   return PlatformUI.isWorkbenchRunning();
}