Child field event handling issue in custom HorizontalFieldManager - blackberry

I am trying to create a customized list field where, I have more then 2 clickable buttons in each row. For that i have customized the HorizontalFieldManager and created own manager to align the field elements. Now UI is perfectly fine.
But, I am struggling to handle the events work for both.
Step-1 I have used fieldChangedListener for buttons added in row. It is working fine
public void fieldChanged(Field field, int context) {}
step-2 have used navigation click to handle event on the parent manager.
protected boolean navigationClick(int status, int time) {
Field field = getFieldWithFocus();
Dialog.alert("shops field clicked");
return super.navigationClick(status, time);
}
Now, even the navigationClick event works. But as the button is the child field added to VFM. When i click on the button both the VFM and button event comes together.
How could i restrict only to the button while it is clicked on the ButtonField.

If I understood your question correctly, you want the navigationClick() to be called only for the child field (clickable button) without being called for the manager. Sorry to disappoint you, but you can't.The navigation click event will always be called first for the manager and only than the manager will propagate the event to the child field. The same hold for keys events, touch events, focus events and etc...
Describe what you are trying to achieve, add a code snippet and I am sure we will find a solution.

Related

How to make content navigation button (remains pressed when clicked) in Vaadin

I created basic vertical layout that work as side menu and now I want to place some buttons in it. Few of them gonna work as common side menu buttons, they just change page content so I want to mark that they are clicked in some way, how can I achive that? Or maybe there is better way?
As stated in the 5th version of Vaadin7 manual, you can attach an event listener to the Button.
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
// show the button has been clicked with a CSS class:
button.addStyleName("v-button-clicked");
}
});
Don’t forget to define the v-button-clicked class. Of course you’re free to add the class of your liking through the .addStyleName() method.

Vaadin: force Button to be visually disabled

I have several TextField's inside a window along with a Button, e.g. aButton.
The TextField's, Button, and window all have setImmediate(True).
When a TextField loses focus some validation code is executed and if it fails it calls:
aButton.setEnabled(False);
When incorrect data is entered into one TextField and then focus is lost the debugger shows that aButton.setEnabled(False) is called but aButton still looks enabled.
Two possible things can happen from here:
1.) If one modifies data in another TextField and exits that field (loses focus), the validation can be successful or not for that field but the system knows to call aButton.setEnabled(False) as the previous TextField is still invalid. This time though aButton is visually disabled.
2.) If one clicks on aButton which is visually enabled it produces this warning then visually becomes disabled:
Warning: Ignoring variable change for disabled component < class 'ui.button.Button'>, caption=OK
Currently using Vaadin 6.7.3
Are there any known work arounds to force aButton to visually become disabled immediately (force the client to update) after manually setting it to be disabled?
Sadly I have only Vaadin 7 at my disposal right now, but I checked this anyway. It works as you wanted it to work and I have to jump to the conclusion that this should be the same in Vaadin 6.7.3. This part is not really different in Vaadin7... Have you tried this feature in an isolated code (only a textbox and the button)?
VerticalLayout vlTestContent = new VerticalLayout();
final Button butChangeMe = new Button("Enabled");
final TextField tf = new TextField("Blur", "default value");
tf.addBlurListener(new BlurListener() {
private static final long serialVersionUID = 5544993392287938660L;
#Override
public void blur(BlurEvent event) {
butChangeMe.setCaption("Disabled");
butChangeMe.setEnabled(false);
}
});
Button but = new Button("Change button", new ClickListener() {
private static final long serialVersionUID = -2235317499126190105L;
#Override
public void buttonClick(ClickEvent event) {
butChangeMe.setCaption("Enabled");
butChangeMe.setEnabled(true);
}
});
vlTestContent.addComponent(butChangeMe);
vlTestContent.addComponent(tf);
vlTestContent.addComponent(but);
(The second button is just for fun)
button.setVisible(false) will always work. You need to be careful to not fire up a another event on the focus lost event that ends up setting the visibility of the button to true.
You can request a repaint of a component or the whole window, but the whole point of the framework is that you will never need to do that, because visually modified components will automatically repaint on each request.
Just to be curious, do you let your request to finish before trying to see if the browser updates? Or you look at your browser right after you pass the setVisible() line in your debugger ?
I think that your point nr 2 happens because you clicked on the button, and what happens in this order is: 1st your focus lost event runs (which probably disables your button), 2nd button click runs and somehow a repaint is requested for that button because a state change happened in the button but a repaint show the warning that it won't do anything with it because it is disabled (was just disable by the focus lost event)
As a side note. I think this UI won't make for a good user experience, it should be the other way arround, if a validation is ok, then show the button (or better, always show the button, but enable/disable instead) But it depends...

