org.eclipse.core.commands.common.NotDefinedException Java Examples

The following examples show how to use org.eclipse.core.commands.common.NotDefinedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommandExecutionManager.java    From ContentAssist with MIT License 6 votes vote down vote up
/**
 * Receives a command that is about to execute.
 * @param commandId the identifier of the command that is about to execute
 * @param event the event that will be passed to the <code>execute</code> method
 */
@Override
public void preExecute(String commandId, ExecutionEvent event) {
    long time = Time.getCurrentTime();
    String path = recorder.getActiveInputFilePath();
    
    ExecutionMacro macro = new ExecutionMacro(time, "Exec", path, commandId);
    recorder.recordExecutionMacro(macro);
    
    try {
        String id = event.getCommand().getCategory().getId();
        if (id.endsWith("category.refactoring")) {
            recorder.setParentMacro(macro);
            
            TriggerMacro trigger = new TriggerMacro(time, "Refactoring", path, TriggerMacro.Kind.BEGIN);
            recorder.recordTriggerMacro(trigger);
        }
    } catch (NotDefinedException e) {
        e.printStackTrace();
    }
}
 
Example #2
Source File: CodeAssistAdvancedConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static String getKeyboardShortcut(ParameterizedCommand command) {
	IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
	fgLocalBindingManager.setBindings(bindingService.getBindings());
	try {
		Scheme activeScheme= bindingService.getActiveScheme();
		if (activeScheme != null)
			fgLocalBindingManager.setActiveScheme(activeScheme);
	} catch (NotDefinedException e) {
		JavaPlugin.log(e);
	}

	TriggerSequence[] bindings= fgLocalBindingManager.getActiveBindingsDisregardingContextFor(command);
	if (bindings.length > 0)
		return bindings[0].format();
	return null;
}
 
Example #3
Source File: AbstractMenuContributionItem.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("restriction")
protected MenuItem createMenu(Menu parent, String command, Optional<Image> image) {
    MenuItem item = new MenuItem(parent, SWT.NONE);
    ParameterizedCommand parameterizedCommand = createParametrizedCommand(command);
    try {
        item.setText(parameterizedCommand.getName());
    } catch (NotDefinedException e) {
        BonitaStudioLog.error(
                String.format("The command '%s' doesn't have any name defined.", parameterizedCommand.getId()), e);
        item.setText(parameterizedCommand.getId());
    }
    item.addListener(SWT.Selection, e -> {
        if (eHandlerService.canExecute(parameterizedCommand)) {
            eHandlerService.executeHandler(parameterizedCommand);
        } else {
            throw new RuntimeException(String.format("Can't execute command %s", parameterizedCommand.getId()));
        }
    });
    item.setEnabled(true);
    appendShortcut(parameterizedCommand, item);
    image.ifPresent(item::setImage);
    return item;
}
 
Example #4
Source File: EditLocalDocumentUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: EditLocalDocumentUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: XrefExtension.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
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);
		}
	}
}
 
Example #7
Source File: LocalDocumentsDialog.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
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);
	}
}
 
Example #8
Source File: CommandSupport.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get the current set of defined categories corresponding to the included category names
 * 
 * @param ics
 * @return the filtered set of categories
 * 
 * @throws NotDefinedException
 */
private HashSet<Category> getCategories(ICommandService ics) throws NotDefinedException 
{
	if (catHash.isEmpty() && catIncludes != null) {
		Category[] cats = ics.getDefinedCategories();
		for (int i = 0; i < cats.length; i++) {
			for (int j = 0; j < catIncludes.length; j++) {
				if (catIncludes[j].equals(cats[i].getId())) {
					catHash.add(cats[i]);
					break;
				}
			}
		}
	}
	return catHash;
}
 
Example #9
Source File: LocalDocumentsDialog.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
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);
	}
}
 
