ItEr45S19CUTraspasoDeResponsabilidadesTraballoEntreUnidadesPlanificacion: Communicating the action choosen at interface with reassigning command
This commit is contained in:
parent
46aefa250d
commit
9de00bd136
3 changed files with 101 additions and 4 deletions
|
|
@ -21,6 +21,7 @@ package org.navalplanner.web.planner.reassign;
|
|||
|
||||
import static org.navalplanner.business.i18n.I18nHelper._;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
|
@ -35,9 +36,23 @@ import org.zkoss.ganttz.extensions.IContext;
|
|||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class ReassignCommand implements IReassignCommand {
|
||||
|
||||
public interface IConfigurationResult {
|
||||
public void result(ReassignConfiguration configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction(IContext<TaskElement> context) {
|
||||
ReassignController.openOn(context.getRelativeTo());
|
||||
ReassignController.openOn(context.getRelativeTo(),
|
||||
new IConfigurationResult() {
|
||||
@Override
|
||||
public void result(ReassignConfiguration configuration) {
|
||||
doReassignation(configuration);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void doReassignation(ReassignConfiguration configuration) {
|
||||
Validate.notNull(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.navalplanner.web.planner.reassign;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.web.planner.reassign.ReassignController.Type;
|
||||
import org.zkoss.ganttz.data.Task;
|
||||
|
||||
/**
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*
|
||||
*/
|
||||
public class ReassignConfiguration {
|
||||
|
||||
public static ReassignConfiguration create(Type type,
|
||||
LocalDate date) {
|
||||
return new ReassignConfiguration(type, date);
|
||||
}
|
||||
|
||||
private ReassignController.Type type;
|
||||
|
||||
private LocalDate date;
|
||||
|
||||
private ReassignConfiguration(ReassignController.Type type, LocalDate date) {
|
||||
this.type = type;
|
||||
Validate.isTrue(!type.needsAssociatedDate() || date != null);
|
||||
this.date = date == null ? new LocalDate() : date;
|
||||
}
|
||||
|
||||
public List<Task> filterForReassignment(List<Task> list) {
|
||||
List<Task> result = new ArrayList<Task>();
|
||||
for (Task each : list) {
|
||||
if (each.isLeaf() && isChoosenForReassignation(each)) {
|
||||
result.add(each);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isChoosenForReassignation(Task each) {
|
||||
return type == Type.ALL || isAfterDate(each);
|
||||
}
|
||||
|
||||
private boolean isAfterDate(Task each) {
|
||||
LocalDate start = LocalDate.fromDateFields(each.getBeginDate());
|
||||
LocalDate end = LocalDate.fromDateFields(each.getEndDate());
|
||||
return start.compareTo(date) > 0 || end.compareTo(date) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -25,6 +25,8 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.web.planner.reassign.ReassignCommand.IConfigurationResult;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -105,12 +107,13 @@ public class ReassignController extends GenericForwardComposer {
|
|||
|
||||
}
|
||||
|
||||
public static void openOn(org.zkoss.zk.ui.Component component) {
|
||||
public static void openOn(org.zkoss.zk.ui.Component component,
|
||||
IConfigurationResult configurationResult) {
|
||||
Window result = (Window) Executions.createComponents(
|
||||
"/planner/reassign.zul", component, Collections.emptyMap());
|
||||
ReassignController controller = (ReassignController) result
|
||||
.getAttribute("controller");
|
||||
controller.showWindow();
|
||||
controller.showWindow(configurationResult);
|
||||
}
|
||||
|
||||
private Window window;
|
||||
|
|
@ -123,7 +126,10 @@ public class ReassignController extends GenericForwardComposer {
|
|||
|
||||
private Type currentType = Type.ALL;
|
||||
|
||||
private void showWindow() {
|
||||
private IConfigurationResult configurationResult;
|
||||
|
||||
private void showWindow(IConfigurationResult configurationResult) {
|
||||
this.configurationResult = configurationResult;
|
||||
try {
|
||||
window.setMode("modal");
|
||||
} catch (InterruptedException e) {
|
||||
|
|
@ -192,6 +198,11 @@ public class ReassignController extends GenericForwardComposer {
|
|||
}
|
||||
}
|
||||
window.setVisible(false);
|
||||
LocalDate associatedDate = this.associatedDate.getValue() != null ? LocalDate
|
||||
.fromDateFields(this.associatedDate.getValue())
|
||||
: null;
|
||||
configurationResult.result(ReassignConfiguration
|
||||
.create(currentType, associatedDate));
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue