ZK 8.5.0 how to override button widget setLabel function - java

The ZK setLabel() function of Button widget does not work; when the code runs to the line like foobutton.setLabel(mystring), the button disappears from the browser.
In the eclipse IDE, if I hover on the setLabel() function, the IDE shows this message:
If label is changed, the whole component is invalidate.Thus, you want to smart-update, you have to override this method.
Using ZK 8.5.0
Inside the controller class, I declare:
#Wire
Button delSelectedMonitor;
Inside the controller, I implement a class which implements EventListener:
public class onClickHolderEditMode implements EventListener{
public void onEvent(Event event) throws Exception {
clickedDivEditMode = (Div) event.getTarget();
clickedDivIdEditMode = clickedDivEditMode.getId().split(myUtil.monitorholderString)[1];
String curName = getCamNameById(clickedDivIdEditMode);
delSelectedMonitor.setLabel("DELETE:"+clickedDivIdEditMode+","+curName);
}
}
event binding:
tmpdiv.addEventListener("onClick", new onClickHolderEditMode());
My expectation is that when someone clicks the tmpdiv, the button delSelectedMonitor will change its label according to the property of tmpdiv. However as I say previously, the button is just disappearing.
https://www.zkoss.org/wiki/ZK_Client-side_Reference/General_Control/Widget_Customization
I have tried the section "Specify Your Own Widget Class" at the above website link, but the browser will be pending.
Please help, thank you.

I would prefer a different approach.
Why not use a
<button label="#load(vm.xyz)" ... />
(I wrote using MVVM pattern) and modify variable xyz in clicking action?
Check out http://books.zkoss.org/zk-mvvm-book/8.0/syntax/load.html for implementing guide.

Related

Using one JavaFX method for multiple Buttons

Right now I'm using Eclipse Luna, JavaFX and SceneBuilder. I have ~40 buttons, and I'd like to use a generic "buttonPressed" action method that every button can use. Something like this:
public void buttonPressed(ActionEvent event, Button b) {
b.setText("Pressed");
}
When I change the On Action panel in SceneBuilder however, I get the following Exception when I try to run my program:
javafx.fxml.LoadException: Error resolving onAction='#buttonPressed', either the event handler is not in the Namespace or there is an error in the script.
Is there a step I missed? Or does anyone know of an alternate way to use one method to control the on-click behavior of multiple buttons?
Any help appreciated!
As in your comment, the only signatures allowed for an onAction attribute are either zero arguments, or a single argument which is an ActionEvent.
You can get the source of the event as follows:
#FXML
public void buttonPressed(ActionEvent event) {
Object source = event.getSource();
// ...
}
and of course if you know you only registered the handler on buttons, you can do
#FXML
public void buttonPressed(ActionEvent event) {
Button button = (Button) event.getSource();
// ...
}

Javafx : Disabling Menu (MenuButton) auto close

I have a MenuButton that contains only CheckMenuItems. My user will usually check several items and if he has to re-open the menu for each one, he will soon throw his mouse through the screen.
I choose to use a menubutton rather than a combobox because it seems that it's not possible to put checkboxes into a combobox (https://community.oracle.com/thread/2598157).
Anyone has an idea ?
Thank you very much,
Léo
Consider in addition to the menu items to provide a toolbar with toggle buttons.
Note: Drombler FX provides an action framework to keep the state and logic between menu items and toolbar buttons in sync. It supports CheckMenuItems and toggle buttons as well.
Disclaimer: I'm the author of Drombler FX.
Getting Started: http://wiki.drombler.org/GettingStarted
Blog: http://puces-blog.blogspot.ch/search/label/Drombler
This worked for me:
#FXML
public void autoShow() {
checkmenuitem.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
e.consume();
}
});
}
checkmenuitem is the id. When it is clicked, the handle method is executed. For a detailed explanation on the event.consume() method, see this:
What is the meaning of Event consumes in JavaFX
Place the above method in your controller class and then call it from the initialize method in your controller class:
#Override
public void initialize(URL location, ResourceBundle resources) {
autoShow();
}

GWT Auto Refresh Code Jumps To Home Page

