3

だから私はこのクールさを盗みPopupCompositeました、そして私はそれに本当に満足しています.

1つだけ問題があります。が入っている場合はorg.eclipse.swt.widgets.Text、ポップアップを開き、 にフォーカスしてTextを押すと、と のESC両方が破棄されます。TextPopupComposite

Dispose 呼び出しがどこから来ているのか、本当にわかりません。それはShell問題ですか?Shellポップアップには何を使用すればよいですか?

SSCCE :

/**
 * 
 * @author ggrec
 *
 */
public class PopupCompositeTester
{

    public static void main(final String[] args)
    {
        new PopupCompositeTester();
    }

    private PopupCompositeTester()
    {
        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(1, false));

        createContents(shell);

        shell.pack();
        shell.open();
        while (!shell.isDisposed())
        {
            if ( !display.readAndDispatch() )
                display.sleep();
        }
        display.dispose();
    }

    private static void createContents(final Composite parent)
    {
        final Button button = new Button(parent, SWT.PUSH);
        button.setText("Poke Me");

        final PopupComposite popup = new PopupComposite(parent.getShell());
        new Text(popup, SWT.NONE);
        popup.pack();

        button.addSelectionListener(new SelectionAdapter()
        {
            @Override public void widgetSelected(final SelectionEvent e)
            {
                popup.show( Display.getDefault().map(parent, null, button.getLocation()) );
            }
        });
    }
}
4

2 に答える 2

2

これは、テキスト フィールドにフォーカスして Escape キーを押すと、フィールドSWT.TRAVERSE_ESCAPEが親シェルにイベントを送信するためです。シェル(あなたの場合はトップレベルのシェルではない)は、 を呼び出すことで応答しShell.close()ます。テキスト フィールドにトラバース リスナーを追加すると、イベントがキャンセルされます (以下のコード)。

new Text(popup, SWT.NONE).addTraverseListener(new TraverseListener() {
    @Override
    public void keyTraversed(TraverseEvent e) {
        if(e.detail == SWT.TRAVERSE_ESCAPE) {
            e.doit = false;
        }
    }
});

これは、特定の問題に対するかなり大雑把な解決策であることに注意してください。これをテスト目的以外に使用することはお勧めしません。詳細については、こちらをご覧ください - > http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fevents% 2FTraverseEvent.html

そしてここ: http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fwidgets%2FShell.html

于 2013-09-12T14:00:43.677 に答える
0

私の「バグ」は実際には SWT プラットフォームの通常の動作であるため、次の回避策を使用しました。

/**
 * Lazy initialization of the popup composite
 */
private void createPopup()
{
     // popupContainer is now a field
     if (popupContainer != null && !popupContainer.isDisposed())
         return;

     // ... create popup AND its contents ...
}

そしてボタンリスナーで:

createPopup();
popup.show( Display.getDefault().map(parent, null, button.getLocation()) );


ありがとう@blgt

于 2013-09-12T14:53:14.283 に答える