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

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?

Related

ITextPDF - Link creation with PDFAnnotation

I have a question about hyperlinks within pdf documents created with itext. Currently, using the following code written in java, I am able to successfully create links. However, when I hover over the link, the link text is displayed. The client does not want the link text to appear upon hover-over. How can I either remove the hover-over, or give it alternate text to display (e.g. "Course Info")? I am using itext version 5.5.9. I have looked at "iText in Action" chapter 7 but was not able to find what I needed. Is there a better way to create the links? Any help and examples will be appreciated. Thanks.
package edu.ucsd.act.academic.studente2t.util;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfAction;
import com.itextpdf.text.pdf.PdfAnnotation;
import com.itextpdf.text.pdf.PdfBorderArray;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPCellEvent;
import com.itextpdf.text.pdf.PdfWriter;
class LinkInCellEvent implements PdfPCellEvent
{
protected String url;
public LinkInCellEvent(String url)
{
this.url = url;
}
public void cellLayout(PdfPCell cell, Rectangle position,
PdfContentByte[] canvases)
{
PdfWriter writer = canvases[0].getPdfWriter();
PdfAction action = new PdfAction(url);
PdfAnnotation link = PdfAnnotation.createLink(writer, position,
PdfAnnotation.HIGHLIGHT_INVERT, action);
PdfBorderArray border = new PdfBorderArray(0, 0, 0);
link.setBorder(border);
writer.addAnnotation(link);
}
}
This is not an iText problem. It's inherent to PDF. The PDF specification (ISO-32000-1) doesn't say anything about the way viewers should present tool tips for link annotations.
Your client (who probably should also be our client), may be confused by the following concepts:
Additional actions
The only occurrence of the word "tool tip" is in a NOTE when the E (enter) and X (exit) event are described in the section about additional actions. One can use additional actions, for instance on a widget annotation, to have a custom tool tip appear / disappear when someone hovers over a widget annotation.
When you study the PDF standard, you will see that there are several instances where you can define additional action (/AA), but link annotations aren't one of them.
Alternative field name
There's also the /TU entry (formerly known as the user name entry), which is (I quote the spec) an alternative field name that shall be used in place of the actual field name wherever the field shall be identified in the user interface (such as in error or status messages referring to the field). This text is also useful when extracting the document’s contents in support of accessibility to users with disabilities or for other purposes. The value of the /TU entry is often used by viewers as a tool tip, but as you can tell from the description, the /TU entry is specific for fields, not for annotations. It can only be used in a field dictionary, not in an annotation dictionary.
Conclusion:
Whatever is shown when someone hovers over a link annotation is not described in the specification. Every vendor of a PDF viewer may decide what to show (if anything) when a user hovers over a link annotation. There is no way to add something to the PDF that can force the viewer to show something else (or nothing).

How to accomplish drop-down lists in KIE workbench?

I'm new to JBPM and am trying to wrap my head around a new project, and recently noticed that while trying to define some user task forms I couldn't find a form option for a drop-down list
At this point my knowledge of the technology is pretty small, and this seems like a strange limitation at first glance, which should have an easy work-around, but I'm having difficulty finding a quick and dirty solution.
Is this something I'd have to code in Eclipse, or something else?
The answer that #cego provides is correct for "hard-coded" values, if you want to load dynamic values (from a database for example) you can use the Select Box field type and configure it to use a SelectValuesProvider that calculates the combo values.
To create a SelectValuesProvider you should create a java project with a mvn dependency to:
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-form-modeler-api</artifactId>
</dependency>
Once you did that you can create your class that implements org.jbpm.formModeler.core.config.SelectValuesProvider. This interface provides two methods:
String getIdentifier(): should return a unique String that identifies this provider. This String will be shown on the Select Box configuration popup.
Map getSelectOptions(Field field, String value, FormRenderContext renderContext, Locale locale): This method have to return a Map containting the key, text that are going to be load on the Select box. The received parameters are:
Field field: the configuration of the field that is going to be evaluated.
String Value: the current value of the field
FormRenderContext renderContext: a class that contains all the information about the form that is rendered at that moment.
Locale locale: the locale in which is being rendered the form.
Once you've created this provider, you must compile your project and put the jar on the server classpath and restart it. After doing that you'll be able to create a form (or edit an existing one), add a Select Box field and choose your provider on the "Data provider" combo box.
Hope it helps, if you have any doubt please ask and I'll try to create an example.
Regards,
Pere
Ok, for old versions you can do it turning a textbox to a combobox using a RangeProvider. This is a very similar solution to the previous one.
First you should create java project with a mvn dependency to:
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-form-modeler-api</artifactId>
</dependency>
After that you have to create your RangeProvider class that implements org.jbpm.formModeler.api.model.RangeProvider and implement it's methods. As the SelectValuesProvider on the previous example this interface provides two methods:
- String getType(): A unique String to identify the provider
- Map getRangesMap(String namespace): This method have to return a Map containting the key, text that are going to be load on the combo box. It only receives a String parameter, it is an identifier that allows you to get all the information about the form that is being rendered.
Also you have to create a META-INF/beans.xml file to allow to lookup your provider via CDI (I missed this step on the previous example, sorry).
As the previous example, once you've created the provider you must compile your project and put the jar on the server classpath and restart it.
When the server is started you have to create a new form (or open an existing one), add a TextBox field, edit it's properties and write the string returned by your RangeProvider's getType method on the "Range value" property.
Save the field properties and if everything is fine the field would be rendered as a combobox showing the values returned by your provider.
To create a select element(drop-down list) look for "Setting a Range Formula" in this part of the documentation: http://docs.jboss.org/jbpm/v6.1/userguide/chap-formmodeler.html#sect-formmodeler-FormulasExpression

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 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.

Rename class fields accessors in 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.