ItEr32S09ValidacionEProbasFuncionaisItEr31S12: [Bug #66] Using new class LoadChart to simplify the call to refill the chart
This commit is contained in:
parent
b1e42069b0
commit
4d3acfb5f1
3 changed files with 85 additions and 40 deletions
|
|
@ -89,8 +89,6 @@ public abstract class CompanyPlanningModel implements ICompanyPlanningModel {
|
|||
|
||||
private IZoomLevelChangedListener zoomListener;
|
||||
|
||||
private ILoadChartFiller loadChartFiller = new CompanyLoadChartFiller();
|
||||
|
||||
private final class TaskElementNavigator implements
|
||||
IStructureNavigator<TaskElement> {
|
||||
@Override
|
||||
|
|
@ -139,35 +137,30 @@ public abstract class CompanyPlanningModel implements ICompanyPlanningModel {
|
|||
}
|
||||
|
||||
private void setupChart(Timeplot chartComponent, TimeTracker timeTracker) {
|
||||
loadChartFiller.fillChart(chartComponent,
|
||||
timeTracker.getRealInterval(), timeTracker
|
||||
.getHorizontalSize());
|
||||
fillChartOnZoomChange(chartComponent, timeTracker);
|
||||
LoadChart loadChart = new LoadChart(chartComponent,
|
||||
new CompanyLoadChartFiller(), timeTracker);
|
||||
loadChart.fillChart();
|
||||
timeTracker.addZoomListener(fillOnZoomChange(loadChart));
|
||||
}
|
||||
|
||||
private void fillChartOnZoomChange(final Timeplot chartComponent,
|
||||
final TimeTracker timeTracker) {
|
||||
private IZoomLevelChangedListener fillOnZoomChange(
|
||||
final LoadChart loadChart) {
|
||||
|
||||
zoomListener = new IZoomLevelChangedListener() {
|
||||
|
||||
@Override
|
||||
public void zoomLevelChanged(final ZoomLevel detailLevel) {
|
||||
loadChartFiller.setZoomLevel(detailLevel);
|
||||
|
||||
transactionService
|
||||
.runOnReadOnlyTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
loadChartFiller.fillChart(chartComponent,
|
||||
timeTracker.getRealInterval(),
|
||||
timeTracker.getHorizontalSize());
|
||||
loadChart.fillChart();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
timeTracker.addZoomListener(zoomListener);
|
||||
return zoomListener;
|
||||
}
|
||||
|
||||
private PlannerConfiguration<TaskElement> createConfiguration() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.zkforge.timeplot.Timeplot;
|
||||
import org.zkoss.ganttz.timetracker.TimeTracker;
|
||||
|
||||
/**
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*
|
||||
*/
|
||||
public class LoadChart {
|
||||
|
||||
private final Timeplot timeplot;
|
||||
private final ILoadChartFiller filler;
|
||||
private final TimeTracker timeTracker;
|
||||
|
||||
public LoadChart(Timeplot timeplot, ILoadChartFiller filler,
|
||||
TimeTracker timeTracker) {
|
||||
Validate.notNull(filler);
|
||||
Validate.notNull(timeTracker);
|
||||
Validate.notNull(timeplot);
|
||||
this.timeplot = timeplot;
|
||||
this.filler = filler;
|
||||
this.timeTracker = timeTracker;
|
||||
}
|
||||
|
||||
void fillChart() {
|
||||
filler.fillChart(timeplot, timeTracker.getRealInterval(), timeTracker.getHorizontalSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -89,8 +89,6 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
private LocalDate maxDate;
|
||||
|
||||
private ILoadChartFiller loadChartFiller;
|
||||
|
||||
private final class TaskElementNavigator implements
|
||||
IStructureNavigator<TaskElement> {
|
||||
@Override
|
||||
|
|
@ -146,7 +144,16 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
planner.setConfiguration(configuration);
|
||||
|
||||
setupChart(orderReloaded, chartComponent, planner.getTimeTracker(), saveCommand);
|
||||
LoadChart loadChart = setupChart(orderReloaded, chartComponent, planner
|
||||
.getTimeTracker());
|
||||
refillLoadChartWhenNeeded(planner, saveCommand, loadChart);
|
||||
}
|
||||
|
||||
private void refillLoadChartWhenNeeded(Planner planner,
|
||||
ISaveCommand saveCommand,
|
||||
LoadChart loadChart) {
|
||||
planner.getTimeTracker().addZoomListener(fillOnZoomChange(loadChart));
|
||||
saveCommand.addListener(fillChartOnSave(loadChart));
|
||||
}
|
||||
|
||||
private void addAdditional(List<ICommand<TaskElement>> additional,
|
||||
|
|
@ -205,41 +212,36 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
return saveCommand;
|
||||
}
|
||||
|
||||
private void setupChart(Order orderReloaded, Timeplot chartComponent,
|
||||
TimeTracker timeTracker, ISaveCommand saveCommand) {
|
||||
loadChartFiller = new OrderLoadChartFiller(orderReloaded);
|
||||
loadChartFiller.fillChart(chartComponent, timeTracker
|
||||
.getRealInterval(), timeTracker.getHorizontalSize());
|
||||
fillChartOnZoomChange(chartComponent, timeTracker);
|
||||
fillChartOnSave(chartComponent, timeTracker, saveCommand);
|
||||
private LoadChart setupChart(Order orderReloaded, Timeplot chartComponent,
|
||||
TimeTracker timeTracker) {
|
||||
OrderLoadChartFiller loadChartFiller = new OrderLoadChartFiller(
|
||||
orderReloaded);
|
||||
LoadChart result = new LoadChart(chartComponent, loadChartFiller,
|
||||
timeTracker);
|
||||
result.fillChart();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void fillChartOnZoomChange(final Timeplot chartComponent,
|
||||
final TimeTracker timeTracker) {
|
||||
private IZoomLevelChangedListener fillOnZoomChange(final LoadChart loadChart) {
|
||||
zoomListener = new IZoomLevelChangedListener() {
|
||||
|
||||
@Override
|
||||
public void zoomLevelChanged(ZoomLevel detailLevel) {
|
||||
loadChartFiller.setZoomLevel(detailLevel);
|
||||
|
||||
loadChartFiller.fillChart(chartComponent, timeTracker
|
||||
.getRealInterval(), timeTracker.getHorizontalSize());
|
||||
loadChart.fillChart();
|
||||
}
|
||||
};
|
||||
|
||||
timeTracker.addZoomListener(zoomListener);
|
||||
return zoomListener;
|
||||
}
|
||||
|
||||
private void fillChartOnSave(final Timeplot chartComponent,
|
||||
final TimeTracker timeTracker, ISaveCommand saveCommand) {
|
||||
saveCommand.addListener(new IAfterSaveListener() {
|
||||
private IAfterSaveListener fillChartOnSave(final LoadChart loadChart) {
|
||||
IAfterSaveListener result = new IAfterSaveListener() {
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void onAfterSave() {
|
||||
loadChartFiller.fillChart(chartComponent, timeTracker
|
||||
.getRealInterval(), timeTracker.getHorizontalSize());
|
||||
loadChart.fillChart();
|
||||
}
|
||||
});
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
private PlannerConfiguration<TaskElement> createConfiguration(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue