Search in sources :

Example 46 with FocusListener

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);
}
Also used : FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) FocusListener(org.eclipse.swt.events.FocusListener) Test(org.junit.Test)

Example 47 with FocusListener

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();
}
Also used : Browser(org.eclipse.swt.browser.Browser) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) FocusEvent(org.eclipse.swt.events.FocusEvent) Display(org.eclipse.swt.widgets.Display) FocusListener(org.eclipse.swt.events.FocusListener) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseListener(org.eclipse.swt.events.MouseListener) SWT(org.eclipse.swt.SWT) KeyEvent(org.eclipse.swt.events.KeyEvent) KeyListener(org.eclipse.swt.events.KeyListener) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) SelectionListener(org.eclipse.swt.events.SelectionListener) MouseEvent(org.eclipse.swt.events.MouseEvent) FillLayout(org.eclipse.swt.layout.FillLayout) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) MouseListener(org.eclipse.swt.events.MouseListener) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) KeyListener(org.eclipse.swt.events.KeyListener) FocusListener(org.eclipse.swt.events.FocusListener) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 48 with FocusListener

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);
}
Also used : FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 49 with FocusListener

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);
}
Also used : PaintListener(org.eclipse.swt.events.PaintListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) DisposeListener(org.eclipse.swt.events.DisposeListener) FocusListener(org.eclipse.swt.events.FocusListener) Listener(org.eclipse.swt.widgets.Listener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 50 with FocusListener

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));
}
Also used : CLaunchConfigurationTab(org.eclipse.cdt.launch.ui.CLaunchConfigurationTab) LaunchConfigurationConstants(org.eclipse.linuxtools.internal.callgraph.core.LaunchConfigurationConstants) CoreException(org.eclipse.core.runtime.CoreException) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPath(org.eclipse.core.runtime.IPath) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) Composite(org.eclipse.swt.widgets.Composite) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IExtension(org.eclipse.core.runtime.IExtension) SystemTapView(org.eclipse.linuxtools.internal.callgraph.core.SystemTapView) CDebugUtils(org.eclipse.cdt.debug.core.CDebugUtils) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) ICElement(org.eclipse.cdt.core.model.ICElement) IBinary(org.eclipse.cdt.core.model.IBinary) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Window(org.eclipse.jface.window.Window) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) PluginConstants(org.eclipse.linuxtools.internal.callgraph.core.PluginConstants) SelectionListener(org.eclipse.swt.events.SelectionListener) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) TabFolder(org.eclipse.swt.widgets.TabFolder) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Image(org.eclipse.swt.graphics.Image) Spinner(org.eclipse.swt.widgets.Spinner) FocusListener(org.eclipse.swt.events.FocusListener) ArrayList(java.util.ArrayList) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) TwoPaneElementSelector(org.eclipse.ui.dialogs.TwoPaneElementSelector) IWorkspace(org.eclipse.core.resources.IWorkspace) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) GridData(org.eclipse.swt.layout.GridData) ICProject(org.eclipse.cdt.core.model.ICProject) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) TabItem(org.eclipse.swt.widgets.TabItem) Shell(org.eclipse.swt.widgets.Shell) FileDialog(org.eclipse.swt.widgets.FileDialog) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) File(java.io.File) CElementLabelProvider(org.eclipse.cdt.ui.CElementLabelProvider) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) ModifyListener(org.eclipse.swt.events.ModifyListener) IResource(org.eclipse.core.resources.IResource) Platform(org.eclipse.core.runtime.Platform) LabelProvider(org.eclipse.jface.viewers.LabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Aggregations

FocusListener (org.eclipse.swt.events.FocusListener)50 FocusEvent (org.eclipse.swt.events.FocusEvent)49 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 GridData (org.eclipse.swt.layout.GridData)15 KeyEvent (org.eclipse.swt.events.KeyEvent)11 GridLayout (org.eclipse.swt.layout.GridLayout)11 ControlEvent (org.eclipse.swt.events.ControlEvent)10 MouseEvent (org.eclipse.swt.events.MouseEvent)10 Text (org.eclipse.swt.widgets.Text)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 Event (org.eclipse.swt.widgets.Event)9 SelectionListener (org.eclipse.swt.events.SelectionListener)8 Button (org.eclipse.swt.widgets.Button)8 Composite (org.eclipse.swt.widgets.Composite)8 Label (org.eclipse.swt.widgets.Label)8 ControlListener (org.eclipse.swt.events.ControlListener)7 SashForm (org.eclipse.swt.custom.SashForm)6 DisposeEvent (org.eclipse.swt.events.DisposeEvent)6 DisposeListener (org.eclipse.swt.events.DisposeListener)6 Listener (org.eclipse.swt.widgets.Listener)6