Search in sources :

Example 1 with IWorkbenchCommandSupport

use of org.eclipse.ui.commands.IWorkbenchCommandSupport in project Pydev by fabioz.

the class BreakpointConditionEditor method dispose.

public void dispose() {
    if (fViewer.isEditable()) {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchCommandSupport commandSupport = workbench.getCommandSupport();
        commandSupport.removeHandlerSubmission(submission);
    }
    fViewer.getDocument().removeDocumentListener(fDocumentListener);
    fViewer.dispose();
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchCommandSupport(org.eclipse.ui.commands.IWorkbenchCommandSupport)

Example 2 with IWorkbenchCommandSupport

use of org.eclipse.ui.commands.IWorkbenchCommandSupport in project Pydev by fabioz.

the class BreakpointConditionEditor method setEnabled.

/**
 * Return the completion processor associated with this viewer.
 * @return BreakPointConditionCompletionProcessor
 */
/*
    protected BreakpointConditionCompletionProcessor getCompletionProcessor() {
     if (fCompletionProcessor == null) {
         fCompletionProcessor= new BreakpointConditionCompletionProcessor(null);
     }
     return fCompletionProcessor;
    }*/
/**
 * @see org.eclipse.jface.preference.FieldEditor#setEnabled(boolean, org.eclipse.swt.widgets.Composite)
 */
public void setEnabled(boolean enabled) {
    fViewer.setEditable(enabled);
    fViewer.getTextWidget().setEnabled(enabled);
    if (enabled) {
        fViewer.updateViewerColors();
        fViewer.getTextWidget().setFocus();
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchCommandSupport commandSupport = workbench.getCommandSupport();
        commandSupport.addHandlerSubmission(submission);
    } else {
        Color color = fViewer.getControl().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
        fViewer.getTextWidget().setBackground(color);
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchCommandSupport commandSupport = workbench.getCommandSupport();
        commandSupport.removeHandlerSubmission(submission);
    }
    valueChanged();
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Color(org.eclipse.swt.graphics.Color) IWorkbenchCommandSupport(org.eclipse.ui.commands.IWorkbenchCommandSupport)

Example 3 with IWorkbenchCommandSupport

use of org.eclipse.ui.commands.IWorkbenchCommandSupport in project eclipse.platform.ui by eclipse-platform.

the class Bug74982Test method testSelectAllHandlerSendsSelectionEvent.

/**
 * Tests that the <code>SelectAllHandler</code> triggers a selection
 * event. Creates a dialog with a text widget, gives the text widget focus,
 * and then calls the select all command. This should then call the
 * <code>SelectAllHandler</code> and trigger a selection event.
 *
 * @throws ExecutionException
 *             If the <code>SelectAllHandler</code> is broken in some way.
 * @throws NotHandledException
 *             If the dialog does not have focus, or if the
 *             <code>WorkbenchCommandSupport</code> class is broken in
 *             some way.
 */
@Test
public final void testSelectAllHandlerSendsSelectionEvent() throws ExecutionException, NotHandledException {
    // Create a dialog with a text widget.
    IWorkbench fWorkbench = PlatformUI.getWorkbench();
    dialog = new Shell(fWorkbench.getActiveWorkbenchWindow().getShell());
    dialog.setLayout(new GridLayout());
    final Text text = new Text(dialog, SWT.SINGLE);
    text.setText("Mooooooooooooooooooooooooooooo");
    text.setLayoutData(new GridData());
    text.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectionEventFired = true;
        }
    });
    // Open the dialog and give the text widget focus.
    dialog.pack();
    dialog.open();
    text.setFocus();
    // Spin the event loop to make sure focus is set-up properly.
    final Display display = fWorkbench.getDisplay();
    while (display.readAndDispatch()) {
        ((Workbench) fWorkbench).getContext().processWaiting();
    }
    // Get the select all command and execute it.
    final IWorkbenchCommandSupport commandSupport = fWorkbench.getCommandSupport();
    final ICommand selectAllCommand = commandSupport.getCommandManager().getCommand("org.eclipse.ui.edit.selectAll");
    selectAllCommand.execute(null);
    // Check to see if the selection event has been fired.
    assertTrue("The selection event was not fired when the SelectAllHandler was used.", selectionEventFired);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) ICommand(org.eclipse.ui.commands.ICommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) IWorkbenchCommandSupport(org.eclipse.ui.commands.IWorkbenchCommandSupport) Display(org.eclipse.swt.widgets.Display) Test(org.junit.Test)

Example 4 with IWorkbenchCommandSupport

use of org.eclipse.ui.commands.IWorkbenchCommandSupport in project eclipse.platform.ui by eclipse-platform.

the class Bug87856Test method testHandlerLeak.

/**
 * Tests whether the workbench command support (or its dependencies) will leak
 * handlers when the process loop is run. Basically, we're checking to see that
 * removing a handler submission really works.
 */
