Java Code Examples for org.eclipse.ui.IWorkbench

The following examples show how to use org.eclipse.ui.IWorkbench. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void run() {
	IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
	IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
	IWorkbenchPage page= window.getActivePage();
	IAdaptable input;
	if (page != null)
		input= page.getInput();
	else
		input= ResourcesPlugin.getWorkspace().getRoot();
	try {
		workbench.showPerspective(JavaUI.ID_PERSPECTIVE, window, input);
	} catch (WorkbenchException e) {
		ExceptionHandler.handle(e, window.getShell(),
			ActionMessages.OpenJavaPerspectiveAction_dialog_title,
			ActionMessages.OpenJavaPerspectiveAction_error_open_failed);
	}
}
 
Example 2
Source Project: tesb-studio-se   Source File: RefactorRenameHandler.java    License: Apache License 2.0 6 votes vote down vote up
public boolean isEnabled() {
	if (!handler.isEnabled()) {
		return false;
	}
	// disable the command when editor is readonly.
	IWorkbench workbench = PlatformUI.getWorkbench();
	if (workbench == null) {
		return false;
	}
	IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
	if (window == null) {
		return false;
	}
	IWorkbenchPage activePage = window.getActivePage();
	if (activePage == null) {
		return false;
	}
	IEditorPart activeEditor = activePage.getActiveEditor();
	if (activeEditor != null && activeEditor instanceof LocalWSDLEditor) {
		LocalWSDLEditor wsdlEditor = (LocalWSDLEditor) activeEditor;
		return !wsdlEditor.isEditorInputReadOnly();
	}
	return false;
}
 
Example 3
Source Project: IndentGuide   Source File: Starter.java    License: MIT License 6 votes vote down vote up
public void earlyStartup() {
	PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
		public void run() {
			IWorkbench workbench = PlatformUI.getWorkbench();
			IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
			if (window != null) {
				IWorkbenchPage page = window.getActivePage();
				if (page != null) {
					IEditorPart part = page.getActiveEditor();
					if (part != null) {
						addListener(part);
					}
				}
				window.getPartService().addPartListener(new PartListener());
			}
			workbench.addWindowListener(new WindowListener());
		}
	});
}
 
Example 4
Source Project: tlaplus   Source File: UIHelper.java    License: MIT License 6 votes vote down vote up
/**
 * Opens the new window containing the new perspective
 * 
 * @param perspectiveId
 *            new perspective
 * @param input
 *            IAdaptable, or null if no input
 * @return IWorkbenchWindow instance
 * 
 */
