use of org.eclipse.swt.events.FocusListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_Control method test_addFocusListenerFocusLostAdapterLorg_eclipse_swt_events_FocusListener.
@Test
public void test_addFocusListenerFocusLostAdapterLorg_eclipse_swt_events_FocusListener() {
FocusListener listener = FocusListener.focusLostAdapter(e -> eventOccurred = true);
control.addFocusListener(listener);
eventOccurred = false;
control.notifyListeners(SWT.FocusOut, new Event());
assertTrue(eventOccurred);
eventOccurred = false;
control.notifyListeners(SWT.FocusIn, new Event());
assertFalse(eventOccurred);
control.removeFocusListener(listener);
eventOccurred = false;
control.notifyListeners(SWT.FocusIn, new Event());
assertFalse(eventOccurred);
control.notifyListeners(SWT.FocusOut, new Event());
assertFalse(eventOccurred);
}
use of org.eclipse.swt.events.FocusListener in project eclipse.platform.swt by eclipse.
the class Bug528549_browser_MouseFocusEventListeners method main.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(500, 200);
final Browser browser = new Browser(shell, SWT.NONE);
browser.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
System.out.println("Browser Focus lost " + e.toString());
}
@Override
public void focusGained(FocusEvent e) {
System.out.println("Browser Focus gained " + e.toString());
}
});
browser.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
System.out.println("Browser Mouse Up " + e.toString());
}
@Override
public void mouseDown(MouseEvent e) {
System.out.println("Browser Mouse Down " + e.toString());
}
@Override
public void mouseDoubleClick(MouseEvent e) {
System.out.println("Browse Mouse Double click " + e.toString());
}
});
// Below listeners already worked before bug. But good to have around.
browser.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
System.out.println("Browser key released " + e.toString());
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Browser key pressed " + e.toString());
}
});
browser.addMouseWheelListener(e -> System.out.println("Browser scroll event " + e.toString()));
// Generates a lot of events...
browser.addMouseMoveListener(e -> System.out.println("Browser mouse moved " + e.toString()));
Button jsOnButton = new Button(shell, SWT.PUSH);
jsOnButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
jsOnButton.setText("JS Off");
jsOnButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(false)));
Button jsOffButton = new Button(shell, SWT.PUSH);
jsOffButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
jsOffButton.setText("JS On");
jsOffButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(true)));
Button loadNextPage = new Button(shell, SWT.PUSH);
loadNextPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
loadNextPage.setText("Load next page");
loadNextPage.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setText(getNewText())));
browser.setText(getNewText());
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.swt.events.FocusListener in project eclipse.platform.text by eclipse.
the class ContentAssistHandler method installFocusListener.
/**
* Create fFocusListener and install it on fControl.
*/
private void installFocusListener() {
fFocusListener = new FocusListener() {
@Override
public void focusGained(final FocusEvent e) {
if (fHandlerActivation == null)
activateHandler();
}
@Override
public void focusLost(FocusEvent e) {
if (fHandlerActivation != null)
deactivateHandler();
}
};
fControl.addFocusListener(fFocusListener);
}
use of org.eclipse.swt.events.FocusListener in project eclipse.platform.text by eclipse.
the class AbstractInformationControl method addFocusListener.
/**
* {@inheritDoc}
* This method is not intended to be overridden by subclasses.
*/
@Override
public void addFocusListener(final FocusListener listener) {
if (fFocusListeners.isEmpty()) {
fShellListener = new Listener() {
@Override
public void handleEvent(Event event) {
for (FocusListener focusListener : fFocusListeners) {
if (event.type == SWT.Activate) {
focusListener.focusGained(new FocusEvent(event));
} else {
focusListener.focusLost(new FocusEvent(event));
}
}
}
};
fShell.addListener(SWT.Deactivate, fShellListener);
fShell.addListener(SWT.Activate, fShellListener);
}
fFocusListeners.add(listener);
}
use of org.eclipse.swt.events.FocusListener in project linuxtools by eclipse.
the class SystemTapOptionsTab method createFileOption.
private void createFileOption(Composite top) {
Composite browseTop = new Composite(top, SWT.NONE);
browseTop.setLayout(new GridLayout(4, false));
browseTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label suppFileLabel = new Label(browseTop, SWT.NONE);
// $NON-NLS-1$
suppFileLabel.setText(Messages.getString("SystemTapOptionsTab.ScriptSelector"));
scriptFile = new Text(browseTop, SWT.BORDER);
scriptFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
scriptFile.addModifyListener(modifyListener);
// $NON-NLS-1$
workspaceBrowseButton = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton"), null);
workspaceBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapOptionsTab.ResourceButton"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapOptionsTab.SuppresionsFile"));
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
if (dialog.open() == IDialogConstants.OK_ID) {
IResource resource = (IResource) dialog.getFirstResult();
String arg = resource.getFullPath().toString();
scriptFile.setText(workspacePath + arg);
}
}));
// $NON-NLS-1$
fileBrowseButton = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.FileSystem"), null);
fileBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
String filePath = scriptFile.getText();
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
filePath = dialog.open();
if (filePath != null) {
scriptFile.setText(filePath);
}
}));
Label binaryFileLabel = new Label(browseTop, SWT.NONE);
// $NON-NLS-1$
binaryFileLabel.setText(Messages.getString("SystemTapOptionsTab.SelectBinary"));
binaryFile = new Text(browseTop, SWT.BORDER);
binaryFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
binaryFile.addModifyListener(modifyListener);
// $NON-NLS-1$
Button workspaceBrowseButton2 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton2"), null);
workspaceBrowseButton2.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapOptionsTab.SelectResource"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapOptionsTab.SelectSuppressions"));
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
if (dialog.open() == IDialogConstants.OK_ID) {
IResource resource = (IResource) dialog.getFirstResult();
String arg = resource.getFullPath().toString();
binaryFile.setText(workspacePath + arg);
}
}));
// $NON-NLS-1$
Button fileBrowseButton2 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.BrowseFiles"), null);
fileBrowseButton2.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
String filePath = binaryFile.getText();
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
filePath = dialog.open();
if (filePath != null) {
File file = new File(filePath);
if (file.exists())
binaryFile.setText(filePath);
}
}));
Label outputFileLabel = new Label(browseTop, SWT.NONE);
// $NON-NLS-1$
outputFileLabel.setText(Messages.getString("SystemTapOptionsTab.SelectOutput"));
outputFile = new Text(browseTop, SWT.BORDER);
outputFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
outputFile.addModifyListener(modifyListenerOutput);
outputFile.addFocusListener(focusListener);
// $NON-NLS-1$
Button workspaceBrowseButton3 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton2"), null);
workspaceBrowseButton3.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapOptionsTab.SelectResource"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapOptionsTab.SelectSuppressions"));
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
if (dialog.open() == IDialogConstants.OK_ID) {
IResource resource = (IResource) dialog.getFirstResult();
String arg = resource.getFullPath().toString();
outputFile.setText(workspacePath + arg);
checkOverwrite();
updateLaunchConfigurationDialog();
}
}));
// $NON-NLS-1$
Button fileBrowseButton3 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.BrowseFiles"), null);
fileBrowseButton3.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
String filePath = outputFile.getText();
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
filePath = dialog.open();
if (filePath != null) {
outputFile.setText(filePath);
checkOverwrite();
updateLaunchConfigurationDialog();
}
}));
useColourButton = new Button(browseTop, SWT.CHECK);
// $NON-NLS-1$
useColourButton.setText(Messages.getString("SystemTapOptionsTab.ColourCodes"));
useColourButton.addSelectionListener(selectListener);
useColourButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
Aggregations