ButtonField click event

i am not implementing touch event. i am using FieldChangeListener the problem which i am facing is , if i am clicking outside the CustomButtonField then also the click event is generated how should i restrict only to the CustomButtonField.
Thanks alot
The listener will be invoked on all change events but you also get the field that changed (in the fieldChanged function), so why not use that to make sure it is your field that was "changed"?

How to move the focus to the next component in Blackberry?

Can anyone tell me how to move the focus to the next component in the screen?
I have one verticalmanager with verticalscroll. This vertical field manager consists of an edit field with approximately 100 lines of data. Below this vertical field manager I have one button. If I want to move my focus to that button it means I have to pass through all those 100 lines in that edit field.
Is there another way to pass the focus to the button directly by clicking a single button?
Based on Richard's answer and your comment, I think the correct way to set the focus on the submit button when the ESC key is pressed in the edit field is as follows:
public boolean keyChar(char key, int status, int time)
{
if (key==Characters.ESCAPE)
{
submit.setFocus();
}
return super.keyChar(key, status, time);
}
Note: The use of the ESCAPE key might not be the best option. You might want to check if a modifier key (such as Alt) is pressed by checking the status argument and set the focus in that case. You are advised to use your discernment when using this code.
You would have to extend one of the containers of the edit field, process key presses looking for the key press you select (it will have to be one not consumed by the edit field). When received call the setFocus() method on the button.
You could make the field with the 100 lines of text unfocusable. When it is unfocusable, and you scroll over it, the cursor should skip the 100 lines, and go straight to the button at the bottom.
There are options:
use navigationMove (if dx > some value) if edit field not in edit mode
use menu instead of buttons
use hotkeys
use paging in list so there will be no scrolling

Blackberry trackball click, instead of responding to event, context menu is shown why?

I'm running into the following scenario on some devices: when the use clicks on field and expects an response, instead of properly responding to that click event, the device shows the context menu at the bottom center of the screen.
navigationUnclick and trackwheelUnclick
From what I've read, I can override navigationUnclick and trackwheelUnclick to prevent the menu from showing. I'm doing this as the screen level but reproducing the centered-menu scenario is difficult. Is this the correct approch?
Why does this happen? Is there any way to resolve this?
I recently had this happening. I was extending MainScreen to provide some basic functionality, but didn't want the context menus. Returning true from navigationClick() removed this behavior.
public class MyScreen extends MainScreen {
protected boolean navigationClick(int status, int time) {
/*
... custom behavior ...
*/
return true;
// the following line would trigger the context menu
//return super.navigationClick(status, time);
}
}
I didn't need to override navigationUnclick() at all. Unlike #JustinD's approach with override onMenu(), this only prevents the menu from this certain case -- not across the entire screen (which you may want, and that would probably be a better way to do it).
Anyway, that's been my experience with clicks and menus recently.
Can you post your code? Try overriding trackwheelClick and navigationClick instead of the Unlick methods. Also make sure you return true in these methods.
If you override onMenu and just return true (you handled the menu event) then the menu will not show up...assuming you don't need a full menu either - if you want full menu and not context menu then just do what Jan said and you should be fine - make sure to return true or else the event will bubble up and end up with the menu being generated
public class MyClass Extends MainScreen
{
///
// Override onMenu to prevent menu from coming up when you click trackwheel
public boolean onMenu(int instance)
{
return true;
}
}
You could use CONSUME_CLICK style on all Fields in your MainScreen...

Resources