Java 类org.eclipse.core.commands.common.CommandException 实例源码

项目:eclemma    文件:ImportSessionHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {

    final IWorkbenchSite site = HandlerUtil.getActiveSite(event);
    final ICommandService cs = (ICommandService) site
        .getService(ICommandService.class);
    final IHandlerService hs = (IHandlerService) site
        .getService(IHandlerService.class);
    final Command command = cs
        .getCommand(IWorkbenchCommandConstants.FILE_IMPORT);

    try {
      hs.executeCommand(ParameterizedCommand.generateCommand(command,
          Collections.singletonMap(
              IWorkbenchCommandConstants.FILE_IMPORT_PARM_WIZARDID,
              SessionImportWizard.ID)),
          null);
    } catch (CommandException e) {
      EclEmmaUIPlugin.log(e);
    }

    return null;
  }
项目:eclemma    文件:ExportSessionHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {

    final IWorkbenchSite site = HandlerUtil.getActiveSite(event);
    final ICommandService cs = (ICommandService) site
        .getService(ICommandService.class);
    final IHandlerService hs = (IHandlerService) site
        .getService(IHandlerService.class);
    final Command command = cs
        .getCommand(IWorkbenchCommandConstants.FILE_EXPORT);

    try {
      hs.executeCommand(ParameterizedCommand.generateCommand(command,
          Collections.singletonMap(
              IWorkbenchCommandConstants.FILE_EXPORT_PARM_WIZARDID,
              SessionExportWizard.ID)),
          null);
    } catch (CommandException e) {
      EclEmmaUIPlugin.log(e);
    }

    return null;
  }
项目:mytourbook    文件:CommandRunner.java   
/**
* Asynchronously executes a {@link Command} in the Eclipse UI thread.
*
* @see Runnable#run()
* @see Display#asyncExec(Runnable)
* @see #runCommand(String)
**/
public void run()
{
    try
    {
        if (command.isHandled() && command.isEnabled())
        {
            command.executeWithChecks(executionEvent);
        }
    }
    catch (CommandException exception)
    {
        ILog log = MultiTouchPlugin.getDefault().getLog();
        String info = "Unexpected exception while executing " + command; //$NON-NLS-1$
        IStatus status = new Status(IStatus.ERROR, MultiTouchPlugin.PLUGIN_ID, info, exception);
        log.log(status);
    }
}
项目:e4macs    文件:IndentForTabHandler.java   
/**
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Object result = null;
    ITextEditor editor = getTextEditor(event);
    extractUniversalCount(event);       // side effect sets up isUniversalPresent
    Binding indent = null;
    // ^U or no binding results in transform behavior
    if (!isUniversalPresent() && (indent = getBinding(editor,indentKey,indentMode)) != null) {
        String id = indent.getParameterizedCommand().getId(); 
        if (id != null && id.matches(indentExp) && !id.equals(IEmacsPlusCommandDefinitionIds.INDENT_FOR_TAB)) {
            try {
                result = executeCommand(id, null, editor);
            } catch (CommandException e) {
            }
        } else {
            super.execute(event);
        }
    } else {
        super.execute(event);
    }
    return result;
}
项目:e4macs    文件:BaseYankHandler.java   
/**
 * In the console context, use paste as
 * in some consoles (e.g. org.eclipse.debug.internal.ui.views.console.ProcessConsole), updateText
 * will not simulate keyboard input
 *  
 * @param event the ExecutionEvent
 * @param widget The consoles StyledText widget
 */
protected void paste(ExecutionEvent event, StyledText widget) {
        IWorkbenchPart apart = HandlerUtil.getActivePart(event);
        if (apart != null) {
            try {
                IWorkbenchPartSite site = apart.getSite();
                if (site != null) {
                    IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
                    if (service != null) {
                        service.executeCommand(IEmacsPlusCommandDefinitionIds.EMP_PASTE, null);
                        KillRing.getInstance().setYanked(true);
                    }
                }
            } catch (CommandException e) {
            }
        }
}
项目:e4macs    文件:EmacsPlusCmdHandler.java   
/**
 * Execute the command id (with universal-argument, if appropriate)
 * 
 * @param id
 * @param event
 * @return execution result
 */
