Schedule several unassigned queue elements at once

FEA: ItEr65OTS05AlgoritmosLimitantes
This commit is contained in:
Diego Pino Garcia 2010-12-19 14:37:34 +01:00
parent 136cb0540c
commit e3d680e0b1
5 changed files with 101 additions and 25 deletions

View file

@ -20,6 +20,7 @@
package org.navalplanner.web.limitingresources;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@ -144,4 +145,7 @@ public interface ILimitingResourceQueueModel {
LimitingResourceQueueElement oldElement,
LimitingResourceQueueElement newElement);
Set<LimitingResourceQueueElement> assignLimitingResourceQueueElements(
List<LimitingResourceQueueElement> elements);
}

View file

@ -1097,4 +1097,15 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel {
return result;
}
@Override
public Set<LimitingResourceQueueElement> assignLimitingResourceQueueElements(
List<LimitingResourceQueueElement> queueElements) {
Set<LimitingResourceQueueElement> result = new HashSet<LimitingResourceQueueElement>();
for (LimitingResourceQueueElement each: queuesState.inTopologicalOrder(queueElements)) {
result.addAll(assignLimitingResourceQueueElement(each));
}
return result;
}
}

View file

@ -419,6 +419,8 @@ public class LimitingResourcesController extends GenericForwardComposer {
public void render(Row row, Object data) throws Exception {
LimitingResourceQueueElementDTO element = (LimitingResourceQueueElementDTO) data;
row.setValue(data);
row.appendChild(automaticQueueing(element));
row.appendChild(label(element.getOrderName()));
row.appendChild(label(element.getTaskName()));
@ -513,32 +515,16 @@ public class LimitingResourcesController extends GenericForwardComposer {
private void assignLimitingResourceQueueElement(
LimitingResourceQueueElementDTO dto) {
LimitingResourceQueueElement element = dto.getOriginal();
List<LimitingResourceQueueElement> inserted = limitingResourceQueueModel
.assignLimitingResourceQueueElement(element);
if (!inserted.isEmpty()) {
reloadUnassignedLimitingResourceQueueElements();
for (LimitingResourceQueueElement each : inserted) {
// FIXME visually wrong if an element jumps from a queue to
// another
LimitingResourceQueue queue = each.getLimitingResourceQueue();
// Remove all dependency components associated to element
limitingResourcesPanel.removeDependenciesFor(each);
// Dependencies will be created again on refreshing queue
limitingResourcesPanel.refreshQueue(queue);
}
} else {
showErrorMessage(_("Cannot allocate selected element. There is not any queue " +
"that matches resource allocation criteria at any interval of time"));
}
}
private void showErrorMessage(String error) {
try {
Messagebox.show(error, _("Error"), Messagebox.OK, Messagebox.ERROR);
} catch (InterruptedException e) {
.assignLimitingResourceQueueElement(dto.getOriginal());
if (inserted.isEmpty()) {
showErrorMessage(_("Cannot allocate selected element. There is not any queue "
+ "that matches resource allocation criteria at any interval of time"));
return;
}
limitingResourcesPanel.refreshQueues((LimitingResourceQueue.queuesOf(inserted)));
reloadUnassignedLimitingResourceQueueElements();
}
private Checkbox automaticQueueing(
@ -559,7 +545,11 @@ public class LimitingResourcesController extends GenericForwardComposer {
}
public void unschedule(QueueTask task) {
limitingResourceQueueModel.unschedule(task.getLimitingResourceQueueElement());
LimitingResourceQueueElement queueElement = task.getLimitingResourceQueueElement();
LimitingResourceQueue queue = queueElement.getLimitingResourceQueue();
limitingResourceQueueModel.unschedule(queueElement);
limitingResourcesPanel.refreshQueue(queue);
reloadUnassignedLimitingResourceQueueElements();
}
@ -600,7 +590,48 @@ public class LimitingResourcesController extends GenericForwardComposer {
}
public void assignAllSelectedElements() {
List<LimitingResourceQueueElement> elements = getAllSelectedQueueElements();
if (!elements.isEmpty()) {
Set<LimitingResourceQueueElement> inserted = limitingResourceQueueModel
.assignLimitingResourceQueueElements(elements);
clearSelectAllCheckbox();
if (inserted.isEmpty()) {
showErrorMessage(_("Cannot allocate selected element. There is not any queue "
+ "that matches resource allocation criteria at any interval of time"));
return;
}
limitingResourcesPanel.refreshQueues(LimitingResourceQueue.queuesOf(inserted));
reloadUnassignedLimitingResourceQueueElements();
}
}
private void clearSelectAllCheckbox() {
cbSelectAll.setChecked(false);
}
private List<LimitingResourceQueueElement> getAllSelectedQueueElements() {
List<LimitingResourceQueueElement> result = new ArrayList<LimitingResourceQueueElement>();
final Rows rows = gridUnassignedLimitingResourceQueueElements.getRows();
for (Object each : rows.getChildren()) {
final Row row = (Row) each;
Checkbox cbAutoQueueing = getAutoQueueing(row);
if (cbAutoQueueing.isChecked()) {
LimitingResourceQueueElementDTO dto = (LimitingResourceQueueElementDTO) row
.getValue();
result.add((LimitingResourceQueueElement) dto.getOriginal());
}
}
return result;
}
private void showErrorMessage(String error) {
try {
Messagebox.show(error, _("Error"), Messagebox.OK, Messagebox.ERROR);
} catch (InterruptedException e) {
}
}
}

View file

@ -384,7 +384,7 @@ public class LimitingResourcesPanel extends HtmlMacroComponent {
dependencyList.addDependenciesFor(element);
}
public void refreshQueues(Set<LimitingResourceQueue> queues) {
public void refreshQueues(Collection<LimitingResourceQueue> queues) {
for (LimitingResourceQueue each: queues) {
refreshQueue(each);
}

View file

@ -561,4 +561,34 @@ public class QueuesState {
elementsById.put(element.getId(), element);
}
public List<LimitingResourceQueueElement> inTopologicalOrder(List<LimitingResourceQueueElement> queueElements) {
return toList(topologicalIterator(buildSubgraphFor(queueElements)));
}
/**
* Constructs a graph composed only by queueElements
*
* @param queueElements
* @return
*/
private DirectedGraph<LimitingResourceQueueElement, LimitingResourceQueueDependency> buildSubgraphFor(
List<LimitingResourceQueueElement> queueElements) {
SimpleDirectedGraph<LimitingResourceQueueElement, LimitingResourceQueueDependency> result = instantiateDirectedGraph();
// Iterate through elements and construct graph
for (LimitingResourceQueueElement each : queueElements) {
result.addVertex(each);
for (LimitingResourceQueueDependency dependency : each
.getDependenciesAsOrigin()) {
LimitingResourceQueueElement destiny = dependency
.getHasAsDestiny();
if (queueElements.contains(destiny)) {
// Add source, destiny and edge between them
addDependency(result, dependency);
}
}
}
return result;
}
}