We want to auto refresh a page that is built using GWT 2. We used a lot of solutions to do it:
GWT auto refresh
automatic refresh of GWT screen
But neither of them worked properly. The problem is a bit complicated:
The auto refresh works in the home page/tab called "Kazalar":
http://dl.dropbox.com/u/103580364/temp/000766.jpg
But if the user is in another tab then after auto refresh the browser jumps to home page/tab:
http://dl.dropbox.com/u/103580364/temp/000767.jpg
In the above question's answer, the answerer says that we should replace the reloadAll() function with code that recreates that part's view (with some Ajax calls to re-fetch data from server if needed). We couldn't test this part because we don't know how to write the code that recreates a specific part's view. Could someone please give an example on how to do it?
public class TimerExample implements EntryPoint, ClickListener {
public void onModuleLoad() {
Button b = new Button("Click and wait 5 minutes");
b.addClickListener(this);
RootPanel.get().add(b);
}
public void onClick(Widget sender) {
Timer t = new Timer
public void run() {
reloadAll();
}
};
// Schedule the timer to run once in 5 minutes.
t.schedule(5*1000*60);
}
private void reloadAll() {
Window.Location.reload();
}
}
Using a timer is fine.
Assuming you know about GWT activities and places.
The harsh way would be to reload the full module using
Window.Location.replace("url#kalazar:");
You already mentionned it; but a really nicer way (assuming you are implemeting the MVP pattern) would be to create a refresh method on the presenter of the Kalazar view. This way you won't need to reload the page.
private void reloadAll() {
myKalazarPresenter.refresh();
}
private void myKalazarPresenter() {
myKalazarView.clear();
myKalazerView.reInit(kalazarInitializationData);
}
Since you say you can't reInit the view, maybe you could just try to delete and recreate it ?

How to get the TrimBar of a TrimWindow in Eclipse RCP 4?

I put a toolbar on the top of my TrimmedWindow in my application. I have a handler which has to check whether a check button is pressed on this menu bar or not.
I tried putting EMenuService in my execute() method of the handler but it has no useful methods. If I debug into my application I can see my menu in the EMenuService object however.
How can I get my menu from the Eclipse context?
Without code it's hard to help you.
But the basic idea for your handler is the following :
public class BrokerHandler {
#Inject
// the services you need
#Execute
public void execute(IEclipseContext context, #Named(IServiceConstants.ACTIVE_SHELL) Shell shell)
throws InvocationTargetException, InterruptedException {
// do some stuff
}
}
Then, in your application.e4xmi you need to create a Window>Trimmed Window>Trim Bars>Window Trim>Toolbar>Handled Tool Item wich points to your Commands>Command that is binded to your Handlers>Handler pointing to your java class with a method annotated #Execute as described above.
Then each execution of the #Execute method means the user has pressed the toolbar button.
You can pass messages to other parts of your app with the event broker service, or store some of your own stuff in the IEclipseContext.
You can have a look here: http://xseignard.github.com/demoCamp2012/prez/#1
Hope this helps, but your question is too blurry.

How to add listener to Application Editor in the Eclipse?

I am writing a Eclipse RCP Plug-in for displaying the properties of objects displayed in application editor.
My plug-in extends PageBookView. Every time, i select a new object is opened on the ApplicationEditor(which is Canvas widget),i create a new page & save the old page.
ApplicationEditor extends EditorPart. It fires propertyChange events when the objects (on the active editor changes). All i want is to add listener to applicationEditor. When the required event fires, i have to update my page.
Let me put it in a simmple way.
public Class MyPage implements IPage implements **WHICH_LISTENER**
{
public MyPage(ApplicationEditor editor)
{
this.addPropertyChangeListener(editor);
}
. . . . . .
}
Which Listener should i implement to refresh the page by propertyChange().?
PS: Thanks in advance for your precious advices. Feel free to question me for further clarity in the Question! I cannot change the editor design or code, as i am trying to contribute to an open source project OpenVXML.
Your approach of notifying UI-Elements is not optimal. Your UI-Elements should register listeners to the objects which are changing. The question which listener to implement to the editor depends on which object the editor is listen to. In your case the PageBookView needs a reference to ApplicationEditor to register itself, which is not good, because 1. the PageBookView has an unneccessary dependency to the editor and 2) the editor is not responsible for propagating changes, but the object itself. I would do the following.
Your Editor:
public class MyEditor extends EditorPart implements PropertyChangeListener
public void init(IEditorSite site, IEditorInput input) {
// Getting the input and setting it to the editor
this.object = input.getObject();
// add PropertyChangeListener
this.object.addPropertyChangeListener(this)
}
public void propertyChanged(PropertyChangeEvents) {
// some element of the model has changed. Perform here the UI things to react properly on the change.
}
}
The same thing needs to be done on your pageBook.
public class MyPropertyView extends PageBook implements PropertyChangeListener{
initModel() {
// you have to pass the model from the editor to the depending pageBook.
this.model = getModelFromEditor()
this.object.addPropertyChangeListener(this)
}
public void propertyChanged(PropertyChangeEvents) {
// some element of the model has changed. Perform here the UI things to react properly on the change.
}
}
As you can see both UI Elements are reacting directly to the changes in the model.
Another way of displaying objects in an editor is to use ProperyViews, for an further description see http://www.eclipse.org/articles/Article-Tabbed-Properties/tabbed_properties_view.html
A time ago, I've written a simple example for all this notification stuff in Eclipse see here.
HTH Tom

Categories