Unable to type once the Content Assist shell is popped up - eclipse

I have attached a content assist to a text box by using the below code. The content assist is working fine.
But, once I press the 'Ctrl+space', then, All the proposals are displayed in a newly created shell.
Then, I try to type some more characters, but, I'm unable to type, as the new shell has the focus, not the text box.
Is there a way to minic, how the JDT editor does? Even after pressing the Ctrl+space and content proposals are displayed, we are able to type in the editor and the proposals are narrowed down based on the new characters.
private void attachContentAssist(final Text propertyText) {
ContentProposalAdapter contentProposalAdapter = new ContentProposalAdapter(propertyText, new TextContentAdapter(),
this.proposalProvider, KeyStroke.getInstance("Ctrl+Space"), null);
contentProposalAdapter.setLabelProvider(new ContentProposalLabelProvider());
contentProposalAdapter.setPropagateKeys(false);
contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
}

The line:
contentProposalAdapter.setPropagateKeys(false);
is stopping keys received while to pop-up is open being forwarded to the Text control, this is what is stopping the typing working.
Either specify true or remove the line as true is the default.

Related

Creating Netbeans Code Template for tinylog

I am attempting to add a code template to Netbeans so that typing lg followed by Tab will insert a tinylog statement. What I have so far is:
Logger.${logLevel type="org.pmw.tinylog.Logger.*" editable="true" default="info" }("${message}");
This works somewhat and produces a line that looks like:
Logger.info("message");
Pressing Tab moves the cursor between 'info' and 'message'. I can modify the 'message' field, press Tab and move back to the 'info' field. However, if I hit Control-Space and change 'info' to any of the other methods, the new method loads, but the code template wizard shuts down and then Tab just moves code to the right instead of switching between the method name and String parameter.
Have I made an error in my template, or am I asking too much from Netbeans to expect it is possible to keep the wizard alive when I change methods from info(String) to debug(String) for instance?

Shortcuts key for Eclipse for Return - Eclipse

I was a Netbeans user for almost one year. Now, I´m changing my IDE to Eclipse and I´m learning Shortcuts Keys. In Netbeans I used to type "re", then hit Tab key to complete return keyword. How is this done in Eclipse?
While I don't think there is a predefined option for this, your best bet will be to create a custom Java Editor Template. In your Eclipse Preferences, under Java > Editor > Templates, you can create a new template with the following specifications:
Name: re
Context: Java statements
Automatically Insert: Checked
Pattern: return ${retVal:var('${return_type}')};
What this will do is you can type re and then bring up Content Assist using Ctrl+Space. The very first proposal will be this template and it will be selected already. If you hit Enter and it'll insert a line like the following:
return retVal;
At this point, there will be an outline around retVal and you can hit Ctrl+Space again and it'll give you variables you can return that are in scope and match your method's return type or simply type what you want to return.

Eclipse: Perform an action any time an editor receives input

I'm wondering if it is possible to determine what input was just entered inside of an editor in Eclipse - I'm currently working off of the example JDT editor - and then perform an action based on that input.
e.g.: I have a file example.jav open in my editor window. I push the 'a' key. 'a' would appear in the editor window per normal, but 'a' would also print out to the console.
Obviously the operation I'll be performing will be more complicated than a System.out.println() statement, but if someone could help show me where the change gets detected by the editor itself, I can take it from there.
A few notes:
I'm working in Eclipse 3.7.2 with Java 1.7
If you cannot find the JDT example editor, go to Help > Welcome > Samples and click on "Java Editor".
Thanks in advance!
Figured it out!
As the Editor API is so vast in eclipse that it is difficult to know where to start, I focused on adding a KeyListener to my Shell. Turns out that is slightly problematic in SWT, as when an item inside the Shell gains focus, the Shell itself looses focus. After a bit of searching though, I stumbled across someone else who had the same problem. By adding a filter to the Shell's display, you can add a Listener object which works for the entire application. Such as:
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
Shell shell = window.getShell();
shell.getDisplay().addFilter(SWT.KeyDown, new Listener()
{
public void handleEvent(Event event)
{
System.out.println("" + event.character);
}
});
To further this and only worry about keys pressed in a specific non-widget part (otherwise you could just add a KeyListener to that part) you can add a check to make sure that the currently active part is the same as whatever part you wish to perform the actions for by using a simple if check.
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
Shell shell = window.getShell();
shell.getDisplay().addFilter(SWT.KeyDown, new Listener()
{
public void handleEvent(Event event)
{
IWorkbenchPage page = window.getActivePage();
IWorkbenchPart part = page.getActivePart();
IEditorPart editor = page.getActiveEditor();
if(part.equals(editor))
{
System.out.println("" + event.character);
}
}
});
Here is hoping that this helps someone else have an easier time than I had finding the solution!