Example #10
Source File: KeyController2.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
private static BindingManager loadModelBackend(IServiceLocator locator) {
	IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
	BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
	final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
	try {
		Scheme modelActiveScheme = null;
		for (int i = 0; i < definedSchemes.length; i++) {
			final Scheme scheme = definedSchemes[i];
			final Scheme copy = bindingManager.getScheme(scheme.getId());
			copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
			if (definedSchemes[i] == bindingService.getActiveScheme()) {
				modelActiveScheme = copy;
			}
		}
		bindingManager.setActiveScheme(modelActiveScheme);
	} catch (final NotDefinedException e) {
		StatusManager.getManager()
				.handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
						"Keys page found an undefined scheme", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
Example #11
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private static BindingManager loadModelBackend(IServiceLocator locator) {
	IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
	BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
	final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
	try {
		Scheme modelActiveScheme = null;
		for (int i = 0; i < definedSchemes.length; i++) {
			final Scheme scheme = definedSchemes[i];
			final Scheme copy = bindingManager.getScheme(scheme.getId());
			copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
			if (definedSchemes[i] == bindingService.getActiveScheme()) {
				modelActiveScheme = copy;
			}
		}
		bindingManager.setActiveScheme(modelActiveScheme);
	} catch (final NotDefinedException e) {
		StatusManager.getManager()
				.handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
						"Keys page found an undefined scheme", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
Example #12
Source File: KeyController2.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
	// Fix the scheme in the local changes.
	final String defaultSchemeId = bindingService.getDefaultSchemeId();
	final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
	try {
		fBindingManager.setActiveScheme(defaultScheme);
	} catch (final NotDefinedException e) {
		// At least we tried....
	}

	// Restore any User defined bindings
	Binding[] bindings = fBindingManager.getBindings();
	for (int i = 0; i < bindings.length; i++) {
		ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
		String commandId = null;
		if (pCommand != null) {
			commandId = pCommand.getCommand().getId();
		}
		if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
			fBindingManager.removeBinding(bindings[i]);
		}
	}
	bindingModel.refresh(contextModel, lstRemove);
	saveBindings(bindingService);
}
 
Example #13
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
	// Fix the scheme in the local changes.
	final String defaultSchemeId = bindingService.getDefaultSchemeId();
	final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
	try {
		fBindingManager.setActiveScheme(defaultScheme);
	} catch (final NotDefinedException e) {
		// At least we tried....
	}

	// Restore any User defined bindings
	Binding[] bindings = fBindingManager.getBindings();
	for (int i = 0; i < bindings.length; i++) {
		ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
		String commandId = null;
		if (pCommand != null) {
			commandId = pCommand.getCommand().getId();
		}
		if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
			fBindingManager.removeBinding(bindings[i]);
		}
	}
	bindingModel.refresh(contextModel, lstRemove);
	saveBindings(bindingService);
}
 
Example #14
Source File: RepeatHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection, ExecutionEvent event) throws BadLocationException {
	RepeatCommandSupport repeat = RepeatCommandSupport.getInstance();
	String id = repeat.getId();

	try {
		Integer count = repeat.getCount();
		Command c = ((ICommandService)editor.getSite().getService(ICommandService.class)).getCommand(id);
		showMessage(editor, (count != 1) ? String.format(UREPEAT, count, c.getName()) : String.format(REPEAT, c.getName()), false);
	} catch (NotDefinedException e) {
		// won't happen
	}		
	Object result = NO_OFFSET;
	result = repeatLast(editor, id, repeat.getParams());
	return (result instanceof Integer ? (Integer)result : NO_OFFSET);
}
 
Example #15
Source File: CommandBriefKeyHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.IMinibufferExecutable#executeResult(org.eclipse.ui.texteditor.ITextEditor, java.lang.Object)
 */
public boolean executeResult(ITextEditor editor, Object minibufferResult) {
	
	String summary = EMPTY_STR;
	if (minibufferResult != null) {

		IBindingResult bindingR = (IBindingResult) minibufferResult;
		String name = bindingR.getKeyString();
		if (bindingR == null || bindingR.getKeyBinding() == null) {
			summary = String.format(CMD_NO_RESULT, name) + CMD_NO_BINDING;
		} else {
			summary = String.format(CMD_KEY_RESULT,name); 
			Binding binding = bindingR.getKeyBinding();
			try {
				Command com = getCommand(binding);
				if (com != null) {
					summary += normalizeCommandName(com.getName());
				}
			} catch (NotDefinedException e) {
				// can't happen as the Command will be null or valid
			}
		}
	}
	showResultMessage(editor, summary, false);
	return true;
}
 
