Eclipse 4 RCP Disable Part Switch - java

In my (pure) E4 App I want to force the User to enter something in a Text Field before he can move on.
Currently, if nothing has been entered into the Text Field and the focusLost Event is triggered, I reset focus to the Text Field.
Via a ModifyListener I check, if the entered String equals "" and if yes, a fake tooltip is displayed, telling the User to enter something into the Text Field.
The Problem is, if I have two Parts on a PartStack and the Text Field is on my first Part, the User is still able to trigger a Part switch and work on the other Part without having to enter something into the Text Field on the first Part first.
How is it possible to prohibit the User from switching between these Parts, as long as nothing is entered in the Text Field on the first Part?
I donĀ“t want to hide Part 2, the App should still look the same, the user should just not be able to do anything until something has been entered into the Text Field.

If you don't want to hide Part 2, then disable the widgets in that part instead. And display a message that asks the user to provide the necessary input back in Part 1. If the user does, hide that message and enable your widgets.
For example:
if (!isInputSatisfactory())
{
displayMessage("Invalid input");
myButton.setEnabled(false);
}
else
myButton.setEnabled(true);

Related

How to check in java if user is clicking save button unnecessarily and there is nothing to save?

In my piece of code there is one input box so data will be fetched in that box on drop down selection. And if user do not want to insert/update/delete that data and click on save button unnecessarily then i have to show an error message that: "There is nothing to save..You pressed the save button unnecessary."
Currently , i am checking if the data in input box is equals to the database value then show that error but its not working.
if (inputVal1.equals(dbVal1.getValue()) && inputVal2.equals(dbVal2.getValue())) {
addPageError(T_NOTHING_TO_SAVE);
}
Please suggest how to handle this validation in java.
Store the data in a separate variable and simply compare it to the current values in the input box. If you do this, you could even detect if the values were changed, but then changed back to the original value. Apart from this you could also even deactivate the button and compare in an edit-event of the input box if the content has really changed and enable the button accordingly.

Reading alt code JTextArea

I have a barcode that reads :
"SerialNumberALT09ProductNumber"
where ALT09 = Tab.
I read the number in to a JTextArea, if i write the number manually with the tab key on my keyboard i get a valid input i can then text.trim().split("\t");
to get a valid input to get respective serial number and product number. But when reading the barcode who sends ALT09 it does not read anything.
How do i get the JTextArea to accept ALT09 as Tab (or as alternative split on the location).
JTextArea is not getting Tab at all. Tab is interrupted by whole GUI interface to switch to next editable field. Of course you can bend this rule, intercept Tab on parent container and force it to send it to the child JTextArea and then you can even write your won method for KeyPressed event and insert Tab character into the text but it's good approach because it changes user experience. User expects Tab to go to next field but for this particular text area you say that it should be delimiter for your text? Another reason - Tab is similar for Space - so in user experience it's not clear was input right or not.
To avoid all these troubles why not take simple approach:
SerialNumber=ProductNumber
It is clear, visible, predictable, understandable and most off all - doesn't required your question ;)

Hovering Dialogue Box

I am creating a log in form in Java. I have already completed the entire structure of the program, as well, I have designed it's purpose and perfected it's functionality. However, now I am focusing on styling the program. I'm proud of it as it is and it's fine if I don't add this feature, however I really would like to and cannot discover how.
In summary, when a username is typed into the login form, I have a void that runs after the JTextField loses focus. This void searches for possible invalid characters such as spaces. I can successfully change the color of the border on my JTextField, and other attributes I wish to change, however I also would like to have a small dialogue box to hover over the JTextField to say what specifically is wrong with what was typed. (e.g. "Your username cannot contain spaces!").
Ideally, it would be a rectangle that could simply be filled with text, and only appear when the username is deemed incorrect, and be able to disappear when it is fixed ( I can handle the appearance and disappearance most likely, I just need help with creating this box thing ).
Is there any such thing as like a "JHoverBox" or something that I could add to my JTextField?
Well, you can have, as Gene said, a label that's normally empty near the text field, but you can have it coloured like the background colour. This will make the user not able to see it, and when you detect something wrong, you can change the colour and add the text. Simple!

How to use TextChanged event?

I have a text box in which the user enters a unique number. After he enters a number and press tab or enter. I want to write query to search record matching to that unique number. The number is an integer. It will be passport no, pan card no or etc. If it is available in database, I want to display all information of that user.
I don't want to do that on button click.
I was looking for some TextChanged event but I found that the alternative in Java is the methods in document listener. But I am not getting how to use that. Also in Netbeans in the design view it does not show me any event on text changed. How to use Documentlistener to my JFrame/how to fix this?
Here you can find a tutorial on DocumentListeners and example code as well.

How do I fire an action when the user leaves a JTextBox?

I've got a JTextField, and I'd like the system to do some processing on what the user typed whenever the user leaves the text field. The ActionListener that you can add to just the JTextField only fires when the user presses enter, however.
I'd like the processing routine to run whenever the user leaves the text box by any means - tabs, clicks out of it, presses enter, etc. (The processing in question is to save the text the user typed to the appropriate data object, nothing fancy.)
My google-fu has failed on this one: I'm confident that it's possible, I just can't see how.
Add a FocusListener.
It's worth noting that this is a relatively low-level listener. On JComboBox it wont work unless you find the text field (and perhaps button) that the particular PL&F inserts. Swing is a bit odd that way (amongst many other ways).
Although for my money, non-cosmetic changes that happen when focus leaves a field give poor user experience. Much better to do any relevant changes on every change with a listener on the text field's document.
If you want to edit the text as it is typed then you should use an DocumentFilter.
If you want to validate the text as a complete entity then you can use an InputVerifier.

Categories

Resources