2009-10-01 18:46:46 +02:00
|
|
|
/*
|
2010-02-04 06:57:00 +01:00
|
|
|
* This file is part of NavalPlan
|
2009-10-01 18:46:46 +02:00
|
|
|
*
|
|
|
|
|
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
|
|
|
|
* Desenvolvemento Tecnolóxico de Galicia
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-07-20 15:37:40 +02:00
|
|
|
package org.zkoss.ganttz;
|
|
|
|
|
|
2010-01-28 18:27:43 +01:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2009-07-20 15:37:40 +02:00
|
|
|
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();
|
2010-01-28 18:27:43 +01:00
|
|
|
if (StringUtils.isEmpty(command.getImage())) {
|
2010-01-27 14:28:37 +01:00
|
|
|
result.setLabel(command.getName());
|
|
|
|
|
} else {
|
|
|
|
|
result.setImage(command.getImage());
|
|
|
|
|
result.setTooltiptext(command.getName());
|
|
|
|
|
}
|
2009-07-20 15:37:40 +02:00
|
|
|
result.addEventListener(Events.ON_CLICK, new EventListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onEvent(Event event) throws Exception {
|
|
|
|
|
doAction();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|