Merge pull request #78 from dgray16/master

Update Commons Collections
This commit is contained in:
Jeroen Baten 2016-05-05 15:25:01 +02:00
commit a03ce069d2
12 changed files with 855 additions and 773 deletions

View file

@ -24,28 +24,33 @@ Thanks to all the contributors to this new version:
Changes
~~~~~~~
* Update MPXJ
* Update Maven Gettext Plugin
* Update Maven Compiler Plugin
* Update Maven War Plugin
* Update Maven Surfire Plugin
* Update Bonecp
* Update Slf4j API
* Update Slf4j Simple
* Update Guava
* Update Maven Cobertura Plugin
* Update Maven Liquibase Plugin
* Update Liquibase Core
* Update Jackson
* Update LibrePlan version to 1.6.0
* Update Javax Servlet
* Update Jfree
* Update Slf4j API
* Update Slf4j Simple
* Update Log4j
* Update Slf4j
* Update Commons Lang
* Update Commons Math
* Update Commons Collections
* Update MPXJ
* Update Bonecp
* Update Guava
* Update Liquibase Core
* Update Jackson
* Update Javax Servlet
* Update Jfree
* Update JGraphT
* Update DBUnit
* Update Log4j
* Update JodaTime
* Update LibrePlan version to 1.6.0
* Remove Ezmorph

View file

@ -120,8 +120,8 @@
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<!-- ZK -->

View file