Watin - How to set value of textarea (HTML editor)?

I'm trying to set the value of a textfield using the following code:
if (ie.TextField(Find.ById("testField")).Exists)
ie.TextField(Find.ById("testField")).Value = "Test";
The code passes without raising an error, however the textfield is not filled with the value.
I get an exception when I execute the following line:
ie.TextField(Find.ById("testField")).Focus()
The textarea is a tiny_mce editor and one of the html attributes is: style="display: none;"...
Any ideas how I can modify the value of such a field using Watin?
Thanks.
First tinymce is not a textarea. tinymce hides your textarea on initialization and creates a contenteditable iframe which is then used to allow text editing, styling aso...
Second if you want to write the editors content back to the hidden textarea you may do this using
tinymce.get('testField').triggerSave();.
Another way to set the value of your textarea is:
tinymce.get('testField').getDocumentById('testField').value = 'new value';
In case you want to write content directly to your tinymce editor you may choose on of the following
tinymce.get('testField').setContent('my_new_content'); // replaces the editors content
or
tinymce.get('testField').execCommand('mceInsertContent',false, 'my_content_to_be_added'); // adds the content at the carat postion
Here is a simple way to handle this using the Watin Eval function:
var js = "tinyMCE.get('body').setContent('" + bodyCont + "')";
var s = ie.Eval(js);
'body' needs to replaced with the id of the textarea that is hidden by tinymce - do a "view source" in your browser window to find this id.

How to redirect key presses to another shell in an Eclipse-based app?

I'm working on a way to maximise an EditorPart in my Eclipse-based RCP app to be absolutely full-screen, no trim, no menu, and so on. Actually, it's a GEF Editor. It's a bit of a hack, but it kind of works:
GraphicalViewer viewer = (GraphicalViewer)getWorkbenchPart().getAdapter(GraphicalViewer.class);
Control control = viewer.getControl();
Composite oldParent = control.getParent();
Shell shell = new Shell(SWT.APPLICATION_MODAL);
shell.setFullScreen(true);
shell.setMaximized(true);
// Some code here to listen to Esc key to dispose Shell and return...
shell.setLayout(new FillLayout());
control.setParent(shell);
shell.open();
Basically it sets the parent of the GraphicalViewer control to the newly created, maximised Shell. Pressing escape will return the control to it's original parent (code not shown for brevity).
The only thing that doesn't work is receiving global key presses (Del, Ctrl+Z, Ctrl+A) the ones that are declared for the Workbench and forwarded to the EditorPart. Is there any way I can hook into these or redirect them from the EditorPart to forward them on to the GraphicalViewer?
Thanks in advance
The short answer is you can't do that. Once you re-parent that composite out of the workbench window, it's totally busted. The system won't correctly deal with the part, as events (like activation, focus, setBounds(*)) aren't being processed.
The only supported way would be to open a new Workbench window with a perspective that only contained the editor area, and extending your org.eclipse.ui.application.WorkbenchWindowAdvisor.createWindowContents(Shell) method for that window+perspective combination to hide all of the trim you don't want, using org.eclipse.ui.application.IWorkbenchWindowConfigurer.
ex, in MyWorkbenchWindowAdvisor:
public void createWindowContents(Shell shell) {
if (isCreatingSpecialPerspective()) {
final IWorkbenchWindowConfigurer config = getWindowConfigurer();
config.setShowCoolBar(false);
config.setShowFastViewBars(false);
config.setShowMenuBar(false);
config.setShowPerspectiveBar(false);
config.setShowProgressIndicator(false);
config.setShowStatusLine(false);
}
super.createWindowContents(shell);
}
Also check out http://code.google.com/p/eclipse-fullscreen/ which has EPLed code in it concerned with running an RCP program with fullscreen support.
My suggestion is to try to approach this problem from another angle. Instead of listening for keystrokes in your code and acting upon them, define your own key binding scheme and then create commands and make them use this scheme. This would mean that you no longer have to listen for the key strokes in your code, but instead do whatever needs to be done through commands executed by these key strokes.