private Object dispatchId(ITextEditor editor, String id, Map<String,Object> params) {
    Object result = null;
    if (id != null) {
        ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class);
        if (ics != null) {
            Command command = ics.getCommand(id);
            if (command != null) {
                try {
                    result = executeCommand(id, (Map<String,?>)params, null, getThisEditor());
                } catch (CommandException e) {}
            }
        }
    }
    return result;
}
项目:e4macs    文件:EmacsPlusUtils.java   
private static Object executeCommand(String commandId, Map<String,?> parameters, Event event, ICommandService ics, IHandlerService ihs)
throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException {
    Object result = null;
    if (ics != null && ihs != null) {
        Command command = ics.getCommand(commandId);
        if (command != null) {
            try {
                MarkUtils.setIgnoreDispatchId(true);
                ParameterizedCommand pcommand = ParameterizedCommand.generateCommand(command, parameters);
                if (pcommand != null) {
                    result = ihs.executeCommand(pcommand, event);
                }
            } finally {
                MarkUtils.setIgnoreDispatchId(false);
            }       
        }
    }
    return result;
}
项目:e4macs    文件:ConsoleCopyCutHandler.java   
/**
 * @see com.mulgasoft.emacsplus.commands.ConsoleCmdHandler#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent)
 */
@Override
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
    Object result = null;
    IDocument doc = viewer.getDocument();
    try {
        IWorkbenchPartSite site = activePart.getSite();
        if (site != null) {
            IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
            if (doc != null && service != null) {
                doc.addDocumentListener(KillRing.getInstance());
                String cmdId = getId(event, viewer);
                if (cmdId != null) {
                    result = service.executeCommand(cmdId, null);
                }
            }
        }
    } catch (CommandException e) {
        // Shouldn't happen as the Command id will be null or valid
        e.printStackTrace();
    } finally {
        if (doc != null) {
            doc.removeDocumentListener(KillRing.getInstance());
        }
        // clear kill command flag
        KillRing.getInstance().setKill(null, false);
    }

    MarkUtils.clearConsoleMark(viewer);
    return result;
}
项目:e4macs    文件:GlobalWhitespaceHandler.java   
/**
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Object result = null;
    ITextEditor editor = getTextEditor(event);
    if (editor != null) {
        try {
            result = executeCommand(IEmacsPlusCommandDefinitionIds.SHOW_WHITESPACE_CHARACTERS,null,editor);
        } catch (CommandException e) {
            // ignore
        }
    }
    return result;
}
项目:e4macs    文件:KbdMacroEndCallHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {
    ITextEditor editor = getTextEditor(event);
    if (editor != null) {
        KbdMacroSupport support = KbdMacroSupport.getInstance(); 
        // returns true if macro was being defined, else false
        if (!support.endKbdMacro()){
            if (support.hasKbdMacro()) {
                try {
                    executeCommand(IEmacsPlusCommandDefinitionIds.KBDMACRO_EXECUTE, null, editor);
                } catch (CommandException e) {}
            }
        }
    }
    return null;
}
项目:e4macs    文件:LineModeHandler.java   
/**
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Object result = null;
    ITextEditor editor = getTextEditor(event);
    if (editor != null) {
        try {
            ;
            result = executeCommand(IEmacsPlusCommandDefinitionIds.LINENUMBER_TOGGLE,null,editor);
        } catch (CommandException e) {
            // ignore
        }
    }
    return result;
}
项目:e4macs    文件:EmacsPlusCmdHandler.java   
/**
 * Make a parameter map, if it uses one, for this command
 * @param command
 * @param count
 * @param params
 * @return the populated map, or an empty one
 */
private Map<String,Object> getParams(Command command, Map<String,Object> params) {
    try {
        if (command.getParameter(UNIVERSAL) != null) {
            if (params.isEmpty()) {
                params = new HashMap<String, Object>();
            }
            params.put(UNIVERSAL, Integer.toString(getUniversalCount()));
        }
    } catch (CommandException e) {} // won't happen
    return params;
}
项目:e4macs    文件:EmacsPlusCmdHandler.java   
void executeUniversal(ITextEditor editor, String id, Event event, int count, boolean isNumeric) 
throws NotDefinedException, ExecutionException, CommandException {
    String did = null;
    if ((did = getInternalCmd(id)) != null) {
        // Emacs+ internal commands should support +- universal-argument
        EmacsPlusUtils.executeCommand(did, count, event, editor);
    } else if (count != 1 && (isUniversalCmd(id) || (alwaysUniversal && !id.startsWith(EmacsPlusUtils.MULGASOFT)))) {
        // only non-Emacs+ commands should be invoked here
        executeWithDispatch(editor, getUniversalCmd(id), count);
    } else {
        executeCommand(id, event, editor);
    }
}
项目:e4macs    文件:EmacsPlusUtils.java   
private static Object executeCommand(String commandId, Event event, IHandlerService service)
throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException {
    Object result = null;
    if (service != null) {
        try {
            MarkUtils.setIgnoreDispatchId(true);
            result =  service.executeCommand(commandId, event);
        } finally {
            MarkUtils.setIgnoreDispatchId(false);
        }       
    }
    return result;
}
项目:org.csstudio.display.builder    文件:SearchView.java   
/** React to selections, button presses, ... */
private void configureActions()
{
    // Start a channel search
    search.addSelectionListener(new SelectionAdapter()
    {
        @Override
        public void widgetSelected(final SelectionEvent e)
        {
            searchForChannels();
        }
    });

    // Channel Table: Allow dragging of PVs with archive
    final Table table = channel_table.getTable();
    new ControlSystemDragSource(table)
    {
        @Override
        public Object getSelection()
        {
            final IStructuredSelection selection = (IStructuredSelection) channel_table.getSelection();
            // To allow transfer of array, the data must be
            // of the actual array type, not Object[]
            final Object[] objs = selection.toArray();
            final ChannelInfo[] channels = Arrays.copyOf(objs, objs.length, ChannelInfo[].class);
            return channels;
        }
    };

    // Double-clicks should have the same effect as context menu -> Data Browser
    getSite().setSelectionProvider(channel_table);
    channel_table.addDoubleClickListener(new IDoubleClickListener()
    {
        @Override
        public void doubleClick(DoubleClickEvent event)
        {
            //casting is needed for RAP
            IHandlerService handlerService = getSite().getService(IHandlerService.class);
            try
            {
                handlerService.executeCommand("org.csstudio.trends.databrowser3.OpenDataBrowserPopup", null);
            } catch (CommandException ex) {
                Activator.getLogger().log(Level.WARNING, "Failed to open data browser", ex); //$NON-NLS-1$
            }
        }
    });

    // Add context menu for object contributions
    final MenuManager menu = new MenuManager();
    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    table.setMenu(menu.createContextMenu(table));
    getSite().registerContextMenu(menu, channel_table);
}
项目:e4macs    文件:EmacsPlusUtils.java   
public static Object executeCommand(String commandId, Integer count, Event event, IWorkbenchPart editor) 
throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException {    
        Map<String, Integer> parameters = new HashMap<String, Integer>();
        parameters.put(EmacsPlusUtils.UNIVERSAL_ARG, count);
    return (editor == null) ? executeCommand(commandId, parameters, event) : executeCommand(commandId, parameters, event, editor);
}
项目:e4macs    文件:EmacsPlusCmdHandler.java   
/**
 * If the Command accepts the universal-argument, then invoke it appropriately
 * otherwise simply execute it with no arguments.
 * 
 * To accept the universal-argument, the Command must either:
 *   1) Have a parameter named "universalArg" [for Emacs+ commands] - or -
 *   2) Be present in the universal command hash table [for pre-existing commands]
 *   
 * @param editor
 * @param count
 * @param cmd
 * @param isNumeric true if argument was entered as a number (rather than plain ^Us)
 *         - which we don't handle yet
 * @throws NotDefinedException
 * @throws ExecutionException
 * @throws CommandException
 */
void executeUniversal(ITextEditor editor, Command cmd, Event event, int count, boolean isNumeric)
throws NotDefinedException, ExecutionException, CommandException {
    // pass universal arg if non-default and cmd accepts it
    String id = cmd.getId();
    if (cmd.getParameter(UNIVERSAL) != null) {
        EmacsPlusUtils.executeCommand(id, count, event, editor);
    } else {
        executeUniversal(editor, id, event, count, isNumeric);
    }

}
项目:e4macs    文件:EmacsPlusUtils.java   
/**
 * Invoke the specified parameterized command using the handler service
 * 
 * @param commandId
 * @param parameters
 * @param event
 * @param editor
 * @return the result of the execution
 * @throws ExecutionException
 * @throws NotDefinedException
 * @throws NotEnabledException
 * @throws NotHandledException
 * @throws CommandException
 */
public static Object executeCommand(String commandId, Map<String,?> parameters, Event event)
throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException {
    return executeCommand(commandId, parameters, event,
            (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class),
            (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class));
}
项目:e4macs    文件:EmacsPlusUtils.java   
/**
 * Invoke the specified parameterized command using the handler service from the editor site
 * 
 * @param commandId
 * @param parameters
 * @param event
 * @param editor
 * @return the result of the execution
 * @throws ExecutionException
 * @throws NotDefinedException
 * @throws NotEnabledException
 * @throws NotHandledException
 * @throws CommandException
 */
public static Object executeCommand(String commandId, Map<String,?> parameters, Event event, IWorkbenchPart editor)
throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException {
    return executeCommand(commandId,parameters,event,
            (ICommandService) editor.getSite().getService(ICommandService.class),
            (IHandlerService) editor.getSite().getService(IHandlerService.class));
}
项目:e4macs    文件:EmacsPlusCmdHandler.java   
/**
 * Invoke the specified command using the handler service
 * 
 * @param commandId
 * @param event
 * @param editor
 * @return execution result
 * @throws CommandException 
 */
protected Object executeCommand(String commandId,Event event, IEditorPart editor) throws ExecutionException, CommandException {
    return EmacsPlusUtils.executeCommand(commandId, event, editor);
}
项目:e4macs    文件:EmacsPlusCmdHandler.java   
/**
 * Invoke the specified command using the generic handler service
 * 
 * @param commandId
 * @param event
 * @param editor
 * @return execution result
 * @throws CommandException 
 */
protected Object executeCommand(String commandId,Event event) throws ExecutionException, CommandException {
    return EmacsPlusUtils.executeCommand(commandId, event);
}
项目:e4macs    文件:EmacsPlusCmdHandler.java   
/**
 * Invoke the specified parameterized command using the handler service
 * @param commandId
 * @param params
 * @param event
 * @param editor
 * @return execution result
 * @throws ExecutionException
 * @throws CommandException
 */
protected Object executeCommand(String commandId, Map<String,?> params, Event event, IEditorPart editor) throws ExecutionException, CommandException {
    return EmacsPlusUtils.executeCommand(commandId, params, event, editor);
}
项目:e4macs    文件:EmacsPlusUtils.java   
/**
 * Invoke the specified command using the handler service
 * 
 * @param commandId
 * @param event
 * @param editor
 * @throws ExecutionException
 * @throws NotDefinedException
 * @throws NotEnabledException
 * @throws NotHandledException
 * @throws CommandException 
 */
public static Object executeCommand(String commandId, Event event)
throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException {
    return executeCommand(commandId,event,(IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class));
}
项目:e4macs    文件:EmacsPlusUtils.java   
/**
 * Invoke the specified command using the handler service from the editor site
 * 
 * @param commandId
 * @param event
 * @param editor
 * @throws ExecutionException
 * @throws NotDefinedException
 * @throws NotEnabledException
 * @throws NotHandledException
 * @throws CommandException 
 */
public static Object executeCommand(String commandId, Event event, IWorkbenchPart editor)
throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException {
    return executeCommand(commandId,event,(IHandlerService) editor.getSite().getService(IHandlerService.class));
}