Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Content proposal (auto complete) of StyledText
Content proposal (auto complete) of StyledText [message #506545] Thu, 07 January 2010 17:14 Go to next message
Helmut Neubauer is currently offline Helmut NeubauerFriend
Messages: 54
Registered: July 2009
Member
I'm looking for an example to implement content proposal features in a StyledTexted control but I failed.

I tried to adapt this code snippet I found for a Text instance:
		// "." and "#" will also activate the content proposals
		char[] autoActivationCharacters = new char[] { '.', '#' };
		KeyStroke keyStroke;
		try {
			keyStroke = KeyStroke.getInstance("Ctrl+Space");
			// assume that myTextControl has already been created in some way
			ContentProposalAdapter adapter = new ContentProposalAdapter(text,
					new TextContentAdapter(),
					new SimpleContentProposalProvider(new String[] {
							"ProposalOne", "ProposalTwo", "ProposalThree" }),
					keyStroke, autoActivationCharacters);
		} catch (ParseException e) {
			e.printStackTrace();
		}


text should be a StyledText object. It doesn't work. Please help. Thanks.
Re: Content proposal (auto complete) of StyledText [message #507462 is a reply to message #506545] Wed, 13 January 2010 14:52 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

I don't know if this is quite what you're looking for, but since no other
answers have surfaced I thought this could be helpful. Snippet
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet320.java?view=co
demonstrates a basic implementation of content assist at the swt level.

Grant


"Helmut Neubauer" <helmut.neubauer@cognidata.de> wrote in message
news:hi5mdu$che$1@build.eclipse.org...
> I'm looking for an example to implement content proposal features in a
StyledTexted control but I failed.
>
> I tried to adapt this code snippet I found for a Text instance:
> // "." and "#" will also activate the content proposals
> char[] autoActivationCharacters = new char[] { '.', '#' };
> KeyStroke keyStroke;
> try {
> keyStroke = KeyStroke.getInstance("Ctrl+Space");
> // assume that myTextControl has already been created in some way
> ContentProposalAdapter adapter = new ContentProposalAdapter(text,
> new TextContentAdapter(),
> new SimpleContentProposalProvider(new String[] {
> "ProposalOne", "ProposalTwo", "ProposalThree" }),
> keyStroke, autoActivationCharacters);
> } catch (ParseException e) {
> e.printStackTrace();
> }
>
> text should be a StyledText object. It doesn't work. Please help. Thanks.
>
Re: Content proposal (auto complete) of StyledText [message #532904 is a reply to message #507462] Tue, 11 May 2010 14:19 Go to previous messageGo to next message
Sam Hazim is currently offline Sam HazimFriend
Messages: 2
Registered: May 2010
Junior Member
Thanks Grant, for the original example Snippet320 - very helpful.

I do have an issue with it that is proving difficult to resolve.

Basically, once our popupShell appears, it can sometimes contain so many TableItems that it displays a scrollbar. There are three main actions in this 'problem'.

(1) From here, the user clicks the scrollbar. The click does not register, and the popupShell visibility is lost.

Step (2) - now, the user enters more text (to redisplay the popupShell) and then proceeds to click on the table area itself. Now they have focus on the table and can proceed to click and drag on the scrollbar, which works as intended.

Now the final step (3). Once (2) has been done, the user can then go back to the text box and start typing away. Focus remains on the text box where they are typing, and the popupShell is displayed. The user can click their mouse directly on the scroll bars (keeping their text entry active on the text box) and the scroll bar clicks work as intended.

To demonstrate this it may be useful to modify Snippet320 to use 50 items in the loop instead of the current 5.

So my question is, how can I enable the use of the scrollbar from the very second it is generated, without having to force the user to click on the table area itself (which is not intuitive).

Thanks for your help, and your helpful example.
Re: Content proposal (auto complete) of StyledText [message #533065 is a reply to message #532904] Wed, 12 May 2010 07:37 Go to previous message
Sam Hazim is currently offline Sam HazimFriend
Messages: 2
Registered: May 2010
Junior Member
Well that turned out to be easier than I thought Embarrassed


Change our line from

Listener focusOutListener = new Listener() {
			public void handleEvent(Event event) {
				//popupShell.setVisible(false);
				//async is needed to wait until focus reaches its new Control/
				display.asyncExec(new Runnable() {
					public void run() {
						if (display.isDisposed()) return;
						Control control = display.getFocusControl();
						if (control == null || (control != searchBox && control != table)) {
							popupShell.setVisible(false);
						}
					}
				});
			}
		};



To

Listener focusOutListener = new Listener() {
			public void handleEvent(Event event) {
				//popupShell.setVisible(false);
				//async is needed to wait until focus reaches its new Control/
				display.asyncExec(new Runnable() {
					public void run() {
						if (display.isDisposed()) return;
						Control control = display.getFocusControl();
						if (control == null || (control != searchBox && control != table && control != popupShell)) {
							popupShell.setVisible(false);
						}
					}
				});
			}
		};

Previous Topic:Databinding a list to a ListViewer on selection
Next Topic:Do the twisties in a tree with columns always have to be in the first column?
Goto Forum:
  


Current Time: Thu Mar 28 17:19:28 GMT 2024

Powered by FUDForum. Page generated in 0.02798 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top