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

The following examples show how to use org.eclipse.ui.IWorkbench#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: KeyAssistHandler.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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 2
Source File: Utils.java    From EasyShell with 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 3
Source File: KeyAssistHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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 4
Source File: WorkbenchStartup.java    From google-cloud-eclipse with 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 5
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@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()]));
}
 
Example 6
Source File: KeysPreferencePage.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void init(IWorkbench workbench) {
	keyController = new KeyController2();
	keyController.init(workbench, lstRemove);
	model = keyController.getBindingModel();
	
	commandService = (ICommandService) workbench.getService(ICommandService.class);
	Collection definedCommandIds = commandService.getDefinedCommandIds();
	
	fDefaultCategory = commandService.getCategory(null);
	fBindingService = (IBindingService) workbench.getService(IBindingService.class);

	commandImageService = (ICommandImageService) workbench.getService(ICommandImageService.class);
}
 
Example 7
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@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()]));
}
 
Example 8
Source File: KeysPreferencePage.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void init(IWorkbench workbench) {
	keyController = new KeyController2();
	keyController.init(workbench, lstRemove);
	model = keyController.getBindingModel();
	
	commandService = (ICommandService) workbench.getService(ICommandService.class);
	Collection definedCommandIds = commandService.getDefinedCommandIds();
	
	fDefaultCategory = commandService.getCategory(null);
	fBindingService = (IBindingService) workbench.getService(IBindingService.class);

	commandImageService = (ICommandImageService) workbench.getService(ICommandImageService.class);
}
 
Example 9
Source File: AbstractShieldCommandStartup.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void earlyStartup() {
	Set<String> unusedCommand = getUnusedCommandSet();
	IWorkbench workbench = PlatformUI.getWorkbench();
	ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
	Command command;
	for (String commandId : unusedCommand) {
		command = commandService.getCommand(commandId);
		command.undefine();
	}
}
 
Example 10
Source File: ShieldStartup.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void earlyStartup() {
	IWorkbench workbench = PlatformUI.getWorkbench();
	// 在工作台初始化后,移除平台默认的 scheme
	IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);

	Scheme[] schemes = bindingService.getDefinedSchemes();
	for (int i = 0; i < schemes.length; i++) {
		String id = schemes[i].getId();
		if (id.equals(platformDefaultScheme) || id.equals(platformEmacsScheme)) {
			schemes[i].undefine();
		}
	}
}
 
Example 11
Source File: KeyController2.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@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()]));
}
 
Example 12
Source File: KeysPreferencePage.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void init(IWorkbench workbench) {
	keyController = new KeyController2();
	keyController.init(workbench, lstRemove);
	model = keyController.getBindingModel();
	
	commandService = (ICommandService) workbench.getService(ICommandService.class);
	Collection definedCommandIds = commandService.getDefinedCommandIds();
	
	fDefaultCategory = commandService.getCategory(null);
	fBindingService = (IBindingService) workbench.getService(IBindingService.class);

	commandImageService = (ICommandImageService) workbench.getService(ICommandImageService.class);
}
 
Example 13
Source File: TrimTraceHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench == null) {
        return false;
    }
    @SuppressWarnings("null")
    IHandlerService service = workbench.getService(IHandlerService.class);
    // we need the current state, and the map, but the command and the
    // trigger are
    // not necessary for getCurrentSelection
    ExecutionEvent executionEvent = new ExecutionEvent(null, Collections.emptyMap(), null, service.getCurrentState());
    final Object element = HandlerUtil.getCurrentSelection(executionEvent);

    if (!(element instanceof TreeSelection)) {
        return false;
    }
    /*
     * plugin.xml should have done type/count verification already
     */
    Object firstElement = ((TreeSelection) element).getFirstElement();
    ITmfTrace trace = null;
    if (firstElement instanceof TmfCommonProjectElement) {
        TmfCommonProjectElement traceElem = (TmfCommonProjectElement) firstElement;
        if (traceElem instanceof TmfTraceElement) {
            traceElem = ((TmfTraceElement) traceElem).getElementUnderTraceFolder();
        }
        trace = traceElem.getTrace();
    }
    if (trace == null || !isValid(trace)) {
        return false;
    }

    /* Only enable the action if a time range is currently selected */
    TmfTraceManager tm = TmfTraceManager.getInstance();
    TmfTimeRange selectionRange = tm.getTraceContext(trace).getSelectionRange();
    return !(selectionRange.getStartTime().equals(selectionRange.getEndTime()));
}
 
Example 14
Source File: PCalTranslateAutomaticallyHandler.java    From tlaplus with MIT License 5 votes vote down vote up
@Execute
public void execute(final ExecutionEvent event, final IWorkbench workbench) throws ExecutionException {
	// Toggle the IHandler's state at the UI level (check mark on/off) and
	// unsubscribe/subscribe the EventHandler.
	final IEventBroker eventBroker = workbench.getService(IEventBroker.class);
	if (HandlerUtil.toggleCommandState(event.getCommand())) {
		eventBroker.unsubscribe(this);
	} else {
		eventBroker.unsubscribe(this);
		Assert.isTrue(eventBroker.subscribe(TLAEditor.PRE_SAVE_EVENT, this));
	}
}
 
