eclipse text editor fixed line length - java

I am making an Eclipse plugin and it includes a built-in textEditor implementation, which shall be displaying an SQL query from the database.
However, I want it to only be allowing to create a 72-character-long lines. Therefore, if i write and endless line, I want it to jump into a new line automatically once the line is 72 characters long.
I am now able to load the statement and display it there, cutting the line at 72 characters, but if i edit the query in the editor, it lets me to create a line at any length.
I tried to look for a parameter or a method that would set it, but I failed.
Does anybody have any idea?
Thanks a lot!

Why dont you try using regular expression .Refer the below link for an example.
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet196.java

Related

How to fix IndexOutOfBoundsException issue

I am quiet new to java and below is my java code. When I execute this java program I am getting an exception as
java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
I have already find out the reason why i am getting error.
When i open this csv file in normal text editor then i dont see any issue with the data. But when i try to open the file in VI editor in Ubuntu then i can see there is ^M line character and this is causing the exception. When i edit the file and remove the ^M and run the program again then its working fine and inserting data into table.
It is the line break on Windows PCs which is being read as ^M in VIM based editors and i am getting this file from windows and i am reading this in ubuntu.
Here is the screenshot where i can see ^M and it is at the index 4.
I see replaceAll function in java but i dont know how to use it and where exactly i need to use it. I only need to remove ^M and read the file.. Please help
I tried with condition String line = line1.replaceAll("^M",""); but still getting same exception. I am not sure is there any other way to handle this in exception or other logic
Based on comments and stack trace, editing the answer;
So here's what's happening;
You have a file with certain number of entries in each row that you are doing some action upon.
But due the contol m character (^M), the java code is not behaving as expected.
Your lines where the control M character is observed is basically split into two separate lines when you are reading it from the bufferedReader.readLine() method.
Now ideally, your file would have the number of columns that is already know to you.
But for the lines with control M character, not the columns have been split (as per explaination above).
In my opinion, you can do either of the two;
You can remove the control M characters from your file, either
manually or through any linux operation (Refer:
remove ^M characters from file using sed)
Change the for loop to run for a limit that is based on columns List instead of the heading List, since columns list is a more appropriate list representing the dynamically split line of the file.
for (int i = 0; i < columns.size(); i++) {
If you go for Option 2, you may also need to change the logic in your loop. Since I am not aware of your DB model and file, I guess you are better equipped to do so.

Unwrap lines after increasing line length in code style

In a Java project that I'm working on with IntelliJ, we increased the allowed line length in the code style.
IntelliJ happily wraps lines that are longer than allowed by code style when auto-formatting. However, I would like to do the opposite: unwrap multiple lines that are way shorter than allowed.
Is there a way to clear unnecessary line breaks when auto-formatting with IntelliJ?
Well, this is a workaround for sure, but you can:
Select the full file with Ctrl+A
Join all lines with Ctrl+Shift+J
Reformat file with Ctrl+Alt+L

I want to transfer information from Google Docs to Google Spreadsheet

I currently have a large amount of information sorted into table form on google docs, an example can be seen below:
I would like to transfer all of this information into Google Spreadsheet form. With lines 1-5 going across columns B-F, respectively, and the information going underneath each respective column.
Would I need to use a script to accomplish this task? If so, what type of script should I use, and where can I access such a script (i.e. potentially find a freelance programmer who can write it for me, if necessary). Are there any other ways this task could be accomplished? All of the information in the google docs is very standardized thus there is not any sort of variation which could complicate a script. If a script could transfer one set of 5, it could work on all of the sets.
Thank you, let me know if you need any more information.
This can be done with a lot of different languages. I would approach this using Java just because I am most familiar with it. I would start by downloading the Google Doc as plaintext (.txt). Then run it through line by line parsing it into .csv format. From there you can import it directly into Google Sheets.
You can do this with Notepad++ or equivalent editor. Need to use find and replace tool using extended keys.
Like for replacing a line break search for \r\n and replace with any you need.
If you can place \t [tab space] between fields you can simply paste them onto sheet they align into columns.
So here you can replace double line breaks with some symbol then single line break with \t and then again replace the symbol with single line break. you get all data in columns structure.

How can you get the current caret position in terminal with Java?

I've looked at JLine, Lanterna, and others, but I'm not seeing a simple way to find the current caret position in the terminal with these tools. I've looked at a number of escape codes, tput, etc. But, I'm looking for the easiest way to get the current column and row where the caret is located with Java. Maybe I haven't found the right call in these libraries...
What's the easiest way to get the row and column of the caret in the terminal?
I'm looking for a pure textual library so that I can re-write the buffer. I'm aware of ansi escape codes and how to manipulate them to produce the effects I'm after. What I'm trying to do is make a Java prompt library in the vain of Inquirer.js for Node. It has a number of simple ways to get info from the user (lists, questions, split lists, etc). All of it text -- so all of it without a UI, and so non-swing. I don't want swing, I just want a decent terminal UI experience.
Edit2
With the http://docs.oracle.com/javase/7/docs/api/javax/swing/text/Caret.html Caret Interface, you can create a CaretListener Object in order to find a caret position.
So you would have to create a new CaretListener that responds to the GUI, with the getDot() method.
This might help... with code anyway.
http://bestjavapractices.blogspot.com.au/2011/11/get-current-caret-position-in.html
Now at the moment that would only work on a GUI/SwingComponents and I'm not sure if that would work for a terminal application ,which is what you want, where I assume you would be using command line arguments and such to get things to work.
I don't think that you could do this as I think the terminal is really just printing out the output, but I will keep checking for a little while anyway.
If you could tell me what you are trying to use the caret for that would help in my efforts.
Hope this helps.
If it doesn't you may need to look through some more Text Toolkits, such as
JCurses - http://sourceforge.net/projects/javacurses/
Charva - http://www.pitman.co.za/projects/charva/index.html
Current version of Lanterna can read the cursor position using ANSI CSI: https://github.com/mabe02/lanterna/blob/master/src/main/java/com/googlecode/lanterna/terminal/ansi/ANSITerminal.java#L266
And here you can find simple Java solution how to send the ANSI command and read from System.in reported cursor position.
How to read the cursor position given by the terminal (ANSI Device Status Report) in JAVA

How can I output data with special characters visible?

I have a text file that was provided to me and no one knows the encoding on it. Looking at it in a text editor, everything looks fine, aligned properly into neat columns.
However, I'm seeing some anomalies when I read the data. Even though, visually, the field "Foo" appears in the same columns in the text file (for instance, in columns 15-20), when I try to pull it out using substring(15,20) my data varies wildly. Sometimes I'll pull bytes 11-16, sometimes 18-23, sometimes 15-20...there's no consistency between records.
I suspect that there are some special chartacters, invisible to my text editor, but readable by (and counted in the index of) the String methods. Is there any way in Java to dump the contents of the file with any special characters visible so I can see what I need to Strings I need replace with regex?
If not in Java, can anyone recommed a tool that may be able to help me out?
I would start with having a look at the file directly. Any code adds a layer of doubt. Take a Total Commander (or equivalent on your platform), view the file (F3) and switch to hex mode. You suggest that the special characters behavior is not even consistent between lines, so you should get some visual clue about the format before you even attempt to fix it algorithmically.
Have you tried printing the contents of the file as individual integers or bytes? That way you can see if there are any hidden characters.

Categories

Resources