public static IWorkbenchWindow openPerspectiveInNewWindow(String perspectiveId, IAdaptable input) {
	IWorkbench workbench = Activator.getDefault().getWorkbench();
	IWorkbenchWindow window = null;
	try {
		// avoids flicking, from implementation above
		window = workbench.openWorkbenchWindow(perspectiveId, input);

		// show intro
		if (InitialPerspective.ID.equals(perspectiveId) && workbench.getIntroManager().hasIntro()) {
			// IIntroPart intro =
			workbench.getIntroManager().showIntro(window, true);
		}

	} catch (WorkbenchException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return window;
}
 
Example 5
Source Project: n4js   Source File: ADocSpecExportWizard.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void init(IWorkbench targetWorkbench, IStructuredSelection currentSelection) {
	this.selection = currentSelection;

	List<?> selectedResources = IDE.computeSelectedResources(currentSelection);
	if (!selectedResources.isEmpty()) {
		this.selection = new StructuredSelection(selectedResources);
	}

	setWindowTitle("AsciiDoc Specification Export");
	setNeedsProgressMonitor(true);

	configAdocPage = new SpecConfigAdocPage("Configuration Page");
	processAdocPage = new SpecProcessPage("Process Page");
	comparePage = new SpecComparePage("Compare Page", "Adoc");
	summaryPage = new SpecExportCodeSummaryPage("Summary Page");
	processOutputPage = new SpecProcessPage("Process Page");

	taskGenAdoc = new TaskGenerateAdoc(jsDoc2SpecProcessor, resourceSetProvider, n4JSCore, selection,
			configAdocPage, processAdocPage);
	taskWriteFiles = new TaskWriteFiles(processOutputPage, taskGenAdoc);

	addVisibilityListeners();
}
 
Example 6
Source Project: tracecompass   Source File: TmfOpenTraceHelper.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the editor with the specified input. Returns null if there is no
 * opened editor with that input. If restore is requested, the method finds and
 * returns the editor even if it is not restored yet after a restart.
 *
 * @param input
 *            the editor input
 * @param restore
 *            true if the editor should be restored
 * @return an editor with input equals to <code>input</code>
 */
private static IEditorPart findEditor(IEditorInput input, boolean restore) {
    final IWorkbench wb = PlatformUI.getWorkbench();
    final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
    for (IEditorReference editorReference : activePage.getEditorReferences()) {
        try {
            IEditorInput editorInput = editorReference.getEditorInput();
            if (editorInput.equals(input)) {
                return editorReference.getEditor(restore);
            }
        } catch (PartInitException e) {
            // do nothing
        }
    }
    return null;
}
 
Example 7
Source Project: olca-app   Source File: Navigator.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Returns the instance of the navigation view or NULL if there is# no such
 * instance available.
 */
public static Navigator getInstance() {
	IWorkbench workbench = PlatformUI.getWorkbench();
	if (workbench == null)
		return null;
	IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
	if (window == null)
		return null;
	IWorkbenchPage page = window.getActivePage();
	if (page == null)
		return null;
	IViewPart part = page.findView(ID);
	if (part instanceof Navigator)
		return (Navigator) part;
	return null;
}
 
Example 8
public Object execute(ExecutionEvent event) throws ExecutionException {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
	BindingService service = (BindingService) bindingService;
	ArrayList<Binding> lstBinding = new ArrayList<Binding>(Arrays.asList(bindingService.getBindings()));
	List<String> lstRemove = Constants.lstRemove;
	Iterator<Binding> it = lstBinding.iterator();
	while (it.hasNext()) {
		Binding binding = it.next();
		ParameterizedCommand pCommand = binding.getParameterizedCommand();
		if (pCommand == null || lstRemove.contains(pCommand.getCommand().getId())) {
			it.remove();
		}
	}
	service.getKeyboard().openKeyAssistShell(lstBinding);
	return null;
}
 
Example 9
Source Project: EasyShell   Source File: Utils.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private static void executeCommand(IWorkbench workbench, String commandName, Map<String, Object> params) {
    if (workbench == null) {
        workbench = PlatformUI.getWorkbench();
    }
    // get command
    ICommandService commandService = (ICommandService)workbench.getService(ICommandService.class);
    Command command = commandService != null ? commandService.getCommand(commandName) : null;
    // get handler service
    //IBindingService bindingService = (IBindingService)workbench.getService(IBindingService.class);
    //TriggerSequence[] triggerSequenceArray = bindingService.getActiveBindingsFor("de.anbos.eclipse.easyshell.plugin.commands.open");
    IHandlerService handlerService = (IHandlerService)workbench.getService(IHandlerService.class);
    if (command != null && handlerService != null) {
        ParameterizedCommand paramCommand = ParameterizedCommand.generateCommand(command, params);
        try {
            handlerService.executeCommand(paramCommand, null);
        } catch (Exception e) {
            Activator.logError(Activator.getResourceString("easyshell.message.error.handlerservice.execution"), paramCommand.toString(), e, true);
        }
    }
}
 
Example 10
Source Project: APICloud-Studio   Source File: UIUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Opens the internal help in the Studio's internal browser.
 * 
 * @param url
 * @return A boolean value indicating a successful operations or not.
 */
public static boolean openHelpInBrowser(String url)
{
	IWorkbench workbench = PlatformUI.getWorkbench();
	if (workbench != null)
	{
		IWorkbenchHelpSystem helpSystem = workbench.getHelpSystem();
		URL resolvedURL = helpSystem.resolve(url, true);
		if (resolvedURL != null)
		{
			return openInBroswer(resolvedURL, true, IWorkbenchBrowserSupport.AS_EDITOR
					| IWorkbenchBrowserSupport.STATUS);
		}
		else
		{
			IdeLog.logError(UIPlugin.getDefault(), "Unable to resolve the Help URL for " + url); //$NON-NLS-1$
			return false;
		}
	}
	return false;
}
 
Example 11
Source Project: google-cloud-eclipse   Source File: WorkbenchStartup.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void earlyStartup() {
  final IWorkbench workbench = PlatformUI.getWorkbench();
  GcpStatusMonitoringService service = workbench.getService(GcpStatusMonitoringService.class);
  if (service != null) {
    service.addStatusChangeListener(
        result -> {
          ICommandService commandService = workbench.getService(ICommandService.class);
          if (commandService != null) {
            commandService.refreshElements(
                "com.google.cloud.tools.eclipse.ui.status.showGcpStatus", null);
          }
        });
  }
}
 
Example 12
Source Project: elexis-3-core   Source File: UserCasePreferences.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void init(IWorkbench workbench){
	getPreferenceStore().setValue(Preferences.USR_DEFCASELABEL, Fall.getDefaultCaseLabel());
	getPreferenceStore().setValue(Preferences.USR_DEFCASEREASON, Fall.getDefaultCaseReason());
	getPreferenceStore().setValue(Preferences.USR_DEFLAW, Fall.getDefaultCaseLaw());
	// read the sorting for this user form prefs, convert to LinkedList for editing
	String topItemsSortingStr = CoreHub.userCfg.get(Preferences.USR_TOPITEMSSORTING, "");
	String[] topItemsSorting = topItemsSortingStr.split(PREFSDELIMITER_REGEX);
	topItemsLinkedList = new LinkedList<String>(Arrays.asList(topItemsSorting));
}
 
Example 13
private void removePartListener()
{
	IWorkbench workbench = null;
	try
	{
		workbench = PlatformUI.getWorkbench();
	}
	catch (Exception e)
	{
		// ignore, may be running headless, like in tests
	}
	if (workbench != null)
	{
		IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
		IPartService partService;
		for (IWorkbenchWindow window : windows)
		{
			partService = window.getPartService();
			if (partService != null)
			{
				partService.removePartListener(fPartListener);
			}
			window.removePerspectiveListener(fPerspectiveListener);
		}
		PlatformUI.getWorkbench().removeWindowListener(fWindowListener);
	}
}
 
Example 14
Source Project: olca-app   Source File: ExportWizard.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
	setWindowTitle(M.ILCDNetworkExport);
	setDefaultPageImageDescriptor(RcpActivator.imageDescriptorFromPlugin(
			RcpActivator.PLUGIN_ID, "/icons/network_wiz.png"));
	setNeedsProgressMonitor(true);
	selectionPage = new ExportWizardPage();
}
 