@ -30,7 +30,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.joda.time.LocalDate;
import org.zkoss.ganttz.adapters.DomainDependency;
import org.zkoss.ganttz.adapters.IAdapterToTaskFundamentalProperties;
@ -65,23 +65,25 @@ import org.zkoss.zul.Window;
public class FunctionalityExposedForExtensions<T> implements IContext<T> {
private static class OneToOneMapper<T> implements IDomainAndBeansMapper<T> {
private Map<T, Task> fromDomainToTask = new HashMap<T, Task>();
private Map<Task, T> fromTaskToDomain = new HashMap<Task, T>();
private Map<T, Task> fromDomainToTask = new HashMap<>();
private Map<Task, TaskContainer> fromTaskToParent = new HashMap<Task, TaskContainer>();
private Map<Task, T> fromTaskToDomain = new HashMap<>();
private List<Task> topLevel = new ArrayList<Task>();
private Map<Task, TaskContainer> fromTaskToParent = new HashMap<>();
private List<Task> topLevel = new ArrayList<>();
@Override
public Task findAssociatedBean(T domainObject)
throws IllegalArgumentException {
if (domainObject == null) {
public Task findAssociatedBean(T domainObject) throws IllegalArgumentException {
if ( domainObject == null ) {
throw new IllegalArgumentException("domainObject is null");
}
if (!fromDomainToTask.containsKey(domainObject)) {
if ( !fromDomainToTask.containsKey(domainObject) ) {
throw new IllegalArgumentException("not found " + domainObject);
}
return fromDomainToTask.get(domainObject);
}
@ -96,9 +98,9 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
fromDomainToTask.put(domainObject, task);
fromTaskToDomain.put(task, domainObject);
if (position.isAppendToTop()) {
if ( position.isAppendToTop() ) {
topLevel.add(task);
} else if (position.isAtTop()) {
} else if ( position.isAtTop() ) {
topLevel.add(position.getInsertionPosition(), task);
} else {
fromTaskToParent.put(task, position.getParent());
@ -110,34 +112,39 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
fromDomainToTask.remove(domainObject);
fromTaskToDomain.remove(toBeRemoved);
TaskContainer parent = fromTaskToParent.get(toBeRemoved);
if (parent != null) {
if ( parent != null ) {
parent.remove(toBeRemoved);
}
fromTaskToParent.remove(toBeRemoved);
topLevel.remove(toBeRemoved);
}
@Override
public T findAssociatedDomainObject(Task task)
throws IllegalArgumentException {
if (task == null) {
public T findAssociatedDomainObject(Task task) throws IllegalArgumentException {
if ( task == null ) {
throw new IllegalArgumentException("taskBean is null");
}
if (!fromTaskToDomain.containsKey(task)) {
if ( !fromTaskToDomain.containsKey(task) ) {
throw new IllegalArgumentException();
}
return fromTaskToDomain.get(task);
}
@Override
public Position findPositionFor(Task task) {
List<TaskContainer> ancestors = ancestorsOf(task);
if (ancestors.isEmpty()) {
if ( ancestors.isEmpty() ) {
return Position.createAtTopPosition(topLevel.indexOf(task));
}
TaskContainer parent = ancestors.get(0);
return Position.createPosition(ancestors, parent.getTasks()
.indexOf(task));
return Position.createPosition(ancestors, parent.getTasks().indexOf(task));
}
@Override
@ -146,18 +153,21 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
}
private List<TaskContainer> ancestorsOf(Task task) {
ArrayList<TaskContainer> result = new ArrayList<TaskContainer>();
ArrayList<TaskContainer> result = new ArrayList<>();
TaskContainer taskContainer = fromTaskToParent.get(task);
while (taskContainer != null) {
result.add(taskContainer);
taskContainer = fromTaskToParent.get(taskContainer);
}
return result;
}
@Override
public List<? extends TaskContainer> getParents(Task task) {
Position position = findPositionFor(task);
return position.getAncestors();
}
@ -171,39 +181,38 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
private TimeTracker timeTracker;
private final PlannerConfiguration<T> configuration;
public FunctionalityExposedForExtensions(Planner planner,
PlannerConfiguration<T> configuration,
GanttZKDiagramGraph diagramGraph) {
public FunctionalityExposedForExtensions(
Planner planner, PlannerConfiguration<T> configuration, GanttZKDiagramGraph diagramGraph) {
this.planner = planner;
this.configuration = configuration;
this.adapter = configuration.getAdapter();
this.navigator = configuration.getNavigator();
this.diagramGraph = diagramGraph;
final IDetailItemModificator firstLevelModificators = configuration
.getFirstLevelModificators();
final IDetailItemModificator secondLevelModificators = configuration
.getSecondLevelModificators();
final IDetailItemModificator firstLevelModificators = configuration.getFirstLevelModificators();
final IDetailItemModificator secondLevelModificators = configuration.getSecondLevelModificators();
Calendar calendarRightNow = Calendar.getInstance();
LocalDate localDateRightNow = LocalDate.fromCalendarFields(calendarRightNow);
LocalDate initDate = localDateRightNow.minusYears(1);
LocalDate endDate = localDateRightNow.plusYears(5);
this.timeTracker = new TimeTracker(new Interval(
TimeTrackerState.year(initDate.getYear()),
TimeTrackerState.year(endDate.getYear())),
planner.getZoomLevel(), firstLevelModificators,
secondLevelModificators, planner);
this.timeTracker = new TimeTracker(
new Interval(TimeTrackerState.year(initDate.getYear()), TimeTrackerState.year(endDate.getYear())),
planner.getZoomLevel(),
firstLevelModificators,
secondLevelModificators,
planner);
}
/**
* @param insertionPosition
* the position in which to register the task at top level. It
* can be <code>null</code>
* @param insertionPosition the position in which to register the task at top level.
* It can be <code>null</code>
* @param accumulatedDependencies
* @param data
* @param parent
*
* @return
*/
private Task buildAndRegister(Position position, List<DomainDependency<T>> accumulatedDependencies, T data) {
@ -212,15 +221,17 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
final Task result = build(data);
if (!navigator.isLeaf(data)) {
if ( !navigator.isLeaf(data) ) {
TaskContainer container = (TaskContainer) result;
int i = 0;
for (T child : navigator.getChildren(data)) {
container.add(buildAndRegister(position.down(container, i),
accumulatedDependencies, child));
i++;
}
} else if (navigator.isMilestone(data)) {
} else if ( navigator.isMilestone(data) ) {
Milestone milestone = (Milestone) result;
milestone.setOwner(position.getParent());
}
@ -230,6 +241,7 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
result.setShowingAdvances(planner.showAdvancesRightNow());
mapper.register(position, result, data);
return result;
}
@ -245,14 +257,17 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
}
public void add(Position position, Collection<? extends T> domainObjects) {
List<DomainDependency<T>> totalDependencies = new ArrayList<DomainDependency<T>>();
List<Task> tasksCreated = new ArrayList<Task>();
List<DomainDependency<T>> totalDependencies = new ArrayList<>();
List<Task> tasksCreated = new ArrayList<>();
for (T object : domainObjects) {
Task task = buildAndRegister(position, totalDependencies, object);
tasksCreated.add(task);
}
updateTimeTracker(tasksCreated);
if (position.isAppendToTop() || position.isAtTop()) {
if ( position.isAppendToTop() || position.isAtTop() ) {
this.diagramGraph.addTopLevel(tasksCreated);
} else {
this.diagramGraph.addTasks(tasksCreated);
@ -260,10 +275,11 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
parent.addAll(position.getInsertionPosition(), tasksCreated);
this.diagramGraph.childrenAddedTo(parent);
}
for (Dependency dependency : DomainDependency.toDependencies(mapper,
totalDependencies)) {
for (Dependency dependency : DomainDependency.toDependencies(mapper, totalDependencies)) {
this.diagramGraph.addWithoutEnforcingConstraints(dependency);
}
this.diagramGraph.enforceAllRestrictions();
this.planner.addTasks(position, tasksCreated);
}
@ -271,7 +287,8 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
private void updateTimeTracker(List<Task> tasksCreated) {
for (Task task : tasksCreated) {
timeTracker.trackPosition(task);
if (task.isContainer()) {
if ( task.isContainer() ) {
TaskContainer container = (TaskContainer) task;
updateTimeTracker(container.getTasks());
}
@ -310,6 +327,7 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
diagramGraph.remove(task);
task.removed();
planner.removeTask(task);
return position;
}
@ -330,20 +348,19 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
private DomainDependency<T> toDomainDependency(Dependency bean) {
T source = mapper.findAssociatedDomainObject(bean.getSource());
T destination = mapper
.findAssociatedDomainObject(bean.getDestination());
DomainDependency<T> dep = DomainDependency.createDependency(source,
destination, bean.getType());
T destination = mapper.findAssociatedDomainObject(bean.getDestination());
DomainDependency<T> dep = DomainDependency.createDependency(source, destination, bean.getType());
return dep;
}
public void addDependency(Dependency dependency) {
if (!canAddDependency(dependency)) {
if ( !canAddDependency(dependency) ) {
return;
}
diagramGraph.add(dependency);
getDependencyList().addDependencyComponent(
getTaskList().asDependencyComponent(dependency));
getDependencyList().addDependencyComponent(getTaskList().asDependencyComponent(dependency));
adapter.addDependency(toDomainDependency(dependency));
}
@ -352,8 +369,7 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
}
private boolean canAddDependency(Dependency dependency) {
return diagramGraph.canAddDependency(dependency)
&& adapter.canAddDependency(toDomainDependency(dependency));
return diagramGraph.canAddDependency(dependency) && adapter.canAddDependency(toDomainDependency(dependency));
}
private DependencyList getDependencyList() {
@ -370,18 +386,22 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
* Substitutes the dependency for a new one with the same source and
* destination but with the specified type. If the new dependency cannot be
* added, the old one remains.
*
* @param dependency
* @param type
* the new type
*
* @return true only if the new dependency can be added.
*/
public boolean changeType(Dependency dependency, DependencyType type) {
Dependency newDependency = dependency.createWithType(type);
boolean canAddDependency = diagramGraph.canAddDependency(newDependency);
if (canAddDependency) {
if ( canAddDependency ) {
removeDependency(dependency);
addDependency(newDependency);
}
return canAddDependency;
}
@ -398,19 +418,20 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
@Override
public void showCriticalPath() {
CriticalPathCalculator<Task, Dependency> criticalPathCalculator = CriticalPathCalculator
.create(configuration.isDependenciesConstraintsHavePriority());
CriticalPathCalculator<Task, Dependency> criticalPathCalculator =
CriticalPathCalculator.create(configuration.isDependenciesConstraintsHavePriority());
List<Task> criticalPath = criticalPathCalculator.calculateCriticalPath(diagramGraph);
List<Task> criticalPath = criticalPathCalculator
.calculateCriticalPath(diagramGraph);
for (Task task : diagramGraph.getTasks()) {
task.setInCriticalPath(isInCriticalPath(criticalPath, task));
}
}
private boolean isInCriticalPath(List<Task> criticalPath, Task task) {
if (task.isContainer()) {
List<Task> allTaskLeafs = ((TaskContainer) task).getAllTaskLeafs();
if ( task.isContainer() ) {
List<Task> allTaskLeafs = task.getAllTaskLeafs();
return CollectionUtils.containsAny(criticalPath, allTaskLeafs);
} else {
return criticalPath.contains(task);
@ -419,13 +440,15 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
@Override
public List<T> getCriticalPath() {
List<T> result = new ArrayList<T>();
CriticalPathCalculator<Task, Dependency> criticalPathCalculator = CriticalPathCalculator
.create(configuration.isDependenciesConstraintsHavePriority());
for (Task each : criticalPathCalculator
.calculateCriticalPath(diagramGraph)) {
List<T> result = new ArrayList<>();
CriticalPathCalculator<Task, Dependency> criticalPathCalculator =
CriticalPathCalculator.create(configuration.isDependenciesConstraintsHavePriority());
for (Task each : criticalPathCalculator.calculateCriticalPath(diagramGraph)) {
result.add(mapper.findAssociatedDomainObject(each));
}
return result;
}
@ -488,49 +511,56 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
}
private HashMap<String, String> buildParameters(Component parent) {
HashMap<String, String> parameters = new HashMap<String, String>();
HashMap<String, String> parameters = new HashMap<>();
Checkbox expanded = (Checkbox) parent.getFellow("print_expanded");
Checkbox resources = (Checkbox) parent.getFellow("print_resources");
Checkbox labels = (Checkbox) parent.getFellow("print_labels");
Checkbox advances = (Checkbox) parent.getFellow("print_advances");
Checkbox reportedHours = (Checkbox) parent
.getFellow("print_reported_hours");
Checkbox moneyCostBar = (Checkbox) parent
.getFellow("print_money_cost_bar");
Checkbox reportedHours = (Checkbox) parent.getFellow("print_reported_hours");
Checkbox moneyCostBar = (Checkbox) parent.getFellow("print_money_cost_bar");
parameters.put("extension", ".png");
if (expanded.isChecked() == true) {
if ( expanded.isChecked() ) {
parameters.put("expanded", "all");
}
if (labels.isChecked() == true) {
if ( labels.isChecked() ) {
parameters.put("labels", "all");
}
if (advances.isChecked() == true) {
if ( advances.isChecked() ) {
parameters.put("advances", "all");
}
if (reportedHours.isChecked() == true) {
if ( reportedHours.isChecked() ) {
parameters.put("reportedHours", "all");
}
if (moneyCostBar.isChecked() == true) {
if ( moneyCostBar.isChecked() ) {
parameters.put("moneyCostBar", "all");
}
if (resources.isChecked() == true) {
if ( resources.isChecked() ) {
parameters.put("resources", "all");
}
parameters.put("zoom", planner.getZoomLevel().getInternalName());
return parameters;
}
public void print() {
if (!isPrintEnabled()) {
if ( !isPrintEnabled() ) {
throw new UnsupportedOperationException("print is not supported");
}
final Window printProperties = (Window) Executions.createComponents(
"/planner/print_configuration.zul", planner, null);
final Window printProperties =
(Window) Executions.createComponents("/planner/print_configuration.zul", planner, null);
Button printButton = (Button) printProperties.getFellow("printButton");
printButton.addEventListener(Events.ON_CLICK, new EventListener() {
@Override
public void onEvent(Event event) {
@ -538,6 +568,7 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
configuration.print(buildParameters(printProperties),planner);
}
});
printButton.setParent(printProperties);
try {
@ -551,13 +582,14 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
@Override
public List<Task> getTasksOrderedByStartDate() {
List<Task> tasks = diagramGraph.getTasks();
Collections.sort(tasks, new Comparator<Task>() {
Collections.sort(tasks, new Comparator<Task>() {
@Override
public int compare(Task o1, Task o2) {
return o1.getBeginDate().compareTo(o2.getBeginDate());
}
});
return tasks;
}
@ -571,7 +603,7 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
private void setExpandAll(boolean expand, List<Task> tasks) {
for (Task task : tasks) {
if (task instanceof TaskContainer) {
if ( task instanceof TaskContainer ) {
((TaskContainer) task).setExpanded(expand);
}
}

View file

@ -26,7 +26,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.apache.commons.collections.ComparatorUtils;
import org.apache.commons.collections4.comparators.NullComparator;
import org.apache.commons.lang3.Validate;
import org.joda.time.LocalDate;
import org.zkoss.ganttz.data.GanttDate;
@ -35,15 +35,14 @@ import org.zkoss.ganttz.util.Interval;
public class LoadTimeLine {
@SuppressWarnings("unchecked")
private static final Comparator<GanttDate> nullSafeComparator =
ComparatorUtils.nullLowComparator(ComparatorUtils.naturalComparator());
private static final Comparator<GanttDate> nullSafeComparator = new NullComparator<>(false);
public static Comparator<LoadTimeLine> byStartAndEndDate() {
return new Comparator<LoadTimeLine>() {
@Override
public int compare(LoadTimeLine o1, LoadTimeLine o2) {
int result = nullSafeComparator.compare(o1.getStartPeriod(), o2.getStartPeriod());
if ( result == 0 ) {
return nullSafeComparator.compare(o1.getEndPeriod(), o2.getEndPeriod());
}
@ -151,7 +150,7 @@ public class LoadTimeLine {
GanttDate end = null;
for (LoadTimeLine loadTimeLine : timeLines) {
if( !loadTimeLine.isEmpty() ) {
if ( !loadTimeLine.isEmpty() ) {
Validate.notNull(loadTimeLine.getStart());
start = min(start, loadTimeLine.getStart());
Validate.notNull(loadTimeLine.getEnd());

View file

@ -285,9 +285,8 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
@SuppressWarnings("unchecked")
private Separator getSeparator() {
List<Component> children = getToolbar().getChildren();
Separator separator = ComponentsFinder.findComponentsOfType(Separator.class, children).get(0);
return separator;
return ComponentsFinder.findComponentsOfType(Separator.class, children).get(0);
}
private Component getToolbar() {
@ -364,12 +363,12 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
// Insert additional filters if any
Component additionalFilter = getFirstOptionalFilter();
if( additionalFilter != null ) {
if ( additionalFilter != null ) {
getFellow("additionalFilterInsertionPoint1").appendChild(additionalFilter);
}
additionalFilter = getSecondOptionalFilter();
if( additionalFilter != null ) {
if ( additionalFilter != null ) {
getFellow("additionalFilterInsertionPoint2").appendChild(additionalFilter);
}
@ -378,10 +377,10 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
listZoomLevels = (Listbox) getFellow("listZoomLevels");
listZoomLevels.setSelectedIndex(timeTracker.getDetailLevel().ordinal());
if( paginationType == PaginationType.INTERNAL_PAGINATION && refreshNameFilter ) {
if ( paginationType == PaginationType.INTERNAL_PAGINATION && refreshNameFilter ) {
setupNameFilter();
}
else if( paginationType == PaginationType.NONE ) {
else if ( paginationType == PaginationType.NONE ) {
getFellow("filterByNameCombo").setVisible(false);
getFellow("filterByNameLabel").setVisible(false);
}
@ -443,15 +442,15 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
filterByNameCombo.getChildren().clear();
int size = groups.size();
if( size > numberOfGroupsByName ) {
if ( size > numberOfGroupsByName ) {
int position = 0;
while(position < size) {
while (position < size) {
String firstName = groups.get(position).getConceptName();
String lastName;
int newPosition = position + numberOfGroupsByName;
if( newPosition - 1 < size ) {
if ( newPosition - 1 < size ) {
lastName = groups.get(newPosition - 1).getConceptName();
}
else {
@ -483,7 +482,7 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
* @return
*/
private List<LoadTimeLine> getGroupsToShow() {
if( paginationType != PaginationType.INTERNAL_PAGINATION || filterByNamePosition == -1 ) {
if ( paginationType != PaginationType.INTERNAL_PAGINATION || filterByNamePosition == -1 ) {
return groups;
}
@ -522,7 +521,7 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
LongOperationFeedback.execute(componentOnWhichGiveFeedback, new ILongOperation() {
@Override
public void doAction() {
if( paginationType == PaginationType.INTERNAL_PAGINATION ) {
if ( paginationType == PaginationType.INTERNAL_PAGINATION ) {
//if the pagination is internal, we are in charge of repainting the graph
treeModel = createModelForTree();
@ -563,6 +562,7 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
public void changeChartVisibility(boolean visible) {
visibleChart = visible;
chartVisibilityListeners.fireEvent(new IListenerNotification<IChartVisibilityChangedListener>() {
@Override
public void doNotify(IChartVisibilityChangedListener listener) {
@ -588,7 +588,7 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
}
public Combobox getPaginationFilterCombobox() {
if( paginationType == PaginationType.EXTERNAL_PAGINATION ) {
if ( paginationType == PaginationType.EXTERNAL_PAGINATION ) {
return (Combobox) getFellow("filterByNameCombo");
}

View file

@ -23,7 +23,7 @@ package org.libreplan.web.common.components;
import java.util.Comparator;
import org.apache.commons.collections.comparators.BooleanComparator;
import org.apache.commons.collections4.comparators.BooleanComparator;
import org.apache.commons.lang.Validate;
import org.libreplan.business.INewObject;
import org.zkoss.zk.ui.ext.AfterCompose;
@ -45,13 +45,13 @@ import org.zkoss.zul.api.Grid;
* in order to work properly. They notify the {@link NewDataSortableGrid} in which are
* included when they are requested to be sorted.
*<p>
*
* @author Javier Moran Rua <jmoran@igalia.com>
*/
public class NewDataSortableColumn extends Column implements AfterCompose {
private static class NewObjectDecoratorComparator implements
Comparator<Object> {
private static class NewObjectDecoratorComparator implements Comparator<Object> {
private Comparator<Object> decoratedComparator;
public NewObjectDecoratorComparator(Comparator<Object> c) {
@ -61,7 +61,7 @@ public class NewDataSortableColumn extends Column implements AfterCompose {
@Override
public int compare(Object o1, Object o2) {
if (!doComparingObjectsSupportInterface(o1, o2)) {
if ( !doComparingObjectsSupportInterface(o1, o2) ) {
return decoratedComparator.compare(o1, o2);
} else {
return decorateBehaviour((INewObject) o1, (INewObject) o2);
@ -73,11 +73,11 @@ public class NewDataSortableColumn extends Column implements AfterCompose {
}
private int decorateBehaviour(INewObject o1, INewObject o2) {
if (o1.isNewObject() == o2.isNewObject()) {
if ( o1.isNewObject() == o2.isNewObject() ) {
return decoratedComparator.compare(o1, o2);
}
return BooleanComparator.getTrueFirstComparator().compare(
o1.isNewObject(), o2.isNewObject());
return BooleanComparator.getTrueFirstComparator().compare(o1.isNewObject(), o2.isNewObject());
}
}
@ -94,10 +94,11 @@ public class NewDataSortableColumn extends Column implements AfterCompose {
@Override
public boolean sort(boolean ascending) {
Grid grid = getGrid();
if (grid instanceof NewDataSortableGrid) {
if ( grid instanceof NewDataSortableGrid ) {
((NewDataSortableGrid) grid).setSortedColumn(this);
((NewDataSortableGrid) grid).setLastSortedColumnAscending(ascending);
}
return super.sort(ascending);
}
@ -105,11 +106,11 @@ public class NewDataSortableColumn extends Column implements AfterCompose {
public void afterCompose() {
Grid g = getGrid();
if (g instanceof NewDataSortableGrid) {
if ( g instanceof NewDataSortableGrid ) {
NewDataSortableGrid castedGrid = (NewDataSortableGrid) g;
// The first registered column is responsible for ordering
if (castedGrid.getSortedColumn() == null) {
if ( castedGrid.getSortedColumn() == null ) {
markInGridAsColumnToOrder(castedGrid);
}
}
@ -118,12 +119,10 @@ public class NewDataSortableColumn extends Column implements AfterCompose {
private void markInGridAsColumnToOrder(NewDataSortableGrid parentGrid) {
parentGrid.setSortedColumn(this);
if ("ascending".equals(getSortDirection())) {
parentGrid.setLastSortedColumnAscending(
Boolean.TRUE.booleanValue());
} else if ("descending".equals(getSortDirection())) {
parentGrid.setLastSortedColumnAscending(
Boolean.FALSE.booleanValue());
if ( "ascending".equals(getSortDirection()) ) {
parentGrid.setLastSortedColumnAscending(true);
} else if ( "descending".equals(getSortDirection()) ) {
parentGrid.setLastSortedColumnAscending(false);
}
}

View file

@ -81,7 +81,7 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
private List selectedFilters = new ArrayList();
private String selectedFiltersText = new String("");
private String selectedFiltersText = "";
public void afterCompose() {
super.afterCompose();
@ -104,15 +104,17 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
@Override
public boolean service(AuRequest request, boolean everError) {
String command = request.getCommand();
if (command.equals("closeBandbox")) {
if ( command.equals("closeBandbox") ) {
pickElementFromListAndCloseBandbox();
return true;
}
return false;
}
});
listbox.addEventListener(Events.ON_OK, new EventListener() {
listbox.addEventListener(Events.ON_OK, new EventListener() {
@Override
public void onEvent(Event event) {
pickElementFromListAndCloseBandbox();
@ -125,11 +127,10 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
* Search for matching elements while typing on bandbox
*/
bandbox.addEventListener("onChanging", new EventListener() {
@Override
public void onEvent(Event event) {
final String inputText = ((InputEvent) event).getValue();
if ((inputText == null) || (inputText.isEmpty())) {
if ( (inputText == null) || (inputText.isEmpty()) ) {
clear();
listbox.setSelectedIndex(0);
Events.postEvent(Events.ON_CHANGE, listbox, null);
@ -145,7 +146,7 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
@Override
public void onEvent(Event event) {
List<Listitem> items = listbox.getItems();
if (!items.isEmpty()) {
if ( !items.isEmpty() ) {
listbox.setSelectedIndex(0);
items.get(0).setFocus(true);
}
@ -154,20 +155,22 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
}
private void initFinder() {
if (multipleFiltersFinder != null) {
if (listbox != null) {
if ( multipleFiltersFinder != null ) {
if ( listbox != null ) {
initListbox();
}
if (bandbox != null) {
if ( bandbox != null ) {
initBandbox();
}
}
}
private void pickElementFromListAndCloseBandbox() {
if(getSelectedItem() != null) {
if ( getSelectedItem() != null ) {
final Object object = getSelectedItem().getValue();
if (multipleFiltersFinder.isValidNewFilter(selectedFilters, object)) {
if ( multipleFiltersFinder.isValidNewFilter(selectedFilters, object) ) {
addSelectedElement(object);
clearListbox();
listbox.setModel(getSubModel());
@ -186,16 +189,16 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
private void searchMultipleFilters(String inputText) {
// update the filters list if some filter was deleted
boolean someRemoved = multipleFiltersFinder.updateDeletedFilters(
selectedFilters, inputText);
if (someRemoved) {
boolean someRemoved = multipleFiltersFinder.updateDeletedFilters(selectedFilters, inputText);
if ( someRemoved ) {
updateselectedFiltersText();
updateBandboxValue();
} else {
// find the filter set to show it in the listbox
String newFilterText = multipleFiltersFinder
.getNewFilterText(inputText);
if ((newFilterText != null) && (!newFilterText.isEmpty())) {
String newFilterText = multipleFiltersFinder.getNewFilterText(inputText);
if ( (newFilterText != null) && (!newFilterText.isEmpty()) ) {
listbox.setModel(getSubModel(newFilterText));
listbox.invalidate();
} else {
@ -213,7 +216,7 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
}
public void addSelectedElement(Object obj) {
if (obj != null) {
if ( obj != null ) {
addFilter(obj);
updateselectedFiltersText();
updateBandboxValue();
@ -223,10 +226,11 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
private void addFilter(Object obj) {
FilterPair newFilter = (FilterPair) obj;
for (FilterPair filter : (List<FilterPair>) selectedFilters) {
if ((filter.getType().equals(newFilter.getType()))
&& (filter.getPattern().equals(newFilter.getPattern()))) {
throw new WrongValueException(bandbox,
_("filter already exists"));
if ( (filter.getType().equals(newFilter.getType())) &&
(filter.getPattern().equals(newFilter.getPattern())) ) {
throw new WrongValueException(bandbox, _("filter already exists"));
}
}
selectedFilters.add(obj);
@ -234,13 +238,12 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
public List getSelectedElements() {
updateBandboxValue();
if (this.multipleFiltersFinder != null) {
if (!multipleFiltersFinder.isValidFormatText(selectedFilters,
bandbox.getValue())) {
throw new WrongValueException(bandbox,
_("format filters are not valid"));
if ( this.multipleFiltersFinder != null ) {
if ( !multipleFiltersFinder.isValidFormatText(selectedFilters, bandbox.getValue()) ) {
throw new WrongValueException(bandbox, _("format filters are not valid"));
}
}
return selectedFilters;
}
@ -250,6 +253,7 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
@SuppressWarnings("unchecked")
private ListModel getSubModel() {
List result = multipleFiltersFinder.getFirstTenFilters();
return new SimpleListModel(result);
}
@ -260,6 +264,7 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
@SuppressWarnings("unchecked")
private ListModel getSubModel(String inputText) {
List result = multipleFiltersFinder.getMatching(inputText);
return new SimpleListModel(result);
}
@ -270,13 +275,13 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
public void addHeaders() {
clearHeaderIfNecessary();
final String[] headers = multipleFiltersFinder.getHeaders();
for (int i = 0; i < headers.length; i++) {
listhead.getChildren().add(new Listheader(_(headers[i])));
for (String header : headers) {
listhead.getChildren().add(new Listheader(_(header)));
}
}
private void clearHeaderIfNecessary() {
if (listhead.getChildren() != null) {
if ( listhead.getChildren() != null ) {
listhead.getChildren().clear();
}
}
@ -295,12 +300,12 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
}
private Object getBean(String beanName) {
HttpServletRequest servletRequest = (HttpServletRequest) Executions
.getCurrent().getNativeRequest();
ServletContext servletContext = servletRequest.getSession()
.getServletContext();
WebApplicationContext webApplicationContext = WebApplicationContextUtils
.getWebApplicationContext(servletContext);
HttpServletRequest servletRequest = (HttpServletRequest) Executions.getCurrent().getNativeRequest();
ServletContext servletContext = servletRequest.getSession().getServletContext();
WebApplicationContext webApplicationContext =
WebApplicationContextUtils.getWebApplicationContext(servletContext);
return webApplicationContext.getBean(beanName);
}
@ -309,8 +314,7 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
}
public void setFinder(String classname) {
multipleFiltersFinder = (IMultipleFiltersFinder) getBean(StringUtils
.uncapitalize(classname));
multipleFiltersFinder = (IMultipleFiltersFinder) getBean(StringUtils.uncapitalize(classname));
initFinder();
}
@ -324,16 +328,17 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
}
private void clearListbox() {
List<Object> list = new ArrayList<Object>();
List<Object> list = new ArrayList<>();
listbox.setModel(new SimpleListModel(list));
listbox.invalidate();
}
public List<Object> asList(ListModel model) {
List<Object> result = new ArrayList<Object>();
List<Object> result = new ArrayList<>();
for (int i = 0; i < model.getSize(); i++) {
result.add(model.getElementAt(i));
}
return result;
}
@ -358,14 +363,14 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
}
private void updateWidth() {
if ((widthBandbox != null) && (!widthBandbox.isEmpty())) {
if ( (widthBandbox != null) && (!widthBandbox.isEmpty()) ) {
this.bandbox.setWidth(widthBandbox);
this.listbox.setWidth(widthListbox);
}
}
private void updateHeight() {
if ((heightBbox != null) && (!heightBbox.isEmpty())) {
if ( (heightBbox != null) && (!heightBbox.isEmpty()) ) {
this.bandbox.setHeight(heightBbox);
}
}
@ -377,8 +382,7 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
private void updateselectedFiltersText() {
selectedFiltersText = "";
for (Object obj : selectedFilters) {
selectedFiltersText = selectedFiltersText
.concat(multipleFiltersFinder.objectToString(obj));
selectedFiltersText = selectedFiltersText.concat(multipleFiltersFinder.objectToString(obj));
}
}
@ -392,9 +396,11 @@ public class BandboxMultipleSearch extends HtmlMacroComponent {
public void addSelectedElements(List<FilterPair> sessionFilterPairs) {
selectedFilters.clear();
for (FilterPair filterPair : sessionFilterPairs) {
addFilter(filterPair);
}
updateselectedFiltersText();
updateBandboxValue();
}

View file

@ -26,7 +26,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.collections.comparators.BooleanComparator;
import org.apache.commons.collections4.comparators.BooleanComparator;
import org.libreplan.business.planner.limiting.entities.Gap.GapOnQueue;
@ -45,12 +45,12 @@ public class GapsMergeSort {
*/
private static class CurrentGap implements Comparable<CurrentGap> {
static List<CurrentGap> convert(
Collection<? extends Iterator<GapOnQueue>> iterators) {
List<CurrentGap> result = new ArrayList<CurrentGap>();
static List<CurrentGap> convert(Collection<? extends Iterator<GapOnQueue>> iterators) {
List<CurrentGap> result = new ArrayList<>();
for (Iterator<GapOnQueue> iterator : iterators) {
result.add(new CurrentGap(iterator));
}
return result;
}
@ -65,6 +65,7 @@ public class GapsMergeSort {
public GapOnQueue consume() {
GapOnQueue result = getCurrent();
current = null;
return result;
}
@ -73,12 +74,14 @@ public class GapsMergeSort {
}
private GapOnQueue getCurrent() {
if (hasFinished()) {
if ( hasFinished() ) {
throw new IllegalStateException("already finished");
}
if (current != null) {
if ( current != null ) {
return current;
}
return current = iterator.next();
}
@ -88,53 +91,61 @@ public class GapsMergeSort {
*/
@Override
public int compareTo(CurrentGap other) {
int finishComparison = BooleanComparator.getFalseFirstComparator()
.compare(hasFinished(), other.hasFinished());
if (finishComparison != 0) {
int finishComparison =
BooleanComparator.getFalseFirstComparator().compare(hasFinished(), other.hasFinished());
if ( finishComparison != 0 ) {
return finishComparison;
} else if (hasFinished()) {
} else if ( hasFinished() ) {
assert other.hasFinished();
return 0;
} else {
assert !hasFinished() && !other.hasFinished();
return getCurrent().getGap().compareTo(
other.getCurrent().getGap());
return getCurrent().getGap().compareTo(other.getCurrent().getGap());
}
}
}
public static List<GapOnQueue> sort(
List<List<GapOnQueue>> orderedListsOfGaps) {
public static List<GapOnQueue> sort(List<List<GapOnQueue>> orderedListsOfGaps) {
List<GapOnQueue> result = new ArrayList<GapOnQueue>();
List<GapOnQueue> result = new ArrayList<>();
if (orderedListsOfGaps.isEmpty()) {
if ( orderedListsOfGaps.isEmpty() ) {
return result;
}
if (orderedListsOfGaps.size() == 1) {
if ( orderedListsOfGaps.size() == 1 ) {
return orderedListsOfGaps.get(0);
}
List<CurrentGap> currentGaps = CurrentGap.convert(iteratorsFor(orderedListsOfGaps));
CurrentGap min = Collections.min(currentGaps);
while (!currentGaps.isEmpty() && !min.hasFinished()) {
result.add(min.consume());
if (min.hasFinished()) {
if ( min.hasFinished() ) {
currentGaps.remove(min);
if (!currentGaps.isEmpty()) {
if ( !currentGaps.isEmpty() ) {
min = Collections.min(currentGaps);
}
}
}
return result;
}
private static List<Iterator<GapOnQueue>> iteratorsFor(
List<List<GapOnQueue>> orderedListsOfGaps) {
List<Iterator<GapOnQueue>> result = new ArrayList<Iterator<GapOnQueue>>();
private static List<Iterator<GapOnQueue>> iteratorsFor(List<List<GapOnQueue>> orderedListsOfGaps) {
List<Iterator<GapOnQueue>> result = new ArrayList<>();
for (List<GapOnQueue> each : orderedListsOfGaps) {
result.add(each.iterator());
}
return result;
}

View file

@ -49,14 +49,13 @@ public class ResourcesLoadTabCreator {
private final IOrderPlanningGate orderPlanningGate;
public static ITab create(Mode mode,
ResourceLoadController resourceLoadController,
ResourceLoadController resourceLoadControllerGlobal,
IOrderPlanningGate orderPlanningGate,
Component breadcrumbs) {
return new ResourcesLoadTabCreator(mode, resourceLoadController,
resourceLoadControllerGlobal, orderPlanningGate,
breadcrumbs)
.build();
ResourceLoadController resourceLoadController,
ResourceLoadController resourceLoadControllerGlobal,
IOrderPlanningGate orderPlanningGate,
Component breadcrumbs) {
return new ResourcesLoadTabCreator(
mode, resourceLoadController, resourceLoadControllerGlobal, orderPlanningGate, breadcrumbs).build();
}
private final Mode mode;
@ -67,10 +66,11 @@ public class ResourcesLoadTabCreator {
private final Component breadcrumbs;
private ResourcesLoadTabCreator(Mode mode,
ResourceLoadController resourceLoadController,
ResourceLoadController resourceLoadControllerGlobal,
IOrderPlanningGate orderPlanningGate,
Component breadcrumbs) {
ResourceLoadController resourceLoadController,
ResourceLoadController resourceLoadControllerGlobal,
IOrderPlanningGate orderPlanningGate,
Component breadcrumbs) {
this.mode = mode;
this.resourceLoadController = resourceLoadController;
this.resourceLoadControllerGlobal = resourceLoadControllerGlobal;
@ -87,20 +87,16 @@ public class ResourcesLoadTabCreator {
private ITab createOrderResourcesLoadTab() {
IComponentCreator componentCreator = new IComponentCreator() {
@Override
public org.zkoss.zk.ui.Component create(
org.zkoss.zk.ui.Component parent) {
Map<String, Object> arguments = new HashMap<String, Object>();
public org.zkoss.zk.ui.Component create(org.zkoss.zk.ui.Component parent) {
Map<String, Object> arguments = new HashMap<>();
arguments.put("resourceLoadController", resourceLoadController);
return Executions.createComponents(
"/resourceload/_resourceloadfororder.zul", parent,
arguments);
return Executions.createComponents("/resourceload/_resourceloadfororder.zul", parent, arguments);
}
};
return new CreatedOnDemandTab(_("Resources Load"), "order-load",
componentCreator) {
return new CreatedOnDemandTab(_("Resources Load"), "order-load", componentCreator) {
@Override
protected void afterShowAction() {
@ -111,8 +107,7 @@ public class ResourcesLoadTabCreator {
breadcrumbs.appendChild(new Label(_("Resources Load")));
breadcrumbs.appendChild(new Image(BREADCRUMBS_SEPARATOR));
Order currentOrder = mode.getOrder();
resourceLoadController
.setPlanningControllerEntryPoints(orderPlanningGate);
resourceLoadController.setPlanningControllerEntryPoints(orderPlanningGate);
resourceLoadController.filterBy(currentOrder);
resourceLoadController.reload();
breadcrumbs.appendChild(new Label(currentOrder.getName()));
@ -123,37 +118,33 @@ public class ResourcesLoadTabCreator {
private ITab createGlobalResourcesLoadTab() {
final IComponentCreator componentCreator = new IComponentCreator() {
@Override
public org.zkoss.zk.ui.Component create(
org.zkoss.zk.ui.Component parent) {
Map<String, Object> arguments = new HashMap<String, Object>();
arguments.put("resourceLoadController",
resourceLoadControllerGlobal);
return Executions.createComponents(
"/resourceload/_resourceload.zul", parent, arguments);
public org.zkoss.zk.ui.Component create(org.zkoss.zk.ui.Component parent) {
Map<String, Object> arguments = new HashMap<>();
arguments.put("resourceLoadController", resourceLoadControllerGlobal);
return Executions.createComponents("/resourceload/_resourceload.zul", parent, arguments);
}
};
return new CreatedOnDemandTab(_("Resources Load"), "company-load",
componentCreator) {
return new CreatedOnDemandTab(_("Resources Load"), "company-load", componentCreator) {
@Override
protected void beforeShowAction() {
if (!SecurityUtils
.isSuperuserOrUserInRoles(UserRole.ROLE_PLANNING)) {
if ( !SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PLANNING) ) {
Util.sendForbiddenStatusCodeInHttpServletResponse();
}
}
@Override
protected void afterShowAction() {
resourceLoadControllerGlobal
.setPlanningControllerEntryPoints(orderPlanningGate);
resourceLoadControllerGlobal.setPlanningControllerEntryPoints(orderPlanningGate);
resourceLoadControllerGlobal.filterBy(null);
resourceLoadControllerGlobal.reload();
if (breadcrumbs.getChildren() != null) {
if ( breadcrumbs.getChildren() != null ) {
breadcrumbs.getChildren().clear();
}
breadcrumbs.appendChild(new Image(BREADCRUMBS_SEPARATOR));
breadcrumbs.appendChild(new Label(getSchedulingLabel()));
breadcrumbs.appendChild(new Image(BREADCRUMBS_SEPARATOR));

View file

@ -116,7 +116,7 @@ public class ResourceLoadController implements Composer {
@Autowired
private IAdHocTransactionService transactionService;
private List<IToolbarCommand> commands = new ArrayList<IToolbarCommand>();
private List<IToolbarCommand> commands = new ArrayList<>();
private PlanningState filterBy;
@ -177,25 +177,28 @@ public class ResourceLoadController implements Composer {
private List<VisualizationModifier> visualizationModifiers = null;
private List<VisualizationModifier> getVisualizationModifiers() {
if (visualizationModifiers != null) {
if ( visualizationModifiers != null ) {
return visualizationModifiers;
}
return visualizationModifiers = buildVisualizationModifiers();
}
private List<IListenerAdder> listenersToAdd = null;
private List<IListenerAdder> getListenersToAdd() {
if (listenersToAdd != null) {
if ( listenersToAdd != null ) {
return listenersToAdd;
}
List<IListenerAdder> result = new ArrayList<>();
for (VisualizationModifier each : getVisualizationModifiers()) {
if (each instanceof IListenerAdder) {
if ( each instanceof IListenerAdder ) {
result.add((IListenerAdder) each);
}
}
result.add(new GoToScheduleListener());
return listenersToAdd = result;
}
@ -209,10 +212,10 @@ public class ResourceLoadController implements Composer {
public IOnTransaction<Void> reload() {
return new IOnTransaction<Void>() {
@Override
public Void execute() {
reloadInTransaction();
return null;
}
};
@ -222,7 +225,9 @@ public class ResourceLoadController implements Composer {
for (VisualizationModifier each : getVisualizationModifiers()) {
each.checkDependencies();
}
ResourceLoadParameters parameters = new ResourceLoadParameters(filterBy);
for (VisualizationModifier each : getVisualizationModifiers()) {
each.applyToParameters(parameters);
}
@ -230,7 +235,8 @@ public class ResourceLoadController implements Composer {
ResourceLoadDisplayData dataToShow = resourceLoadModel.calculateDataToDisplay(parameters);
timeTracker = buildTimeTracker(dataToShow);
if (resourcesLoadPanel == null) {
if ( resourcesLoadPanel == null ) {
resourcesLoadPanel = buildPanel(dataToShow);
listeners.addListeners(resourcesLoadPanel, getListenersToAdd());
parent.getChildren().clear();
@ -241,8 +247,7 @@ public class ResourceLoadController implements Composer {
}
} else {
resourcesLoadPanel.init(dataToShow.getLoadTimeLines(),
timeTracker);
resourcesLoadPanel.init(dataToShow.getLoadTimeLines(), timeTracker);
listeners.addListeners(resourcesLoadPanel, getListenersToAdd());
}
@ -256,25 +261,30 @@ public class ResourceLoadController implements Composer {
private TimeTracker buildTimeTracker(ResourceLoadDisplayData dataToShow) {
ZoomLevel zoomLevel = getZoomLevel(dataToShow);
TimeTracker result = new TimeTracker(dataToShow.getViewInterval(),
zoomLevel, SeveralModificators.create(),
SeveralModificators.create(createBankHolidaysMarker()),
parent);
TimeTracker result = new TimeTracker(
dataToShow.getViewInterval(),
zoomLevel,
SeveralModificators.create(),
SeveralModificators.create(createBankHolidaysMarker()),
parent);
setupZoomLevelListener(result);
return result;
}
private ZoomLevel getZoomLevel(ResourceLoadDisplayData dataToShow) {
if (filterBy != null) {
if ( filterBy != null ) {
Order order = filterBy.getOrder();
ZoomLevel sessionZoom = FilterUtils.readZoomLevel(order);
if (sessionZoom != null) {
if ( sessionZoom != null ) {
return sessionZoom;
}
}
ZoomLevel sessionZoom = FilterUtils.readZoomLevelResourcesLoad();
if (sessionZoom != null) {
if ( sessionZoom != null ) {
return sessionZoom;
}
@ -287,11 +297,10 @@ public class ResourceLoadController implements Composer {
}
private IZoomLevelChangedListener getSessionZoomLevelListener() {
IZoomLevelChangedListener zoomListener = new IZoomLevelChangedListener() {
return new IZoomLevelChangedListener() {
@Override
public void zoomLevelChanged(ZoomLevel detailLevel) {
if (filterBy != null) {
if ( filterBy != null ) {
Order order = filterBy.getOrder();
FilterUtils.writeZoomLevel(order, detailLevel);
} else {
@ -299,12 +308,11 @@ public class ResourceLoadController implements Composer {
}
}
};
return zoomListener;
}
private ResourcesLoadPanel buildPanel(ResourceLoadDisplayData dataToShow) {
return new ResourcesLoadPanel(dataToShow.getLoadTimeLines(),
return new ResourcesLoadPanel(
dataToShow.getLoadTimeLines(),
timeTracker, parent,
resourceLoadModel.isExpandResourceLoadViewCharts(),
PaginationType.EXTERNAL_PAGINATION);
@ -318,47 +326,48 @@ public class ResourceLoadController implements Composer {
// Only by dates and bandbox filter on global resources load
if ( filterBy == null ) {
LocalDate startDate = FilterUtils.readResourceLoadsStartDate();
LocalDate endDate = FilterUtils.readResourceLoadsEndDate();
LocalDate startDate = FilterUtils.readResourceLoadsStartDate();
LocalDate endDate = FilterUtils.readResourceLoadsEndDate();
User user = resourceLoadModel.getUser();
User user = resourceLoadModel.getUser();
// Calculate filter based on user preferences
if ( user != null ) {
if ( startDate == null && !FilterUtils.hasResourceLoadsStartDateChanged()) {
if ( user.getResourcesLoadFilterPeriodSince() != null ) {
startDate = new LocalDate().minusMonths(user.getResourcesLoadFilterPeriodSince());
} else {
// Default filter start
startDate = new LocalDate().minusDays(1);
}
}
if ( (endDate == null) && !FilterUtils.hasResourceLoadsEndDateChanged()
&& (user.getResourcesLoadFilterPeriodTo() != null) ) {
endDate = new LocalDate().plusMonths(user.getResourcesLoadFilterPeriodTo());
// Calculate filter based on user preferences
if ( user != null ) {
if ( startDate == null && !FilterUtils.hasResourceLoadsStartDateChanged() ) {
if ( user.getResourcesLoadFilterPeriodSince() != null ) {
startDate = new LocalDate().minusMonths(user.getResourcesLoadFilterPeriodSince());
} else {
// Default filter start
startDate = new LocalDate().minusDays(1);
}
}
if ( (endDate == null) &&
!FilterUtils.hasResourceLoadsEndDateChanged() &&
(user.getResourcesLoadFilterPeriodTo() != null) ) {
result.add(new ByDatesFilter(onChange, filterBy, startDate, endDate));
List<FilterPair> filterPairs = FilterUtils.readResourceLoadsBandbox();
if ( (filterPairs == null || filterPairs.isEmpty()) &&
user.getResourcesLoadFilterCriterion() != null ) {
filterPairs = new ArrayList<>();
filterPairs.add(new FilterPair(
ResourceAllocationFilterEnum.Criterion, user
.getResourcesLoadFilterCriterion()
.getFinderPattern(), user
.getResourcesLoadFilterCriterion()));
endDate = new LocalDate().plusMonths(user.getResourcesLoadFilterPeriodTo());
}
}
WorkersOrCriteriaBandbox bandbox = new WorkersOrCriteriaBandbox(onChange, filterBy, filterTypeChanger,
resourcesSearcher, filterPairs);
result.add(new ByDatesFilter(onChange, filterBy, startDate, endDate));
result.add(bandbox);
result.add(new ByNamePaginator(onChange, filterBy, filterTypeChanger, bandbox));
List<FilterPair> filterPairs = FilterUtils.readResourceLoadsBandbox();
if ( (filterPairs == null || filterPairs.isEmpty()) && user.getResourcesLoadFilterCriterion() != null ) {
filterPairs = new ArrayList<>();
filterPairs.add(new FilterPair(
ResourceAllocationFilterEnum.Criterion,
user.getResourcesLoadFilterCriterion().getFinderPattern(),
user.getResourcesLoadFilterCriterion()));
}
WorkersOrCriteriaBandbox bandbox =
new WorkersOrCriteriaBandbox(onChange, filterBy, filterTypeChanger, resourcesSearcher, filterPairs);
result.add(bandbox);
result.add(new ByNamePaginator(onChange, filterBy, filterTypeChanger, bandbox));
}
result.add(new LoadChart(onChange, filterBy));
return result;
}
@ -372,13 +381,14 @@ public class ResourceLoadController implements Composer {
@Override
public Object addAndReturnListener(ResourcesLoadPanel panel) {
ISeeScheduledOfListener listener = new ISeeScheduledOfListener() {
@Override
public void seeScheduleOf(LoadTimeLine taskLine) {
onSeeScheduleOf(taskLine);
}
};
panel.addSeeScheduledOfListener(listener);
return listener;
}
@ -389,26 +399,25 @@ public class ResourceLoadController implements Composer {
TaskElement task = (TaskElement) taskLine.getRole().getEntity();
Order order = resourceLoadModel.getOrderByTask(task);
if (resourceLoadModel.userCanRead(order,
SecurityUtils.getSessionUserLoginName())) {
if (order.isScheduled()) {
planningControllerEntryPoints.goToTaskResourceAllocation(order,
task);
if ( resourceLoadModel.userCanRead(order, SecurityUtils.getSessionUserLoginName()) ) {
if ( order.isScheduled() ) {
planningControllerEntryPoints.goToTaskResourceAllocation(order, task);
} else {
try {
Messagebox.show(_("The project has no scheduled elements"),
_("Information"), Messagebox.OK,
Messagebox.INFORMATION);
Messagebox.show(
_("The project has no scheduled elements"), _("Information"),
Messagebox.OK, Messagebox.INFORMATION);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
} else {
try {
Messagebox
.show(_("You don't have read access to this project"),
_("Information"), Messagebox.OK,
Messagebox.INFORMATION);
Messagebox.show(
_("You don't have read access to this project"), _("Information"),
Messagebox.OK, Messagebox.INFORMATION);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
@ -451,8 +460,7 @@ public class ResourceLoadController implements Composer {
}
}
private static class FilterTypeChanger extends VisualizationModifier
implements IListenerAdder {
private static class FilterTypeChanger extends VisualizationModifier implements IListenerAdder {
private boolean filterByResources = true;
@ -472,7 +480,6 @@ public class ResourceLoadController implements Composer {
@Override
public Object addAndReturnListener(ResourcesLoadPanel panel) {
IFilterChangedListener listener = new IFilterChangedListener() {
@Override
public void filterChanged(boolean newValue) {
if ( filterByResources != newValue ) {
@ -481,7 +488,9 @@ public class ResourceLoadController implements Composer {
}
}
};
panel.addFilterListener(listener);
return listener;
}
}
@ -509,12 +518,14 @@ public class ResourceLoadController implements Composer {
if ( isAppliedToOrder() ) {
return;
}
panel.setFirstOptionalFilter(buildTimeFilter());
}
private Hbox buildTimeFilter() {
startBox.setValue(asDate(startDateValue));
startBox.setWidth("100px");
startBox.addEventListener(Events.ON_CHANGE, new EventListener() {
@Override
public void onEvent(Event event) {
@ -529,6 +540,7 @@ public class ResourceLoadController implements Composer {
endBox.setValue(asDate(endDateValue));
endBox.setWidth("100px");
endBox.addEventListener(Events.ON_CHANGE, new EventListener() {
@Override
public void onEvent(Event event) {
@ -547,6 +559,7 @@ public class ResourceLoadController implements Composer {
hbox.appendChild(new Label(_("To") + ":"));
hbox.appendChild(endBox);
hbox.setAlign("center");
return hbox;
}
@ -566,6 +579,7 @@ public class ResourceLoadController implements Composer {
DependingOnFiltering(Runnable onChange, PlanningState filterBy, FilterTypeChanger filterType) {
super(onChange, filterBy);
this.filterType = filterType;
this.filteringByResource = filterType.isFilterByResources();
}
@ -601,6 +615,7 @@ public class ResourceLoadController implements Composer {
FilterTypeChanger filterType,
IResourcesSearcher resourcesSearcher,
List<FilterPair> selectedFilters) {
super(onChange, filterBy, filterType);
this.resourcesSearcher = resourcesSearcher;
@ -619,6 +634,7 @@ public class ResourceLoadController implements Composer {
if ( isAppliedToOrder() ) {
return;
}
panel.setSecondOptionalFilter(buildBandboxFilterer());
}
@ -633,8 +649,7 @@ public class ResourceLoadController implements Composer {
@Override
public void onEvent(Event event) throws Exception {
entitiesSelected = getSelected();
FilterUtils.writeResourceLoadsParameters(bandBox
.getSelectedElements());
FilterUtils.writeResourceLoadsParameters(bandBox.getSelectedElements());
notifyChange();
}
});
@ -651,6 +666,7 @@ public class ResourceLoadController implements Composer {
private Label getLabel() {
updateLabelValue();
return label;
}
@ -675,6 +691,7 @@ public class ResourceLoadController implements Composer {
if ( isAppliedToOrder() ) {
return;
}
entitiesSelected = null;
bandBox.setFinder(getFinderToUse());
updateLabelValue();
@ -704,7 +721,7 @@ public class ResourceLoadController implements Composer {
}
}
if ( !criteria.isEmpty() ) {
if ( !criteria.isEmpty()) {
resources.addAll(resourcesSearcher.searchBoth().byCriteria(criteria).execute());
}
@ -742,6 +759,7 @@ public class ResourceLoadController implements Composer {
PlanningState filterBy,
FilterTypeChanger filterTypeChanger,
WorkersOrCriteriaBandbox bandbox) {
super(onChange, filterBy, filterTypeChanger);
this.bandbox = bandbox;
this.currentPosition = initialPage();
@ -756,13 +774,15 @@ public class ResourceLoadController implements Composer {
IPaginationFilterChangedListener listener = new IPaginationFilterChangedListener() {
@Override
public void filterChanged(int newPosition) {
if (currentPosition != newPosition) {
if ( currentPosition != newPosition ) {
currentPosition = newPosition;
notifyChange();
}
}
};
panel.addPaginationFilterListener(listener);
return listener;
}
@ -787,6 +807,7 @@ public class ResourceLoadController implements Composer {
@Override
void updateUI(ResourcesLoadPanel panel, ResourceLoadDisplayData generatedData) {
panel.setInternalPaginationDisabled(bandbox.hasEntitiesSelected());
Paginator<? extends BaseEntity> paginator = generatedData.getPaginator();
List<? extends BaseEntity> newAllEntities = paginator.getAll();
@ -794,9 +815,10 @@ public class ResourceLoadController implements Composer {
if ( this.allEntitiesShown == null || !equivalent(this.allEntitiesShown, newAllEntities) ) {
this.currentPosition = initialPage();
this.allEntitiesShown = newAllEntities;
updatePages(panel.getPaginationFilterCombobox(),
pagesByName(this.allEntitiesShown,
paginator.getPageSize()));
updatePages(
panel.getPaginationFilterCombobox(),
pagesByName(this.allEntitiesShown, paginator.getPageSize()));
}
}
@ -804,12 +826,15 @@ public class ResourceLoadController implements Composer {
if ( a == null || b == null ) {
return false;
}
if ( a.size() != b.size() ) {
return false;
}
for (int i = 0; i < a.size(); i++) {
BaseEntity aElement = a.get(i);
BaseEntity bElement = b.get(i);
if ( !ObjectUtils.equals(aElement.getId(), bElement.getId()) ) {
return false;
}
@ -822,6 +847,7 @@ public class ResourceLoadController implements Composer {
if ( filterByNameCombo == null ) {
return;
}
filterByNameCombo.getChildren().clear();
Comboitem lastItem = new Comboitem();
@ -847,24 +873,21 @@ public class ResourceLoadController implements Composer {
if ( list.isEmpty() ) {
return new ArrayList<>();
}
Object first = list.get(0);
if ( first instanceof Resource ) {
return pagesByName(as(Resource.class, list), pageSize,
new INameExtractor<Resource>() {
return pagesByName(as(Resource.class, list), pageSize, new INameExtractor<Resource>() {
@Override
public String getNameOf(Resource resource) {
return resource.getName();
}
});
} else {
return pagesByName(as(Criterion.class, list), pageSize,
new INameExtractor<Criterion>() {
} else {
return pagesByName(as(Criterion.class, list), pageSize, new INameExtractor<Criterion>() {
@Override
public String getNameOf(Criterion criterion) {
return criterion.getType().getName() + ": "
+ criterion.getName();
return criterion.getType().getName() + ": " + criterion.getName();
}
});
}
@ -879,7 +902,6 @@ public class ResourceLoadController implements Composer {
for (int startPos = 0; startPos < elements.size(); startPos += pageSize) {
int endPos = Math.min(startPos + pageSize - 1, elements.size() - 1);
String first = nameExtractor.getNameOf(elements.get(startPos));
String end = nameExtractor.getNameOf(elements.get(endPos));
Comboitem item = buildPageCombo(startPos, first, end);
@ -922,18 +944,18 @@ public class ResourceLoadController implements Composer {
}
void setup(ResourcesLoadPanel panel) {
panel.setLoadChart(buildChart(panel, emitter));
panel.setLoadChart(buildChart(emitter));
}
public Object addAndReturnListener(ResourcesLoadPanel panel) {
IChartVisibilityChangedListener visibilityChangedListener = fillOnChartVisibilityChange();
panel.addChartVisibilityListener(visibilityChangedListener);
return visibilityChangedListener;
}
private IChartVisibilityChangedListener fillOnChartVisibilityChange() {
IChartVisibilityChangedListener result = new IChartVisibilityChangedListener() {
return new IChartVisibilityChangedListener() {
@Override
public void chartVisibilityChanged(final boolean visible) {
if ( visible && loadChart != null ) {
@ -941,10 +963,9 @@ public class ResourceLoadController implements Composer {
}
}
};
return result;
}
private Tabbox buildChart(ResourcesLoadPanel resourcesLoadPanel, Emitter<Timeplot> timePlot) {
private Tabbox buildChart(Emitter<Timeplot> timePlot) {
Tabbox chartComponent = new Tabbox();
chartComponent.setOrient("vertical");
chartComponent.setHeight("200px");
@ -957,8 +978,7 @@ public class ResourceLoadController implements Composer {
Tabpanels chartTabpanels = new Tabpanels();
Tabpanel loadChartPannel = new Tabpanel();
// avoid adding Timeplot since it has some pending issues
CompanyPlanningModel.appendLoadChartAndLegend(loadChartPannel,
timePlot);
CompanyPlanningModel.appendLoadChartAndLegend(loadChartPannel, timePlot);
chartTabpanels.appendChild(loadChartPannel);
chartComponent.appendChild(chartTabpanels);
@ -975,9 +995,8 @@ public class ResourceLoadController implements Composer {
emitter.emit(newLoadChart);
}
private Timeplot buildLoadChart(ResourcesLoadPanel resourcesLoadPanel,
ResourceLoadDisplayData generatedData,
TimeTracker timeTracker) {
private Timeplot buildLoadChart(
ResourcesLoadPanel resourcesLoadPanel, ResourceLoadDisplayData generatedData, TimeTracker timeTracker) {
Timeplot chartLoadTimeplot = createEmptyTimeplot();
@ -993,14 +1012,13 @@ public class ResourceLoadController implements Composer {
}
private IZoomLevelChangedListener fillOnZoomChange(final ResourcesLoadPanel resourcesLoadPanel) {
IZoomLevelChangedListener zoomListener = new IZoomLevelChangedListener() {
return new IZoomLevelChangedListener() {
@Override
public void zoomLevelChanged(ZoomLevel detailLevel) {
if ( loadChart == null ) {
return;
}
loadChart.setZoomLevel(detailLevel);
if ( resourcesLoadPanel.isVisibleChart() ) {
@ -1009,8 +1027,6 @@ public class ResourceLoadController implements Composer {
adjustZoomPositionScroll(resourcesLoadPanel);
}
};
return zoomListener;
}
}
@ -1021,6 +1037,7 @@ public class ResourceLoadController implements Composer {
private Timeplot createEmptyTimeplot() {
Timeplot timeplot = new Timeplot();
timeplot.appendChild(new Plotinfo());
return timeplot;
}
@ -1070,6 +1087,7 @@ public class ResourceLoadController implements Composer {
private BankHolidaysMarker createBankHolidaysMarker() {
BaseCalendar defaultCalendar = configurationDAO.getConfiguration().getDefaultCalendar();
return BankHolidaysMarker.create(defaultCalendar);
}
@ -1078,15 +1096,12 @@ public class ResourceLoadController implements Composer {
}
PlanningState createPlanningState(final Order order) {
return transactionService
.runOnReadOnlyTransaction(new IOnTransaction<PlanningState>() {
@Override
public PlanningState execute() {
return planningStateCreator.retrieveOrCreate(
parent.getDesktop(), order);
}
});
return transactionService.runOnReadOnlyTransaction(new IOnTransaction<PlanningState>() {
@Override
public PlanningState execute() {
return planningStateCreator.retrieveOrCreate(parent.getDesktop(), order);
}
});
}
public void setPlanningControllerEntryPoints(IOrderPlanningGate planningControllerEntryPoints) {

13
pom.xml
View file

@ -388,15 +388,14 @@
<classifier>jdk15</classifier>
</dependency>
<!-- Commons collections -->
<!-- Commons Collections -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<!-- Commons lang -->
<!-- Commons Lang -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>