How to add refactor option to my custom editor? - java

I have my own custom editor and now I want to add refactor option to this editor. I know I can add a new menu item for the same, but I want to use the existing refactor option. Like when user selects text and if it is valid variable (in Java) the all other variables are highlighted and later it is replaced. Also, I want to reuse the same refactor option and not provide new menu item.
Any pointers on how to go about this?
I followed the link: Eclipse rename/refactoring override
Now I get the notifications during each refactor but for my custom editor refactor -> rename menu is disabled. How do I enable it?

Related

How to document runtime of a function with Javadoc

I'm want to document the asymptotic runtime of a function, as it will be used for algorithm-engineering for graph problems.
What's the most idiomatic way to do this? Is there a way to create new tags in Javadoc like #return or #author?
I provided an example below, which is the method to delete a vertex in the graph.
/**
* Runtime: O( degreeOf(v) ) because every neighbour of [v] also needs to be updated.
*/
fun deleteVertex(v: V): SimpleGraph<V> {
if (v in m.keys) {
for (nb in m[v]!!)
m[nb]!!.remove(v)
m.remove(v)
}
return this
}
To create custom tags for Javadocs, simply follow these instructions.
You can create other customizations for Javadoc. For example, in Eclipse, you can create "templates" so that when you create new classes or add new methods, the IDE automatically apply this template to add a (Javadoc) comment formatted in the prescribed style of the template you applied. You can save these templates in an XML file so that you could share it with other members of your team. I am sure that IntelliJ and other modern IDEs will have similar features. I am just more familiarized with Eclipse. Here is a video I created many years ago on how to create a Code Formatter in Eclipse. If you advance to the 1:48 mark, you will see "Code Template" right above the "Code Formatter" option I selected in the video. Creating a code template is much easier than a formatter.
To do this, simply click on Windows > Preferences menu to get the Preferences popup. There, select Java > Code Style > Code Templates. in the right pane, expand Comments and select the component you wish to create a comment template for, for example Methods. Click Edit button and format the Javadoc comment to your liking. Obviously, you will have to do a bit of research to get really creative with your comments. For example, you might need to figure out how to use system variables or create your own. For example, in the image below, I made use the year variable to apply the current year whenever I create a new class.
Once you finish with all your template customizations, simply click the Export button and use the File Chooser dialog to save the file wherever you would like.
One last tip, if you need to embed code snippets in your Javadocs, you can follow the recommendations in this article. I do this very often. Sometimes I find it useful to embed a few lines of code to illustrate different use cases for the method. That way, other developers can see how to use the method in the correct context.

Rebuild eclipse editor

I have an eclipse plugin that ships with an editor.
I added a preference to change the color of the syntax highlighting but these changes only apply after I restart the editor manually.
I implemented syntax highlighting via an DefaultDamagerRepairer that gets a Scanner returning a token and in that token I define the respective color. I change the returning token via a PropertyChangeListener applied to the respective preference but as mentioned before the editor does not display the new color until I restart it.
Is there a way to rebuild or redraw the editor programatically?
I have found out that it will update the new colors partly if I start typing in the editor. I assume that this is because of the PresentationReconciler I have set up but I didn't find a way to force this reconciler to recompute the editor's content.
Call the invalidateTextPresentation method of your ITextViewer / ISourceViewer to get it to rebuild the whole screen using the new settings.

Adding your own custom macros like "sout"in IntelliJ

I really like to be able to type sout and get System.out.println. In fact, I like it so much that I want to add more of these. For example, fb could be final boolean.
How do I add that?
Like said in the comments, these macros are called "Live Templates".
To create one:
open the settings menu
select the "Live Templates" entry in the left menu
select the category where you like to create your new template
press the "+" button on the right hand side of the settings menu window
add the abbreviation, "fb" in your case
add a description
... and then the text:
final boolean
($END$ can be omitted here)
Now select the context (link is beneath the text field) where this template will be used and recognized by IDEA
I've used the contexts Java Statement, Expression, Declaration and Other (but "Other" isn't shown in the list of contexts).
It could like this:
To use it write fb on the appropriate place and either wait until IDEA suggests to use the template or press ctrl + space to activate the auto complete, it should create:
final boolean
You may find some more information about creating and editing live templates on the official help page: Creating and Editing Live Templates

How can i add some text (i.e. kind of "about" info) in Preferences in Android

I'd like to add a short text (2-3 sentences) to my preferences screen (which is created using xml with PreferenceScreen, etc), in order to provide some kind of short help/description for the user.
I tried using Preference, i.e. custom preference, but i cannot see more than 1 line in the title and more than 2 lines in the summary.
You can't do a lot of customization to a preference widgets.
Two options:
1) SMSpopup approach. Opening a new window with the information. Check the About preference.
Check the src code.
2) Softkeyboard approach. Using the normal preference but setting it disabled. Check the src code.

In an Eclipse RCP editor, what is the best way to handle missing mandatory fields?

On an Eclipse RCP application, I'm building an Editor in which some fields are mandatory.
If the user saves the editor with theses fields not filled, what is the best way/practice to handle this ?
(my first guess is to show an error dialog if theses fields are empty in doSave() method but I'm not sure it's the "eclipse" way to deal with this kind of problem)
If you consider some dialog box like "Create a New Java Project",
you simply cannot do any action (like "Next" or "Finish" until you fill the one mandatory field ("Project name")
So it is different than checking on the doSave() event.
If that field is invalid (like if the project name already exist), a warning is displayed in the zone at the top.
If the field is correctly filled, then you can save.
(Note: I know this is not an Editor, but it can give you an idea about the mandatory fields management in eclipse)
alt text http://ds.informatik.uni-marburg.de/MAGE/gdt/images/tutorial/NewJavaProject.png
I agree with VonC and would disable the "Save" button, as long as the user has filed all the important fields.
Showig a warning which fields the user has to fill would help a lot.
EDIT:
Create a component which added himself as change listener. When someone changes the component, you can check whether the input is correct.
Create a window whith all the self-checking components and add the window as listener to all the components.
When somebody change a compounent you can directly check if the input is valid and the user can step to the next page or save the page.
In RCP (Example FieldEditorPreferencePage) a lot of components have the doSave() and isValid() methods.
In isValid() you can check all the components you can find in the window and in doSave(), you sould check the isValid() state, when it is not done automatically, and do some additional save actions.
You could use FieldDecorations to mark the mandatory fields and provide visual feedback if the content of a field is incorrect.

Categories