diff --git a/ganttzk/pom.xml b/ganttzk/pom.xml
index 5c068c08f..d273872c6 100644
--- a/ganttzk/pom.xml
+++ b/ganttzk/pom.xml
@@ -137,7 +137,7 @@
org.jgrapht
- jgrapht-jdk1.5
+ jgrapht-core
diff --git a/ganttzk/src/main/java/org/zkoss/ganttz/data/GanttDiagramGraph.java b/ganttzk/src/main/java/org/zkoss/ganttz/data/GanttDiagramGraph.java
index 8f00ba385..36ecb37a7 100644
--- a/ganttzk/src/main/java/org/zkoss/ganttz/data/GanttDiagramGraph.java
+++ b/ganttzk/src/main/java/org/zkoss/ganttz/data/GanttDiagramGraph.java
@@ -61,6 +61,7 @@ import org.zkoss.ganttz.util.ReentranceGuard.IReentranceCases;
* This class contains a graph with the {@link Task tasks} as vertexes and the
* {@link Dependency dependency} as arcs. It enforces the rules embodied in the
* dependencies and in the duration of the tasks using listeners.
+ *
* @author Óscar González Fernández
*/
public class GanttDiagramGraph> implements ICriticalPathCalculable {
@@ -75,8 +76,7 @@ public class GanttDiagramGraph> implements ICritical
}
@Override
- public void setStartDate(GanttDate previousStart,
- GanttDate previousEnd, GanttDate newStart) {
+ public void setStartDate(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart) {
}
@Override
@@ -98,8 +98,7 @@ public class GanttDiagramGraph> implements ICritical
boolean isContainer(V task);
- void registerDependenciesEnforcerHookOn(V task,
- IDependenciesEnforcerHookFactory hookFactory);
+ void registerDependenciesEnforcerHookOn(V task, IDependenciesEnforcerHookFactory hookFactory);
GanttDate getStartDate(V task);
@@ -109,9 +108,8 @@ public class GanttDiagramGraph> implements ICritical
void setEndDateFor(V task, GanttDate newEnd);
- public List> getConstraints(
- ConstraintCalculator calculator, Set withDependencies,
- Point point);
+ List> getConstraints(ConstraintCalculator calculator, Set withDependencies,
+ Point point);
List> getStartConstraintsFor(V task);
@@ -142,10 +140,11 @@ public class GanttDiagramGraph> implements ICritical
@Override
public Task getOwner(Task task) {
- if (task instanceof Milestone) {
+ if ( task instanceof Milestone ) {
Milestone milestone = (Milestone) task;
return milestone.getOwner();
}
+
return null;
}
@@ -165,14 +164,12 @@ public class GanttDiagramGraph> implements ICritical
}
@Override
- public void registerDependenciesEnforcerHookOn(Task task,
- IDependenciesEnforcerHookFactory hookFactory) {
+ public void registerDependenciesEnforcerHookOn(Task task, IDependenciesEnforcerHookFactory hookFactory) {
task.registerDependenciesEnforcerHook(hookFactory);
}
@Override
- public Dependency createInvisibleDependency(Task origin,
- Task destination, DependencyType type) {
+ public Dependency createInvisibleDependency(Task origin, Task destination, DependencyType type) {
return new Dependency(origin, destination, type, false);
}
@@ -225,11 +222,10 @@ public class GanttDiagramGraph> implements ICritical
}
@Override
- public List> getConstraints(
- ConstraintCalculator calculator,
- Set withDependencies, Point pointBeingModified) {
- return Dependency.getConstraintsFor(calculator, withDependencies,
- pointBeingModified);
+ public List> getConstraints(ConstraintCalculator calculator,
+ Set withDependencies, Point pointBeingModified) {
+
+ return Dependency.getConstraintsFor(calculator, withDependencies, pointBeingModified);
}
@Override
@@ -249,31 +245,28 @@ public class GanttDiagramGraph> implements ICritical
}
- public static class GanttZKDiagramGraph extends
- GanttDiagramGraph {
+ public static class GanttZKDiagramGraph extends GanttDiagramGraph {
- private GanttZKDiagramGraph(boolean scheduleBackwards,
- List> globalStartConstraints,
- List> globalEndConstraints,
- boolean dependenciesConstraintsHavePriority) {
- super(scheduleBackwards, GANTTZK_ADAPTER, globalStartConstraints,
- globalEndConstraints,
+ private GanttZKDiagramGraph(boolean scheduleBackwards, List> globalStartConstraints,
+ List> globalEndConstraints, boolean dependenciesConstraintsHavePriority) {
+
+ super(scheduleBackwards, GANTTZK_ADAPTER, globalStartConstraints, globalEndConstraints,
dependenciesConstraintsHavePriority);
}
}
public interface IGraphChangeListener {
- public void execute();
+ void execute();
}
public static GanttZKDiagramGraph create(boolean scheduleBackwards,
- List> globalStartConstraints,
- List> globalEndConstraints,
- boolean dependenciesConstraintsHavePriority) {
- return new GanttZKDiagramGraph(scheduleBackwards,
- globalStartConstraints,
- globalEndConstraints, dependenciesConstraintsHavePriority);
+ List> globalStartConstraints,
+ List> globalEndConstraints,
+ boolean dependenciesConstraintsHavePriority) {
+
+ return new GanttZKDiagramGraph(scheduleBackwards, globalStartConstraints, globalEndConstraints,
+ dependenciesConstraintsHavePriority);
}
private final IAdapter adapter;
@@ -282,9 +275,9 @@ public class GanttDiagramGraph> implements ICritical
private final TopologicalSorter topologicalSorter;
- private List topLevelTasks = new ArrayList();
+ private List topLevelTasks = new ArrayList<>();
- private Map fromChildToParent = new HashMap();
+ private Map fromChildToParent = new HashMap<>();
private final List> globalStartConstraints;
@@ -302,14 +295,12 @@ public class GanttDiagramGraph> implements ICritical
@Override
protected void postAction() {
- executeGraphChangeListeners(new ArrayList(
- postGraphChangeListeners));
+ executeGraphChangeListeners(new ArrayList<>(postGraphChangeListeners));
}
@Override
protected void preAction() {
- executeGraphChangeListeners(new ArrayList(
- preGraphChangeListeners));
+ executeGraphChangeListeners(new ArrayList<>(preGraphChangeListeners));
}
private void executeGraphChangeListeners(List graphChangeListeners) {
@@ -323,9 +314,9 @@ public class GanttDiagramGraph> implements ICritical
}
};
- private List preGraphChangeListeners = new ArrayList();
+ private List preGraphChangeListeners = new ArrayList<>();
- private List postGraphChangeListeners = new ArrayList();
+ private List postGraphChangeListeners = new ArrayList<>();
public void addPreGraphChangeListener(IGraphChangeListener preGraphChangeListener) {
preGraphChangeListeners.add(preGraphChangeListener);
@@ -343,15 +334,13 @@ public class GanttDiagramGraph> implements ICritical
postGraphChangeListeners.remove(postGraphChangeListener);
}
- public void addPreChangeListeners(
- Collection extends IGraphChangeListener> preChangeListeners) {
+ public void addPreChangeListeners(Collection extends IGraphChangeListener> preChangeListeners) {
for (IGraphChangeListener each : preChangeListeners) {
addPreGraphChangeListener(each);
}
}
- public void addPostChangeListeners(
- Collection extends IGraphChangeListener> postChangeListeners) {
+ public void addPostChangeListeners(Collection extends IGraphChangeListener> postChangeListeners) {
for (IGraphChangeListener each : postChangeListeners) {
addPostGraphChangeListener(each);
}
@@ -363,22 +352,22 @@ public class GanttDiagramGraph> implements ICritical
List> globalStartConstraints,
List> globalEndConstraints,
boolean dependenciesConstraintsHavePriority) {
- return new GanttDiagramGraph(scheduleBackwards, adapter,
- globalStartConstraints,
- globalEndConstraints, dependenciesConstraintsHavePriority);
+
+ return new GanttDiagramGraph<>(scheduleBackwards, adapter, globalStartConstraints, globalEndConstraints,
+ dependenciesConstraintsHavePriority);
}
- protected GanttDiagramGraph(boolean scheduleBackwards,
- IAdapter adapter,
- List> globalStartConstraints,
- List> globalEndConstraints,
- boolean dependenciesConstraintsHavePriority) {
+ protected GanttDiagramGraph(boolean scheduleBackwards, IAdapter adapter,
+ List> globalStartConstraints,
+ List> globalEndConstraints,
+ boolean dependenciesConstraintsHavePriority) {
+
this.scheduleBackwards = scheduleBackwards;
this.adapter = adapter;
this.globalStartConstraints = globalStartConstraints;
this.globalEndConstraints = globalEndConstraints;
this.dependenciesConstraintsHavePriority = dependenciesConstraintsHavePriority;
- this.graph = new SimpleDirectedGraph(adapter.getDependencyType());
+ this.graph = new SimpleDirectedGraph<>(adapter.getDependencyType());
this.topologicalSorter = new TopologicalSorter();
}
@@ -386,24 +375,28 @@ public class GanttDiagramGraph> implements ICritical
enforcer.enforceRestrictionsOn(withoutVisibleIncomingDependencies(getTopLevelTasks()));
}
- private List withoutVisibleIncomingDependencies(
- Collection extends V> tasks) {
- List result = new ArrayList();
+ private List withoutVisibleIncomingDependencies(Collection extends V> tasks) {
+ List result = new ArrayList<>();
for (V each : tasks) {
- if (noVisibleDependencies(isScheduleForward() ? graph
- .incomingEdgesOf(each) : graph.outgoingEdgesOf(each))) {
+
+ boolean condition = noVisibleDependencies(isScheduleForward() ? graph.incomingEdgesOf(each)
+ : graph.outgoingEdgesOf(each));
+
+ if ( condition ) {
result.add(each);
}
}
+
return result;
}
private boolean noVisibleDependencies(Collection extends D> dependencies) {
for (D each : dependencies) {
- if (adapter.isVisible(each)) {
+ if ( adapter.isVisible(each) ) {
return false;
}
}
+
return true;
}
@@ -429,12 +422,12 @@ public class GanttDiagramGraph> implements ICritical
private Map taskPointsByDepthCached = null;
private Map taskPointsByDepth() {
- if (taskPointsByDepthCached != null) {
+ if ( taskPointsByDepthCached != null ) {
return taskPointsByDepthCached;
}
- Map result = new HashMap();
- Map> visitedBy = new HashMap>();
+ Map result = new HashMap<>();
+ Map> visitedBy = new HashMap<>();
Queue withoutIncoming = getInitial(withoutVisibleIncomingDependencies(getTopLevelTasks()));
for (TaskPoint each : withoutIncoming) {
@@ -443,36 +436,35 @@ public class GanttDiagramGraph> implements ICritical
while (!withoutIncoming.isEmpty()) {
TaskPoint current = withoutIncoming.poll();
+
for (TaskPoint each : current.getImmediateSuccessors()) {
- initializeIfNeededForKey(visitedBy, each,
- new HashSet());
+
+ initializeIfNeededForKey(visitedBy, each, new HashSet());
Set visitors = visitedBy.get(each);
visitors.add(current);
- Set predecessorsRequired = each
- .getImmediatePredecessors();
- if (visitors.containsAll(predecessorsRequired)) {
- initializeIfNeededForKey(result, each,
- result.get(current) + 1);
+ Set predecessorsRequired = each.getImmediatePredecessors();
+
+ if ( visitors.containsAll(predecessorsRequired) ) {
+ initializeIfNeededForKey(result, each, result.get(current) + 1);
withoutIncoming.offer(each);
}
}
}
- return taskPointsByDepthCached = Collections
- .unmodifiableMap(result);
+ return taskPointsByDepthCached = Collections.unmodifiableMap(result);
}
- private void initializeIfNeededForKey(Map map, K key,
- T initialValue) {
- if (!map.containsKey(key)) {
+ private void initializeIfNeededForKey(Map map, K key, T initialValue) {
+ if ( !map.containsKey(key) ) {
map.put(key, initialValue);
}
}
private LinkedList getInitial(List initial) {
- LinkedList result = new LinkedList();
+ LinkedList result = new LinkedList<>();
for (V each : initial) {
result.add(allPointsPotentiallyModified(each));
}
+
return result;
}
@@ -480,11 +472,9 @@ public class GanttDiagramGraph> implements ICritical
taskPointsByDepthCached = null;
}
- public List sort(
- Collection extends Recalculation> recalculationsToBeSorted) {
+ public List sort(Collection extends Recalculation> recalculationsToBeSorted) {
- List result = new ArrayList(
- recalculationsToBeSorted);
+ List result = new ArrayList<>(recalculationsToBeSorted);
final Map taskPointsByDepth = taskPointsByDepth();
Collections.sort(result, new Comparator() {
@@ -492,17 +482,18 @@ public class GanttDiagramGraph> implements ICritical
public int compare(Recalculation o1, Recalculation o2) {
int o1Depth = onNullDefault(
taskPointsByDepth.get(o1.taskPoint),
- Integer.MAX_VALUE, "no depth value for "
- + o1.taskPoint);
+ Integer.MAX_VALUE, "no depth value for " + o1.taskPoint);
+
int o2Depth = onNullDefault(
taskPointsByDepth.get(o2.taskPoint),
- Integer.MAX_VALUE, "no depth value for "
- + o2.taskPoint);
+ Integer.MAX_VALUE, "no depth value for " + o2.taskPoint);
+
int result = o1Depth - o2Depth;
- if (result == 0) {
- return asInt(o1.parentRecalculation)
- - asInt(o2.parentRecalculation);
+
+ if ( result == 0 ) {
+ return asInt(o1.parentRecalculation) - asInt(o2.parentRecalculation);
}
+
return result;
}
@@ -510,59 +501,62 @@ public class GanttDiagramGraph> implements ICritical
return b ? 1 : 0;
}
});
+
return result;
}
}
- private static T onNullDefault(T value, T defaultValue,
- String warnMessage) {
- if (value == null) {
- if (warnMessage != null) {
+ private static T onNullDefault(T value, T defaultValue, String warnMessage) {
+ if ( value == null ) {
+ if ( warnMessage != null ) {
LOG.warn(warnMessage);
}
+
return defaultValue;
}
+
return value;
}
public void addTask(V original) {
- List stack = new LinkedList();
+ List stack = new LinkedList<>();
stack.add(original);
- List dependenciesToAdd = new ArrayList();
+ List dependenciesToAdd = new ArrayList<>();
+
while (!stack.isEmpty()){
+
V task = stack.remove(0);
graph.addVertex(task);
topologicalSorter.recalculationNeeded();
adapter.registerDependenciesEnforcerHookOn(task, enforcer);
- if (adapter.isContainer(task)) {
+
+ if ( adapter.isContainer(task) ) {
+
for (V child : adapter.getChildren(task)) {
fromChildToParent.put(child, task);
stack.add(0, child);
- dependenciesToAdd.add(adapter.createInvisibleDependency(
- child, task, DependencyType.END_END));
- dependenciesToAdd.add(adapter.createInvisibleDependency(
- task, child, DependencyType.START_START));
+ dependenciesToAdd.add(adapter.createInvisibleDependency(child, task, DependencyType.END_END));
+ dependenciesToAdd.add(adapter.createInvisibleDependency(task, child, DependencyType.START_START));
}
+
} else {
V owner = adapter.getOwner(task);
- if(owner != null) {
- dependenciesToAdd.add(adapter.createInvisibleDependency(
- task, owner, DependencyType.END_END));
- dependenciesToAdd.add(adapter.createInvisibleDependency(
- owner, task, DependencyType.START_START));
+ if( owner != null ) {
+ dependenciesToAdd.add(adapter.createInvisibleDependency(task, owner, DependencyType.END_END));
+ dependenciesToAdd.add(adapter.createInvisibleDependency(owner, task, DependencyType.START_START));
}
}
}
+
for (D each : dependenciesToAdd) {
add(each, false);
}
}
private interface IDependenciesEnforcer {
- public void setStartDate(GanttDate previousStart,
- GanttDate previousEnd, GanttDate newStart);
+ void setStartDate(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart);
- public void setNewEnd(GanttDate previousEnd, GanttDate newEnd);
+ void setNewEnd(GanttDate previousEnd, GanttDate newEnd);
}
/**
@@ -592,7 +586,7 @@ public class GanttDiagramGraph> implements ICritical
*
*/
public interface IDependenciesEnforcerHook extends IDependenciesEnforcer {
- public void positionPotentiallyModified();
+ void positionPotentiallyModified();
}
public interface IDependenciesEnforcerHookFactory {
@@ -601,24 +595,22 @@ public class GanttDiagramGraph> implements ICritical
* {@link INotificationAfterDependenciesEnforcement notifier} to notify
* the changes that have happened due to the algorithm.
*/
- public IDependenciesEnforcerHook create(T task,
- INotificationAfterDependenciesEnforcement notifier);
+ IDependenciesEnforcerHook create(T task, INotificationAfterDependenciesEnforcement notifier);
- public IDependenciesEnforcerHook create(T task);
+ IDependenciesEnforcerHook create(T task);
}
public interface INotificationAfterDependenciesEnforcement {
- public void onStartDateChange(GanttDate previousStart,
- GanttDate previousEnd, GanttDate newStart);
+ void onStartDateChange(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart);
- public void onEndDateChange(GanttDate previousEnd, GanttDate newEnd);
+ void onEndDateChange(GanttDate previousEnd, GanttDate newEnd);
}
- private static final INotificationAfterDependenciesEnforcement EMPTY_NOTIFICATOR = new INotificationAfterDependenciesEnforcement() {
+ private static final INotificationAfterDependenciesEnforcement EMPTY_NOTIFICATOR =
+ new INotificationAfterDependenciesEnforcement() {
@Override
- public void onStartDateChange(GanttDate previousStart,
- GanttDate previousEnd, GanttDate newStart) {
+ public void onStartDateChange(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart) {
}
@Override
@@ -633,7 +625,7 @@ public class GanttDiagramGraph> implements ICritical
*/
public class DeferedNotifier {
- private Map notificationsPending = new LinkedHashMap();
+ private Map notificationsPending = new LinkedHashMap<>();
public void add(V task, StartDateNofitication notification) {
retrieveOrCreateFor(task).setStartDateNofitication(notification);
@@ -641,10 +633,11 @@ public class GanttDiagramGraph> implements ICritical
private NotificationPendingForTask retrieveOrCreateFor(V task) {
NotificationPendingForTask result = notificationsPending.get(task);
- if (result == null) {
+ if ( result == null ) {
result = new NotificationPendingForTask();
notificationsPending.put(task, result);
}
+
return result;
}
@@ -653,8 +646,7 @@ public class GanttDiagramGraph> implements ICritical
}
public void doNotifications() {
- for (NotificationPendingForTask each : notificationsPending
- .values()) {
+ for (NotificationPendingForTask each : notificationsPending.values()) {
each.doNotification();
}
notificationsPending.clear();
@@ -667,23 +659,24 @@ public class GanttDiagramGraph> implements ICritical
private LengthNotification lengthNofitication;
- void setStartDateNofitication(
- StartDateNofitication startDateNofitication) {
- this.startDateNofitication = this.startDateNofitication == null ? startDateNofitication
- : this.startDateNofitication
- .coalesce(startDateNofitication);
+ void setStartDateNofitication(StartDateNofitication startDateNofitication) {
+
+ this.startDateNofitication = (this.startDateNofitication == null) ? startDateNofitication :
+ this.startDateNofitication.coalesce(startDateNofitication);
}
void setLengthNofitication(LengthNotification lengthNofitication) {
- this.lengthNofitication = this.lengthNofitication == null ? lengthNofitication
- : this.lengthNofitication.coalesce(lengthNofitication);
+
+ this.lengthNofitication = (this.lengthNofitication == null) ? lengthNofitication :
+ this.lengthNofitication.coalesce(lengthNofitication);
}
void doNotification() {
- if (startDateNofitication != null) {
+ if ( startDateNofitication != null ) {
startDateNofitication.doNotification();
}
- if (lengthNofitication != null) {
+
+ if ( lengthNofitication != null ) {
lengthNofitication.doNotification();
}
}
@@ -696,25 +689,23 @@ public class GanttDiagramGraph> implements ICritical
private final GanttDate previousEnd;
private final GanttDate newStart;
- public StartDateNofitication(
- INotificationAfterDependenciesEnforcement notification,
- GanttDate previousStart, GanttDate previousEnd,
- GanttDate newStart) {
+ public StartDateNofitication(INotificationAfterDependenciesEnforcement notification,
+ GanttDate previousStart,
+ GanttDate previousEnd,
+ GanttDate newStart) {
+
this.notification = notification;
this.previousStart = previousStart;
this.previousEnd = previousEnd;
this.newStart = newStart;
}
- public StartDateNofitication coalesce(
- StartDateNofitication startDateNofitication) {
- return new StartDateNofitication(notification, previousStart,
- previousEnd, startDateNofitication.newStart);
+ public StartDateNofitication coalesce(StartDateNofitication startDateNofitication) {
+ return new StartDateNofitication(notification, previousStart, previousEnd, startDateNofitication.newStart);
}
void doNotification() {
- notification
- .onStartDateChange(previousStart, previousEnd, newStart);
+ notification.onStartDateChange(previousStart, previousEnd, newStart);
}
}
@@ -724,9 +715,10 @@ public class GanttDiagramGraph> implements ICritical
private final GanttDate previousEnd;
private final GanttDate newEnd;
- public LengthNotification(
- INotificationAfterDependenciesEnforcement notification,
- GanttDate previousEnd, GanttDate newEnd) {
+ public LengthNotification(INotificationAfterDependenciesEnforcement notification,
+ GanttDate previousEnd,
+ GanttDate newEnd) {
+
this.notification = notification;
this.previousEnd = previousEnd;
this.newEnd = newEnd;
@@ -734,8 +726,7 @@ public class GanttDiagramGraph> implements ICritical
}
public LengthNotification coalesce(LengthNotification lengthNofitication) {
- return new LengthNotification(notification, previousEnd,
- lengthNofitication.newEnd);
+ return new LengthNotification(notification, previousEnd, lengthNofitication.newEnd);
}
void doNotification() {
@@ -743,10 +734,9 @@ public class GanttDiagramGraph> implements ICritical
}
}
- private class DependenciesEnforcer implements
- IDependenciesEnforcerHookFactory {
+ private class DependenciesEnforcer implements IDependenciesEnforcerHookFactory {
- private ThreadLocal deferedNotifier = new ThreadLocal();
+ private ThreadLocal deferedNotifier = new ThreadLocal<>();
/**
* It creates a {@link IDependenciesEnforcerHook} that starts the
@@ -754,12 +744,10 @@ public class GanttDiagramGraph> implements ICritical
* modifications records the changes onNotification.
*/
@Override
- public IDependenciesEnforcerHook create(V task,
- INotificationAfterDependenciesEnforcement notificator) {
+ public IDependenciesEnforcerHook create(V task, INotificationAfterDependenciesEnforcement notificator) {
return withPositionPotentiallyModified(
task,
- onlyEnforceDependenciesOnEntrance(onEntrance(task),
- onNotification(task, notificator)));
+ onlyEnforceDependenciesOnEntrance(onEntrance(task), onNotification(task, notificator)));
}
@Override
@@ -774,8 +762,7 @@ public class GanttDiagramGraph> implements ICritical
private IDependenciesEnforcer onEntrance(final V task) {
return new IDependenciesEnforcer() {
- public void setStartDate(GanttDate previousStart,
- GanttDate previousEnd, GanttDate newStart) {
+ public void setStartDate(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart) {
taskPositionModified(task);
}
@@ -792,23 +779,22 @@ public class GanttDiagramGraph> implements ICritical
* dependencies enforcement algorithm.
*/
private IDependenciesEnforcer onNotification(final V task,
- final INotificationAfterDependenciesEnforcement notification) {
+ final INotificationAfterDependenciesEnforcement notification) {
return new IDependenciesEnforcer() {
@Override
- public void setStartDate(GanttDate previousStart,
- GanttDate previousEnd, GanttDate newStart) {
- StartDateNofitication startDateNotification = new StartDateNofitication(
- notification, previousStart, previousEnd,
- newStart);
+ public void setStartDate(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart) {
+
+ StartDateNofitication startDateNotification =
+ new StartDateNofitication(notification, previousStart, previousEnd, newStart);
+
deferedNotifier.get().add(task, startDateNotification);
}
@Override
public void setNewEnd(GanttDate previousEnd, GanttDate newEnd) {
- LengthNotification lengthNotification = new LengthNotification(
- notification, previousEnd, newEnd);
+ LengthNotification lengthNotification = new LengthNotification(notification, previousEnd, newEnd);
deferedNotifier.get().add(task, lengthNotification);
}
};
@@ -819,13 +805,12 @@ public class GanttDiagramGraph> implements ICritical
* Enrich {@link IDependenciesEnforcer} with
* {@link IDependenciesEnforcerHook#positionPotentiallyModified()}.
*/
- private IDependenciesEnforcerHook withPositionPotentiallyModified(
- final V task, final IDependenciesEnforcer enforcer) {
+ private IDependenciesEnforcerHook withPositionPotentiallyModified(final V task,
+ final IDependenciesEnforcer enforcer) {
return new IDependenciesEnforcerHook() {
@Override
- public void setStartDate(GanttDate previousStart,
- GanttDate previousEnd, GanttDate newStart) {
+ public void setStartDate(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart) {
enforcer.setStartDate(previousStart, previousEnd, newStart);
}
@@ -850,74 +835,64 @@ public class GanttDiagramGraph> implements ICritical
* onEntrance. Otherwise it delegates to
* notifier.
*/
- private IDependenciesEnforcer onlyEnforceDependenciesOnEntrance(
- final IDependenciesEnforcer onEntrance,
- final IDependenciesEnforcer notifier) {
+ private IDependenciesEnforcer onlyEnforceDependenciesOnEntrance(final IDependenciesEnforcer onEntrance,
+ final IDependenciesEnforcer notifier) {
return new IDependenciesEnforcer() {
@Override
public void setStartDate(final GanttDate previousStart,
- final GanttDate previousEnd, final GanttDate newStart) {
- positionsUpdatingGuard
- .entranceRequested(new IReentranceCases() {
+ final GanttDate previousEnd,
+ final GanttDate newStart) {
+
+ positionsUpdatingGuard.entranceRequested(new IReentranceCases() {
+ @Override
+ public void ifNewEntrance() {
+ onNewEntrance(new IAction() {
@Override
- public void ifNewEntrance() {
- onNewEntrance(new IAction() {
-
- @Override
- public void doAction() {
- notifier.setStartDate(
- previousStart,
- previousEnd, newStart);
- onEntrance.setStartDate(
- previousStart, previousEnd,
- newStart);
- }
- });
- }
-
- @Override
- public void ifAlreadyInside() {
- notifier.setStartDate(previousStart,
- previousEnd, newStart);
-
+ public void doAction() {
+ notifier.setStartDate(previousStart, previousEnd, newStart);
+ onEntrance.setStartDate(previousStart, previousEnd, newStart);
}
});
+ }
+
+ @Override
+ public void ifAlreadyInside() {
+ notifier.setStartDate(previousStart, previousEnd, newStart);
+
+ }
+ });
}
@Override
- public void setNewEnd(final GanttDate previousEnd,
- final GanttDate newEnd) {
- positionsUpdatingGuard
- .entranceRequested(new IReentranceCases() {
+ public void setNewEnd(final GanttDate previousEnd, final GanttDate newEnd) {
+ positionsUpdatingGuard.entranceRequested(new IReentranceCases() {
+
+ @Override
+ public void ifNewEntrance() {
+ onNewEntrance(new IAction() {
@Override
- public void ifNewEntrance() {
- onNewEntrance(new IAction() {
-
- @Override
- public void doAction() {
- notifier.setNewEnd(previousEnd,
- newEnd);
- onEntrance.setNewEnd(previousEnd,
- newEnd);
- }
- });
- }
-
- @Override
- public void ifAlreadyInside() {
+ public void doAction() {
notifier.setNewEnd(previousEnd, newEnd);
+ onEntrance.setNewEnd(previousEnd, newEnd);
}
});
+ }
+
+ @Override
+ public void ifAlreadyInside() {
+ notifier.setNewEnd(previousEnd, newEnd);
+ }
+ });
}
};
}
void enforceRestrictionsOn(Collection extends V> tasks) {
- List allRecalculations = new ArrayList();
+ List allRecalculations = new ArrayList<>();
for (V each : tasks) {
allRecalculations.addAll(getRecalculationsNeededFrom(each));
}
@@ -925,12 +900,12 @@ public class GanttDiagramGraph> implements ICritical
}
void enforceRestrictionsOn(V task) {
- enforceRestrictionsOn(getRecalculationsNeededFrom(task),
- Collections.singleton(task));
+ enforceRestrictionsOn(getRecalculationsNeededFrom(task), Collections.singleton(task));
}
void enforceRestrictionsOn(final List recalculations,
final Collection extends V> initiallyModified) {
+
executeWithPreAndPostActionsOnlyIfNewEntrance(new IAction() {
@Override
public void doAction() {
@@ -939,8 +914,7 @@ public class GanttDiagramGraph> implements ICritical
});
}
- private void executeWithPreAndPostActionsOnlyIfNewEntrance(
- final IAction action) {
+ private void executeWithPreAndPostActionsOnlyIfNewEntrance(final IAction action) {
positionsUpdatingGuard.entranceRequested(new IReentranceCases() {
@Override
@@ -1011,6 +985,7 @@ public class GanttDiagramGraph> implements ICritical
});
}
});
+
return result;
}
@@ -1019,22 +994,24 @@ public class GanttDiagramGraph> implements ICritical
@Override
public void doAction() {
List recalculationsNeededFrom = getRecalculationsNeededFrom(task);
- doRecalculations(recalculationsNeededFrom,
- Collections.singletonList(task));
+ doRecalculations(recalculationsNeededFrom, Collections.singletonList(task));
}
});
}
private void doRecalculations(List recalculationsNeeded,
Collection extends V> initiallyModified) {
- Set allModified = new HashSet();
+
+ Set allModified = new HashSet<>();
allModified.addAll(initiallyModified);
+
for (Recalculation each : recalculationsNeeded) {
boolean modified = each.doRecalculation();
if ( modified ) {
allModified.add(each.taskPoint.task);
}
}
+
List shrunkContainers = shrunkContainersOfModified(allModified);
for (V each : getTaskAffectedByShrinking(shrunkContainers)) {
doRecalculations(getRecalculationsNeededFrom(each),
@@ -1043,59 +1020,65 @@ public class GanttDiagramGraph> implements ICritical
}
private List getTaskAffectedByShrinking(List shrunkContainers) {
- List tasksAffectedByShrinking = new ArrayList();
+ List tasksAffectedByShrinking = new ArrayList<>();
for (V each : shrunkContainers) {
+
for (D eachDependency : graph.outgoingEdgesOf(each)) {
- if (adapter.getType(eachDependency) == DependencyType.START_START
- && adapter.isVisible(eachDependency)) {
- tasksAffectedByShrinking.add(adapter
- .getDestination(eachDependency));
+
+ boolean condition = adapter.getType(eachDependency) == DependencyType.START_START &&
+ adapter.isVisible(eachDependency);
+
+ if ( condition ) {
+ tasksAffectedByShrinking.add(adapter.getDestination(eachDependency));
}
}
}
+
return tasksAffectedByShrinking;
}
- private List shrunkContainersOfModified(
- Set allModified) {
+ private List shrunkContainersOfModified(Set allModified) {
Set topmostToShrink = getTopMostThatCouldPotentiallyNeedShrinking(allModified);
- List allToShrink = new ArrayList();
+ List allToShrink = new ArrayList<>();
+
for (V each : topmostToShrink) {
allToShrink.addAll(getContainersBottomUp(each));
}
- List result = new ArrayList();
+
+ List result = new ArrayList<>();
for (V each : allToShrink) {
boolean modified = enforceParentShrinkage(each);
- if (modified) {
+ if ( modified ) {
result.add(each);
}
}
+
return result;
}
- private Set getTopMostThatCouldPotentiallyNeedShrinking(
- Collection modified) {
- Set result = new HashSet();
+ private Set getTopMostThatCouldPotentiallyNeedShrinking(Collection modified) {
+ Set result = new HashSet<>();
for (V each : modified) {
V t = getTopmostFor(each);
- if (adapter.isContainer(t)) {
+ if ( adapter.isContainer(t) ) {
result.add(t);
}
}
+
return result;
}
- private Collection extends V> getContainersBottomUp(
- V container) {
+ private Collection extends V> getContainersBottomUp(V container) {
List result = new ArrayList();
List tasks = adapter.getChildren(container);
for (V each : tasks) {
- if (adapter.isContainer(each)) {
+ if ( adapter.isContainer(each) ) {
result.addAll(getContainersBottomUp(each));
result.add(each);
}
}
result.add(container);
+
return result;
}
@@ -1104,13 +1087,13 @@ public class GanttDiagramGraph> implements ICritical
GanttDate firstStart = getSmallestBeginDateFromChildrenFor(container);
GanttDate lastEnd = getBiggestEndDateFromChildrenFor(container);
GanttDate previousEnd = adapter.getEndDateFor(container);
- if (firstStart.after(oldBeginDate) || previousEnd.after(lastEnd)) {
- adapter.setStartDateFor(container,
- GanttDate.max(firstStart, oldBeginDate));
- adapter.setEndDateFor(container,
- GanttDate.min(lastEnd, previousEnd));
+
+ if ( firstStart.after(oldBeginDate) || previousEnd.after(lastEnd) ) {
+ adapter.setStartDateFor(container, GanttDate.max(firstStart, oldBeginDate));
+ adapter.setEndDateFor(container, GanttDate.min(lastEnd, previousEnd));
return true;
}
+
return false;
}
}
@@ -1125,18 +1108,21 @@ public class GanttDiagramGraph> implements ICritical
private List getChildrenDates(V container, Point point) {
List children = adapter.getChildren(container);
- List result = new ArrayList();
- if (children.isEmpty()) {
+ List result = new ArrayList<>();
+
+ if ( children.isEmpty() ) {
result.add(getDateFor(container, point));
}
+
for (V each : children) {
result.add(getDateFor(each, point));
}
+
return result;
}
GanttDate getDateFor(V task, Point point) {
- if (point.equals(Point.START)) {
+ if ( point.equals(Point.START) ) {
return adapter.getStartDate(task);
} else {
return adapter.getEndDateFor(task);
@@ -1144,29 +1130,33 @@ public class GanttDiagramGraph> implements ICritical
}
List getRecalculationsNeededFrom(V task) {
- List result = new ArrayList();
- Set parentRecalculationsAlreadyDone = new HashSet();
+ List result = new ArrayList<>();
+ Set parentRecalculationsAlreadyDone = new HashSet<>();
Recalculation first = recalculationFor(allPointsPotentiallyModified(task));
first.couldHaveBeenModifiedBeforehand();
- result.addAll(getParentsRecalculations(parentRecalculationsAlreadyDone,
- first.taskPoint));
+ result.addAll(getParentsRecalculations(parentRecalculationsAlreadyDone, first.taskPoint));
result.add(first);
- Queue pendingOfVisit = new LinkedList();
+ Queue pendingOfVisit = new LinkedList<>();
pendingOfVisit.offer(first);
- Map alreadyVisited = new HashMap();
+ Map alreadyVisited = new HashMap<>();
alreadyVisited.put(first, first);
while (!pendingOfVisit.isEmpty()) {
+
Recalculation current = pendingOfVisit.poll();
+
for (TaskPoint each : current.taskPoint.getImmediateSuccessors()) {
+
if ( each.isImmediatelyDerivedFrom(current.taskPoint) ) {
continue;
}
+
Recalculation recalculationToAdd = getRecalcualtionToAdd(each, alreadyVisited);
recalculationToAdd.comesFromPredecessor(current);
+
if ( !alreadyVisited.containsKey(recalculationToAdd) ) {
result.addAll(getParentsRecalculations(parentRecalculationsAlreadyDone, each));
result.add(recalculationToAdd);
@@ -1175,62 +1165,71 @@ public class GanttDiagramGraph> implements ICritical
}
}
}
+
return topologicalSorter.sort(result);
}
- private Recalculation getRecalcualtionToAdd(TaskPoint taskPoint,
- Map alreadyVisited) {
+ private Recalculation getRecalcualtionToAdd(TaskPoint taskPoint, Map alreadyVisited) {
Recalculation result = recalculationFor(taskPoint);
- if (alreadyVisited.containsKey(result)) {
+
+ if ( alreadyVisited.containsKey(result) ) {
return alreadyVisited.get(result);
} else {
return result;
}
}
- private List getParentsRecalculations(
- Set parentRecalculationsAlreadyDone,
- TaskPoint taskPoint) {
- List result = new ArrayList();
+ private List getParentsRecalculations(Set parentRecalculationsAlreadyDone,
+ TaskPoint taskPoint) {
+ List result = new ArrayList<>();
+
for (TaskPoint eachParent : parentsRecalculationsNeededFor(taskPoint)) {
+
Recalculation parentRecalculation = parentRecalculation(eachParent.task);
- if (!parentRecalculationsAlreadyDone
- .contains(parentRecalculation)) {
+
+ if ( !parentRecalculationsAlreadyDone.contains(parentRecalculation) ) {
parentRecalculationsAlreadyDone.add(parentRecalculation);
result.add(parentRecalculation);
}
}
+
return result;
}
private Set parentsRecalculationsNeededFor(TaskPoint current) {
- Set result = new LinkedHashSet();
- if (current.areAllPointsPotentiallyModified()) {
+ Set result = new LinkedHashSet<>();
+
+ if ( current.areAllPointsPotentiallyModified() ) {
List path = fromTaskToTop(current.task);
- if (path.size() > 1) {
+
+ if ( path.size() > 1 ) {
path = path.subList(1, path.size());
Collections.reverse(path);
result.addAll(asBothPoints(path));
}
}
+
return result;
}
private Collection extends TaskPoint> asBothPoints(List parents) {
- List result = new ArrayList();
+ List result = new ArrayList<>();
for (V each : parents) {
result.add(allPointsPotentiallyModified(each));
}
+
return result;
}
private List fromTaskToTop(V task) {
- List result = new ArrayList();
+ List result = new ArrayList<>();
V current = task;
- while (current != null) {
+
+ while ( current != null ) {
result.add(current);
current = fromChildToParent.get(current);
}
+
return result;
}
@@ -1248,7 +1247,7 @@ public class GanttDiagramGraph> implements ICritical
private final TaskPoint taskPoint;
- private Set recalculationsCouldAffectThis = new HashSet();
+ private Set recalculationsCouldAffectThis = new HashSet<>();
private boolean recalculationCalled = false;
@@ -1277,8 +1276,7 @@ public class GanttDiagramGraph> implements ICritical
}
private boolean haveToDoCalculation() {
- return recalculationsCouldAffectThis.isEmpty()
- || predecessorsHaveBeenModified();
+ return recalculationsCouldAffectThis.isEmpty() || predecessorsHaveBeenModified();
}
private boolean predecessorsHaveBeenModified() {
@@ -1296,19 +1294,20 @@ public class GanttDiagramGraph> implements ICritical
private boolean taskChangesPosition() {
ChangeTracker tracker = trackTaskChanges();
- Constraint.initialValue(noRestrictions())
- .withConstraints(getConstraintsToApply())
- .apply();
+ Constraint.initialValue(noRestrictions()).withConstraints(getConstraintsToApply()).apply();
return tracker.taskHasChanged();
}
@SuppressWarnings("unchecked")
private List> getConstraintsToApply() {
- Constraint weakForces = scheduleBackwards ? new WeakForwardForces()
- : new WeakBackwardsForces();
- Constraint dominatingForces = scheduleBackwards ? new DominatingBackwardForces()
- : new DominatingForwardForces();
- if (dependenciesConstraintsHavePriority) {
+
+ Constraint weakForces =
+ scheduleBackwards ? new WeakForwardForces() : new WeakBackwardsForces();
+
+ Constraint dominatingForces =
+ scheduleBackwards ? new DominatingBackwardForces() : new DominatingForwardForces();
+
+ if ( dependenciesConstraintsHavePriority ) {
return asList(weakForces, dominatingForces);
} else {
return asList(weakForces, dominatingForces, weakForces);
@@ -1346,8 +1345,7 @@ public class GanttDiagramGraph> implements ICritical
private final class NoRestrictions extends PositionRestrictions {
public NoRestrictions(TaskPoint taskPoint) {
- super(adapter.getStartDate(taskPoint.task), adapter
- .getEndDateFor(taskPoint.task));
+ super(adapter.getStartDate(taskPoint.task), adapter.getEndDateFor(taskPoint.task));
}
@Override
@@ -1372,14 +1370,18 @@ public class GanttDiagramGraph> implements ICritical
}
DatesBasedPositionRestrictions biggerThan(GanttDate start, GanttDate end) {
- ComparisonType type = isScheduleForward() ? ComparisonType.BIGGER_OR_EQUAL_THAN
- : ComparisonType.BIGGER_OR_EQUAL_THAN_LEFT_FLOATING;
+
+ ComparisonType type = isScheduleForward() ? ComparisonType.BIGGER_OR_EQUAL_THAN :
+ ComparisonType.BIGGER_OR_EQUAL_THAN_LEFT_FLOATING;
+
return new DatesBasedPositionRestrictions(type, start, end);
}
DatesBasedPositionRestrictions lessThan(GanttDate start, GanttDate end) {
- ComparisonType type = isScheduleForward() ? ComparisonType.LESS_OR_EQUAL_THAN_RIGHT_FLOATING
- : ComparisonType.LESS_OR_EQUAL_THAN;
+
+ ComparisonType type = isScheduleForward() ? ComparisonType.LESS_OR_EQUAL_THAN_RIGHT_FLOATING :
+ ComparisonType.LESS_OR_EQUAL_THAN;
+
return new DatesBasedPositionRestrictions(type, start, end);
}
@@ -1388,27 +1390,22 @@ public class GanttDiagramGraph> implements ICritical
private Constraint startConstraint;
private Constraint endConstraint;
- public DatesBasedPositionRestrictions(
- ComparisonType comparisonType, GanttDate start,
- GanttDate end) {
+ public DatesBasedPositionRestrictions(ComparisonType comparisonType, GanttDate start, GanttDate end) {
super(start, end);
- this.startConstraint = ConstraintOnComparableValues
- .instantiate(comparisonType, start);
- this.endConstraint = ConstraintOnComparableValues.instantiate(
- comparisonType, end);
+ this.startConstraint = ConstraintOnComparableValues.instantiate(comparisonType, start);
+ this.endConstraint = ConstraintOnComparableValues.instantiate(comparisonType, end);
}
boolean satisfies(PositionRestrictions other) {
- if (DatesBasedPositionRestrictions.class.isInstance(other)) {
- return satisfies(DatesBasedPositionRestrictions.class
- .cast(other));
+ if ( DatesBasedPositionRestrictions.class.isInstance(other) ) {
+ return satisfies(DatesBasedPositionRestrictions.class.cast(other));
}
+
return false;
}
private boolean satisfies(DatesBasedPositionRestrictions other) {
- return startConstraint.isSatisfiedBy(other.getStart())
- && endConstraint.isSatisfiedBy(other.getEnd());
+ return startConstraint.isSatisfiedBy(other.getStart()) && endConstraint.isSatisfiedBy(other.getEnd());
}
@Override
@@ -1435,8 +1432,8 @@ public class GanttDiagramGraph> implements ICritical
}
public boolean taskHasChanged() {
- return areNotEqual(adapter.getStartDate(task), this.start)
- || areNotEqual(adapter.getEndDateFor(task), this.end);
+ return areNotEqual(adapter.getStartDate(task), this.start) ||
+ areNotEqual(adapter.getEndDateFor(task), this.end);
}
}
@@ -1460,11 +1457,11 @@ public class GanttDiagramGraph> implements ICritical
private PositionRestrictions resultingRestrictions = noRestrictions();
- protected PositionRestrictions applyConstraintTo(
- PositionRestrictions restrictions) {
- if (adapter.isFixed(task)) {
+ protected PositionRestrictions applyConstraintTo(PositionRestrictions restrictions) {
+ if ( adapter.isFixed(task) ) {
return restrictions;
}
+
resultingRestrictions = enforceUsingPreviousRestrictions(restrictions);
return resultingRestrictions;
}
@@ -1480,8 +1477,7 @@ public class GanttDiagramGraph> implements ICritical
}
private void checkStartConstraints(GanttDate finalStart) {
- Constraint
- .checkSatisfyResult(getStartConstraints(), finalStart);
+ Constraint.checkSatisfyResult(getStartConstraints(), finalStart);
}
private void checkEndConstraints(GanttDate finalEnd) {
@@ -1492,8 +1488,7 @@ public class GanttDiagramGraph> implements ICritical
abstract List> getEndConstraints();
- abstract PositionRestrictions enforceUsingPreviousRestrictions(
- PositionRestrictions restrictions);
+ abstract PositionRestrictions enforceUsingPreviousRestrictions(PositionRestrictions restrictions);
}
abstract class Dominating extends Forces {
@@ -1524,32 +1519,31 @@ public class GanttDiagramGraph> implements ICritical
}
@Override
- PositionRestrictions enforceUsingPreviousRestrictions(
- PositionRestrictions restrictions) {
- if (parentRecalculation) {
+ PositionRestrictions enforceUsingPreviousRestrictions(PositionRestrictions restrictions) {
+ if ( parentRecalculation ) {
// avoid interference from task containers shrinking
return enforcePrimaryPoint(restrictions);
- } else if (taskPoint.areAllPointsPotentiallyModified()) {
+ } else if ( taskPoint.areAllPointsPotentiallyModified() ) {
return enforceBoth(restrictions);
- } else if (taskPoint.somePointPotentiallyModified()) {
+ } else if ( taskPoint.somePointPotentiallyModified() ) {
return enforceSecondaryPoint(restrictions);
}
+
return restrictions;
}
- private PositionRestrictions enforceBoth(
- PositionRestrictions restrictions) {
+ private PositionRestrictions enforceBoth(PositionRestrictions restrictions) {
ChangeTracker changeTracker = trackTaskChanges();
PositionRestrictions currentRestrictions = enforcePrimaryPoint(restrictions);
- if (changeTracker.taskHasChanged() || parentRecalculation
- || couldHaveBeenModifiedBeforehand) {
+
+ if ( changeTracker.taskHasChanged() || parentRecalculation || couldHaveBeenModifiedBeforehand ) {
return enforceSecondaryPoint(currentRestrictions);
}
+
return currentRestrictions;
}
- private PositionRestrictions enforcePrimaryPoint(
- PositionRestrictions originalRestrictions) {
+ private PositionRestrictions enforcePrimaryPoint(PositionRestrictions originalRestrictions) {
GanttDate newDominatingPointDate = calculatePrimaryPointDate(originalRestrictions);
return enforceRestrictionsFor(primary, newDominatingPointDate);
}
@@ -1560,78 +1554,75 @@ public class GanttDiagramGraph> implements ICritical
* return the existent commanding point date
* @param originalRestrictions
*/
- private GanttDate calculatePrimaryPointDate(
- PositionRestrictions originalRestrictions) {
- GanttDate newDate = Constraint
- . initialValue(null)
- .withConstraints(
- getConstraintsFrom(originalRestrictions,
- getPrimaryPoint()))
+ private GanttDate calculatePrimaryPointDate(PositionRestrictions originalRestrictions) {
+
+ GanttDate newDate = Constraint. initialValue(null)
+ .withConstraints(getConstraintsFrom(originalRestrictions, getPrimaryPoint()))
.withConstraints(getConstraintsFor(getPrimaryPoint()))
.applyWithoutFinalCheck();
- if (newDate == null) {
+
+ if ( newDate == null ) {
return getTaskDateFor(getPrimaryPoint());
}
+
return newDate;
}
private List> getConstraintsFor(Point point) {
Validate.isTrue(isSupportedPoint(point));
switch (point) {
+
case START:
return getStartConstraints();
+
case END:
return getEndConstraints();
+
default:
throw new RuntimeException("shouldn't happen");
}
}
- private PositionRestrictions enforceSecondaryPoint(
- PositionRestrictions restrictions) {
+ private PositionRestrictions enforceSecondaryPoint(PositionRestrictions restrictions) {
GanttDate newSecondaryPointDate = calculateSecondaryPointDate(restrictions);
- if (newSecondaryPointDate == null) {
+ if ( newSecondaryPointDate == null ) {
return restrictions;
}
- restrictions = enforceRestrictionsFor(getSecondaryPoint(),
- newSecondaryPointDate);
- if (taskPoint.onlyModifies(getSecondaryPoint())) {
- // primary point constraints could be the ones "commanding"
- // now
+
+ restrictions = enforceRestrictionsFor(getSecondaryPoint(), newSecondaryPointDate);
+
+ if ( taskPoint.onlyModifies(getSecondaryPoint()) ) {
+
+ // primary point constraints could be the ones "commanding" now
GanttDate potentialPrimaryDate = calculatePrimaryPointDate(restrictions);
- if (!doSatisfyOrderCondition(potentialPrimaryDate,
- getTaskDateFor(getPrimaryPoint()))) {
- return enforceRestrictionsFor(getPrimaryPoint(),
- potentialPrimaryDate);
+
+ if ( !doSatisfyOrderCondition(potentialPrimaryDate, getTaskDateFor(getPrimaryPoint())) ) {
+ return enforceRestrictionsFor(getPrimaryPoint(), potentialPrimaryDate);
}
}
+
return restrictions;
}
- private GanttDate calculateSecondaryPointDate(
- PositionRestrictions restrictions) {
- GanttDate newEnd = Constraint
- . initialValue(null)
- .withConstraints(
- getConstraintsFrom(restrictions,
- getSecondaryPoint()))
+ private GanttDate calculateSecondaryPointDate(PositionRestrictions restrictions) {
+
+ GanttDate newEnd = Constraint. initialValue(null)
+ .withConstraints(getConstraintsFrom(restrictions, getSecondaryPoint()))
.withConstraints(getConstraintsFor(getSecondaryPoint()))
.applyWithoutFinalCheck();
+
return newEnd;
}
- protected abstract boolean doSatisfyOrderCondition(
- GanttDate supposedlyBefore, GanttDate supposedlyAfter);
+ protected abstract boolean doSatisfyOrderCondition(GanttDate supposedlyBefore, GanttDate supposedlyAfter);
- private PositionRestrictions enforceRestrictionsFor(Point point,
- GanttDate newDate) {
+ private PositionRestrictions enforceRestrictionsFor(Point point, GanttDate newDate) {
GanttDate old = getTaskDateFor(point);
- if (areNotEqual(old, newDate)) {
+ if ( areNotEqual(old, newDate) ) {
setTaskDateFor(point, newDate);
}
- return createRestrictionsFor(getTaskDateFor(Point.START),
- getTaskDateFor(Point.END));
+ return createRestrictionsFor(getTaskDateFor(Point.START), getTaskDateFor(Point.END));
}
GanttDate getTaskDateFor(Point point) {
@@ -1639,55 +1630,62 @@ public class GanttDiagramGraph> implements ICritical
return getDateFor(task, point);
}
- protected abstract PositionRestrictions createRestrictionsFor(
- GanttDate start, GanttDate end);
+ protected abstract PositionRestrictions createRestrictionsFor(GanttDate start, GanttDate end);
private void setTaskDateFor(Point point, GanttDate date) {
Validate.isTrue(isSupportedPoint(point));
switch (point) {
+
case START:
adapter.setStartDateFor(task, date);
break;
+
case END:
adapter.setEndDateFor(task, date);
}
}
- private List> getConstraintsFrom(
- PositionRestrictions restrictions, Point point) {
+ private List> getConstraintsFrom(PositionRestrictions restrictions, Point point) {
Validate.isTrue(isSupportedPoint(point));
switch (point) {
+
case START:
return restrictions.getStartConstraints();
+
case END:
return restrictions.getEndConstraints();
+
default:
throw new RuntimeException("shouldn't happen");
}
}
protected List> getConstraintsForPrimaryPoint() {
- List> result = new ArrayList>();
- if (dependenciesConstraintsHavePriority) {
+ List> result = new ArrayList<>();
+
+ if ( dependenciesConstraintsHavePriority ) {
result.addAll(getTaskConstraints(getPrimaryPoint()));
result.addAll(getDependenciesConstraintsFor(getPrimaryPoint()));
-
} else {
result.addAll(getDependenciesConstraintsFor(getPrimaryPoint()));
result.addAll(getTaskConstraints(getPrimaryPoint()));
}
+
result.addAll(getGlobalConstraintsToApply(getPrimaryPoint()));
+
return result;
}
- private Collection> getGlobalConstraintsToApply(
- Point point) {
+ private Collection> getGlobalConstraintsToApply(Point point) {
Validate.isTrue(isSupportedPoint(point));
switch (point) {
+
case START:
return globalStartConstraints;
+
case END:
return globalEndConstraints;
+
default:
throw new RuntimeException("shouldn't happen");
}
@@ -1697,11 +1695,9 @@ public class GanttDiagramGraph> implements ICritical
return getDependenciesConstraintsFor(getSecondaryPoint());
}
- private List> getDependenciesConstraintsFor(
- Point point) {
+ private List> getDependenciesConstraintsFor(Point point) {
final Set withDependencies = getDependenciesAffectingThisTask();
- return adapter.getConstraints(getCalculator(),
- withDependencies, point);
+ return adapter.getConstraints(getCalculator(), withDependencies, point);
}
protected abstract Set getDependenciesAffectingThisTask();
@@ -1709,10 +1705,13 @@ public class GanttDiagramGraph> implements ICritical
private List> getTaskConstraints(Point point) {
Validate.isTrue(isSupportedPoint(point));
switch (point) {
+
case START:
return adapter.getStartConstraintsFor(task);
+
case END:
return adapter.getEndConstraintsFor(task);
+
default:
throw new RuntimeException("shouldn't happen");
}
@@ -1772,15 +1771,12 @@ public class GanttDiagramGraph> implements ICritical
}
@Override
- protected PositionRestrictions createRestrictionsFor(
- GanttDate start, GanttDate end) {
+ protected PositionRestrictions createRestrictionsFor(GanttDate start, GanttDate end) {
return biggerThan(start, end);
}
@Override
- protected boolean doSatisfyOrderCondition(
- GanttDate supposedlyBefore,
- GanttDate supposedlyAfter) {
+ protected boolean doSatisfyOrderCondition(GanttDate supposedlyBefore, GanttDate supposedlyAfter) {
return supposedlyBefore.compareTo(supposedlyAfter) <= 0;
}
@@ -1813,15 +1809,12 @@ public class GanttDiagramGraph> implements ICritical
}
@Override
- protected PositionRestrictions createRestrictionsFor(
- GanttDate start, GanttDate end) {
+ protected PositionRestrictions createRestrictionsFor(GanttDate start, GanttDate end) {
return lessThan(start, end);
}
@Override
- protected boolean doSatisfyOrderCondition(
- GanttDate supposedlyBefore,
- GanttDate supposedlyAfter) {
+ protected boolean doSatisfyOrderCondition(GanttDate supposedlyBefore, GanttDate supposedlyAfter) {
return supposedlyBefore.compareTo(supposedlyAfter) >= 0;
}
@@ -1840,21 +1833,23 @@ public class GanttDiagramGraph> implements ICritical
}
@Override
- PositionRestrictions enforceUsingPreviousRestrictions(
- PositionRestrictions restrictions) {
+ PositionRestrictions enforceUsingPreviousRestrictions(PositionRestrictions restrictions) {
+
GanttDate result = Constraint. initialValue(null)
.withConstraints(restrictions.getStartConstraints())
.withConstraints(getStartConstraints())
.applyWithoutFinalCheck();
- if (result != null) {
+
+ if ( result != null ) {
enforceRestrictions(result);
return biggerThan(result, adapter.getEndDateFor(task));
}
+
return restrictions;
}
private void enforceRestrictions(GanttDate result) {
- if (!result.equals(getStartDate(task))) {
+ if ( !result.equals(getStartDate(task)) ) {
adapter.setStartDateFor(task, result);
}
}
@@ -1864,16 +1859,18 @@ public class GanttDiagramGraph> implements ICritical
class WeakBackwardsForces extends Forces {
@Override
- PositionRestrictions enforceUsingPreviousRestrictions(
- PositionRestrictions restrictions) {
+ PositionRestrictions enforceUsingPreviousRestrictions(PositionRestrictions restrictions) {
+
GanttDate result = Constraint. initialValue(null)
.withConstraints(restrictions.getEndConstraints())
.withConstraints(getEndConstraints())
.applyWithoutFinalCheck();
- if (result != null) {
+
+ if ( result != null ) {
enforceRestrictions(result);
return lessThan(adapter.getStartDate(task), result);
}
+
return restrictions;
}
@@ -1888,7 +1885,7 @@ public class GanttDiagramGraph> implements ICritical
}
private void enforceRestrictions(GanttDate newEnd) {
- if (!newEnd.equals(getEndDateFor(task))) {
+ if ( !newEnd.equals(getEndDateFor(task)) ) {
adapter.setEndDateFor(task, newEnd);
}
}
@@ -1906,29 +1903,33 @@ public class GanttDiagramGraph> implements ICritical
public String toString() {
return String.format(
"%s, parentRecalculation: %s, predecessors: %s",
- taskPoint, parentRecalculation,
+ taskPoint,
+ parentRecalculation,
asSimpleString(recalculationsCouldAffectThis));
}
- private String asSimpleString(
- Collection extends Recalculation> recalculations) {
+ private String asSimpleString(Collection extends Recalculation> recalculations) {
StringBuilder result = new StringBuilder();
result.append("[");
+
for (Recalculation each : recalculations) {
result.append(each.taskPoint).append(", ");
}
result.append("]");
+
return result.toString();
}
@Override
public boolean equals(Object obj) {
- if (Recalculation.class.isInstance(obj)) {
+ if ( Recalculation.class.isInstance(obj) ) {
Recalculation other = Recalculation.class.cast(obj);
+
return new EqualsBuilder().append(parentRecalculation, other.parentRecalculation)
.append(taskPoint, other.taskPoint)
.isEquals();
}
+
return false;
}
}
@@ -1938,11 +1939,13 @@ public class GanttDiagramGraph> implements ICritical
graph.removeVertex(task);
topLevelTasks.remove(task);
fromChildToParent.remove(task);
- if (adapter.isContainer(task)) {
+
+ if ( adapter.isContainer(task) ) {
for (V t : adapter.getChildren(task)) {
remove(t);
}
}
+
topologicalSorter.recalculationNeeded();
enforcer.enforceRestrictionsOn(needingEnforcing);
}
@@ -1961,24 +1964,20 @@ public class GanttDiagramGraph> implements ICritical
}
private boolean isForbidden(D dependency) {
- if (!adapter.isVisible(dependency)) {
- // the invisible dependencies, the ones used to implement container
- // behavior are not forbidden
+ if ( !adapter.isVisible(dependency) ) {
+ // the invisible dependencies, the ones used to implement container behavior are not forbidden
return false;
}
- boolean endEndDependency = DependencyType.END_END == dependency
- .getType();
- boolean startStartDependency = DependencyType.START_START == dependency
- .getType();
+ boolean endEndDependency = DependencyType.END_END == dependency.getType();
+ boolean startStartDependency = DependencyType.START_START == dependency.getType();
V source = adapter.getSource(dependency);
V destination = adapter.getDestination(dependency);
boolean destinationIsContainer = adapter.isContainer(destination);
boolean sourceIsContainer = adapter.isContainer(source);
- return (destinationIsContainer && endEndDependency)
- || (sourceIsContainer && startStartDependency);
+ return (destinationIsContainer && endEndDependency) || (sourceIsContainer && startStartDependency);
}
@@ -1991,14 +1990,15 @@ public class GanttDiagramGraph> implements ICritical
}
private void add(D dependency, boolean enforceRestrictions) {
- if (isForbidden(dependency)) {
+ if ( isForbidden(dependency) ) {
return;
}
+
V source = adapter.getSource(dependency);
V destination = adapter.getDestination(dependency);
graph.addEdge(source, destination, dependency);
topologicalSorter.recalculationNeeded();
- if (enforceRestrictions) {
+ if ( enforceRestrictions ) {
enforceRestrictions(destination);
}
}
@@ -2016,16 +2016,17 @@ public class GanttDiagramGraph> implements ICritical
}
public List getTasks() {
- return new ArrayList(graph.vertexSet());
+ return new ArrayList<>(graph.vertexSet());
}
public List getVisibleDependencies() {
- ArrayList result = new ArrayList();
+ ArrayList result = new ArrayList<>();
for (D dependency : graph.edgeSet()) {
- if (adapter.isVisible(dependency)) {
+ if ( adapter.isVisible(dependency) ) {
result.add(dependency);
}
}
+
return result;
}
@@ -2038,15 +2039,17 @@ public class GanttDiagramGraph> implements ICritical
}
public List getInitialTasks() {
- List result = new ArrayList();
+ List result = new ArrayList<>();
for (V task : graph.vertexSet()) {
int dependencies = graph.inDegreeOf(task);
- if ((dependencies == 0)
- || (dependencies == getNumberOfIncomingDependenciesByType(
- task, DependencyType.END_END))) {
+
+ if ( (dependencies == 0) ||
+ (dependencies == getNumberOfIncomingDependenciesByType(task, DependencyType.END_END)) ) {
+
result.add(task);
}
}
+
return result;
}
@@ -2055,18 +2058,20 @@ public class GanttDiagramGraph> implements ICritical
}
public Set getOutgoingTasksFor(V task) {
- Set result = new HashSet();
+ Set result = new HashSet<>();
for (D dependency : graph.outgoingEdgesOf(task)) {
result.add(adapter.getDestination(dependency));
}
+
return result;
}
public Set getIncomingTasksFor(V task) {
- Set result = new HashSet();
+ Set result = new HashSet<>();
for (D dependency : graph.incomingEdgesOf(task)) {
result.add(adapter.getSource(dependency));
}
+
return result;
}
@@ -2076,11 +2081,11 @@ public class GanttDiagramGraph> implements ICritical
private boolean isSomeVisibleAndNotEndEnd(Set dependencies) {
for (D each : dependencies) {
- if (!each.getType().equals(DependencyType.END_END)
- && adapter.isVisible(each)) {
+ if ( !each.getType().equals(DependencyType.END_END) && adapter.isVisible(each) ) {
return true;
}
}
+
return false;
}
@@ -2090,22 +2095,23 @@ public class GanttDiagramGraph> implements ICritical
private boolean isSomeVisibleAndNotStartStart(Set dependencies) {
for (D each : dependencies) {
- if (!each.getType().equals(DependencyType.START_START)
- && adapter.isVisible(each)) {
+ if ( !each.getType().equals(DependencyType.START_START) && adapter.isVisible(each) ) {
return true;
}
}
+
return false;
}
public List getLatestTasks() {
- List tasks = new ArrayList();
+ List tasks = new ArrayList<>();
for (V task : graph.vertexSet()) {
int dependencies = graph.outDegreeOf(task);
- if ((dependencies == 0)
- || (dependencies == getNumberOfOutgoingDependenciesByType(
- task, DependencyType.START_START))) {
+
+ if ( (dependencies == 0) ||
+ (dependencies == getNumberOfOutgoingDependenciesByType(task, DependencyType.START_START)) ) {
+
tasks.add(task);
}
}
@@ -2113,60 +2119,63 @@ public class GanttDiagramGraph> implements ICritical
return tasks;
}
- private int getNumberOfIncomingDependenciesByType(V task,
- DependencyType dependencyType) {
+ private int getNumberOfIncomingDependenciesByType(V task, DependencyType dependencyType) {
int count = 0;
for (D dependency : graph.incomingEdgesOf(task)) {
- if (adapter.getType(dependency).equals(dependencyType)) {
+ if ( adapter.getType(dependency).equals(dependencyType) ) {
count++;
}
}
+
return count;
}
- private int getNumberOfOutgoingDependenciesByType(V task,
- DependencyType dependencyType) {
+ private int getNumberOfOutgoingDependenciesByType(V task, DependencyType dependencyType) {
int count = 0;
for (D dependency : graph.outgoingEdgesOf(task)) {
- if (adapter.getType(dependency).equals(dependencyType)) {
+ if ( adapter.getType(dependency).equals(dependencyType) ) {
count++;
}
}
+
return count;
}
public boolean isContainer(V task) {
- if (task == null) {
+ if ( task == null ) {
return false;
}
+
return adapter.isContainer(task);
}
public boolean contains(V container, V task) {
- if ((container == null) || (task == null)) {
+ if ( (container == null) || (task == null) ) {
return false;
}
- if (adapter.isContainer(container)) {
+
+ if ( adapter.isContainer(container) ) {
return adapter.getChildren(container).contains(task);
}
+
return false;
}
public boolean doesNotProvokeLoop(D dependency) {
- Set reachableFromDestination = destinationPoint(dependency)
- .getReachable();
+ Set reachableFromDestination = destinationPoint(dependency).getReachable();
for (TaskPoint each : reachableFromDestination) {
- if (each.sendsModificationsThrough(dependency)) {
+
+ if ( each.sendsModificationsThrough(dependency) ) {
return false;
}
}
+
return true;
}
TaskPoint destinationPoint(D dependency) {
V destination = getDependencyDestination(dependency);
- return new TaskPoint(destination,
- getDestinationPoint(dependency.getType()));
+ return new TaskPoint(destination, getDestinationPoint(dependency.getType()));
}
private Point getDestinationPoint(DependencyType type) {
@@ -2196,13 +2205,11 @@ public class GanttDiagramGraph> implements ICritical
}
private V getDependencySource(D dependency) {
- return isScheduleForward() ? adapter.getSource(dependency) : adapter
- .getDestination(dependency);
+ return isScheduleForward() ? adapter.getSource(dependency) : adapter.getDestination(dependency);
}
private V getDependencyDestination(D dependency) {
- return isScheduleForward() ? adapter.getDestination(dependency)
- : adapter.getSource(dependency);
+ return isScheduleForward() ? adapter.getDestination(dependency) : adapter.getSource(dependency);
}
TaskPoint allPointsPotentiallyModified(V task) {
@@ -2224,8 +2231,10 @@ public class GanttDiagramGraph> implements ICritical
Validate.notNull(entryPoint);
this.task = task;
this.entryPoint = entryPoint;
- this.pointsModified = isDominatingPoint(entryPoint) ? EnumSet.of(
- Point.START, Point.END) : EnumSet.of(entryPoint);
+
+ this.pointsModified =
+ isDominatingPoint(entryPoint) ? EnumSet.of(Point.START, Point.END) : EnumSet.of(entryPoint);
+
this.isContainer = adapter.isContainer(task);
}
@@ -2237,19 +2246,21 @@ public class GanttDiagramGraph> implements ICritical
@Override
public boolean equals(Object obj) {
- if (TaskPoint.class.isInstance(obj)) {
+ if ( TaskPoint.class.isInstance(obj) ) {
TaskPoint other = TaskPoint.class.cast(obj);
- return new EqualsBuilder().append(task, other.task)
+
+ return new EqualsBuilder()
+ .append(task, other.task)
.append(pointsModified, other.pointsModified)
.isEquals();
}
+
return false;
}
@Override
public int hashCode() {
- return new HashCodeBuilder().append(task).append(pointsModified)
- .toHashCode();
+ return new HashCodeBuilder().append(task).append(pointsModified).toHashCode();
}
public boolean areAllPointsPotentiallyModified() {
@@ -2257,8 +2268,7 @@ public class GanttDiagramGraph> implements ICritical
}
public boolean somePointPotentiallyModified() {
- return pointsModified.contains(Point.START)
- || pointsModified.contains(Point.END);
+ return pointsModified.contains(Point.START) || pointsModified.contains(Point.END);
}
public boolean onlyModifies(Point point) {
@@ -2266,110 +2276,109 @@ public class GanttDiagramGraph> implements ICritical
}
Set getReachable() {
- Set result = new HashSet();
- Queue pending = new LinkedList();
+ Set result = new HashSet<>();
+ Queue pending = new LinkedList<>();
result.add(this);
pending.offer(this);
+
while (!pending.isEmpty()) {
TaskPoint current = pending.poll();
Set immendiate = current.getImmediateSuccessors();
+
for (TaskPoint each : immendiate) {
- if (!result.contains(each)) {
+ if ( !result.contains(each) ) {
result.add(each);
pending.offer(each);
}
}
}
+
return result;
}
public boolean isImmediatelyDerivedFrom(TaskPoint other) {
- return this.task.equals(other.task)
- && other.pointsModified.containsAll(this.pointsModified);
+ return this.task.equals(other.task) && other.pointsModified.containsAll(this.pointsModified);
}
private Set cachedInmmediateSuccesors = null;
public Set getImmediateSuccessors() {
- if (cachedInmmediateSuccesors != null) {
+ if ( cachedInmmediateSuccesors != null ) {
return cachedInmmediateSuccesors;
}
- Set result = new HashSet();
+ Set result = new HashSet<>();
result.addAll(getImmediatelyDerivedOnSameTask());
Set candidates = immediateDependencies();
for (D each : candidates) {
- if (this.sendsModificationsThrough(each)) {
+ if ( this.sendsModificationsThrough(each) ) {
result.add(destinationPoint(each));
}
}
- return cachedInmmediateSuccesors = Collections
- .unmodifiableSet(result);
+
+ return cachedInmmediateSuccesors = Collections.unmodifiableSet(result);
}
private Set cachedImmediatePredecessors = null;
public Set getImmediatePredecessors() {
- if (cachedImmediatePredecessors != null) {
+ if ( cachedImmediatePredecessors != null ) {
return cachedImmediatePredecessors;
}
- Set result = new HashSet();
- if (!isDominatingPoint(entryPoint)) {
+
+ Set result = new HashSet<>();
+ if ( !isDominatingPoint(entryPoint) ) {
TaskPoint dominating = allPointsPotentiallyModified(task);
assert isDominatingPoint(dominating.entryPoint);
assert this.isImmediatelyDerivedFrom(dominating);
result.add(dominating);
}
+
for (D each : immediateIncomingDependencies()) {
- if (this.receivesModificationsThrough(each)) {
+ if ( this.receivesModificationsThrough(each) ) {
TaskPoint sourcePoint = sourcePoint(each);
result.add(sourcePoint);
}
}
- return cachedImmediatePredecessors = Collections
- .unmodifiableSet(result);
+
+ return cachedImmediatePredecessors = Collections.unmodifiableSet(result);
}
private Collection getImmediatelyDerivedOnSameTask() {
for (Point each : pointsModified) {
- if (isDominatingPoint(each)) {
- return Collections.singletonList(new TaskPoint(task, each
- .getOther()));
+ if ( isDominatingPoint(each) ) {
+ return Collections.singletonList(new TaskPoint(task, each.getOther()));
}
}
+
return Collections.emptyList();
}
private Set immediateDependencies() {
- return isScheduleForward() ? graph.outgoingEdgesOf(this.task)
- : graph.incomingEdgesOf(this.task);
+ return isScheduleForward() ? graph.outgoingEdgesOf(this.task) : graph.incomingEdgesOf(this.task);
}
private Set immediateIncomingDependencies() {
- return isScheduleForward() ? graph.incomingEdgesOf(this.task)
- : graph.outgoingEdgesOf(this.task);
+ return isScheduleForward() ? graph.incomingEdgesOf(this.task) : graph.outgoingEdgesOf(this.task);
}
public boolean sendsModificationsThrough(D dependency) {
V source = getDependencySource(dependency);
- Point dependencySourcePoint = getSourcePoint(adapter
- .getType(dependency));
+ Point dependencySourcePoint = getSourcePoint(adapter.getType(dependency));
- return source.equals(task)
- && (!isContainer || pointsModified
- .contains(dependencySourcePoint));
+ return source.equals(task) && (!isContainer || pointsModified.contains(dependencySourcePoint));
}
private Point getSourcePoint(DependencyType type) {
Point[] sourceAndDestination = type.getSourceAndDestination();
+
return sourceAndDestination[isScheduleForward() ? 0 : 1];
}
private boolean receivesModificationsThrough(D dependency) {
V destination = getDependencyDestination(dependency);
- Point destinationPoint = getDestinationPoint(adapter
- .getType(dependency));
+ Point destinationPoint = getDestinationPoint(adapter.getType(dependency));
return destination.equals(task) && entryPoint == destinationPoint;
}
@@ -2383,6 +2392,7 @@ public class GanttDiagramGraph> implements ICritical
while (fromChildToParent.containsKey(result)) {
result = fromChildToParent.get(result);
}
+
return result;
}
@@ -2416,9 +2426,10 @@ public class GanttDiagramGraph> implements ICritical
@Override
public List getChildren(V task) {
- if (!isContainer(task)) {
+ if ( !isContainer(task) ) {
return Collections.emptyList();
}
+
return adapter.getChildren(task);
}
diff --git a/libreplan-webapp/pom.xml b/libreplan-webapp/pom.xml
index edb76d9f7..3da9ba644 100644
--- a/libreplan-webapp/pom.xml
+++ b/libreplan-webapp/pom.xml
@@ -444,6 +444,7 @@
javax.servlet-api
+
javax.mail
@@ -488,7 +489,7 @@
org.jgrapht
- jgrapht-jdk1.5
+ jgrapht-core
diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/I18nHelper.java b/libreplan-webapp/src/main/java/org/libreplan/web/I18nHelper.java
index 861d6e590..ed73cdc73 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/web/I18nHelper.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/web/I18nHelper.java
@@ -40,23 +40,21 @@ public class I18nHelper {
private static Locale defaultLang = Locale.ENGLISH;
- private static HashMap localesCache = new HashMap();
+ private static HashMap localesCache = new HashMap<>();
public static I18n getI18n() {
setPreferredLocale();
Locale locale = Locales.getCurrent();
- if (localesCache.keySet().contains(locale)) {
+ if ( localesCache.keySet().contains(locale) ) {
return localesCache.get(locale);
}
- I18n i18n = I18nFactory.getI18n(I18nHelper.class, locale,
- org.xnap.commons.i18n.I18nFactory.FALLBACK);
+ I18n i18n = I18nFactory.getI18n(I18nHelper.class, locale, org.xnap.commons.i18n.I18nFactory.FALLBACK);
// The language returned is not the same as the requested by the user
- if (!locale.getLanguage().equals(
- i18n.getResources().getLocale().getLanguage())) {
+ if ( !locale.getLanguage().equals(i18n.getResources().getLocale().getLanguage()) ) {
// Force it to be default language
i18n = getDefaultI18n();
}
@@ -67,11 +65,10 @@ public class I18nHelper {
private static void setPreferredLocale() {
Execution execution = Executions.getCurrent();
- if (execution != null) {
+ if ( execution != null ) {
Locale userLocale = getUserLocale();
- Charsets.setPreferredLocale((HttpSession) execution.getSession()
- .getNativeSession(), userLocale);
- if (userLocale != null) {
+ Charsets.setPreferredLocale((HttpSession) execution.getSession().getNativeSession(), userLocale);
+ if ( userLocale != null ) {
Locales.setThreadLocal(userLocale);
}
}
@@ -79,18 +76,17 @@ public class I18nHelper {
private static Locale getUserLocale() {
User user = UserUtil.getUserFromSession();
- if (user != null) {
- return user.getApplicationLanguage().getLocale();
- }
- return null;
+
+ return (user != null) ? user.getApplicationLanguage().getLocale() : null;
}
private static I18n getDefaultI18n() {
I18n i18n = localesCache.get(defaultLang);
- if (i18n == null) {
- i18n = I18nFactory.getI18n(I18nHelper.class, defaultLang,
- org.xnap.commons.i18n.I18nFactory.FALLBACK);
+
+ if ( i18n == null ) {
+ i18n = I18nFactory.getI18n(I18nHelper.class, defaultLang, org.xnap.commons.i18n.I18nFactory.FALLBACK);
}
+
return i18n;
}
@@ -114,8 +110,7 @@ public class I18nHelper {
return getI18n().tr(text, o1, o2, o3);
}
- public static String _(String text, Object o1, Object o2, Object o3,
- Object o4) {
+ public static String _(String text, Object o1, Object o2, Object o3, Object o4) {
return getI18n().tr(text, o1, o2, o3, o4);
}
diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java
index b048af54a..d0d437025 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java
@@ -111,8 +111,7 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
this.disabled = disabled;
}
- public CustomMenuItem(String name, String url,
- List children) {
+ public CustomMenuItem(String name, String url, List children) {
this.name = name;
this.unencodedURL = url;
this.encodedURL = Executions.getCurrent().encodeURL(url);
@@ -135,20 +134,22 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
public boolean contains(String requestPath) {
for (CustomMenuItem item : thisAndChildren()) {
- if (requestContains(requestPath, item.unencodedURL)) {
+ if ( requestContains(requestPath, item.unencodedURL) ) {
return true;
}
}
+
return false;
}
private List thisAndChildren() {
- List items = new ArrayList();
+ List items = new ArrayList<>();
items.add(this);
items.addAll(children);
for (CustomMenuItem child : children) {
items.addAll(child.children);
}
+
return items;
}
@@ -167,14 +168,12 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
}
private static IGlobalViewEntryPoints findGlobalViewEntryPoints() {
- return (IGlobalViewEntryPoints) getSpringContext().getBean(
- "globalView", IGlobalViewEntryPoints.class);
+ return getSpringContext().getBean("globalView", IGlobalViewEntryPoints.class);
}
private static WebApplicationContext getSpringContext() {
Execution current = Executions.getCurrent();
- HttpServletRequest request = (HttpServletRequest) current
- .getNativeRequest();
+ HttpServletRequest request = (HttpServletRequest) current.getNativeRequest();
ServletContext context = request.getSession().getServletContext();
return WebApplicationContextUtils.getWebApplicationContext(context);
@@ -185,7 +184,7 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
private IGlobalViewEntryPoints globalView;
public CustomMenuController() {
- this.firstLevel = new ArrayList();
+ this.firstLevel = new ArrayList<>();
this.globalView = findGlobalViewEntryPoints();
initializeMenu();
activateCurrentOne();
@@ -193,28 +192,38 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
}
private void activateCurrentOne() {
- String requestPath = Executions.getCurrent().getDesktop()
- .getRequestPath();
+ String requestPath = Executions.getCurrent().getDesktop().getRequestPath();
+
for (CustomMenuItem ci : this.firstLevel) {
- if (ci.contains(requestPath)) {
+
+ if ( ci.contains(requestPath) ) {
+
ci.setActive(true);
+
for (CustomMenuItem child : ci.children) {
- if (child.contains(requestPath)) {
+
+ if ( child.contains(requestPath) ) {
+
child.setActive(true);
+
for (CustomMenuItem c : child.children) {
- if (c.contains(requestPath)) {
+
+ if ( c.contains(requestPath) ) {
+
c.setActive(true);
return;
}
}
+
return;
}
}
+
return;
}
}
- if (requestPath.isEmpty()) {
+ if ( requestPath.isEmpty() ) {
CustomMenuItem item = this.firstLevel.get(0);
item.setActive(true);
item.children.get(0).setActive(true);
@@ -225,27 +234,26 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
return OnZKDesktopRegistry.getLocatorFor(IMenuItemsRegister.class);
}
- private CustomMenuController topItem(String name, String url,
- String helpUri, Collection extends CustomMenuItem> items) {
- return topItem(name, url, helpUri,
- items.toArray(new CustomMenuItem[items.size()]));
+ private CustomMenuController topItem(String name, String url, String helpUri,
+ Collection extends CustomMenuItem> items) {
+
+ return topItem(name, url, helpUri, items.toArray(new CustomMenuItem[items.size()]));
}
- private CustomMenuController topItem(String name, String url,
- String helpUri,
- CustomMenuItem... items) {
+ private CustomMenuController topItem(String name, String url, String helpUri, CustomMenuItem... items) {
return topItem(name, url, helpUri, false, items);
}
- private CustomMenuController topItem(String name, String url,
- String helpLink,
- boolean disabled, CustomMenuItem... items) {
+ private CustomMenuController topItem(String name, String url, String helpLink, boolean disabled,
+ CustomMenuItem... items) {
+
CustomMenuItem parent = new CustomMenuItem(name, url, disabled);
parent.setHelpLink(helpLink);
this.firstLevel.add(parent);
for (CustomMenuItem child : items) {
parent.appendChildren(child);
}
+
return this;
}
@@ -253,296 +261,316 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
return new CustomMenuItem(name, url, helpLink);
}
- private CustomMenuItem subItem(String name, ICapture urlCapture,
- String helpLink) {
- return new CustomMenuItem(name, EntryPointsHandler.capturePath(urlCapture),
- helpLink);
+ private CustomMenuItem subItem(String name, ICapture urlCapture, String helpLink) {
+ return new CustomMenuItem(name, EntryPointsHandler.capturePath(urlCapture), helpLink);
}
public void initializeMenu() {
- List planningItems = new ArrayList();
- if (SecurityUtils.isSuperuserOrRolePlanningOrHasAnyAuthorization()) {
- planningItems.add(subItem(_("Company view"), new ICapture() {
- @Override
- public void capture() {
- globalView.goToCompanyScheduling();
- }
- }, "01-introducion.html"));
- planningItems.add(subItem(_("Projects"), new ICapture() {
- @Override
- public void capture() {
- globalView.goToOrdersList();
- }
- }, "01-introducion.html#id2"));
+ List planningItems = new ArrayList<>();
+ if ( SecurityUtils.isSuperuserOrRolePlanningOrHasAnyAuthorization() ) {
+
+ planningItems.add(
+ subItem(
+ _("Company view"),
+ new ICapture() {
+ @Override
+ public void capture() {
+ globalView.goToCompanyScheduling();
+ }
+ },
+ "01-introducion.html"));
+
+ planningItems.add(subItem(
+ _("Projects"),
+ new ICapture() {
+ @Override
+ public void capture() {
+ globalView.goToOrdersList();
+ }
+ },
+ "01-introducion.html#id2"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PLANNING)) {
- planningItems.add(subItem(_("Resources Load"), new ICapture() {
- @Override
- public void capture() {
- globalView.goToCompanyLoad();
- }
- }, "01-introducion.html#id1"));
- planningItems.add(subItem(_("Queue-based Resources"), new ICapture() {
- @Override
- public void capture() {
- globalView.goToLimitingResources();
- }
- }, "01-introducion.html"));
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PLANNING) ) {
+ planningItems.add(subItem(
+ _("Resources Load"),
+ new ICapture() {
+ @Override
+ public void capture() {
+ globalView.goToCompanyLoad();
+ }
+ },
+ "01-introducion.html#id1"));
+
+ planningItems.add(subItem(
+ _("Queue-based Resources"),
+ new ICapture() {
+ @Override
+ public void capture() {
+ globalView.goToLimitingResources();
+ }
+ },
+ "01-introducion.html"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TEMPLATES)) {
- planningItems.add(subItem(_("Templates"),
- "/templates/templates.zul", ""));
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TEMPLATES) ) {
+ planningItems.add(subItem(_("Templates"), "/templates/templates.zul", ""));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_IMPORT_PROJECTS)) {
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_IMPORT_PROJECTS) ) {
// In order of see the Import project option in the menu
- planningItems.add(subItem(_("Import project"),
- "/orders/imports/projectImport.zul", ""));
+ planningItems.add(subItem(_("Import project"), "/orders/imports/projectImport.zul", ""));
}
- //TODO There is some problem here!
- /*planningItems.add(subItem(_("Logs"), new ICapture() {
- @Override
- public void capture() {
- globalView.goToLogs();
- }
- }, "01-asd"));*/
-
- if (!planningItems.isEmpty()) {
+ if ( !planningItems.isEmpty() ) {
topItem(_("Planning"), "/planner/index.zul", "", planningItems);
}
- List resourcesItems = new ArrayList();
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_WORKERS)) {
- resourcesItems.add(subItem(_("Workers"),
+ List resourcesItems = new ArrayList<>();
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_WORKERS) ) {
+ resourcesItems.add(subItem(
+ _("Workers"),
"/resources/worker/worker.zul",
"05-recursos.html#xesti-n-de-traballadores"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MACHINES)) {
- resourcesItems.add(subItem(_("Machines"),
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MACHINES) ) {
+ resourcesItems.add(subItem(
+ _("Machines"),
"/resources/machine/machines.zul",
"05-recursos.html#xesti-n-de-m-quinas"));
}
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_VIRTUAL_WORKERS)) {
- resourcesItems.add(subItem(_("Virtual Workers"),
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_VIRTUAL_WORKERS) ) {
+ resourcesItems.add(subItem(
+ _("Virtual Workers"),
"/resources/worker/virtualWorkers.zul",
"05-recursos.html#xesti-n-de-traballadores"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_CALENDARS)) {
- resourcesItems.add(subItem(_("Calendars"),
- "/calendars/calendars.zul", "03-calendarios.html"));
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_CALENDARS) ) {
+ resourcesItems.add(subItem(_("Calendars"), "/calendars/calendars.zul", "03-calendarios.html"));
}
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_CALENDAR_EXCEPTION_DAYS)) {
- resourcesItems.add(subItem(_("Calendar Exception Days"),
- "/excetiondays/exceptionDays.zul", ""));
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_CALENDAR_EXCEPTION_DAYS) ) {
+ resourcesItems.add(subItem(_("Calendar Exception Days"), "/excetiondays/exceptionDays.zul", ""));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_CRITERIA)) {
- resourcesItems.add(subItem(_("Criteria"),
- "/resources/criterions/criterions.zul",
- "02-criterios.html#id1"));
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_CRITERIA) ) {
+ resourcesItems.add(subItem(_("Criteria"), "/resources/criterions/criterions.zul", "02-criterios.html#id1"));
}
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_PROGRESS_TYPES)) {
- resourcesItems.add(subItem(_("Progress Types"),
- "/advance/advanceTypes.zul", "04-avances.html#id1"));
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PROGRESS_TYPES) ) {
+ resourcesItems.add(subItem(_("Progress Types"), "/advance/advanceTypes.zul", "04-avances.html#id1"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_LABELS)) {
- resourcesItems.add(subItem(_("Labels"), "/labels/labelTypes.zul",
- "10-etiquetas.html"));
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_LABELS) ) {
+ resourcesItems.add(subItem(_("Labels"), "/labels/labelTypes.zul", "10-etiquetas.html"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MATERIALS)) {
- resourcesItems.add(subItem(_("Materials"),
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MATERIALS) ) {
+ resourcesItems.add(subItem(
+ _("Materials"),
"/materials/materials.zul",
"11-materiales.html#administraci-n-de-materiais"));
}
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_MATERIAL_UNITS)) {
- resourcesItems.add(subItem(_("Material Units"),
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MATERIAL_UNITS) ) {
+ resourcesItems.add(subItem(
+ _("Material Units"),
"/unittypes/unitTypes.zul",
"11-materiales.html#administraci-n-de-materiais"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_QUALITY_FORMS)) {
- resourcesItems
- .add(subItem(_("Quality Forms"),
- "/qualityforms/qualityForms.zul",
- "12-formularios-calidad.html#administraci-n-de-formularios-de-calidade"));
- }
- if (!resourcesItems.isEmpty()) {
- topItem(_("Resources"), "/resources/worker/worker.zul", "",
- resourcesItems);
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_QUALITY_FORMS) ) {
+ resourcesItems.add(subItem(
+ _("Quality Forms"),
+ "/qualityforms/qualityForms.zul",
+ "12-formularios-calidad.html#administraci-n-de-formularios-de-calidade"));
}
- List costItems = new ArrayList();
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEETS)) {
- costItems.add(subItem(_("Timesheets"),
- "/workreports/workReport.zul", "09-partes.html#id3"));
+ if ( !resourcesItems.isEmpty() ) {
+ topItem(_("Resources"), "/resources/worker/worker.zul", "", resourcesItems);
}
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEETS_TEMPLATES)) {
- costItems.add(subItem(_("Timesheets Templates"),
- "/workreports/workReportTypes.zul", "09-partes.html#id2"));
+
+ List costItems = new ArrayList<>();
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEETS) ) {
+ costItems.add(subItem(_("Timesheets"), "/workreports/workReport.zul", "09-partes.html#id3"));
}
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEET_LINES_LIST)) {
- costItems.add(subItem(_("Timesheet Lines List"),
- "/workreports/workReportQuery.zul", "09-partes.html#id4"));
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEETS_TEMPLATES) ) {
+ costItems.add(subItem(
+ _("Timesheets Templates"),
+ "/workreports/workReportTypes.zul",
+ "09-partes.html#id2"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_EXPENSES)) {
- costItems.add(subItem(_("Expenses"),
- "/expensesheet/expenseSheet.zul", ""));
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEET_LINES_LIST) ) {
+ costItems.add(subItem(
+ _("Timesheet Lines List"),
+ "/workreports/workReportQuery.zul",
+ "09-partes.html#id4"));
}
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_COST_CATEGORIES)) {
- costItems.add(subItem(_("Cost Categories"),
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_EXPENSES) ) {
+ costItems.add(subItem(_("Expenses"), "/expensesheet/expenseSheet.zul", ""));
+ }
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_COST_CATEGORIES) ) {
+ costItems.add(subItem(
+ _("Cost Categories"),
"/costcategories/costCategory.zul",
"14-custos.html#categor-as-de-custo"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_HOURS_TYPES)) {
- costItems.add(subItem(_("Hours Types"),
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_HOURS_TYPES) ) {
+ costItems.add(subItem(
+ _("Hours Types"),
"/typeofworkhours/typeOfWorkHours.zul",
"14-custos.html#administraci-n-de-horas-traballadas"));
}
- if (!costItems.isEmpty()) {
+
+ if ( !costItems.isEmpty() ) {
topItem(_("Cost"), "/workreports/workReport.zul", "", costItems);
}
- List configurationItems = new ArrayList();
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MAIN_SETTINGS)) {
- configurationItems
- .add(subItem(_("Main Settings"),
- "/common/configuration.zul",
- "16-ldap-authentication.html"));
+ List configurationItems = new ArrayList<>();
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MAIN_SETTINGS) ) {
+ configurationItems.add(subItem(
+ _("Main Settings"),
+ "/common/configuration.zul",
+ "16-ldap-authentication.html"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_USER_ACCOUNTS)) {
- configurationItems.add(subItem(_("User Accounts"),
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_USER_ACCOUNTS) ) {
+ configurationItems.add(subItem(
+ _("User Accounts"),
"/users/users.zul",
"13-usuarios.html#administraci-n-de-usuarios"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PROFILES)) {
- configurationItems.add(subItem(_("Profiles"),
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PROFILES) ) {
+ configurationItems.add(subItem(
+ _("Profiles"),
"/profiles/profiles.zul",
"13-usuarios.html#administraci-n-de-perfiles"));
}
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_JOB_SCHEDULING)) {
- configurationItems.add(subItem(_("Job Scheduling"),
- "/common/job_scheduling.zul",
- "19-scheduler.html"));
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_JOB_SCHEDULING) ) {
+ configurationItems.add(subItem(_("Job Scheduling"), "/common/job_scheduling.zul", "19-scheduler.html"));
}
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_EDIT_EMAIL_TEMPLATES)) {
- configurationItems.add(subItem(_("Edit E-mail Templates"),
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_EDIT_EMAIL_TEMPLATES) ) {
+ configurationItems.add(subItem(
+ _("Edit E-mail Templates"),
"/email/email_templates.zul",
"email-templates.html"));
}
- if (!configurationItems.isEmpty()) {
- topItem(_("Configuration"), "/common/configuration.zul", "",
- configurationItems);
+ if ( !configurationItems.isEmpty() ) {
+ topItem(_("Configuration"), "/common/configuration.zul", "", configurationItems);
}
- List communicationsItems = new ArrayList();
- if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_COMPANIES)) {
- communicationsItems.add(subItem(_("Companies"),
- "/externalcompanies/externalcompanies.zul", ""));
+ List communicationsItems = new ArrayList<>();
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_COMPANIES) ) {
+ communicationsItems.add(subItem(_("Companies"), "/externalcompanies/externalcompanies.zul", ""));
}
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_SEND_TO_SUBCONTRACTORS)) {
- communicationsItems.add(subItem(_("Send To Subcontractors"),
- "/subcontract/subcontractedTasks.zul", ""));
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_SEND_TO_SUBCONTRACTORS) ) {
+ communicationsItems.add(subItem(_("Send To Subcontractors"), "/subcontract/subcontractedTasks.zul", ""));
}
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_RECEIVED_FROM_SUBCONTRACTORS)) {
- communicationsItems.add(subItem(_("Received From Subcontractors"),
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_RECEIVED_FROM_SUBCONTRACTORS) ) {
+ communicationsItems.add(subItem(
+ _("Received From Subcontractors"),
"/subcontract/subcontractorCommunications.zul", ""));
}
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_SEND_TO_CUSTOMERS)) {
- communicationsItems.add(subItem(_("Send To Customers"),
- "/subcontract/reportAdvances.zul", ""));
- }
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_RECEIVED_FROM_CUSTOMERS)) {
- communicationsItems.add(subItem(_("Received From Customers"),
- "/subcontract/customerCommunications.zul", ""));
- }
- if (!communicationsItems.isEmpty()) {
- topItem(_("Communications"),
- "/externalcompanies/externalcompanies.zul", "",
- communicationsItems);
+
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_SEND_TO_CUSTOMERS) ) {
+ communicationsItems.add(subItem(_("Send To Customers"), "/subcontract/reportAdvances.zul", ""));
}
- List reportsItems = new ArrayList();
- if (SecurityUtils
- .isSuperuserOrUserInRoles(UserRole.ROLE_HOURS_WORKED_PER_RESOURCE_REPORT)) {
- reportsItems.add(subItem(_("Hours Worked Per Resource"),
+ if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_RECEIVED_FROM_CUSTOMERS) ) {
+ communicationsItems.add(subItem(
+ _("Received From Customers"),
+ "/subcontract/customerCommunications.zul", ""));
+ }
+
+ if ( !communicationsItems.isEmpty() ) {
+ topItem(_("Communications"), "/externalcompanies/externalcompanies.zul", "", communicationsItems);
+ }
+
+ List