2009-07-20 15:37:40 +02:00
|
|
|
package org.zkoss.ganttz;
|
|
|
|
|
|
|
|
|
|
import org.zkoss.ganttz.extensions.ICommand;
|
|
|
|
|
import org.zkoss.ganttz.extensions.IContext;
|
|
|
|
|
import org.zkoss.zk.ui.event.Event;
|
|
|
|
|
import org.zkoss.zk.ui.event.EventListener;
|
|
|
|
|
import org.zkoss.zk.ui.event.Events;
|
|
|
|
|
import org.zkoss.zul.Button;
|
|
|
|
|
|
2009-07-20 15:37:41 +02:00
|
|
|
class CommandContextualized<T> {
|
2009-07-20 15:37:40 +02:00
|
|
|
|
2009-07-20 15:37:41 +02:00
|
|
|
public static <T> CommandContextualized<T> create(ICommand<T> command,
|
|
|
|
|
IContext<T> context) {
|
|
|
|
|
return new CommandContextualized<T>(command, context);
|
2009-07-20 15:37:40 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-20 15:37:41 +02:00
|
|
|
private final ICommand<T> command;
|
2009-07-20 15:37:40 +02:00
|
|
|
|
2009-07-20 15:37:41 +02:00
|
|
|
private final IContext<T> context;
|
2009-07-20 15:37:40 +02:00
|
|
|
|
2009-07-20 15:37:41 +02:00
|
|
|
private CommandContextualized(ICommand<T> command, IContext<T> context) {
|
2009-07-20 15:37:40 +02:00
|
|
|
this.command = command;
|
|
|
|
|
this.context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void doAction() {
|
|
|
|
|
command.doAction(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Button toButton() {
|
|
|
|
|
Button result = new Button();
|
|
|
|
|
result.setLabel(command.getName());
|
|
|
|
|
result.addEventListener(Events.ON_CLICK, new EventListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onEvent(Event event) throws Exception {
|
|
|
|
|
doAction();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|