Search in sources :

Example 1 with HelpListener

use of org.eclipse.swt.events.HelpListener in project translationstudio8 by heartsome.

the class TSWizardDialog method configureShell.

/*
	 * (non-Javadoc) Method declared on Window.
	 */
protected void configureShell(Shell newShell) {
    super.configureShell(newShell);
    // Register help listener on the shell
    newShell.addHelpListener(new HelpListener() {

        public void helpRequested(HelpEvent event) {
            // call perform help on the current page
            if (currentPage != null) {
                currentPage.performHelp();
            }
        }
    });
}
Also used : HelpEvent(org.eclipse.swt.events.HelpEvent) HelpListener(org.eclipse.swt.events.HelpListener)

Example 2 with HelpListener

use of org.eclipse.swt.events.HelpListener in project translationstudio8 by heartsome.

the class ProjectSettingDialog method addListeners.

protected void addListeners(final TreeViewer viewer) {
    viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {

        private void handleError() {
            try {
                // remove the listener temporarily so that the events caused
                // by the error handling dont further cause error handling
                // to occur.
                viewer.removePostSelectionChangedListener(this);
                // select Current PageAgain;
                if (lastSuccessfulNode == null) {
                    return;
                }
                getTreeViewer().setSelection(new StructuredSelection(lastSuccessfulNode));
                getCurrentPage().setVisible(true);
                // clear Selected Node
                setSelectedNodePreference(null);
            } finally {
                viewer.addPostSelectionChangedListener(this);
            }
        }

        public void selectionChanged(SelectionChangedEvent event) {
            final Object selection = getSingleSelection(event.getSelection());
            if (selection instanceof IPreferenceNode) {
                BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                    public void run() {
                        if (!isCurrentPageValid()) {
                            handleError();
                        } else if (!showPage((IPreferenceNode) selection)) {
                            // Page flipping wasn't successful
                            handleError();
                        } else {
                            // Everything went well
                            lastSuccessfulNode = (IPreferenceNode) selection;
                        }
                    }
                });
            }
        }
    });
    ((Tree) viewer.getControl()).addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(final SelectionEvent event) {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IPreferenceNode singleSelection = getSingleSelection(selection);
            boolean expanded = viewer.getExpandedState(singleSelection);
            viewer.setExpandedState(singleSelection, !expanded);
        }
    });
    // Register help listener on the tree to use context sensitive help
    viewer.getControl().addHelpListener(new HelpListener() {

        public void helpRequested(HelpEvent event) {
            if (getCurrentPage() == null) {
                // no current page? open dialog's help
                openDialogHelp();
                return;
            }
            // A) A typical path: the current page has registered its own help link
            // via WorkbenchHelpSystem#setHelp(). When just call it and let
            // it handle the help request.
            Control pageControl = getCurrentPage().getControl();
            if (pageControl != null && pageControl.isListening(SWT.Help)) {
                getCurrentPage().performHelp();
                return;
            }
            // B) Less typical path: no standard listener has been created for the page.
            // In this case we may or may not have an override of page's #performHelp().
            // 1) Try to get default help opened for the dialog;
            openDialogHelp();
            // 2) Next call currentPage's #performHelp(). If it was overridden, it might switch help
            // to something else.
            getCurrentPage().performHelp();
        }

        private void openDialogHelp() {
            if (getPageContainer() == null)
                return;
            for (Control currentControl = getPageContainer(); currentControl != null; currentControl = currentControl.getParent()) {
                if (currentControl.isListening(SWT.Help)) {
                    currentControl.notifyListeners(SWT.Help, new Event());
                    break;
                }
            }
        }
    });
}
Also used : HelpEvent(org.eclipse.swt.events.HelpEvent) HelpListener(org.eclipse.swt.events.HelpListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) Control(org.eclipse.swt.widgets.Control) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) DisposeEvent(org.eclipse.swt.events.DisposeEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) HelpEvent(org.eclipse.swt.events.HelpEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 3 with HelpListener

use of org.eclipse.swt.events.HelpListener in project dbeaver by serge-rider.

the class BaseObjectEditPage method createControl.

@Override
public final void createControl(Composite parent) {
    Control pageContents = createPageContents(parent);
    setControl(pageContents);
    pageContents.addHelpListener(new HelpListener() {

        @Override
        public void helpRequested(HelpEvent e) {
            performHelp();
        }
    });
}
Also used : HelpEvent(org.eclipse.swt.events.HelpEvent) HelpListener(org.eclipse.swt.events.HelpListener) Control(org.eclipse.swt.widgets.Control)

Example 4 with HelpListener

use of org.eclipse.swt.events.HelpListener in project yyl_example by Relucent.

the class MyGridLayout method main.

public static void main(String[] args) {
    final Display display = Display.getDefault();
    final Shell shell = new Shell();
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    gridLayout.makeColumnsEqualWidth = false;
    //# GridLayout gridLayout = new GridLayout(2,false);
    gridLayout.marginTop = 10;
    gridLayout.marginLeft = 5;
    gridLayout.verticalSpacing = 2;
    new Button(shell, SWT.NONE).setText("b1");
    new Button(shell, SWT.NONE).setText("button2");
    Button b3 = new Button(shell, SWT.NONE);
    b3.setText("b3");
    new Button(shell, SWT.NONE).setText("button5");
    new Button(shell, SWT.NONE).setText("btn6");
    //选中按钮,点击F1帮助 执行该事件
    b3.addHelpListener(new HelpListener() {

        public void helpRequested(HelpEvent arg0) {
            System.out.println("点击了帮助");
        }
    });
    GridData gridData = new GridData();
    //# new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    //# new GridData(GridData.FILL_HORIZONTAL);
    //# new GridData(GridData.FILL_VERTICAL);
    //# new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 2;
    //# gridData.horizontalAlignment = GridData.BEGINNING; 
    //# gridData.horizontalAlignment = GridData.CENTER;
    //# gridData.horizontalAlignment = GridData.END; 
    //# gridData.horizontalAlignment = GridData.FILL; 
    // gridDate.horizontalAlignment = 10; 
    gridData.grabExcessHorizontalSpace = false;
    // gridData.widthHint = 80;
    // gridData.heightHint = 20;
    b3.setLayoutData(gridData);
    shell.setLayout(gridLayout);
    shell.setText("GridLayout");
    shell.setSize(200, 200);
    shell.layout();
    shell.open();
    while (!shell.isDisposed()) if (!display.readAndDispatch())
        display.sleep();
}
Also used : HelpEvent(org.eclipse.swt.events.HelpEvent) HelpListener(org.eclipse.swt.events.HelpListener) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Display(org.eclipse.swt.widgets.Display)

Aggregations

HelpEvent (org.eclipse.swt.events.HelpEvent)4 HelpListener (org.eclipse.swt.events.HelpListener)4 Control (org.eclipse.swt.widgets.Control)2 IPreferenceNode (org.eclipse.jface.preference.IPreferenceNode)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Display (org.eclipse.swt.widgets.Display)1 Event (org.eclipse.swt.widgets.Event)1 Shell (org.eclipse.swt.widgets.Shell)1 Tree (org.eclipse.swt.widgets.Tree)1