Group data in class

FEA: ItEr75S11PreventLooseChanges
This commit is contained in:
Óscar González Fernández 2011-08-05 16:46:44 +02:00
parent 6543b9f771
commit 12d7d8bcad
4 changed files with 89 additions and 75 deletions

View file

@ -30,21 +30,13 @@ import org.navalplanner.business.planner.entities.TaskElement;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.web.planner.order.PlanningStateCreator.PlanningState;
import org.zkoss.ganttz.data.resourceload.LoadTimeLine;
import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
import org.zkoss.ganttz.util.Interval;
public interface IResourceLoadModel {
void initGlobalView(boolean filterByResources);
ResourceLoadDisplayData calculateDataToDisplay(boolean filterByResources);
void initGlobalView(PlanningState filterBy, boolean filterByResources);
List<LoadTimeLine> getLoadTimeLines();
Interval getViewInterval();
ZoomLevel calculateInitialZoomLevel();
ResourceLoadDisplayData calculateDataToDisplay(PlanningState filterBy,
boolean filterByResources);
Order getOrderByTask(TaskElement task);

View file

@ -171,19 +171,9 @@ public class ResourceLoadController implements Composer {
filterHasChanged = (filterByResources != currentFilterByResources);
currentFilterByResources = filterByResources;
if (filterBy == null) {
if (resourcesLoadPanel == null) {
resetAdditionalFilters();
}
resourceLoadModel.initGlobalView(filterByResources);
} else {
if (resourcesLoadPanel == null) {
deleteAdditionalFilters();
}
resourceLoadModel.initGlobalView(filterBy, filterByResources);
}
timeTracker = buildTimeTracker();
buildResourcesLoadPanel();
ResourceLoadDisplayData dataToShow = calculateDataToDisplay(filterByResources);
timeTracker = buildTimeTracker(dataToShow);
buildResourcesLoadPanel(dataToShow);
parent.getChildren().clear();
parent.appendChild(resourcesLoadPanel);
@ -196,6 +186,23 @@ public class ResourceLoadController implements Composer {
}
firstLoad = false;
}
private ResourceLoadDisplayData calculateDataToDisplay(
boolean filterByResources) {
if (filterBy == null) {
if (resourcesLoadPanel == null) {
resetAdditionalFilters();
}
return resourceLoadModel
.calculateDataToDisplay(filterByResources);
} else {
if (resourcesLoadPanel == null) {
deleteAdditionalFilters();
}
return resourceLoadModel.calculateDataToDisplay(filterBy,
filterByResources);
}
}
});
}
@ -254,10 +261,10 @@ public class ResourceLoadController implements Composer {
.size()]));
}
private TimeTracker buildTimeTracker() {
zoomLevel = (timeTracker == null) ? resourceLoadModel
.calculateInitialZoomLevel() : timeTracker.getDetailLevel();
return new TimeTracker(resourceLoadModel.getViewInterval(), zoomLevel,
private TimeTracker buildTimeTracker(ResourceLoadDisplayData dataToShow) {
zoomLevel = (timeTracker == null) ? dataToShow.getInitialZoomLevel()
: timeTracker.getDetailLevel();
return new TimeTracker(dataToShow.getViewInterval(), zoomLevel,
SeveralModificators.create(),
SeveralModificators.create(createBankHolidaysMarker()), parent);
}
@ -268,7 +275,7 @@ public class ResourceLoadController implements Composer {
return BankHolidaysMarker.create(defaultCalendar);
}
private void buildResourcesLoadPanel() {
private void buildResourcesLoadPanel(ResourceLoadDisplayData data) {
if (resourcesLoadPanel != null) {
if(bandBox != null) {
//if the filter has changed, we have to clear the model and
@ -290,15 +297,15 @@ public class ResourceLoadController implements Composer {
resourcesLoadPanel.setInternalPaginationDisabled(
!bandBox.getSelectedElements().isEmpty());
}
resourcesLoadPanel.init(resourceLoadModel.getLoadTimeLines(),
timeTracker);
resourcesLoadPanel.init(data.getLoadTimeLines(), timeTracker);
resourcesLoadPanel.setLoadChart(buildChart());
if(filterHasChanged) {
addNameFilterListener();
}
} else {
resourcesLoadPanel = new ResourcesLoadPanel(resourceLoadModel
.getLoadTimeLines(), timeTracker, parent, resourceLoadModel
resourcesLoadPanel = new ResourcesLoadPanel(
data.getLoadTimeLines(), timeTracker, parent,
resourceLoadModel
.isExpandResourceLoadViewCharts(), PaginationType.EXTERNAL_PAGINATION);
if(filterBy == null) {

View file

@ -0,0 +1,52 @@
package org.navalplanner.web.resourceload;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.joda.time.LocalDate;
import org.zkoss.ganttz.data.resourceload.LoadTimeLine;
import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
import org.zkoss.ganttz.util.Interval;
public class ResourceLoadDisplayData {
private final List<LoadTimeLine> timeLines;
private final Interval viewInterval;
public ResourceLoadDisplayData(List<LoadTimeLine> timeLines) {
this.timeLines = timeLines;
this.viewInterval = getViewIntervalFrom(timeLines);
}
private static Interval getViewIntervalFrom(List<LoadTimeLine> timeLines) {
if (timeLines.isEmpty()) {
return new Interval(new Date(), plusFiveYears(new Date()));
}
return LoadTimeLine.getIntervalFrom(timeLines);
}
private static Date plusFiveYears(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.YEAR, 5);
return calendar.getTime();
}
public List<LoadTimeLine> getLoadTimeLines() {
return timeLines;
}
public Interval getViewInterval() {
return viewInterval;
}
public ZoomLevel getInitialZoomLevel() {
Interval interval = getViewInterval();
return ZoomLevel.getDefaultZoomByDates(
new LocalDate(interval.getStart()),
new LocalDate(interval.getFinish()));
}
}

View file

@ -26,7 +26,6 @@ import static org.navalplanner.web.I18nHelper._;
import static org.navalplanner.web.planner.order.PlanningStateCreator.and;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@ -87,8 +86,6 @@ import org.zkoss.ganttz.data.GanttDate;
import org.zkoss.ganttz.data.resourceload.LoadPeriod;
import org.zkoss.ganttz.data.resourceload.LoadTimeLine;
import org.zkoss.ganttz.data.resourceload.TimeLineRole;
import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
import org.zkoss.ganttz.util.Interval;
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@ -118,9 +115,6 @@ public class ResourceLoadModel implements IResourceLoadModel {
@Autowired
private IScenarioManager scenarioManager;
private List<LoadTimeLine> loadTimeLines;
private Interval viewInterval;
private PlanningState filterBy;
private boolean filterByResources = true;
@ -171,20 +165,21 @@ public class ResourceLoadModel implements IResourceLoadModel {
@Override
@Transactional(readOnly = true)
public void initGlobalView(boolean filterByResources) {
public ResourceLoadDisplayData calculateDataToDisplay(boolean filterByResources) {
filterBy = null;
this.filterByResources = filterByResources;
doGlobalView();
return new ResourceLoadDisplayData(calculateLoadTimeLines());
}
@Override
@Transactional(readOnly = true)
public void initGlobalView(PlanningState filterBy, boolean filterByResources) {
public ResourceLoadDisplayData calculateDataToDisplay(PlanningState filterBy,
boolean filterByResources) {
this.filterBy = filterBy;
this.filterBy.reattach();
this.filterBy.reassociateResourcesWithSession();
this.filterByResources = filterByResources;
doGlobalView();
return new ResourceLoadDisplayData(calculateLoadTimeLines());
}
@Override
@ -220,22 +215,6 @@ public class ResourceLoadModel implements IResourceLoadModel {
return false;
}
private void doGlobalView() {
loadTimeLines = calculateLoadTimeLines();
if (!loadTimeLines.isEmpty()) {
viewInterval = LoadTimeLine.getIntervalFrom(loadTimeLines);
} else {
viewInterval = new Interval(new Date(), plusFiveYears(new Date()));
}
}
private Date plusFiveYears(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.YEAR, 5);
return calendar.getTime();
}
private List<LoadTimeLine> calculateLoadTimeLines() {
List<LoadTimeLine> result = new ArrayList<LoadTimeLine>();
if (filterByResources) {
@ -947,22 +926,6 @@ public class ResourceLoadModel implements IResourceLoadModel {
type, role);
}
@Override
public List<LoadTimeLine> getLoadTimeLines() {
return loadTimeLines;
}
@Override
public Interval getViewInterval() {
return viewInterval;
}
public ZoomLevel calculateInitialZoomLevel() {
Interval interval = getViewInterval();
return ZoomLevel.getDefaultZoomByDates(new LocalDate(interval
.getStart()), new LocalDate(interval.getFinish()));
}
@Override
public void setResourcesToShow(List<Resource> resourcesList) {
this.resourcesToShowList.clear();