@Test
public final void testHandlerLeak() {
    IWorkbench fWorkbench = PlatformUI.getWorkbench();
    final IWorkbenchCommandSupport commandSupport = fWorkbench.getCommandSupport();
    final ICommandService commandService = fWorkbench.getAdapter(ICommandService.class);
    final String commandId = Bug87856Test.class.getName();
    final Command command = commandService.getCommand(commandId);
    // Submit a handler.
    IHandler handler = new AbstractHandler() {

        @Override
        public Object execute(Map parameterValuesByName) {
            // Do nothing
            return null;
        }
    };
    HandlerSubmission submission = new HandlerSubmission(null, null, null, command.getId(), handler, Priority.MEDIUM);
    commandSupport.addHandlerSubmission(submission);
    /*
		 * Remove the handler with no replacement, and hold on to the handler via a weak
		 * reference.
		 */
    commandSupport.removeHandlerSubmission(submission);
    submission = null;
    final WeakReference<IHandler> reference = new WeakReference<>(handler);
    handler = null;
    // Attempt to force garbage collection.
    System.gc();
    System.runFinalization();
    Thread.yield();
    System.gc();
    System.runFinalization();
    Thread.yield();
    System.gc();
    System.runFinalization();
    Thread.yield();
    // Check to see if the reference has been cleared.
    assertTrue("We should not hold on to a handler after the submission has been removed.", reference.isEnqueued() || (reference.get() == null));
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) HandlerSubmission(org.eclipse.ui.commands.HandlerSubmission) Command(org.eclipse.core.commands.Command) WeakReference(java.lang.ref.WeakReference) IHandler(org.eclipse.ui.commands.IHandler) IWorkbenchCommandSupport(org.eclipse.ui.commands.IWorkbenchCommandSupport) Map(java.util.Map) ICommandService(org.eclipse.ui.commands.ICommandService) AbstractHandler(org.eclipse.ui.commands.AbstractHandler) Test(org.junit.Test)

Example 5 with IWorkbenchCommandSupport

use of org.eclipse.ui.commands.IWorkbenchCommandSupport in project eclipse.platform.ui by eclipse-platform.

the class MultiPageKeyBindingTest method testSwitch.

/**
 * Tests that the key bindings are updated when the page is switched in a
 * multi-page editor part.
 *
 * @throws CoreException
 *             If the project or file cannot be created.
 * @throws ParseException
 *             The expected key sequence cannot be parsed.
 */
@Test
public void testSwitch() throws CoreException, ParseException {
    // $NON-NLS-1$
    final String extension = "multi";
    // $NON-NLS-1$
    final String fileName = "A." + extension;
    // Open a new test window.
    IWorkbenchWindow window = openTestWindow();
    // Create a blurb file.
    IWorkbenchPage page = window.getActivePage();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject testProject = workspace.getRoot().getProject(// $NON-NLS-1$
    "MultiPageKeyBindingTest Project");
    testProject.create(null);
    testProject.open(null);
    IFile multiFile = testProject.getFile(fileName);
    multiFile.create(new ByteArrayInputStream(new byte[0]), true, null);
    // Open a blurb file.
    IEditorInput editorInput = new FileEditorInput(multiFile);
    IEditorPart editorPart = page.openEditor(editorInput, // $NON-NLS-1$
    "org.eclipse.ui.tests.multipageeditor.TestMultiPageEditor");
    TestMultiPageEditor multiPageEditorPart = (TestMultiPageEditor) editorPart;
    // Switch to the second tab
    window.getShell().forceActive();
    Display display = Display.getCurrent();
    while (display.readAndDispatch()) {
    }
    multiPageEditorPart.setPage(1);
    // Check that "Ctrl+Shift+5" is the bound key.
    IWorkbenchCommandSupport commandSupport = window.getWorkbench().getCommandSupport();
    ICommandManager commandManager = commandSupport.getCommandManager();
    KeySequence expectedKeyBinding = KeySequence.getInstance(// $NON-NLS-1$
    "Ctrl+Shift+5");
    String commandId = commandManager.getPerfectMatch(expectedKeyBinding);
    // $NON-NLS-1$
    assertEquals("org.eclipse.ui.tests.TestCommandId", commandId);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ICommandManager(org.eclipse.ui.commands.ICommandManager) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbenchCommandSupport(org.eclipse.ui.commands.IWorkbenchCommandSupport) IProject(org.eclipse.core.resources.IProject) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkspace(org.eclipse.core.resources.IWorkspace) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) KeySequence(org.eclipse.ui.keys.KeySequence) IEditorInput(org.eclipse.ui.IEditorInput) Display(org.eclipse.swt.widgets.Display) Test(org.junit.Test)

Aggregations

IWorkbenchCommandSupport (org.eclipse.ui.commands.IWorkbenchCommandSupport)7 IWorkbench (org.eclipse.ui.IWorkbench)5 Test (org.junit.Test)5 Map (java.util.Map)3 Display (org.eclipse.swt.widgets.Display)3 AbstractHandler (org.eclipse.ui.commands.AbstractHandler)3 HandlerSubmission (org.eclipse.ui.commands.HandlerSubmission)3 ICommand (org.eclipse.ui.commands.ICommand)3 IHandler (org.eclipse.ui.commands.IHandler)3 Shell (org.eclipse.swt.widgets.Shell)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 WeakReference (java.lang.ref.WeakReference)1 Command (org.eclipse.core.commands.Command)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1