Example 15
Source File: DartPubService.java    From dartboard with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void get(IProject project) {
	IPath location = project.getLocation();
	if (location == null) {
		LOG.log(DartLog.createError(NLS.bind(Messages.PubSync_CouldNotDeterminePath, project.getName())));
		return;
	}
	boolean offline = preferences.getBoolean(GlobalConstants.P_OFFLINE_PUB);
	IWorkbench workbench = PlatformUIUtil.getWorkbench();
	PubService pub = workbench.getService(PubService.class);
	pub.get(project, offline);
}
 
Example 16
Source File: WakaTime.java    From eclipse-wakatime with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void earlyStartup() {
    final IWorkbench workbench = PlatformUI.getWorkbench();

    // listen for save file events
    ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
    executionListener = new CustomExecutionListener();
    commandService.addExecutionListener(executionListener);

    workbench.getDisplay().asyncExec(new Runnable() {
        public void run() {
            IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
            if (window == null) return;

            // setup wakatime menu
            //MenuHandler handler = new MenuHandler();
            String debug = ConfigFile.get("settings", "debug");
            DEBUG = debug != null && debug.trim().equals("true");


            WakaTime.log.debug("Initializing WakaTime plugin (https://wakatime.com) v"+VERSION);

            // prompt for apiKey if not set
            String apiKey = ConfigFile.get("settings", "api_key");
            if (apiKey == "") {
                promptForApiKey(window);
            }

            Dependencies.configureProxy();

            if (!Dependencies.isPythonInstalled()) {
                Dependencies.installPython();
                if (!Dependencies.isPythonInstalled()) {
                    MessageDialog dialog = new MessageDialog(window.getShell(),
                        "Warning!", null,
                        "WakaTime needs Python installed. Please install Python from python.org/downloads, then restart Eclipse.",
                        MessageDialog.WARNING, new String[]{IDialogConstants.OK_LABEL}, 0);
                    dialog.open();
                }
            }
            checkCore();

            if (window.getPartService() == null) return;

            // listen for caret movement
            if (window.getPartService().getActivePartReference() != null &&
                window.getPartService().getActivePartReference().getPage() != null &&
                window.getPartService().getActivePartReference().getPage().getActiveEditor() != null
            ) {
                IEditorPart part = window.getPartService().getActivePartReference().getPage().getActiveEditor();
                if (!(part instanceof AbstractTextEditor))
                    return;
                ((StyledText)part.getAdapter(Control.class)).addCaretListener(new CustomCaretListener());
            }

            // listen for change of active file
            window.getPartService().addPartListener(editorListener);

            if (window.getPartService().getActivePart() == null) return;
            if (window.getPartService().getActivePart().getSite() == null) return;
            if (window.getPartService().getActivePart().getSite().getPage() == null) return;
            if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return;
            if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return;

            // log file if one is opened by default
            IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput();
            if (input instanceof IURIEditorInput) {
                URI uri = ((IURIEditorInput)input).getURI();
                if (uri != null && uri.getPath() != null) {
                    String currentFile = uri.getPath();
                    long currentTime = System.currentTimeMillis() / 1000;
                    if (!currentFile.equals(WakaTime.getDefault().lastFile) || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) {
                        WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), false);
                        WakaTime.getDefault().lastFile = currentFile;
                        WakaTime.getDefault().lastTime = currentTime;
                    }
                }
            }

            WakaTime.log.debug("Finished initializing WakaTime plugin (https://wakatime.com) v"+VERSION);
        }
    });
}
 
Example 17
Source File: BindKeysHelper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param contextId defines the keys context we'll work with...
 *
 * We'll only remove/add bindings to this context.
 */
public BindKeysHelper(String contextId) {
    Assert.isNotNull(contextId);
    this.contextId = contextId;

    // Set the context we're working with.
    Set<String> activeContextIds = new HashSet<>();
    activeContextIds.add(contextId);
    contextManager.setActiveContextIds(activeContextIds);

    // Check that the context we're working with actually exists
    IWorkbench workbench = PlatformUI.getWorkbench();
    bindingService = (IBindingService) workbench.getService(IBindingService.class);
    IContextService contextService = (IContextService) workbench.getService(IContextService.class);
    Context context = contextService.getContext(contextId);
    if (context == null || context.isDefined() == false) {
        throw new RuntimeException("The context: " + contextId + " does not exist.");
    }

    Scheme activeScheme = bindingService.getActiveScheme();
    final Scheme[] definedSchemes = bindingService.getDefinedSchemes();

    // Make a copy we can work with locally (we'll apply changes later based on this copy).
    try {
        for (int i = 0; i < definedSchemes.length; i++) {
            final Scheme scheme = definedSchemes[i];
            final Scheme copy = localChangeManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
        }
        localChangeManager.setActiveScheme(activeScheme);
    } catch (final NotDefinedException e) {
        throw new Error("There is a programmer error in the bind keys helper"); //$NON-NLS-1$
    }
    localChangeManager.setLocale(bindingService.getLocale());
    localChangeManager.setPlatform(bindingService.getPlatform());
    Binding[] bindings = bindingService.getBindings();
    for (Binding binding : bindings) {
        initialState.add(binding);
    }
    localChangeManager.setBindings(bindings);
}