Example #16
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private static BindingManager loadModelBackend(IServiceLocator locator) {
	IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
	BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
	final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
	try {
		Scheme modelActiveScheme = null;
		for (int i = 0; i < definedSchemes.length; i++) {
			final Scheme scheme = definedSchemes[i];
			final Scheme copy = bindingManager.getScheme(scheme.getId());
			copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
			if (definedSchemes[i] == bindingService.getActiveScheme()) {
				modelActiveScheme = copy;
			}
		}
		bindingManager.setActiveScheme(modelActiveScheme);
	} catch (final NotDefinedException e) {
		StatusManager.getManager()
				.handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
						"Keys page found an undefined scheme", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
Example #17
Source File: CommandAproposHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
private void printCommand(String name, Command command, EmacsPlusConsole console) {
	console.printBold(name + SWT.TAB);
	String bindingStrings = CommandHelp.getKeyBindingString(command, true);
	if (bindingStrings != null) {
		console.printContext(A_MSG + bindingStrings + Z_MSG);
	}
	try {
		String desc = command.getDescription();
		if (desc != null) {
			desc = desc.replaceAll(CR, CR + blanks + SWT.TAB);
			console.print(desc + CR);
		} else {
			console.print(CR);
		}
	} catch (NotDefinedException e) {
	}
}
 
Example #18
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
	// Fix the scheme in the local changes.
	final String defaultSchemeId = bindingService.getDefaultSchemeId();
	final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
	try {
		fBindingManager.setActiveScheme(defaultScheme);
	} catch (final NotDefinedException e) {
		// At least we tried....
	}

	// Restore any User defined bindings
	Binding[] bindings = fBindingManager.getBindings();
	for (int i = 0; i < bindings.length; i++) {
		ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
		String commandId = null;
		if (pCommand != null) {
			commandId = pCommand.getCommand().getId();
		}
		if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
			fBindingManager.removeBinding(bindings[i]);
		}
	}
	bindingModel.refresh(contextModel, lstRemove);
	saveBindings(bindingService);
}
 
Example #19
Source File: CommandUtils.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public static Parameterization createParameter( Command command,
		String parameterId, Object value ) throws NotDefinedException,
		ExecutionException, ParameterValueConversionException
{
	ParameterType parameterType = command.getParameterType( parameterId );
	if ( parameterType == null )
	{
		throw new ExecutionException( "Command does not have a parameter type for the given parameter" ); //$NON-NLS-1$
	}

	IParameter param = command.getParameter( parameterId );
	AbstractParameterValueConverter valueConverter = parameterType.getValueConverter( );
	if ( valueConverter == null )
	{
		throw new ExecutionException( "Command does not have a value converter" ); //$NON-NLS-1$
	}

	String valueString = valueConverter.convertToString( value );
	Parameterization parm = new Parameterization( param, valueString );
	return parm;
}
 
Example #20
Source File: EmacsPlusUtils.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #21
Source File: CommandDescribeHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private void printDetails(Command cmd, String[] bindings, String[] abindings, EmacsPlusConsole console) {
	if (bindings.length == 0) {
		console.printBold(SWT.TAB + CMD_NO_BINDING + CR);
	} else {
		for (int i = 0; i < abindings.length; i+=2) {
			console.printBinding(SWT.TAB + abindings[i]);
			console.printContext(A_MSG + abindings[i+1] + Z_MSG + CR);
		}
		for (int i = 0; i < bindings.length; i+=2) {
			boolean printit = true;
			for (int j=0; j < abindings.length; j+=2) {
				if (bindings[i].equals(abindings[j])) {
					printit = false;
					break;
				}
			}
			if (printit) {
				// don't bold non-active bindings
				console.print(SWT.TAB + bindings[i]);
				console.printContext(A_MSG + bindings[i+1] + Z_MSG + CR);
			}
		}
	}
	console.printBold(' ' + CMD_DESC_HEADING + CR + SWT.TAB);
	try {
		console.print(cmd.getDescription());
	} catch (NotDefinedException e) {
	}
}
 
Example #22
Source File: EmacsPlusCmdHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
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);
	}
}
 
Example #23
Source File: CommandUtils.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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 );
	}
}
 
Example #24
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * Cook up a label that is, hopefully, distinct and useful
   * @param cat
   * @return
   */
  String getLabel(Category cat) {
  	String result = null;
  	try {
  		String desc = cat.getDescription();
	result= cat.getName() + DISPLAY_SEPARATOR + (desc != null ? desc : "");	//$NON-NLS-1$
} catch (NotDefinedException e) {}
return result;
  }
 
