ItEr29S13CUVistaRecursosTempoEmpresa: Removing indirection in order to simplify code

Planner was being accessed from OrderPlanningModel so IConfigurationOnTransaction wasn't achieving its mission.
This commit is contained in:
Óscar González Fernández 2009-10-07 00:16:41 +02:00
parent b64b8bafa5
commit 293c5d18e0
3 changed files with 24 additions and 62 deletions

View file

@ -21,28 +21,20 @@
package org.navalplanner.web.planner;
import org.navalplanner.business.orders.entities.Order;
import org.navalplanner.business.planner.entities.TaskElement;
import org.navalplanner.web.common.ViewSwitcher;
import org.navalplanner.web.planner.allocation.ResourceAllocationController;
import org.zkoss.ganttz.Planner;
import org.zkoss.ganttz.adapters.PlannerConfiguration;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public interface IOrderPlanningModel {
public interface IConfigurationOnTransaction {
public void use(PlannerConfiguration<TaskElement> configuration);
public Planner getPlannerBeingConfigured();
}
void createConfiguration(Order order, ViewSwitcher viewSwitcher,
void setConfigurationToPlanner(Planner planner, Order order,
ViewSwitcher viewSwitcher,
ResourceAllocationController resourceAllocationController,
EditTaskController editTaskController,
SplittingController splittingController,
CalendarAllocationController calendarAllocationController,
IConfigurationOnTransaction onTransaction);
CalendarAllocationController calendarAllocationController);
}

View file

@ -21,18 +21,15 @@
package org.navalplanner.web.planner;
import org.navalplanner.business.orders.entities.Order;
import org.navalplanner.business.planner.entities.TaskElement;
import org.navalplanner.web.common.ViewSwitcher;
import org.navalplanner.web.common.entrypoints.IURLHandlerRegistry;
import org.navalplanner.web.common.entrypoints.URLHandler;
import org.navalplanner.web.planner.IOrderPlanningModel.IConfigurationOnTransaction;
import org.navalplanner.web.planner.allocation.ResourceAllocationController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.zkoss.ganttz.Planner;
import org.zkoss.ganttz.adapters.PlannerConfiguration;
import org.zkoss.ganttz.resourceload.ScriptsRequiredByResourceLoadPanel;
import org.zkoss.ganttz.util.OnZKDesktopRegistry;
import org.zkoss.ganttz.util.script.IScriptsRegister;
@ -88,22 +85,9 @@ public class OrderPlanningController implements
@Override
public void showSchedule(Order order) {
model.createConfiguration(order, viewSwitcher,
resourceAllocationController,
editTaskController, splittingController,
calendarAllocationController,
new IConfigurationOnTransaction() {
@Override
public void use(PlannerConfiguration<TaskElement> configuration) {
planner.setConfiguration(configuration);
}
@Override
public Planner getPlannerBeingConfigured() {
return planner;
}
});
model.setConfigurationToPlanner(planner, order, viewSwitcher,
resourceAllocationController, editTaskController,
splittingController, calendarAllocationController);
}
public void registerPlanner(Planner planner) {

View file

@ -90,12 +90,12 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
@Override
@Transactional(readOnly = true)
public void createConfiguration(Order order, ViewSwitcher switcher,
public void setConfigurationToPlanner(Planner planner, Order order,
ViewSwitcher switcher,
ResourceAllocationController resourceAllocationController,
EditTaskController editTaskController,
SplittingController splittingController,
CalendarAllocationController calendarAllocationController,
IConfigurationOnTransaction onTransaction) {
CalendarAllocationController calendarAllocationController) {
Order orderReloaded = reload(order);
if (!orderReloaded.isSomeTaskElementScheduled())
throw new IllegalArgumentException(_(
@ -139,46 +139,32 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
Chart chartComponent = new Chart();
configuration.setChartComponent(chartComponent);
planner.setConfiguration(configuration);
withChartFilling(onTransaction, orderReloaded, chartComponent).use(
configuration);
setupChart(orderReloaded, chartComponent, planner.getTimeTracker());
}
private void setupChart(Order orderReloaded, Chart chartComponent,
TimeTracker timeTracker) {
fillChart(orderReloaded, chartComponent, timeTracker
.getRealInterval(), timeTracker.getHorizontalSize());
fillChartOnZoomChange(orderReloaded, chartComponent, timeTracker);
}
private IZoomLevelChangedListener zoomListener;
private IConfigurationOnTransaction withChartFilling(
final IConfigurationOnTransaction onTransaction,
final Order order,
final Chart chartComponent) {
return new IConfigurationOnTransaction() {
private void fillChartOnZoomChange(final Order order, final Chart chartComponent, final TimeTracker timeTracker) {
zoomListener = new IZoomLevelChangedListener() {
@Override
public Planner getPlannerBeingConfigured() {
return onTransaction.getPlannerBeingConfigured();
}
@Override
public void use(PlannerConfiguration<TaskElement> configuration) {
onTransaction.use(configuration);
final Planner planner = getPlannerBeingConfigured();
final TimeTracker timeTracker = planner.getTimeTracker();
public void zoomLevelChanged(ZoomLevel detailLevel) {
fillChart(order, chartComponent, timeTracker.getRealInterval(),
timeTracker.getHorizontalSize());
zoomListener = new IZoomLevelChangedListener() {
@Override
public void zoomLevelChanged(ZoomLevel detailLevel) {
fillChart(order, chartComponent, timeTracker
.getRealInterval(), timeTracker
.getHorizontalSize());
}
};
timeTracker.addZoomListener(zoomListener);
}
};
timeTracker.addZoomListener(zoomListener);
}
private PlannerConfiguration<TaskElement> createConfiguration(