Java源码示例:org.eclipse.core.commands.NotEnabledException
示例1
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;
}
示例2
/**
* If {@link Preferences#P_TEXT_EDIT_LOCAL} is set, the
* <code> ch.elexis.core.ui.command.startEditLocalDocument </code> command is called with the
* provided {@link Brief}, and the provided {@link IViewPart} is hidden.
*
* @param view
* @param brief
* @return returns true if edit local is started and view is hidden
*/
public static boolean startEditLocalDocument(IViewPart view, Brief brief){
if (CoreHub.localCfg.get(Preferences.P_TEXT_EDIT_LOCAL, false) && brief != null) {
// open for editing
ICommandService commandService =
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command command =
commandService.getCommand("ch.elexis.core.ui.command.startEditLocalDocument"); //$NON-NLS-1$
PlatformUI.getWorkbench().getService(IEclipseContext.class)
.set(command.getId().concat(".selection"), new StructuredSelection(brief));
try {
command.executeWithChecks(
new ExecutionEvent(command, Collections.EMPTY_MAP, view, null));
} catch (ExecutionException | NotDefinedException | NotEnabledException
| NotHandledException e) {
MessageDialog.openError(view.getSite().getShell(), Messages.TextView_errortitle,
Messages.TextView_errorlocaleditmessage);
}
view.getSite().getPage().hideView(view);
return true;
}
return false;
}
示例3
/**
* If {@link Preferences#P_TEXT_EDIT_LOCAL} is set, the
* <code> ch.elexis.core.ui.command.startEditLocalDocument </code> command is called with the
* provided {@link IDocumentLetter}, and the provided {@link IViewPart} is hidden.
*
* @param view
* @param document
* @return returns true if edit local is started and view is hidden
*/
public static boolean startEditLocalDocument(IViewPart view, IDocumentLetter document){
if (CoreHub.localCfg.get(Preferences.P_TEXT_EDIT_LOCAL, false) && document != null) {
// open for editing
ICommandService commandService =
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command command =
commandService.getCommand("ch.elexis.core.ui.command.startEditLocalDocument"); //$NON-NLS-1$
PlatformUI.getWorkbench().getService(IEclipseContext.class)
.set(command.getId().concat(".selection"), new StructuredSelection(document));
try {
command.executeWithChecks(
new ExecutionEvent(command, Collections.EMPTY_MAP, view, null));
} catch (ExecutionException | NotDefinedException | NotEnabledException
| NotHandledException e) {
MessageDialog.openError(view.getSite().getShell(), Messages.TextView_errortitle,
Messages.TextView_errorlocaleditmessage);
}
view.getSite().getPage().hideView(view);
return true;
}
return false;
}
示例4
private void startLocalEdit(Brief brief){
if (brief != null) {
ICommandService commandService =
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command command =
commandService.getCommand("ch.elexis.core.ui.command.startEditLocalDocument"); //$NON-NLS-1$
PlatformUI.getWorkbench().getService(IEclipseContext.class)
.set(command.getId().concat(".selection"), new StructuredSelection(brief));
try {
command.executeWithChecks(
new ExecutionEvent(command, Collections.EMPTY_MAP, this, null));
} catch (ExecutionException | NotDefinedException | NotEnabledException
| NotHandledException e) {
MessageDialog.openError(Display.getDefault().getActiveShell(),
Messages.BriefAuswahl_errorttile,
Messages.BriefAuswahl_erroreditmessage);
}
}
}
示例5
private void endLocalEdit(StructuredSelection selection){
ICommandService commandService =
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command command = commandService.getCommand("ch.elexis.core.ui.command.endLocalDocument"); //$NON-NLS-1$
PlatformUI.getWorkbench().getService(IEclipseContext.class)
.set(command.getId().concat(".selection"), selection);
try {
command
.executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, this, null));
tableViewer.setInput(service.getAll());
} catch (ExecutionException | NotDefinedException | NotEnabledException
| NotHandledException e) {
MessageDialog.openError(getShell(), Messages.LocalDocumentsDialog_errortitle,
Messages.LocalDocumentsDialog_errorendmessage);
}
}
示例6
private void abortLocalEdit(StructuredSelection selection){
ICommandService commandService =
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command command = commandService.getCommand("ch.elexis.core.ui.command.abortLocalDocument"); //$NON-NLS-1$
PlatformUI.getWorkbench().getService(IEclipseContext.class)
.set(command.getId().concat(".selection"), selection);
try {
command.executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, this, null));
tableViewer.setInput(service.getAll());
} catch (ExecutionException | NotDefinedException | NotEnabledException
| NotHandledException e) {
MessageDialog.openError(getShell(), Messages.LocalDocumentsDialog_errortitle,
Messages.LocalDocumentsDialog_errorabortmessage);
}
}
示例7
/**
* Maximize a part. Calling this a second time will "un-maximize" a part.
*
* @param part
* the workbench part
*/
public static void maximize(@NonNull IWorkbenchPart part) {
assertNotNull(part);
IWorkbenchPartSite site = part.getSite();
assertNotNull(site);
// The annotation is to make the compiler not complain.
@Nullable Object handlerServiceObject = site.getService(IHandlerService.class);
assertTrue(handlerServiceObject instanceof IHandlerService);
IHandlerService handlerService = (IHandlerService) handlerServiceObject;
try {
handlerService.executeCommand(IWorkbenchCommandConstants.WINDOW_MAXIMIZE_ACTIVE_VIEW_OR_EDITOR, null);
} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
fail(e.getMessage());
}
}
示例8
/**
* Creates session on passed session group.
* @param group - session group
* @return - trace session group if it's successful else null
* @throws ExecutionException
* @throws NotDefinedException
* @throws NotEnabledException
* @throws NotHandledException
*/
public TraceSessionComponent createSession(ITraceControlComponent group) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
executeCommand(group, "createSession");
ITraceControlComponent[] sessions = group.getChildren();
if ((sessions == null) || (sessions.length == 0)) {
return null;
}
return (TraceSessionComponent)sessions[0];
}
示例9
public static boolean runCommand(final Command c, final ExecutionEvent event) throws ExecutionException {
if (c.isEnabled()) {
try {
c.executeWithChecks(event);
return true;
} catch (NotDefinedException | NotEnabledException | NotHandledException e) {
e.printStackTrace();
}
}
return false;
}
示例10
@Override
public void run(IAction action) {
IHandlerService handlerService = window.getService(IHandlerService.class);
try {
handlerService.executeCommand("org.eclipse.ui.window.quickAccess", null); // //$NON-NLS-1$
} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
e.printStackTrace();
}
}
示例11
public static Object executeCommand( String commandId, Map paramMap )
throws NotDefinedException, ExecutionException,
ParameterValueConversionException, NotEnabledException,
NotHandledException
{
Command cmd = CommandUtils.getCommand( commandId );
List paramList = new ArrayList( );
if ( paramMap != null )
{
for ( Iterator iter = paramMap.entrySet( ).iterator( ); iter.hasNext( ); )
{
Map.Entry entry = (Entry) iter.next( );
String paramId = entry.getKey( ).toString( );
Object value = entry.getValue( );
if ( value != null )
{
paramList.add( createParameter( cmd, paramId, value ) );
}
}
}
if ( paramList.size( ) > 0 )
{
ParameterizedCommand paramCommand = new ParameterizedCommand( cmd,
(Parameterization[]) paramList.toArray( new Parameterization[paramList.size( )] ) );
return getHandlerService( ).executeCommand( paramCommand, null );
}
else
{
return getHandlerService( ).executeCommand( commandId, null );
}
}
示例12
public static Object executeCommand( String commandId )
throws ExecutionException, NotDefinedException,
NotEnabledException, NotHandledException
{
return getHandlerService( ).executeCommand( commandId, null );
}
示例13
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;
}
示例14
@Override
protected Listener createSelectionListener(AbstractProcess process) {
return e -> {
Command command = iCommandService.getCommand(RUN_COMMAND);
Map<String, Object> parameters = new HashMap<>();
parameters.put("process", process);
ExecutionEvent executionEvent = new ExecutionEvent(command, parameters, this, null);
try {
command.executeWithChecks(executionEvent);
} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) {
throw new RuntimeException(String.format("An error occured while executing command %s", RUN_COMMAND),
e1);
}
};
}
示例15
private void makeActions(){
doubleClickAction = new Action() {
public void run(){
ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof IDocument) {
IDocument dh = (IDocument) obj;
DocumentStoreServiceHolder.getService().getPersistenceObject(dh)
.ifPresent(po -> {
ICommandService commandService = (ICommandService) PlatformUI
.getWorkbench().getService(ICommandService.class);
Command command = commandService
.getCommand("ch.elexis.core.ui.command.startEditLocalDocument");
PlatformUI.getWorkbench().getService(IEclipseContext.class).set(
command.getId().concat(".selection"), new StructuredSelection(po));
try {
command.executeWithChecks(
new ExecutionEvent(command, Collections.EMPTY_MAP, null, null));
} catch (ExecutionException | NotDefinedException | NotEnabledException
| NotHandledException e) {
MessageDialog.openError(getSite().getShell(), "Fehler",
"Das Dokument konnte nicht geöffnet werden.");
e.printStackTrace();
}
});
ContextServiceHolder.get().postEvent(ElexisEventTopics.EVENT_UPDATE, dh);
}
}
};
}
示例16
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 executeCommand(commandId, parameters, event, editor);
}
示例17
public void notEnabled(String commandId, NotEnabledException exception) {
}
示例18
@Override
public void notEnabled(String commandId, NotEnabledException exception) {
popEvent();
}
示例19
/**
* Executes an Eclipse command with command ID
* @param commandId
* @throws ExecutionException
* @throws NotDefinedException
* @throws NotEnabledException
* @throws NotHandledException
*/
public void executeCommand(String commandId) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
Object handlerServiceObject = fControlView.getSite().getService(IHandlerService.class);
IHandlerService handlerService = (IHandlerService) handlerServiceObject;
handlerService.executeCommand(COMMAND_CATEGORY_PREFIX + commandId, null);
waitForJobs();
}
示例20
/**
* 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));
}
示例21
/**
* 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 (editor == null) ? executeCommand(commandId, parameters, event) :
executeCommand(commandId,parameters,event,
(ICommandService) editor.getSite().getService(ICommandService.class),
(IHandlerService) editor.getSite().getService(IHandlerService.class));
}
示例22
/**
* Executes an Eclipse command with command ID after selecting passed component
* @param component - component to select in the tree
* @param commandId - command ID
* @throws ExecutionException
* @throws NotDefinedException
* @throws NotEnabledException
* @throws NotHandledException
*/
public void executeCommand(ITraceControlComponent component, String commandId) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
setSelection(component);
executeCommand(commandId);
}
示例23
/**
* Executes an Eclipse command with command ID after selecting passed components
* @param components - array of components to select in the tree
* @param commandId - command ID
* @throws ExecutionException
* @throws NotDefinedException
* @throws NotEnabledException
* @throws NotHandledException
*/
public void executeCommand(ITraceControlComponent[] components, String commandId) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
setSelection(components);
executeCommand(commandId);
}
示例24
/**
* Destroys a given session.
* @param session - session to destroy
* @throws ExecutionException
* @throws NotDefinedException
* @throws NotEnabledException
* @throws NotHandledException
*/
public void destroySession(TraceSessionComponent session) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
executeCommand(session, "destroySession");
}
示例25
/**
* Starts a given session
* @param session - session to start
* @throws ExecutionException
* @throws NotDefinedException
* @throws NotEnabledException
* @throws NotHandledException
*/
public void startSession(TraceSessionComponent session) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
executeCommand(session, "start");
}
示例26
/**
* Stops a given session
* @param session - session to stop
* @throws ExecutionException
* @throws NotDefinedException
* @throws NotEnabledException
* @throws NotHandledException
*/
public void stopSession(TraceSessionComponent session) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
executeCommand(session, "stop");
}
示例27
/**
* 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));
}
示例28
/**
* 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));
}