use of org.eclipse.ui.commands.ICommandService in project eclipse.platform.text by eclipse.
the class EditorTest method testGenericEditorHasWordWrap.
@Test
public void testGenericEditorHasWordWrap() throws Exception {
this.editor.setFocus();
final StyledText editorTextWidget = (StyledText) this.editor.getAdapter(Control.class);
Assert.assertFalse(editorTextWidget.getWordWrap());
Assert.assertFalse(this.editor.isWordWrapEnabled());
// Toggle word wrap
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
Command wordWrapCommand = commandService.getCommand(ITextEditorActionDefinitionIds.WORD_WRAP);
Assert.assertTrue(wordWrapCommand.isDefined());
Assert.assertTrue(wordWrapCommand.isEnabled());
Assert.assertTrue(wordWrapCommand.isHandled());
PlatformUI.getWorkbench().getService(IHandlerService.class).executeCommand(wordWrapCommand.getId(), null);
//
Assert.assertTrue(editorTextWidget.getWordWrap());
Assert.assertTrue(this.editor.isWordWrapEnabled());
}
use of org.eclipse.ui.commands.ICommandService in project eclipse.platform.text by eclipse.
the class EditorTest method testGenericEditorCanUseBlockSelection.
@Test
public void testGenericEditorCanUseBlockSelection() throws Exception {
this.editor.setFocus();
Assert.assertFalse(this.editor.isBlockSelectionModeEnabled());
// Toggle word wrap
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
Command wordWrapCommand = commandService.getCommand(ITextEditorActionDefinitionIds.BLOCK_SELECTION_MODE);
Assert.assertTrue(wordWrapCommand.isDefined());
Assert.assertTrue(wordWrapCommand.isEnabled());
Assert.assertTrue(wordWrapCommand.isHandled());
PlatformUI.getWorkbench().getService(IHandlerService.class).executeCommand(wordWrapCommand.getId(), null);
//
Assert.assertTrue(this.editor.isBlockSelectionModeEnabled());
}
use of org.eclipse.ui.commands.ICommandService in project eclipse.platform.text by eclipse.
the class EditorTest method testGenericEditorCanShowWhitespaceCharacters.
@Test
public void testGenericEditorCanShowWhitespaceCharacters() throws Exception {
this.editor.setFocus();
// Toggle word wrap
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
Command wordWrapCommand = commandService.getCommand(ITextEditorActionDefinitionIds.SHOW_WHITESPACE_CHARACTERS);
Assert.assertTrue(wordWrapCommand.isDefined());
Assert.assertTrue(wordWrapCommand.isEnabled());
Assert.assertTrue(wordWrapCommand.isHandled());
PlatformUI.getWorkbench().getService(IHandlerService.class).executeCommand(wordWrapCommand.getId(), null);
}
use of org.eclipse.ui.commands.ICommandService in project linuxtools by eclipse.
the class VagrantToolBarContributionItem method execute.
private void execute(String id, IStructuredSelection selection) {
ICommandService service = PlatformUI.getWorkbench().getService(ICommandService.class);
Command command = service != null ? service.getCommand(id) : null;
if (command != null && command.isDefined()) {
try {
ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(command, null);
IHandlerService handlerSvc = PlatformUI.getWorkbench().getService(IHandlerService.class);
IEvaluationContext ctx = handlerSvc.getCurrentState();
ctx = new EvaluationContext(ctx, selection);
ctx.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
handlerSvc.executeCommandInContext(pCmd, null, ctx);
} catch (Exception e) {
Activator.log(e);
}
}
}
use of org.eclipse.ui.commands.ICommandService in project linuxtools by eclipse.
the class DockerImagesView method createPartControl.
@Override
public void createPartControl(final Composite parent) {
final FormToolkit toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createForm(parent);
form.setText(DVMessages.getString(NoConnectionSelected));
final Composite container = form.getBody();
GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).applyTo(container);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(container);
createTableViewer(container);
// track selection changes in the Docker Explorer view (only)
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(DockerExplorerView.VIEW_ID, this);
hookContextMenu();
// Look at stored preference to determine if all images should be
// shown or just top-level images. By default, only show
// top-level images.
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
boolean showAll = preferences.getBoolean(SHOW_ALL_IMAGES_PREFERENCE, false);
showAllImages(showAll);
final ICommandService service = getViewSite().getWorkbenchWindow().getService(ICommandService.class);
service.getCommand(SHOW_ALL_IMAGES_COMMAND_ID).getState(TOGGLE_STATE).setValue(showAll);
service.refreshElements(SHOW_ALL_IMAGES_COMMAND_ID, null);
DockerConnectionManager.getInstance().addConnectionManagerListener(this);
// On startup, this view might get set up after the Docker Explorer View
// and so we won't get the notification when it chooses the connection.
// Find out if it has a selection and set our connection appropriately.
ISelection selection = getSite().getWorkbenchWindow().getSelectionService().getSelection(DockerExplorerView.VIEW_ID);
if (selection != null) {
selectionChanged(null, selection);
// also notify DockerConnectionWatcher
DockerConnectionWatcher.getInstance().selectionChanged(null, selection);
}
}
Aggregations