Rename class fields accessors in Eclipse - eclipse

Say I have
public class Person {
int id;
String regDate;
String name;
String surname;
// constructors, setters and getters and toString
If I rename id I want to rename it all across the class setters etc.
Currently I use ctr+f find replace, but that renames also my import statements and comments. :-)
And also if I change type, lets say int to String for id I want type to be changed also all over the class(getters,setters,toString).
Thanks

Open the Outline view -> make sure that fields are visible ("Hide fields" icon at top cannot be pressed) -> select the field you want to rename -> Alt + Shift + R -> give a new name for fields / accessor -> check "Rename getter..." and "Rename setter" -> click "Ok".
Regarding the second part of your question, this type of refactoring is probably currently unavailable because someone suggested it too on Eclipse Community Forums this year in this thread.

Related

Is it possible to make eclipse "new java class wizard" open the class in a specified section of a split screen?

In eclipse, I have split the editor view in two section so I can read from one file while editing the other. The file I read from contains scratch remarks something like
// Student(firstname, lastname, subject, mark)
and I need to create class Student with fields as above. So I write
Student student;
and press the quick-fix shortcut, opening the new java class wizard which creates the new class Student.java and I write
String firstname; String lastname, String mark;
left to be formatted and furnished with setters/getters later automatically.
Unfortunately, the new class opens exactly in that part of the screen where my class with the remarks is, hiding it.
Is there a decent way to persuade the wizard to open the file in the other part of the screen?

How to use autocomplete to add brackets in java project in Eclipse?

Is it possible autocomplete in Eclipse Java project. Something like I type:
public static void clr()
then press something and get:
public static void clr()
{
}
Alt+/ not working in this case.
In your situation, I don't think you will get any shorter than just typing { and Enter.
Alternatively, you could use the template for public_static_method, i.e. start typing pub..., hit Ctrl+Space, select the template (just press down once and then Enter), type in the method's return type and name and then Enter again to get straight to the body.
You can also go to Preferences -> Java -> Editor -> Templates to adapt that template to your own needs (give it a shorter name, or move the { to a separate line) or define your own ones.

How to define a function for use in an ODM decision table w/o changing the XOM?

I'm using ODM 8.5 (the JRules successor). In my Java domain, I have a three-character String field that represents a number, "000" to "999". I'd like to have a decision table that represents logic like:
if field is between "000" and "012" then set the result to "tiny"
if field is between "013" and "060" then set the result to "less tiny"
...
IBM's documentation on defining columns states - "A condition statement is an incomplete BAL predicate expression...". Is there anything in the BAL that does the kind of String comparison I want to do? If not, is it possible to call a function defined in the IRL from the BAL? If so, how? I'm also open to other suggestions on how to handle this simple problem in ODM (without changing the existing Java XOM). Right now, it looks to me that I can't use an ODM decision table, although the underlying logic seems well-suited to a decision table.
This answer is heavily based on Justin Phillips's nice answer to this question, updated for ODM 8.5. Please plus up his answer.
The main idea is to create a function in the Business Object Model (BOM) that can be called from your rules. To add a BOM function:
Right click the bom folder in the Eclipse rules project.
Select New -> BOM Entry from the menu.
Select the Create an empty BOM entry option and then click Finish.
Double click the new BOM entry to bring up the BOM editor view, and
then click New Class.
Enter the class name and then click Finish.
Double click the new BOM class from the list, then under
the Members section, click the New button.
In the New Member
dialog, select the Method option, enter a Name (isBetween),
return Type for the method (boolean), and add three String parameters (testee - the value being tested, min and max). Click the Finish button.
Double click the new method under the Members section, and select the Static and Final options.
Click the Create link under the "Member Verbalization" section and fill in the Template text box with {0} is between {1,min} to {2,max}
Under the BOM to XOM Mapping section, enter your Java code.
11. Go back to the class level BOM editor and set the Execution name to the value void in the "BOM to XOM Mapping" section. This indicates that the BOM class is not linked to a Java class (XOM).
The verbalization for the newly created member should now be accessible when filling out the Test in the Condition Column for the decision table.

How do I use bean validation effectively in Play Framework 2.0

Using Play Framework 2, I'm trying to get "required" validation working, with a custom message using this example code:
A simple Student model:
#Id private Long id;
#Required private String studentName;
#Required #ManyToOne private Classroom classroom;
A simple Student form (view):
#inputText(form("studentName"), '_label -> "Student Name", '_help -> "Please enter name.")
#select(form("classroom.id"), options(Classroom.options), '_label -> "Class", '_default -> "-- Choose an Classroom --")
1. The validation DOES work for the text input but DOES NOT work for the select box. The default value of the select box. Why?
2. Also, when the error is displayed, I get 2 messages. Both the help text and the validation message. Any ideas how I can just get one custom message?
You can hide the constraints by adding '_showConstraints -> false' to your input fields in the views.
To add custom error messages in your controller, you can use
myform.reject("field","error message")
Where field should equal the name of your entity property and the name of your input element.
I'm still figuring out Play just like you, so I'm not sure on the correct approach on how to solve your selectlist problem, but I'd debug your application and see if your form doesn't contain any validation errors anyway but it just doesn't show them.

How to create a generic list with Eclipse EMF?

I want to create a class with Eclipse EMF that contains a List with String objects. I see that Ecore has an EList but I can't change the generic type of the list.
Any idea how to do this?
If you want to generate code that gives you an EList<String>, then add a new EAttribute to an EClass, give it the EType EString, and set its "Upper Bound" property to '-1'.
If you want to create such a list programmatically, you could use the BasicEList for example (org.eclipse.emf.common.util.BasicEList<E>):
EList<String> stringList = new BasicEList<String>();
If you want to see your other options, open the type hierarchy on: org.eclipse.emf.common.util.AbstractEList<E>
Not sure if your question was answered, and what you actually want to do.
If you want to generate Java code from an .ecore file, then I provide here an example using the Eclipse Juno's Sample Ecore Model Editor of EMF (right click on the .ecore file).
Maybe it's not directly what you want, but this might be helpful for someone else.
Suppose you want a method like this in your generated Java class MyClass:
<T extends String> EList<T> getListOfType(Class<T> T)
In your Sample Ecore Model Editor you want to achieve How your method looks in the Ecore Editor by
add to MyClass a "New Child" of EOperation, name it getListOfType
add to getListOfType a "New Child" of ETypeParameter, name it T
add to T a "New Child" of EGeneric Bound Type, you would see a "T extends ?" instead of "T"
click the arrow to "T extends ?", click on "?", in "Property" window choose within the drop down menu of EClassifier an EString, now you would see "T extends EString"
add to getListOfType a "New Child" of EGeneric Return Type
click on the newly create "?" of return type, choose within a drop down menu of EClassifier an EEList
open the arrow of EEList, in the Property window choose within a drop down menu of EType Parameter a "T extends EString"
add to getListOfType a "New Child" of "EParameter"
in the property window of the newly created parameter "null", choose Name as "clazz", EType as "EJavaClass"
in the property window of the new "?" (two level below the node "clazz: EJavaClass"), choose EType Parameter as "T extends EString", now "clazz: EJavaClass" becomes "clazz: EJavaClass"
Now youre .ecore file is ready to be used to generate a java class.