Example #25
Source File: CommandCategoryEditor.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
Category[] sortCats(java.util.List<Category> sCats) {
	Category[] sCatsArray = sCats.toArray(new Category[0]);
	Arrays.sort(sCatsArray, new Comparator<Category>() {
		public int compare(Category o1, Category o2) {
			int result = 0;
			try {
				result = o1.getName().compareTo(o2.getName());
			} catch (NotDefinedException e) {}
			return result;
		}
	});
	return sCatsArray;
}
 
Example #26
Source File: CommandSupport.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
public TreeMap<String, Command> getCommandList(IEditorPart editor, boolean all) {
		ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class);
		Command[] commands = ics.getDefinedCommands();
		commandTree = new TreeMap<String, Command>();
		try {
			HashSet<Category>catHash = (all ? null : getCategories(ics));
			boolean isOk = all;
			for (int i = 0; i < commands.length; i++) {
				if (!isOk && catHash.contains(commands[i].getCategory())) {
					IParameter[] params = commands[i].getParameters(); 
					isOk = commands[i].isHandled();
					// if the command has parameters, they must all be optional
					if (isOk && params != null) {
						for (int j = 0; j < params.length; j++) {
							if (!(isOk = params[j].isOptional())) {
								break;
							}
						}
					}
				}
				if (isOk) {
					commandTree.put(fixName(commands[i].getName()), commands[i]);
				}
				isOk = all;
			}
		} catch (NotDefinedException e) {}
//		getContexts(editor);
		return commandTree;
	}
 
Example #27
Source File: NewCoolbarItem.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public boolean add(String commandId, String label) {
    Command command = commandService.getCommand(commandId);
    if (command != null && command.isDefined() && command.isHandled()) {
        final MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
        try {
            menuItem.setText(label != null ? label : command.getName());
            getCommandImage(commandId).ifPresent(menuItem::setImage);
        } catch (NotDefinedException e1) {
            BonitaStudioLog.error(e1);
            menuItem.setText("unknown command: " + commandId);
        }
        menuItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent event) {
                try {
                    handlerService.executeCommand(command.getId(), null);
                } catch (final Exception e) {
                    BonitaStudioLog.error(e);
                }
            }

        });
        return true;
    }
    return false;
}
 
Example #28
Source File: DocumentsView.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
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);
			}
		}
	};
}
 
Example #29
Source File: CommandKeyHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.IMinibufferExecutable#executeResult(org.eclipse.ui.texteditor.ITextEditor, java.lang.Object)
 */
public boolean executeResult(final ITextEditor editor, final Object minibufferResult) {
	
	if (minibufferResult != null) {
		final EmacsPlusConsole console = EmacsPlusConsole.getInstance();
		console.clear();
		console.activate();

		EmacsPlusUtils.asyncUiRun(new Runnable() {
			public void run() {
				String summary = EMPTY_STR;

				IBindingResult bindingR = (IBindingResult) minibufferResult;
				String name = bindingR.getKeyString();
				if (bindingR == null || bindingR.getKeyBinding() == null) {
					summary = String.format(CMD_NO_RESULT, name) + CMD_NO_BINDING;
					console.print(summary);
				} else {
					Binding binding = bindingR.getKeyBinding();
					summary = String.format(CMD_KEY_RESULT,name); 
					console.print(summary);
					try {
						Command com = getCommand(binding);
						if (com != null) {
							name = normalizeCommandName(com.getName());
							summary += name;
							console.printBinding(name + CR);
							printCmdDetails(getPCommand(binding),console);
						}
					} catch (NotDefinedException e) {
						// can't happen as the Command will be null or valid
					}
				}
				showResultMessage(editor, summary, false);
			}});
	}
	return true;
}
 
Example #30
Source File: CommandBindingHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private void printBinding(String name, CB cb, EmacsPlusConsole console) {
	console.printBold(name + SWT.TAB);
	try {
		console.printContext(cb.name);
		String desc = cb.command.getDescription();
		if (desc != null) {
			desc = desc.replaceAll(CR, EMPTY_STR);
			console.print(DASH_SEPR + desc + CR);
		} else {
			console.print(CR);
		}
	} catch (NotDefinedException e) {
		// can't happen as we've fetched everything from Eclipse directly
	}
}