Package dashlookup.handlers

Source Code of dashlookup.handlers.DashLookupHandler

package dashlookup.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.program.Program;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;

/**
* Our sample handler extends AbstractHandler, an IHandler base class.
* @see org.eclipse.core.commands.IHandler
* @see org.eclipse.core.commands.AbstractHandler
*/
public class DashLookupHandler extends AbstractHandler {
  /**
   * The constructor.
   */
  public DashLookupHandler() {
  }

  /**
   * the command has been executed, so extract extract the needed information
   * from the application context.
   */
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    ISelectionService service = window.getSelectionService();

    if (service != null) {
      ISelection selection = service.getSelection();
      if (selection instanceof ITextSelection) {
        String selectedText = ((ITextSelection) selection).getText();
        if (!selectedText.isEmpty())
          Program.launch("dash://" + selectedText);
      }
    }
    return null;
  }
}
TOP

Related Classes of dashlookup.handlers.DashLookupHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.