Eclipse - Externalizing strings with keys based on component name instead of numbers - java

I use Eclipse Luna 4.4.2
using the "externalize strings" wizard (from right click on the class in the package explorer) it replaces my original strings by another string pointing to the key in the property file.
For example, having this label defined in a class "myFrame" :
JLabel mylabel = new JLabel("original text");
after the wizard the result is:
JLabel mylabel = new JLabel(Messages.getString("myFrame.1")
I would prefer a behavior where the key would be constructed by the component name. It is what happen if I use the other wizard from the windowbuilder view. But this wizard has less options (you can't set to ignore..)
So this result would be better :
JLabel mylabel = new JLabel(Messages.getString("myFrame.mylabel.text")
or even something like
JLabel mylabel = new JLabel(Messages.myFrame_mylabel_text)
I spent a lot of time on searching and found this thread Configuring string externalization in Eclipse to use ${key} as field name
but it is old and I do not have the checkbox "use Eclipe's externalization mechanism" ?!
Also this thread says that the features have been implemented inside Eclipse http://blog.vogella.com/2013/08/12/eclipse-internationalization-part-44-new-features-by-dirk-fauth/
Did I miss some updates ? I installed te latest build of Eclipse-Mars, but it does not help..
Thank you for help !

Related

Read external Files with GlassFish / Vaadin?

I would like to make .txt-files accessible for my VaadinApp on a GlassfishServer.
Lets say I have a .txt-file, its content is 12345.
Now, when I click a button on my Vaadin StartPage, I would like to show the Data that has been written into this .txt-file.
I know how Java Input/Output is working but I have no clue how to make those files accessible for my VaadinApplication running on Glassfish 4.1.2.
Is there a folder I can put the .txt-file in, or how would I access the file?
Thanks
There is component named Label is available in Vaadin.
So that, the values which needs to be shown on the screen can be set as a caption/value for that object.
This can be done either through constructor or setter in that object.We will set the value through the setter as we need to display the value, once the button is clicked. That can be done like this.
Label sampleLabel = new Label();
sampleLabel.setContentMode(com.vaadin.shared.ui.ContentMode.HTML);
Now we will see how this can be added to the label, when a button is clicked.
Button sampleButton = new Button("Click");
sampleButton.addClickListener(event -> sampleLabel.setValue(<call the method that reads data from the text file>));
I hope this will be helpful.
Note: Basically you can place the file anywhere in the system.
But most preferred way.
If you are using maven to build the project, place the files in the resource folder.(src/main/resources)

JDatePicker - How to change the Icon of the Button?

I'm looking for help in placing an Icon instead of the default three dots as shown in this picture.
But I really have no clue how I can do it. The Class DateLabelFormatter just does some String conversions to display the german calendar names.
UtilDateModel modelProjektEnde = new UtilDateModel();
JDatePanelImpl datePanelProjektEnde = new JDatePanelImpl(modelProjektEnde, dateLabelFormatter.getProperties());
dateProjektEnde = new JDatePickerImpl(datePanelProjektEnde, dateLabelFormatter);
simple use this.
myDateChooser.getCalendarButton().setIcon("calendar.png");
Explaination for starters my be unnecessary here but here we go anyway,
If you want a Calendar or DateChooser in your project. You can use
JDateChooser.
Follow steps.
Download JCalendar 1.4.jar library.
Add it to your projects library folder by right clicking on Libraries and select ADD JAR/FOLDER.
if you are using netbeans then right click on your pallete and select pallete manager.
Now select Add from Jar and choose your downloaded libaray and select calendar it's calendar components you want to use. JDateChooser in this case.
Drag and drop this from pallete or declare it in your code.
JDateChooser myDateChooser = new com.toedter.calendar.JDateChooser();
to customize the button icon you can use following code
myDateChooser.setIcon(new ImageIcon(getClass().getResource("/Icons/calendar.png")));
Replace the path string with your icon path.
To change the button background
myDateChooser.getCalendarButton().setBackground(Color.WHITE);
and use can also change foreground, fonts etc this way.

Custom ToolBar with Java Swing for Desktop

I have created a GUI with Java Swing and wanting to create a custom toolbar according to my modules. Below are the images am wanting to use:
These images are placed in the same level as the src folder within my application. I am aware that I can perhaps create a jar with these images so that I can easily access them from within my application but do not know how. I have spent hours trying to make this work.
Below is my GUI that I have created ad wanting to beautify with these images for the toolbar else create an array of labels that will act as a navigation but either approach I couldn't get it to work.
The code below was my last attempt on this:
JToolBar toolbar1 = new JToolBar();
ImageIcon client = new ImageIcon("clients.png");
ImageIcon timesheet = new ImageIcon("timesheets.png");
JButton clientTB = new JButton(client);
JButton timesheetTB = new JButton(timesheet);
toolbar1.add(clientTB );
toolbar1.add(timesheetTB);
add(toolbar1, BorderLayout.NORTH);
I even moved these images and placed them within the class that's calling them.
What could I be doing wrong, please help?
You have a look at the JavaDocs for ImageIcon(String), the String value is "a String specifying a filename or path"
This is a problem, because your images aren't actually files, any more, they have been embedded within your application (typically within the resulting jar file) and no longer be treated like "normal files".
Instead, you need to use Class#getResource which searches the application's classpath for the named resource, something like...
// This assumes that the images are in the default package
// (or the root of the src directory)
ImageIcon client = new ImageIcon(getClass().getResource("/clients.png"));
Now, I have a personal dislike for ImageIcon, because it won't tell you when the image is loaded for some reason, like it can't be found or it's the wrong format.
Instead, I'd use ImageIO to read the image
ImageIcon client = new ImageIcon(ImageIO.read(getClass().getResource("/clients.png")));
which will do two things, first, it will throw a IOException if the image can't be loaded for some reason and two, it won't return until the image is fully loaded, which is helpful.
See Reading/Loading an Image for more details

List the history of text field while typing on the field in an Eclipse RCP application

In my eclipse RCP application i have a text filed to get some values from the user.
Is there any way in eclipse RCP or java to list the old entries while entering the new values [Like content assist]?
Please advice me.
You can use org.eclipse.jface.fieldassist.AutoCompleteField for this. For a text field it might look like this:
new AutoCompleteField(text, new TextContentAdapter(), new String [] {"proposal 1", ...});

Vaadin, where to put images?

I have a Liferay project with Vaadin portlet.
I want to add icon to my buttons.
Button search = new Button("Search");
search.setIcon(new ThemeResource("img/silk/add.png"));
But dont know where i gonna put it? Now i put it in docroot directory.
UPDATE
No i try this.
Button search = new Button("Search");
search.setIcon(new ThemeResource("LifeRayVaadin-portlet/icons/add.png"));
But when i redeploy project in console get
09:34:05,773 WARN [404_jsp:109] /html/VAADIN/themes/liferay/LifeRayVaadin-portlet/icons/add.png
So your portlet is looking for the icons in /html/VAADIN/themes/liferay/LifeRayVaadin-portlet/icons/add.png.
You could create a directory icons under VAADIN and call:
search.setIcon(new ThemeResource("../../icons/add.png"));
ThemeResource without any path will look for the file in VAADIN/themes/yourtheme/ path and thus ../../ will get you (in this case) to /VAADIN/. I personally would never hardcode the name of a theme or a portlet in a project, because when it changes you have to go through every reference and change them.
You can put your images in $PORTLET-NAME/docroot/icons directory and call them using the Path
/$PORTLET-NAME$/icons/add.png
in your case it will be
Button search = new Button("Search");
search.setIcon(new ThemeResource("/$PORLTET-NAME$/icons/add.png"));

Categories