Search in sources :

Example 11 with ICommandService

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());
}
Also used : Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ICommandService(org.eclipse.ui.commands.ICommandService) Test(org.junit.Test)

Example 12 with ICommandService

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());
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ICommandService(org.eclipse.ui.commands.ICommandService) Test(org.junit.Test)

Example 13 with ICommandService

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);
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ICommandService(org.eclipse.ui.commands.ICommandService) Test(org.junit.Test)

Example 14 with ICommandService

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);
        }
    }
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 15 with ICommandService

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);
    }
}
Also used : FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Composite(org.eclipse.swt.widgets.Composite) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ISelection(org.eclipse.jface.viewers.ISelection) ICommandService(org.eclipse.ui.commands.ICommandService)

Aggregations

ICommandService (org.eclipse.ui.commands.ICommandService)38 Command (org.eclipse.core.commands.Command)24 IHandlerService (org.eclipse.ui.handlers.IHandlerService)8 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)7 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)7 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)6 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)6 ExecutionException (org.eclipse.core.commands.ExecutionException)4 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)4 IEvaluationService (org.eclipse.ui.services.IEvaluationService)4 HashMap (java.util.HashMap)3 NotEnabledException (org.eclipse.core.commands.NotEnabledException)3 NotHandledException (org.eclipse.core.commands.NotHandledException)3 State (org.eclipse.core.commands.State)3 ISelection (org.eclipse.jface.viewers.ISelection)3 StyledText (org.eclipse.swt.custom.StyledText)3 Composite (org.eclipse.swt.widgets.Composite)3 Test (org.junit.Test)3 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)2 IHandler (org.eclipse.core.commands.IHandler)2