use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.
the class BindingTableTests method setUp.
@Before
public void setUp() throws Exception {
if (loadedBindings == null) {
IEclipseContext globalContext = TestUtil.getGlobalContext();
workbenchContext = globalContext.createChild("workbenchContext");
loadedBindings = new ArrayList<>();
contextManager = new ContextManager();
ContextSet.setComparator(new ContextSet.CComp(contextManager));
for (int i = 0; i < CONTEXTS.length; i += 3) {
Context context = contextManager.getContext(CONTEXTS[i]);
context.define(CONTEXTS[i + 1], null, CONTEXTS[i + 2]);
}
commandManager = new CommandManager();
Category category = commandManager.getCategory("bogus");
category.define("Bogus", null);
for (int i = 0; i < COMMANDS.length; i += 2) {
Command cmd = commandManager.getCommand(COMMANDS[i]);
cmd.define(COMMANDS[i + 1], null, category);
}
for (int i = 0; i < BINDINGS.length; i += 3) {
KeySequence seq = KeySequence.getInstance(BINDINGS[i + 1]);
Command cmd = commandManager.getCommand(BINDINGS[i]);
loadedBindings.add(new KeyBinding(seq, new ParameterizedCommand(cmd, null), "org.eclipse.ui.defaultAcceleratorConfiguration", BINDINGS[i + 2], null, null, null, Binding.SYSTEM));
}
}
}
use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.
the class KeyDispatcherTest 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);
ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null);
EHandlerService hs = workbenchContext.get(EHandlerService.class);
handler = new CallHandler();
hs.activateHandler(TEST_ID1, handler);
EBindingService bs = workbenchContext.get(EBindingService.class);
TriggerSequence seq = bs.createSequence("CTRL+A");
Binding db = createDefaultBinding(bs, seq, cmd);
bs.activateBinding(db);
ParameterizedCommand cmd2 = cs.createCommand(TEST_ID2, null);
twoStrokeHandler = new CallHandler();
hs.activateHandler(TEST_ID2, twoStrokeHandler);
TriggerSequence twoKeys = bs.createSequence("CTRL+5 CTRL+A");
db = createDefaultBinding(bs, twoKeys, cmd2);
bs.activateBinding(db);
}
use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.
the class CommandManagerTest method testExecutionListener.
@Test
public final void testExecutionListener() {
final String commandId = "myCommand";
final CommandManager commandManager = new CommandManager();
final Category category = commandManager.getCategory(commandId);
category.define("name", null);
final Command command = commandManager.getCommand(commandId);
command.define("name", null, category, null);
final ExecutionListener listener = new ExecutionListener();
commandManager.addExecutionListener(listener);
Exception exception = null;
final ExecutionEvent event = new ExecutionEvent();
try {
command.execute(event);
} catch (final ExecutionException | NotHandledException e) {
exception = e;
}
assertSame("Should have received a pre-execute event for the correct command", commandId, listener.preExecuteId);
assertSame("Should have received a pre-execute event with the correct event", event, listener.preExecuteEvent);
assertSame("Should have received a not-handled event for the correct command", commandId, listener.notHandledId);
assertSame("Should have received a not-handled event with the correct exception", exception, listener.notHandledException);
}
use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.
the class ProgressContantsTest method testCommandPropertyEnablement.
@Test
public void testCommandPropertyEnablement() throws Exception {
openProgressView();
DummyJob okJob = new DummyJob("OK Job", Status.OK_STATUS);
okJob.shouldFinish = false;
IWorkbench workbench = PlatformUI.getWorkbench();
ECommandService commandService = workbench.getService(ECommandService.class);
String commandId = "org.eclipse.ui.tests.progressEnableViewCommand";
// Must use ECommandService#defineCommand to have the proper legacy
// handler hookup beforehand, such as for handler changes
Category category = commandService.defineCategory("org.eclipse.ui.tests.progress.category", "test", "test");
Command command = commandService.defineCommand(commandId, "test", "test", category, new IParameter[0]);
ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, null);
okJob.setProperty(IProgressConstants2.COMMAND_PROPERTY, parameterizedCommand);
okJob.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
okJob.schedule();
processEventsUntil(() -> findProgressInfoItem(okJob) != null, 3000);
ProgressInfoItem item = findProgressInfoItem(okJob);
assertNotNull(item);
assertFalse(item.isTriggerEnabled());
IHandlerService service = workbench.getService(IHandlerService.class);
CommandHandler handler = new CommandHandler();
IHandlerActivation activation = service.activateHandler(commandId, handler);
assertTrue(item.isTriggerEnabled());
service.deactivateHandler(activation);
assertFalse(item.isTriggerEnabled());
okJob.cancel();
okJob.join();
}
use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.
the class DefineCommandsTest method testCreateCommands.
@Test
public void testCreateCommands() {
ECommandService cs = workbenchContext.get(ECommandService.class);
assertNotNull(cs);
assertNotNull(cs.defineCategory(TEST_CAT1, "CAT1", null));
Category category = cs.getCategory(TEST_CAT1);
assertNotNull("need category", category);
assertNotNull("command1", cs.defineCommand(TEST_ID1, "ID1", null, category, null));
assertNotNull("command2", cs.defineCommand(TEST_ID2, "ID2", null, category, null));
Command cmd1 = cs.getCommand(TEST_ID1);
assertNotNull("get command1", cmd1);
try {
assertEquals("ID1", cmd1.getName());
} catch (NotDefinedException e) {
fail(e.getMessage());
}
assertNotNull("get command2", cs.getCommand(TEST_ID2));
assertNotNull("parameterized command", cs.createCommand(TEST_ID1, null));
}
Aggregations