use of org.eclipse.core.commands.Category in project lsp4e by eclipse.
the class CommandExecutor method createEclipseCoreCommand.
private static ParameterizedCommand createEclipseCoreCommand(@NonNull Command command, IPath context, @NonNull IWorkbench workbench) {
// Usually commands are defined via extension point, but we synthesize one on
// the fly for the command ID, since we do not want downstream users
// having to define them.
String commandId = command.getCommand();
@Nullable ICommandService commandService = workbench.getService(ICommandService.class);
org.eclipse.core.commands.Command coreCommand = commandService.getCommand(commandId);
if (!coreCommand.isDefined()) {
ParameterType commandParamType = commandService.getParameterType(LSP_COMMAND_PARAMETER_TYPE_ID);
ParameterType pathParamType = commandService.getParameterType(LSP_PATH_PARAMETER_TYPE_ID);
Category category = commandService.getCategory(LSP_COMMAND_CATEGORY_ID);
IParameter[] parameters = { new CommandEventParameter(commandParamType, command.getTitle(), LSP_COMMAND_PARAMETER_ID), new CommandEventParameter(pathParamType, command.getTitle(), LSP_PATH_PARAMETER_ID) };
coreCommand.define(commandId, null, category, parameters);
}
Map<Object, Object> parameters = new HashMap<>();
parameters.put(LSP_COMMAND_PARAMETER_ID, command);
parameters.put(LSP_PATH_PARAMETER_ID, context);
ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(coreCommand, parameters);
return parameterizedCommand;
}
use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.
the class CommandPersistence method readCategoriesFromRegistry.
/**
* Reads all of the category definitions from the commands extension point.
*
* @param configurationElements The configuration elements in the commands
* extension point; must not be
* <code>null</code>, but may be empty.
* @param configurationElementCount The number of configuration elements that
* are really in the array.
* @param commandManager The command service to which the categories
* should be added; must not be
* <code>null</code>.
*/
private static void readCategoriesFromRegistry(final IConfigurationElement[] configurationElements, final int configurationElementCount, final CommandManager commandManager) {
Category undefCat = commandManager.getCategory(null);
if (!undefCat.isDefined()) {
// Define the uncategorized category.
commandManager.defineUncategorizedCategory(WorkbenchMessages.CommandService_AutogeneratedCategoryName, WorkbenchMessages.CommandService_AutogeneratedCategoryDescription);
}
final List<IStatus> warningsToLog = new ArrayList<>(1);
for (int i = 0; i < configurationElementCount; i++) {
final IConfigurationElement configurationElement = configurationElements[i];
// Read out the category identifier.
final String categoryId = readRequired(configurationElement, ATT_ID, warningsToLog, // $NON-NLS-1$
"Categories need an id");
if (categoryId == null) {
continue;
}
// Read out the name.
final String name = readRequired(// $NON-NLS-1$
configurationElement, // $NON-NLS-1$
ATT_NAME, // $NON-NLS-1$
warningsToLog, // $NON-NLS-1$
"Categories need a name", categoryId);
if (name == null) {
continue;
}
// Read out the description.
final String description = readOptional(configurationElement, ATT_DESCRIPTION);
final Category category = commandManager.getCategory(categoryId);
if (!category.isDefined()) {
category.define(name, description);
}
}
// If there were any warnings, then log them now.
logWarnings(warningsToLog, // $NON-NLS-1$
"Warnings while parsing the commands from the 'org.eclipse.ui.commands' and 'org.eclipse.ui.actionDefinitions' extension points.");
}
use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.
the class BindingLookupTest method defineCommands.
private void defineCommands(IEclipseContext context) {
ECommandService cs = workbenchContext.get(ECommandService.class);
Category category = cs.defineCategory(TEST_CAT1, "CAT1", null);
cs.defineCommand(TEST_ID1, "ID1", null, category, null);
cs.defineCommand(TEST_ID2, "ID2", null, category, null);
}
use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.
the class HandlerTest method defineCommands.
private void defineCommands(IEclipseContext context) {
ECommandService cs = workbenchContext.get(ECommandService.class);
Category category = cs.defineCategory(TEST_CAT1, "CAT1", null);
cs.defineCommand(TEST_ID1, "ID1", null, category, null);
cs.defineCommand(TEST_ID2, "ID2", null, category, null);
cs.defineCommand(TEST_ID3, "ID3", null, category, new IParameter[] { new IParameter() {
@Override
public boolean isOptional() {
return true;
}
@Override
public IParameterValues getValues() throws ParameterValuesException {
return Collections::emptyMap;
}
@Override
public String getName() {
return ACTIVE_INFO_ID;
}
@Override
public String getId() {
return ACTIVE_INFO_ID;
}
} });
}
use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.
the class DefineCommandsTest method testParamizedCommandsSimple.
@Test
public void testParamizedCommandsSimple() {
ECommandService cs = workbenchContext.get(ECommandService.class);
IParameter[] parms = new IParameter[1];
parms[0] = new IParameter() {
@Override
public String getId() {
return "viewId";
}
@Override
public String getName() {
return "View Id";
}
@Override
public IParameterValues getValues() {
return null;
}
@Override
public boolean isOptional() {
return false;
}
};
// command needs to be defined
Category defineCategory = cs.defineCategory(TEST_CAT1, "CAT1", null);
Command command = cs.defineCommand(TEST_ID1_WITH_PARAMETERS, "TEST_ID1_WITH_PARAMETERS", null, defineCategory, parms);
Map<String, Object> parameters = new HashMap<>();
parameters.put("viewId", "Testing");
// afterwards it is possible to create a ParameterizedCommand
ParameterizedCommand createdParamizedCommand = cs.createCommand(TEST_ID1_WITH_PARAMETERS, parameters);
assertNotNull(command);
assertNotNull(createdParamizedCommand);
Command cmd1 = cs.getCommand(TEST_ID1_WITH_PARAMETERS);
assertNotNull("get command1", cmd1);
}
Aggregations