Example 15
@Before
public void setUp() {
  evaluationService = mock( IEvaluationService.class );
  workbench = mock( IWorkbench.class );
  when( workbench.getService( IEvaluationService.class ) ).thenReturn( evaluationService );
  preferences = new WorkspaceScopePreferences( new PreferenceStore() );
  action = new CloseJUnitStatusAction( workbench, preferences );
}
 
Example 16
Source Project: neoscada   Source File: SecurityModelWizard.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This just records the information.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void init ( IWorkbench workbench, IStructuredSelection selection )
{
    this.workbench = workbench;
    this.selection = selection;
    setWindowTitle ( SecurityEditorPlugin.INSTANCE.getString ( "_UI_Wizard_label" ) ); //$NON-NLS-1$
    setDefaultPageImageDescriptor ( ExtendedImageRegistry.INSTANCE.getImageDescriptor ( SecurityEditorPlugin.INSTANCE.getImage ( "full/wizban/NewSecurity" ) ) ); //$NON-NLS-1$
}
 
Example 17
Source Project: dawnsci   Source File: TestUtils.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return IWorkbenchPage
 */
public static IWorkbenchPage getDefaultPage() {
	final IWorkbench bench = PlatformUI.getWorkbench();
	if (bench==null) return null;
	final IWorkbenchWindow[] windows = bench.getWorkbenchWindows();
	if (windows==null) return null;
	
	return windows[0].getActivePage();
}
 
Example 18
Source Project: xtext-xtend   Source File: AbstractSwtBotTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Before
public final void checkNotRunninginUiThread () {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	if (workbench.getDisplay().getThread() == Thread.currentThread()) {
		Assert.fail("This test MUST NOT RUN in SWT's UI thread. Please check the 'Run in UI thread' option of your launch config or build configuration!");
	}
}
 
Example 19
Source Project: codeexamples-eclipse   Source File: Application.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void stop() {
	if (!PlatformUI.isWorkbenchRunning())
		return;
	final IWorkbench workbench = PlatformUI.getWorkbench();
	final Display display = workbench.getDisplay();
	display.syncExec(new Runnable() {
		@Override
		public void run() {
			if (!display.isDisposed())
				workbench.close();
		}
	});
}
 
Example 20
/**
 * This just records the information.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void init(IWorkbench workbench, IStructuredSelection selection) {
	this.workbench = workbench;
	this.selection = selection;
	setWindowTitle(BeansEditorPlugin.INSTANCE.getString("_UI_Wizard_label"));
	setDefaultPageImageDescriptor(ExtendedImageRegistry.INSTANCE.getImageDescriptor(BeansEditorPlugin.INSTANCE.getImage("full/wizban/NewBeans")));
}
 
Example 21
Source Project: neoscada   Source File: GlobalizeModelWizard.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This just records the information.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void init ( IWorkbench workbench, IStructuredSelection selection )
{
    this.workbench = workbench;
    this.selection = selection;
    setWindowTitle ( GlobalizeEditorPlugin.INSTANCE.getString ( "_UI_Wizard_label" ) ); //$NON-NLS-1$
    setDefaultPageImageDescriptor ( ExtendedImageRegistry.INSTANCE.getImageDescriptor ( GlobalizeEditorPlugin.INSTANCE.getImage ( "full/wizban/NewGlobalize" ) ) ); //$NON-NLS-1$
}
 
Example 22
Source Project: gama   Source File: Application.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void stop() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	if ( workbench == null ) { return; }
	final Display display = workbench.getDisplay();
	display.syncExec(() -> {
		if ( !display.isDisposed() ) {
			workbench.close();
		}
	});
}
 
Example 23
Source Project: Pydev   Source File: DebuggerTestUtils.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a run in debug mode for the debug editor
 */
