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();
}
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();
}
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);
}
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));
}
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);
}
Aggregations