Custom Eclipse editor: auto-complete brackets - java

I've created a custom editor for eclipse but I'm having trouble setting up an auto-complete feature (when a developer enters an opening bracket the editor auto-generates the closing bracket). I've looked at the java example and spent some time googling but I'm having trouble finding any information. Any help is greatly appreciated.

I've come up with a solution, sort of. I created a class that implements IContentAssistProcessor. I overrode the computeCompletionProposal function and in it i used the ITextViewer, that is passed in, to get the document. Then I used the IDocument.replace() function to add a closing bracket anytime an open one is typed. The problem with this is the cursor is moved to the end of the closing bracket. any suggestion on how to move it in between the brackets?

Related

JComboBox: arrow-button should be shown at any time

If a JComboBox is not selected, the arrow-button on the right is not shown. This leads to the fact that a combo-box cannot be distinguished from a normal textfield.
The question is now: how is it possible to show the arrow-button permanently? I alrady came across BasicComboBoxUI.createArrowButton() etc., but I did not find out the mechanism of hiding / showing the arrow-button.
Can anyoune give me a hint how to show the arrow-button permanently ?
Can you add below code as first line in your main method.
Toolkit.getDefaultToolkit().setDesktopProperty("win.xpstyle.themeActive",Boolean.FALSE);
and then check your program.
sorry for the inconvenience. Everything is clear now. In have been told that we use a special framework which changes the behaviour. This information would have been useful if given to me earlier... :-(

Eclipse isn't overwriting parenthesis

This isn't really a coding problem, but more of just an Eclipse problem.
Say you're typing x = (1), Eclipse will make the closing parenthesis for you the moment you type '('
It also normally writes over the closing parenthesis as you are typing as well.
However, for some reason when I'm typing, it doesn't automatically write over it and I'm confused because I'm pretty sure I didn't hit any special setting so I have no idea what to do to revert this.
So normally you'll type x = (1), and it'll show as x = (1), but right now it's showing x(1)). How do I change it back??
Thanks for the help!
Check in the Settings Content Assist for your Editor. It has a setting to overwrite or not. And in my case it specifically mentions you can toggle that with Ctrl Key while the assist is active. The other setting related is Editor -> Typing. It also has some brace-close settings.
1 way to solve this problem is by turning off Automatically Closed parentheses. Open the preferences for editing, then go to Java -> Editor -> Typing and turn off parentheses.

Eclipse Luna no syntax coloring

Well I have a problem with one of my classes in Eclipse. In there I define an inner Enum type.
In the picture you can see one of the enum-Constants:https: //www.dropbox.com/s/z9shh52au35mkzy/Pict1.JPG
Now I wanted to add some code to the "setup()" method. Sadly the syntax coloring for the new code doens't show up and even if I create a syntax error inside, it doesn't recognize it. (it works at other places)
https://www.dropbox.com/s/0t6que0pg1hr1tw/Pict2.JPG (can't put pictures in the question yet, I hope you don't mind if I put links there)
Finally, when I save the file and reopen it, the error behaviour is the same, but my pour code looks like this: https://www.dropbox.com/s/9lqzchv4xrnpau6/Pict3.JPG
As you can see, even in the other enum constants, there is just color at keywords and things outside of methods. (If I remove the added code and reopen, it works as if nothing hab happened)
So my question is, how can I fix this?
Thanks in advance.

Eclipse content assist not working in some parts of code

I am using Eclipse Juno and have never had any problems with it, until its content assist stopped working only in some parts of my code. The code below shows what I am talking about:
mWTBatch.setText("Here content assist works");
medCopyBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
mWTBatch.setText(mRTBatch.getText());
mWTExp.setText(mRTExp.getText());
mWTName.setText(mRTName.getText());
mWTQuantity.setText(mRTQuantity.getText());
/* Here content assist is not working */
}
});
mWTBatch.setText("Here it is working again");
That piece of code is just inside one method of my class. The problem is that it works fine inside the methods of the class, but inside objects (new ActionListener(){}) it returns "No default proposals". It has this behavior when I either use "Ctrl+space" or type in "." after the object I want to get suggestions of. I've already searched here for the solution and googled it, but couldn't find a solution. What I have already tried:
Window->Preferences->Editor->Content Assist->Advanced and checked Java Proposals. It didn't work. I've even tried checking it myself, without just using Restore Defaults. I also tried the Java Proposals from the other table. Nothing. At last I tried checking all the fields with Java on them. Nothing worked.
Deleted my workspace folder completely, created a new one and imported my project. As my project is from an SVN repository, I used the project folder inside "trunk" folder, but I didn't copy the content of the folder to the workspace when importing (I need it to be in the repository). Still nothing, it continues with the error.
I reproduced the same situation of the code above into another class of another different project, which was also imported to the workspace, but having its content copied to it. The content assist worked for that one.
I then re-imported the project with the original code from above, but this time copying its content to workspace (which means it had nothing to do anymore with the SVN repository). It didn't work either.
I also checked if the ctrl+space is bind to the content assist on Eclipse settings and it is ok. I also checked if it had nothing to do with advanced key settings of Windows 7 language bar. I had seen on the internet that could be problem, but it was not my case.
I even created a new Java project on the workspace and copied the .java files one by one from the old project, set all the build path manually and in the end it still doesn't work.
For all the first four cases above I also cleaned the projects and closed and reopened them, not forgetting to refresh it after each action. Could anyone tell me how to fix this? I would like to find a solution to this problem, so that others may not be like me on it for 2 days. I think my question is important because I am gathering here many probable solutions found by googling the problem and from StackOverflow, and nothing solved it.
I stumbled into this issue the other day, and after seeing this post thought that I'd have to just live with it.
However, I did find a "hack" around it:
mWTBatch.setText("Here content assist works");
medCopyBtn.addActionListener( //<---------------------- Problem arises because we're inside a function declaration ...
new ActionListener()
{ // <--------------------------------------------- ... yet we're trying to write a function
public void actionPerformed(ActionEvent e)
{
/* Here content assist is not working */
}
}
);
mWTBatch.setText("Here it is working again");
From the content assistants point of view, this is just plain wrong, so we need to give it a little help:
mWTBatch.setText("Here content assist works");
medCopyBtn.addActionListener(
new ActionListener()
// <--------------------------------------------- CURLY BRACKET MISSING
public void actionPerformed(ActionEvent e)
{
/* Here content assist IS WORKING */
}
}
);
mWTBatch.setText("Here it is still working");
This will obviously give you an error upon compilation time, but it gives you full access to the content assist for the rest of the function declaration.
Also, it doesn't matter which curly bracket you remove from inside the function declaration, so long as it's an opening curly bracket.
One other point, if you only remove the opening curly bracket like I did above, then eclipse will NOT add in another closing curly bracket automatically for most cases (because by the time you enter the new opening curly bracket, you've equalised the opening vr closing of curly brackets). You can get around this by deleting the closing curly bracket as well, but then you have to remember to put two curly brackets back.
Hope that helps the 1165 views this question has garnered over the past year =)
Do a search for "Change display language" on the start menu. 'Change keyboards' > Look to see if you have any non English keyboards under 'General' > 'Installed services'. If you have more than just English then pressing Ctrl+Spacebar is changing your focus from Eclipse to the language selector on the taskbar. Remove any other keyboard languages from the list if that is your problem.

Adding text input to a blackberrycanvas

The BlackBerryCanvas documentation says:
This class extends the functionality of the Canvas class to include full touch support and featured text input support.
I have extended BlackBerryCanvas, but am having trouble adding any text input.
It's not that I know what to do but cannot get it work -- I simply do not know how to add a text input box or field.
EDIT: Or have I misunderstood and this is not possible? From reading around, it seems as though it is, but I'm starting to wonder why it's so hard to find anything on it.
EDIT2: I'm think maybe it's something to do with the BlackBerryTextBox?
EDIT3:
Applications using this class can call the #setInputHelper method to get the text input support.
might also be something. It hasn't given me quite enough clues to be able to do it myself though I'm afraid.
Thanks.
If you don't particularly need to use the Canvas hierarchy, I suggest you use the more commonly used Field hierarchy.
That means you should create an application and start with a Screen. An easy concrete implementation of Screen is the FullScreen. To get the text input you are seeking, add an AutoTextEditField to the screen.

Categories