public void launchEditorInDebug() {
    final IWorkbench workBench = PydevPlugin.getDefault().getWorkbench();
    Display display = workBench.getDisplay();

    // Make sure to run the UI thread.
    display.syncExec(new Runnable() {
        @Override
        public void run() {
            JythonLaunchShortcut launchShortcut = new JythonLaunchShortcut();
            launchShortcut.launch(debugEditor, "debug");
        }
    });
}
 
Example 24
public void dispose()
{
	IWorkbench workbench = null;
	try
	{
		workbench = PlatformUI.getWorkbench();
	}
	catch (Exception e)
	{
		// ignore
	}

	if (workbench != null)
	{
		IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
		if (window != null)
		{
			IWorkbenchPage page = window.getActivePage();
			if (page != null)
			{
				page.removePartListener(this);
			}
		}
	}
	if (baseNames != null)
	{
		baseNames.clear();
		baseNames = null;
	}
}
 
Example 25
Source Project: google-cloud-eclipse   Source File: WorkbenchUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Open the specified file in the editor.
 *
 * @param workbench the active workbench
 * @param file the file to open
 */
public static IEditorPart openInEditor(IWorkbench workbench, IFile file) {
  IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
  if (window != null && file != null) {
    IWorkbenchPage page = window.getActivePage();
    try {
      return IDE.openEditor(page, file, true);
    } catch (PartInitException ex) {
      // ignore; we don't have to open the file
    }
  }
  return null;
}
 
Example 26
Source Project: elexis-3-core   Source File: FindingsSettings.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void init(IWorkbench workbench){
	setPreferenceStore(new SettingsPreferenceStore(CoreHub.globalCfg));
	setMessage("Globale Befunde Einstellungen");
	// initialize the model
	if (FindingsServiceComponent.getService() != null) {
		FindingsServiceComponent.getService().findById("", IObservation.class);
	} else {
		getLogger().warn("FindingsService is null - not found.");
		setErrorMessage("Befunde Service konnte nicht geladen werden.");
	}
}
 
Example 27
Source Project: tracecompass   Source File: ImportTraceWizard.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    fSelection = selection;

    setWindowTitle(Messages.ImportTraceWizard_DialogTitle);
    setDefaultPageImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, ICON_PATH));
    setNeedsProgressMonitor(true);
}
 
Example 28
Source Project: aCute   Source File: DotnetExportWizard.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
	setWindowTitle(Messages.DotnetExportWizard_exportProject);

	Iterator<Object> selectionIterator = selection.iterator();
	IFile projectFile = null;

	while (selectionIterator.hasNext() && projectFile == null) {
		IResource resource = (IResource) selectionIterator.next();
		projectFile = getProjectFile(resource.getProject());
	}
	wizardPage = new DotnetExportWizardPage(projectFile);
}
 
Example 29
Source Project: APICloud-Studio   Source File: TeamAction.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Convenience method for getting the current shell.
 * 
 * @return the shell
 */
public Shell getShell() {
	if (shell != null) {
		return shell;
	} else {
		IWorkbench workbench = SVNUIPlugin.getPlugin().getWorkbench();
		if (workbench == null) return null;
		IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
		if (window == null) return null;
		return window.getShell();
	}
}
 
Example 30
@SuppressWarnings("restriction")
public void filterDupliteBind(){
	IWorkbench workbench = PlatformUI.getWorkbench();
	IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
	BindingService service =(BindingService)bindingService;
	BindingManager bindingManager = service.getBindingManager();
	//service.getBindingManager().
	Binding[] bindings = bindingManager.getBindings();
     List<Binding> bindTemp = new ArrayList<Binding>();
     List<String> ids = new ArrayList<String>();
     for(Binding bind : bindings){
		if(null ==bind){
			continue;
		}
		ParameterizedCommand command = bind.getParameterizedCommand();
		if(null == command){
			continue;
		}
		String id = command.getId();
		if(!ids.contains(id)){
			ids.add(id);
			bindTemp.add(bind);
		}
	}
   
     bindingManager.setBindings(bindTemp.toArray(new Binding[ids.size()]));
}