activehelpaction.java

来自「Eclipse 3高级编程一书源码」· Java 代码 · 共 79 行

JAVA
79
字号
/*******************************************************************************
 * Copyright (c) 2003 Berthold Daum.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     Berthold Daum
 *******************************************************************************/
package com.bdaum.SpellChecker.actions;

import org.eclipse.help.ILiveHelpAction;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchPage;

import com.bdaum.SpellChecker.SpellCheckerPlugin;

/**
 * Invoking spell checking via active help
 */
public class ActiveHelpAction implements ILiveHelpAction {
  // JavaScript invocation parameter
  String data;

  /**
   * Accepts the third parameter of the script invocation
   */
  public void setInitializationString(
    String data) {
    // Remember the parameter
    this.data = data;
  }

  /**
   * Runs help action
   */
  public void run() {
    IWorkbench wb = PlatformUI.getWorkbench();
    final IWorkbenchWindow window = 
         (wb.getActiveWorkbenchWindow() == null) ? 
             wb.getWorkbenchWindows()[0] : 
             wb.getActiveWorkbenchWindow();
    if (window == null) return;
    Display display = window.getShell().getDisplay();
    if (display == null) return;
    // Active help does not run in the SWT thread.
    // Therefore we must encapsulate all GUI accesses into
    // a syncExec() method.
    display.syncExec(new Runnable() {
      public void run() {
        // Bring the workbench window into the foreground
        Shell shell = window.getShell();
        shell.setMinimized(false);
        shell.forceActive();
        if (data.equals("install")) {
          // Fetch workbench page
          WorkbenchPage page = (WorkbenchPage) window.getActivePage();
          if (page == null) return;
          // Call Perspective Configuration function
          page.editActionSets();
        } else if (data.equals("start")) {
          // Get the SpellCheckingActionDelegate
          IWorkbenchWindowActionDelegate delegate = 
              SpellCheckerPlugin.getSpellCheckingActionDelegate();
          if (delegate == null) return;
          // Execute the spell checking action
          delegate.run(null);
        }
      }
    });
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?