Java Code Examples for org.eclipse.core.commands.AbstractHandler

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project ccw, under directory /ccw.core/src/java/ccw/repl/.

Source file: REPLView.java

  22 
vote

private void installEvalTopLevelSExpressionCommand(){
  getHandlerService().activateHandler(IClojureEditorActionDefinitionIds.EVALUATE_TOP_LEVEL_S_EXPRESSION,new AbstractHandler(){
    public Object execute(    ExecutionEvent event) throws ExecutionException {
      evalExpression();
      return null;
    }
  }
);
}
 

Example 2

From project incubator, under directory /net.karlmartens.ui/src/net/karlmartens/ui/viewer/.

Source file: TableViewerDeleteCellSelectionManager.java

  20 
vote

private void activateHandler(final IHandlerService service){
  final IHandlerActivation activation=service.activateHandler(IWorkbenchCommandConstants.EDIT_DELETE,new AbstractHandler(){
    @Override public Object execute(    ExecutionEvent event) throws ExecutionException {
      delete();
      return null;
    }
    @Override public void setEnabled(    Object evaluationContext){
      setBaseEnabled(UiUtil.hasFocus(_viewer.getControl(),true));
    }
  }
);
  final Table table=_viewer.getControl();
  new Listener(){
{
      table.addListener(SWT.Dispose,this);
      table.addListener(SWT.FocusIn,this);
      table.addListener(SWT.FocusOut,this);
    }
    @Override public void handleEvent(    Event event){
      if (event.type == SWT.Dispose) {
        handleDispose(event);
      }
 else       if (event.type == SWT.FocusIn || event.type == SWT.FocusOut) {
        ((IHandler2)activation.getHandler()).setEnabled(null);
      }
    }
    private void handleDispose(    Event event){
      table.removeListener(SWT.Dispose,this);
      table.removeListener(SWT.FocusIn,this);
      table.removeListener(SWT.FocusOut,this);
      service.deactivateHandler(activation);
    }
  }
;
}
 

Example 3

From project radrails, under directory /plugins/org.radrails.rails.ui/src/org/radrails/rails/internal/ui/console/.

Source file: RailsShell.java

  20 
vote

@Override public IPageBookViewPage createPage(IConsoleView view){
  page=(IOConsolePage)super.createPage(view);
  IDocument doc=getDocument();
  IHandlerService service=(IHandlerService)view.getSite().getService(IHandlerService.class);
  service.activateHandler("org.eclipse.ui.edit.text.contentAssist.proposals",new AbstractHandler(){
    public Object execute(    ExecutionEvent evt) throws ExecutionException {
      fContentAssistant.showPossibleCompletions();
      return null;
    }
  }
);
  doc.addDocumentListener(this);
  view.getSite().getPage().addPartListener(this);
  return page;
}
 

Example 4

From project rascal-eclipse, under directory /src/org/rascalmpl/eclipse/library/util/.

Source file: NonRascalMenuContributionItem.java

  20 
vote

private String contribute(Category defaultCategory,ICommandService cmdService,IHandlerService handlerService,IConstructor menu){
  String label=((IString)menu.get("label")).getValue();
  if (menu.getName().equals("edit")) {
    throw new RuntimeException("Edit is not support by non rascal windows");
  }
 else   if (menu.getName().equals("action") && menu.has("handler")) {
    String commandId=NON_RASCAL_CONTRIBUTION_COMMAND_PREFIX + encodeLabel(label);
    Command newCommand=cmdService.getCommand(commandId);
    if (!newCommand.isDefined()) {
      newCommand.define(label,"A non rascal contribution",defaultCategory);
    }
    final ICallableValue func=(ICallableValue)menu.get("handler");
    IHandler handler=new AbstractHandler(){
      public Object execute(      ExecutionEvent event) throws ExecutionException {
        ITextSelection selection=(ITextSelection)HandlerUtil.getActiveWorkbenchWindowChecked(event).getSelectionService().getSelection();
        IEditorInput activeEditorInput=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput();
        URI fileRef=new Resources(VF).makeFile(activeEditorInput).getURI();
        final ISourceLocation selectedLine=VF.sourceLocation(fileRef,selection.getOffset(),selection.getLength(),selection.getStartLine() + 1,selection.getEndLine() + 1,0,0);
        final IString selectedText=VF.string(selection.getText());
        if (selectedLine != null) {
          RascalInvoker.invokeAsync(new Runnable(){
            public void run(){
              func.call(new Type[]{TF.stringType(),TF.sourceLocationType()},new IValue[]{selectedText,selectedLine});
            }
          }
,func.getEval());
        }
        return null;
      }
    }
;
    newCommand.setHandler(handler);
    return commandId;
  }
 else {
    throw new NotYetImplemented("Advanced menu structures are not yet implemented.");
  }
}
 

Example 5

From project rj-client, under directory /de.walware.rj.eclient.graphics/src/de/walware/rj/eclient/graphics/.

Source file: RGraphicCompositeActionSet.java

  20 
vote

protected void addTestLocator(final IServiceLocator serviceLocator,final IActionBars actionBars){
  final IToolBarManager toolBar=actionBars.getToolBarManager();
  final IHandler2 handler=new AbstractHandler(){
    @Override public void setEnabled(    final Object evaluationContext){
      setBaseEnabled(fGraphic != null && !fGraphic.isLocatorStarted());
    }
    public Object execute(    final ExecutionEvent event) throws ExecutionException {
      if (fGraphic == null || fGraphic.isLocatorStarted()) {
        return null;
      }
      final AbstractLocalLocator locator=new AbstractLocalLocator(fGraphic){
        @Override protected void finished(        final List<double[]> graphic,        final List<double[]> user){
          final StringBuilder sb=new StringBuilder();
          for (int i=0; i < user.size(); i++) {
            sb.append(Arrays.toString(user.get(i))).append("\n");
          }
          Display.getDefault().asyncExec(new Runnable(){
            public void run(){
              MessageDialog.openInformation(null,"Locator Result",sb.toString());
            }
          }
);
        }
        @Override protected void canceled(){
        }
      }
;
      locator.start();
      return null;
    }
  }
;
  fHandlerCollection.add(".locator.startTest",handler);
  toolBar.appendToGroup(CONTEXT_MENU_GROUP_ID,new HandlerContributionItem(new CommandContributionItemParameter(serviceLocator,null,HandlerContributionItem.NO_COMMAND_ID,null,SharedUIResources.getImages().getDescriptor(SharedUIResources.LOCTOOL_SORT_SCORE_IMAGE_ID),null,null,"Test Locator",null,null,HandlerContributionItem.STYLE_PUSH,null,false),handler));
}