Java Code Examples for org.eclipse.ui.IWorkbenchWindow#getService()

The following examples show how to use org.eclipse.ui.IWorkbenchWindow#getService() . 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: SessionManagerImpl.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void setSession ( final LoginSession session )
{
    checkRealm ();

    if ( this.session != null )
    {
        this.session.dispose ();
    }

    this.session = session;

    if ( this.session != null )
    {
        this.session.register ();
    }

    for ( final IWorkbenchWindow window : PlatformUI.getWorkbench ().getWorkbenchWindows () )
    {
        final ISourceProviderService service = (ISourceProviderService)window.getService ( ISourceProviderService.class );
        final LoginSessionProvider sessionSourceProvider = (LoginSessionProvider)service.getSourceProvider ( LoginSessionProvider.SESSION_STATE );
        sessionSourceProvider.setLoginSession ( session );
    }

    super.setSession ( session );
}
 
Example 2
Source File: EditLabItemUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public static void executeWithParams(PersistentObject parameter){
	try {
		// get the command
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		ICommandService cmdService = (ICommandService) window.getService(ICommandService.class);
		Command cmd = cmdService.getCommand(COMMANDID);
		// create the parameter
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put(PARAMETERID, parameter);
		// build the parameterized command
		ParameterizedCommand pc = ParameterizedCommand.generateCommand(cmd, param);
		// execute the command
		IHandlerService handlerService =
			(IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
				.getService(IHandlerService.class);
		handlerService.executeCommand(pc, null);
	} catch (Exception ex) {
		throw new RuntimeException(COMMANDID, ex);
	}
}
 
Example 3
Source File: EditEigenartikelUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public static void executeWithParams(PersistentObject parameter){
	try {
		// get the command
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		ICommandService cmdService = (ICommandService) window.getService(ICommandService.class);
		Command cmd = cmdService.getCommand(EditEigenartikelUi.COMMANDID);
		// create the parameter
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put(EditEigenartikelUi.PARAMETERID, parameter);
		// build the parameterized command
		ParameterizedCommand pc = ParameterizedCommand.generateCommand(cmd, param);
		// execute the command
		IHandlerService handlerService =
			(IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
				.getService(IHandlerService.class);
		handlerService.executeCommand(pc, null);
	} catch (Exception ex) {
		throw new RuntimeException(EditEigenleistungUi.COMMANDID, ex);
	}
}
 
Example 4
Source File: EditEigenleistungUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public static void executeWithParams(PersistentObject parameter){
	try {
		// get the command
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		ICommandService cmdService = (ICommandService) window.getService(ICommandService.class);
		Command cmd = cmdService.getCommand(EditEigenleistungUi.COMMANDID);
		// create the parameter
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put(EditEigenleistungUi.PARAMETERID, parameter);
		// build the parameterized command
		ParameterizedCommand pc = ParameterizedCommand.generateCommand(cmd, param);
		// execute the command
		IHandlerService handlerService =
			(IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
				.getService(IHandlerService.class);
		handlerService.executeCommand(pc, null);
	} catch (Exception ex) {
		throw new RuntimeException(EditEigenleistungUi.COMMANDID, ex);
	}
}
 
Example 5
Source File: ManageOrganizationWizard.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public ManageOrganizationWizard(Organization organization) {
    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    this.commandService = activeWorkbenchWindow.getService(ECommandService.class);
    this.handlerService = activeWorkbenchWindow.getService(EHandlerService.class);
    activeOrganizationProvider = new ActiveOrganizationProvider();
    setWindowTitle(Messages.manageOrganizationTitle);
    store = RepositoryManager.getInstance().getCurrentRepository().getRepositoryStore(OrganizationRepositoryStore.class);
    setDefaultPageImageDescriptor(Pics.getWizban());
    setNeedsProgressMonitor(true);
    organizationToEdit = Optional.ofNullable(organization);
    organizationToEdit.ifPresent(orga -> {
        if (activeOrganizationProvider.getActiveOrganization().equals(orga.getName())) {
            addActiveOrganizationAdapter(orga);
        }
    });
}
 
Example 6
Source File: KeyBindingsManager.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private void dispose() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        //During Eclipse shutdown the active workbench window is null
        return;
    }
    Object serviceObject = window.getService(IHandlerService.class);
    IHandlerService service = (IHandlerService) serviceObject;
    for (IHandlerActivation activation : fHandlerActivations) {
        service.deactivateHandler(activation);
    }
    fHandlerActivations.clear();

    fGoToMessageForKeyBinding = null;
    fFindForKeyBinding = null;
    fMoveUpForKeyBinding = null;
    fMoveDownForKeyBinding = null;
    fMoveLeftForKeyBinding = null;
    fMoveRightForKeyBinding = null;
    fShowNodeStartForKeyBinding = null;
    fShowNodeEndForKeyBinding = null;
}
 
Example 7
Source File: OpenXFindPanelHandler.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override // IHandler
public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    IEditorPart part = window.getActivePage().getActiveEditor();

    XFindPanel panel = XFindPanelManager.getXFindPanel(part, true);
    if (panel != null) {
        panel.showPanel();
    }
    else {
        // failed to create XFindPanel, execute standard command "Find and Replace".   
        IHandlerService handlerService = (IHandlerService)window.getService(IHandlerService.class);
        try {
            handlerService.executeCommand(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE, null);
        } catch (Exception ex) {
            LogHelper.logError("Command " + IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE + " not found");   //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

    return null;
}
 
Example 8
Source File: ServiceUtils.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an OSGi service from {@link ExecutionEvent}. It looks up a service in the following
 * locations (if exist) in the given order:
 *
 * {@code HandlerUtil.getActiveSite(event)}
 * {@code HandlerUtil.getActiveEditor(event).getEditorSite()}
 * {@code HandlerUtil.getActiveEditor(event).getSite()}
 * {@code HandlerUtil.getActiveWorkbenchWindow(event)}
 * {@code PlatformUI.getWorkbench()}
 */
public static <T> T getService(ExecutionEvent event, Class<T> api) {
  IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
  if (activeSite != null) {
    return activeSite.getService(api);
  }

  IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
  if (activeEditor != null) {
    IEditorSite editorSite = activeEditor.getEditorSite();
    if (editorSite != null) {
      return editorSite.getService(api);
    }
    IWorkbenchPartSite site = activeEditor.getSite();
    if (site != null) {
      return site.getService(api);
    }
  }

  IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
  if (workbenchWindow != null) {
    return workbenchWindow.getService(api);
  }

  return PlatformUI.getWorkbench().getService(api);
}
 
Example 9
Source File: DropWorkbenchChangeListener.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void hookWindow(IWorkbenchWindow window) {
	if (window == null) {
		return;
	}
	window.addPageListener(this);
	window.addPerspectiveListener(this);
	IPartService partService = (IPartService) window.getService(IPartService.class);
	partService.addPartListener(this);
	windowChanged(window);
}
 
Example 10
Source File: NattableUtil.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 刷新 Command 的可用状态
 * @param nameSpace
 * @param properties
 *            ;
 */
public static void refreshCommand(String nameSpace, String properties) {
	if (nameSpace != null && properties != null) {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		IEvaluationService evaluationService = (IEvaluationService) window.getService(IEvaluationService.class);
		if (evaluationService != null) {
			evaluationService.requestEvaluation(nameSpace + "." + properties);
		}
	}
}
 
Example 11
Source File: ApplicationWorkbenchWindowAdvisor.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
	public void postWindowOpen() {
		IWorkbenchWindow workbenchWindow = getWindowConfigurer().getWindow();
//		workbenchWindow.getShell().setMaximized(true);
		
		restorEditorHistory();
		saveEditorHistory();
		
		final ICommandService commandService = (ICommandService) workbenchWindow.getService(ICommandService.class);
	
		// 在程序主体窗口打开之前,更新打开工具栏的菜单,让它初始化菜单图片 --robert 2012-03-19
		commandService.refreshElements("net.heartsome.cat.ts.openToolBarCommand", null);

		// 添加监听
		addViewPartVisibleListener(workbenchWindow);

		addWorkplaceListener();
		// 自动检查更新
		automaticCheckUpdate();
		
		// 设置将文件拖到导航视图时的模式为直接复制
		setDragModle();
		
		setListenerToPespective(commandService);
		
		setIdToHelpSystem();
		
		setProgressIndicatorVisible(false);
		
		setInitLinkEnable();
		
		// 处理 hunspell 内置词典内置文件
		try {
			CommonFunction.unZipHunspellDics();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
 
Example 12
Source File: NattableUtil.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 刷新 Command 的可用状态
 * @param nameSpace
 * @param properties
 *            ;
 */
public static void refreshCommand(String nameSpace, String properties) {
	if (nameSpace != null && properties != null) {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		IEvaluationService evaluationService = (IEvaluationService) window.getService(IEvaluationService.class);
		if (evaluationService != null) {
			evaluationService.requestEvaluation(nameSpace + "." + properties);
		}
	}
}
 
Example 13
Source File: N4JSApplicationWorkbenchWindowAdvisor.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The 'Show View' dialog behavior slightly changed with E4. Even if the views are properly removed via activities
 * (by the unique view IDs) the content provider creates the root category for the unavailable views as well since
 * it is using the {@link MApplication}.
 */
private void reviewDisabledCategoriesFromAppModel() {
	final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	final MApplication service = workbenchWindow.getService(MApplication.class);
	for (Iterator<MPartDescriptor> itr = service.getDescriptors().iterator(); itr.hasNext(); /**/) {
		final MPartDescriptor descriptor = itr.next();
		if (isView(descriptor) && isDisabledView(descriptor)) {
			itr.remove();
		}
	}
}
 
Example 14
Source File: PreferencesActionDelegate.java    From LogViewer with Eclipse Public License 2.0 4 votes vote down vote up
public void run(LogViewer view, Shell shell) {
	
	/* 
	 * first try: create dialog with preference page
	 * 
	IPreferencePage page = new RulePreferencePage();
	PreferenceManager mgr = new PreferenceManager();
	IPreferenceNode node = new PreferenceNode("1", page);
	mgr.addToRoot(node);
	PreferenceDialog dialog = new PreferenceDialog(shell, mgr);
	dialog.create();
	dialog.setMessage(page.getTitle());
	dialog.open();
	*/

	/*
	 * second try: use command framework 
	 */

	// get services
	IWorkbenchWindow window = view.getSite().getWorkbenchWindow();
	ICommandService cS = (ICommandService)window.getService(ICommandService.class);
	IHandlerService hS = (IHandlerService)window.getService(IHandlerService.class);
	
	// get command for preference pages
	Command cmd        = cS.getCommand("org.eclipse.ui.window.preferences");

	// add parameter preferencePageId
	Map<String,Object> params = new HashMap<String,Object>();
	params.put("preferencePageId", "de.anbos.eclipse.logviewer.plugin.LogViewer.page1.3");

	// create command with parameters
	ParameterizedCommand pC = ParameterizedCommand.generateCommand(cmd, params);
	
	// execute parametrized command
	try {
		hS.executeCommand(pC, null);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 15
Source File: StartLaunchConfigMenuPDETest.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("cast")
private static IEclipseContext getEclipseContext() {
  IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
  return ( IEclipseContext )activeWorkbenchWindow.getService( IEclipseContext.class );
}
 
Example 16
Source File: WorkbenchUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static Object getService(Class<?> api) {
	IWorkbenchWindow w = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	return  w.getService(api);
}
 
Example 17
Source File: WorkbenchUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void refreshMainMenu() {
  	IWorkbenchWindow w = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
WorkbenchWindow ww = (WorkbenchWindow)w;
  	IMenuService service = (IMenuService)w.getService(IMenuService.class);
  	service.populateContributionManager((ContributionManager)ww.getActionBars().getMenuManager(), MenuUtil.MAIN_MENU);
  }