ItEr44S13CUMarcarUnidadeTraballoExportableItEr43S18: Pulling up scheduling state handling code to TreeNodeOnListWithSchedulingState
This commit is contained in:
parent
e5233c2e52
commit
f45e75f0dc
2 changed files with 77 additions and 26 deletions
|
|
@ -48,14 +48,13 @@ import org.navalplanner.business.materials.entities.MaterialAssignment;
|
|||
import org.navalplanner.business.templates.entities.OrderElementTemplate;
|
||||
import org.navalplanner.business.templates.entities.OrderLineGroupTemplate;
|
||||
import org.navalplanner.business.trees.ITreeParentNode;
|
||||
import org.navalplanner.business.trees.TreeNodeOnList;
|
||||
|
||||
|
||||
public class OrderLineGroup extends OrderElement implements
|
||||
ITreeParentNode<OrderElement> {
|
||||
|
||||
private final class ChildrenManipulator extends
|
||||
TreeNodeOnList<OrderElement> {
|
||||
TreeNodeOnListWithSchedulingState<OrderElement> {
|
||||
|
||||
private final OrderLineGroup parent;
|
||||
|
||||
|
|
@ -65,30 +64,6 @@ public class OrderLineGroup extends OrderElement implements
|
|||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onChildAdded(OrderElement newChild) {
|
||||
if (parent != null) {
|
||||
SchedulingState schedulingState = newChild
|
||||
.getSchedulingState();
|
||||
removeSchedulingStateFromParent(newChild);
|
||||
parent.getSchedulingState().add(schedulingState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onChildRemoved(OrderElement previousChild) {
|
||||
removeSchedulingStateFromParent(previousChild);
|
||||
}
|
||||
|
||||
private void removeSchedulingStateFromParent(
|
||||
OrderElement previousChild) {
|
||||
SchedulingState schedulingState = previousChild
|
||||
.getSchedulingState();
|
||||
if (!schedulingState.isRoot()) {
|
||||
schedulingState.getParent().removeChild(schedulingState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setParentIfRequired(OrderElement newChild) {
|
||||
if (parent != null) {
|
||||
|
|
@ -96,6 +71,18 @@ public class OrderLineGroup extends OrderElement implements
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateWithNewChild(SchedulingState newChildState) {
|
||||
if (parent != null) {
|
||||
parent.getSchedulingState().add(newChildState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SchedulingState getSchedulingStateFrom(OrderElement node) {
|
||||
return node.getSchedulingState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITreeParentNode<OrderElement> getParent() {
|
||||
return OrderLineGroup.this.getParent();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.navalplanner.business.orders.entities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.trees.ITreeNode;
|
||||
import org.navalplanner.business.trees.TreeNodeOnList;
|
||||
|
||||
/**
|
||||
* Takes into account the scheduling state when modifying the tree. <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public abstract class TreeNodeOnListWithSchedulingState<T extends ITreeNode<T>>
|
||||
extends TreeNodeOnList<T> {
|
||||
|
||||
protected TreeNodeOnListWithSchedulingState(List<T> children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
protected abstract SchedulingState getSchedulingStateFrom(T node);
|
||||
|
||||
protected void updateSchedulingStateGiven(T node) {
|
||||
removeFromPreviousSchedulingState(node);
|
||||
updateWithNewChild(getSchedulingStateFrom(node));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onChildAdded(T newChild) {
|
||||
updateSchedulingStateGiven(newChild);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onChildRemoved(T previousChild) {
|
||||
removeFromPreviousSchedulingState(previousChild);
|
||||
}
|
||||
|
||||
protected abstract void updateWithNewChild(SchedulingState newChildState);
|
||||
|
||||
protected void removeFromPreviousSchedulingState(T node) {
|
||||
SchedulingState schedulingState = getSchedulingStateFrom(node);
|
||||
if (!schedulingState.isRoot()) {
|
||||
schedulingState.getParent().removeChild(schedulingState);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue