org.eclipse.ui.commands.ICommandService#addExecutionListener ( )源码实例Demo

下面列出了org.eclipse.ui.commands.ICommandService#addExecutionListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * setup
 */
private void setup()
{
	try
	{
		// listen for execution events
		Object service = PlatformUI.getWorkbench().getService(ICommandService.class);

		if (service instanceof ICommandService)
		{
			ICommandService commandService = (ICommandService) service;

			commandService.addExecutionListener(this);
		}
	}
	catch (IllegalStateException e)
	{
		// workbench not yet started, or may be running headless (like in core unit tests)
	}
	// listen for element visibility events
	BundleManager manager = BundleManager.getInstance();

	manager.addElementVisibilityListener(this);
}
 
源代码2 项目: e4macs   文件: KbdMacroSupport.java
/**
 * Start the definition of a keyboard macro
 * 
 * @param editor
 * @param append - if true, append to the current definition
 */
public void startKbdMacro(ITextEditor editor, boolean append) {
	
	if (!isExecuting()) {
		setEditor(editor);
		isdefining = true;
		ics = (ICommandService) editor.getSite().getService(ICommandService.class);
		// listen for command executions
		ics.addExecutionListener(this);
		addDocumentListener(editor);
		if (!append || kbdMacro == null) {
			kbdMacro = new KbdMacro();
		}
		setViewer(findSourceViewer(editor));
		if (viewer instanceof ITextViewerExtension) {
			((ITextViewerExtension) viewer).prependVerifyKeyListener(whileDefining);
		} else {
			viewer = null;
		}
		// add a listener for ^G
		Beeper.addBeepListener(KbdMacroBeeper.beeper);
		currentCommand = null;
	}
}
 
源代码3 项目: n4js   文件: N4JSExternalLibraryStartup.java
@Override
public void earlyStartup() {
	// Client code can still clone the repository on demand. (Mind plug-in UI tests.)

	// TODO this should be a job that we can wait for
	new Thread(() -> {
		// trigger index loading which will potentially announce a recovery build on all projects to be
		// necessary

		// XXX it is crucial to call isEmpty before isRecoveryBuildRequired is checked, since isEmpty
		// will set internal state that is afterwards queried by isRecoveryBuildRequired
		boolean indexIsEmpty = builderState.isEmpty();

		// check if this recovery build was really required
		if (descriptionPersister.isRecoveryBuildRequired() || indexIsEmpty) {
			// TODO return something like a Future that allows to say
			// descriptionPersister.scheduleRecoveryBuildOnContributions().andThen(buildManager...)
			descriptionPersister.scheduleRecoveryBuildOnContributions();
			Map<String, String> args = Maps.newHashMap();
			IBuildFlag.RECOVERY_BUILD.addToMap(args);
			builderStateDiscarder.forgetLastBuildState(Arrays.asList(workspace.getRoot().getProjects()), args);
		}
	}).start();

	// Add listener to monitor Cut and Copy commands
	ICommandService commandService = PlatformUI.getWorkbench().getAdapter(ICommandService.class);
	if (commandService != null) {
		commandService.addExecutionListener(new CheckNodeModulesSyncOnRefresh());
	}
}
 
源代码4 项目: ContentAssist   文件: CommandExecutionManager.java
/**
 * Registers a command manager with the command service of the workbench.
 * @param cm the command manager
 */
public static void register(CommandExecutionManager cm) {
    ICommandService cs = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
    if (cs != null) {
        cs.addExecutionListener(cm);
    }
}
 
源代码5 项目: CodeCheckerEclipsePlugin   文件: StartupJob.java
/**
 * Runs this job on UI thread.
 * @param monitor ProgressBar
 * @return Return Status.
 */
public IStatus runInUIThread(IProgressMonitor monitor) {
    CcGlobalConfiguration.getInstance();
    
    try { // TODO: find a better solution...
        Thread.sleep(WAIT_TIME);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        Logger.log(IStatus.ERROR, e.getMessage());
        Logger.log(IStatus.INFO, Logger.getStackTrace(e));
    }

    Logger.log(IStatus.INFO, "adding addResourceChangeListener ");
    ResourcesPlugin.getWorkspace().addResourceChangeListener(new ResourceChangeListener(),
            IResourceChangeEvent.POST_BUILD |
            IResourceDelta.OPEN | IResourceChangeEvent.PRE_DELETE);
    
    ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    commandService.addExecutionListener(new ISaveCommandExecutionListener());

    // check all open projects
    for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
        projectOpened(project);
    }
    Logger.log(IStatus.INFO, "CodeChecker reports had been parsed.");

    // check all open windows
    IWorkbench wb = PlatformUI.getWorkbench();
    for (IWorkbenchWindow win : wb.getWorkbenchWindows()) {
        addListenerToWorkbenchWindow(win);
    }
    return Status.OK_STATUS;
}
 
private void addListeners() {
	fWidgetEventSource= fViewer.getTextWidget();
	if (fWidgetEventSource != null) {
		fWidgetEventSource.addVerifyKeyListener(fEventListener);
		fWidgetEventSource.addMouseListener(fEventListener);
		fWidgetEventSource.addFocusListener(fEventListener);
	}

	ICommandService commandService= (ICommandService)PlatformUI.getWorkbench().getAdapter(ICommandService.class);
	if (commandService != null)
		commandService.addExecutionListener(fEventListener);
}
 
源代码7 项目: e4macs   文件: MetaXMinibuffer.java
/**
 * @see com.mulgasoft.emacsplus.minibuffer.CompletionMinibuffer#addOtherListeners(IWorkbenchPage, ISourceViewer, StyledText)
 */
@Override
protected void addOtherListeners(IWorkbenchPage page, ISourceViewer viewer, StyledText widget) {
	ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getAdapter(ICommandService.class);
	if (commandService != null) {
		commandService.addExecutionListener(this);
	}
	super.addOtherListeners(page, viewer, widget);
}
 
源代码8 项目: eclipse-wakatime   文件: WakaTime.java
@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);
        }
    });
}