Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content Proposal Dialog Reopens if ENTER is used for ContentProposalAdapter's KeyStroke in RWT #54

Open
ifurnadjiev opened this issue Sep 12, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@ifurnadjiev
Copy link
Contributor

ifurnadjiev commented Sep 12, 2022

Moved from Bug 580712.

Content Proposal Dialog Reopens if ENTER is used for ContentProposalAdapter's KeyStroke in RWT

Summary

In our solution, we're using a text field paired with a ContentProposalAdapter. Then keystroke to activate the ContentProposalAdapter is ENTER. In our SWT application the process of hitting ENTER and selecting a proposal works without any issue. However in RWT, the problem is that once ENTER is used to select a proposal, the proposal pop-up opens again.

  • RAP version:
    • 3.14.0-SDK-4.17.0
  • Browser (issue present in all browsers that I tried):
    • 105.0.1343.27 Edge
    • 105.0.5195.102 Chrome
    • 104.0.2 Firefox

Possibly similar issue: Bug 445464 - ContentProposalAdapter proposals popup stays visible if Combo is used as a control

Steps to Recreate Issue

Run the attached snippet as an RWT application

  1. In the field labeled "Content Proposal KeyStroke = ENTER", hit ENTER
  2. Select a proposal and hit ENTER
    Expected: Content Proposal Dialog closes
    Actual: Content Proposal Dialog reopens

NOTE: I've also added another field titled "Content Proposal KeyStroke = HOME" to demonstrate that this workflow works fine if the Content Proposal keystroke is set to anything else. This would indicate that the issue is around enter being used both by the ContentProposalAdapter and selecting items in the proposal pop-up.

@ifurnadjiev
Copy link
Contributor Author

ifurnadjiev commented Sep 12, 2022

Snippet to reproduce the issue:

package main;

import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.IContentProposal;
import org.eclipse.jface.fieldassist.IContentProposalListener;
import org.eclipse.jface.fieldassist.IContentProposalProvider;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.rap.rwt.application.AbstractEntryPoint;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

@SuppressWarnings({ "javadoc", "serial" })
public class Snippet extends AbstractEntryPoint
{
    @Override
    protected void createContents(Composite parent)
    {
        new Label(parent, SWT.NONE).setText("Content Proposal KeyStroke = ENTER"); //$NON-NLS-1$
        Text enterTextField = new Text(parent, SWT.BORDER);
        ContentProposalAdapter enterContentProposalAdapter = new ContentProposalAdapter(enterTextField,
                new TextContentAdapter(), new SnippetContentProposalProvider(), KeyStroke.getInstance(SWT.CR), null);
        enterContentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE);
        enterContentProposalAdapter.addContentProposalListener(new SnippetContentProposalListener());

        new Label(parent, SWT.NONE).setText("Content Proposal KeyStroke = HOME"); //$NON-NLS-1$
        Text escTextField = new Text(parent, SWT.BORDER);
        ContentProposalAdapter escContentProposalAdapter = new ContentProposalAdapter(escTextField,
                new TextContentAdapter(), new SnippetContentProposalProvider(), KeyStroke.getInstance(SWT.HOME), null);
        escContentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE);
        escContentProposalAdapter.addContentProposalListener(new SnippetContentProposalListener());
    }

    private class SnippetContentProposalProvider implements IContentProposalProvider
    {
        public IContentProposal[] getProposals(String contents, int position)
        {
            return new SnippetContentProposal[] { new SnippetContentProposal("Proposal A"), //$NON-NLS-1$
                    new SnippetContentProposal("Proposal B"), new SnippetContentProposal("Proposal C") }; //$NON-NLS-1$ //$NON-NLS-2$
        }

    }

    private class SnippetContentProposal implements IContentProposal
    {
        private final String label;

        public SnippetContentProposal(String label)
        {
            this.label = label;
        }

        public String getContent()
        {
            return null;
        }

        public int getCursorPosition()
        {
            return 0;
        }

        public String getLabel()
        {
            return label;
        }

        public String getDescription()
        {
            return null;
        }

    }

    private class SnippetContentProposalListener implements IContentProposalListener
    {
        public void proposalAccepted(IContentProposal proposal)
        {
            System.out.println("Proposal Accepted: " + ((SnippetContentProposal)proposal).getLabel()); //$NON-NLS-1$
        }

    }

}

@mknauer mknauer added the bug Something isn't working label Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants