001: /**
002: * Copyright 2004 Carlos Silva A.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: */package com.csa.lgantt.model;
017:
018: import java.util.Date;
019:
020: public class Constraint {
021: public static final byte MODE_END_BEGIN = 0;
022: public static final byte MODE_END_END = 1;
023: public static final byte MODE_BEGIN_BEGIN = 2;
024: public static final byte MODE_BEGIN_END = 3;
025: // datos
026: /**
027: * Mode
028: * <ul>
029: * <li> 1 : EB
030: * <li> 2 : EE
031: * <li> 3 : BE
032: * <li> 4 : BB
033: * </ul>
034: */
035: protected byte mode;
036: protected long msDelay;
037:
038: // asociaciones
039: protected Task masterTask = null;
040: protected Task slaveTask = null;
041:
042: // transientes
043:
044: // metodos publicos
045: /**
046: * Genera un constraint. Ejecuta {@link Task#addConstraint} para terminar de
047: * anexar
048: */
049: public Constraint(Task master, Task slave) throws GanttException {
050: masterTask = master;
051: slaveTask = slave;
052: slaveTask.addConstraint(this );
053: }
054:
055: /**
056: * Retorna la fecha de partida de la tarea esclava de acuerdo a la
057: * informacion de la tarea principal.
058: *
059: * @return
060: */
061: public Date getStartDate() {
062: // System.out.println("Constraint.getStartDate() mode="+mode+ " entre
063: // "+masterTask.getName()+" y "+ slaveTask.getName());
064: Date start = null;
065: DateOrganizer dorg = masterTask.project.getDateOrganizer();
066: switch (mode) {
067: case MODE_END_BEGIN:
068: start = masterTask.getFinishDate();
069: start = dorg.getEndDate(start, msDelay);
070: break;
071: case MODE_BEGIN_BEGIN:
072: start = masterTask.getStartDate();
073: start = dorg.getEndDate(start, msDelay);
074: break;
075: case MODE_END_END:
076: start = masterTask.getFinishDate();
077: start = dorg.getEndDate(start, msDelay
078: - slaveTask.getWorkLength());
079: break;
080: default: // BEGIN_END
081: start = masterTask.getStartDate();
082: start = dorg.getEndDate(start, msDelay
083: - slaveTask.getWorkLength());
084: }
085: start = dorg.getNextPossibleStart(start);
086: // System.out.println(" "+start);
087: return start;
088: }
089:
090: /**
091: * Remueve el constraint de los hijos y deja este constraint sin uso.
092: */
093: public void remove() {
094: // Primero se asigna dirty
095: slaveTask.setDirty();
096: masterTask.setDirty();
097: // y luego se remueven sus links
098: masterTask.childConstraints.remove(this );
099: slaveTask.constraints.remove(this );
100: slaveTask.project.sendChange(new ProjectChange(
101: ProjectChange.CONSTRAINT, slaveTask));
102: slaveTask = null;
103: masterTask = null;
104:
105: }
106:
107: public Task getMasterTask() {
108: return masterTask;
109: }
110:
111: public Task getSlaveTask() {
112: return slaveTask;
113: }
114:
115: public byte getMode() {
116: return mode;
117: }
118:
119: public void setMode(byte newMode) {
120: mode = newMode;
121: slaveTask.setDirty();
122: slaveTask.project.sendChange(new ProjectChange(
123: ProjectChange.CONSTRAINT, slaveTask));
124: }
125:
126: public long getMsDelay() {
127: return msDelay;
128: }
129:
130: public void setMsDelay(long newDelay) {
131: msDelay = newDelay;
132: slaveTask.setDirty();
133: slaveTask.project.sendChange(new ProjectChange(
134: ProjectChange.CONSTRAINT, slaveTask));
135: }
136:
137: /**
138: * @return a string using numbers and time units as: 1d 4h 5m
139: */
140: public String getHumanReadableDelay() {
141: return masterTask.project.getDateOrganizer()
142: .getHumanReadableLap(msDelay);
143: }
144:
145: /**
146: * sets the length using abreviations such as: 5w 3d 2h 5m 58s 235S (five
147: * weeks, 3 days, 2 hours, 5 minutes, fifty eight seconds and two hundred and
148: * thirty five milliseconds).
149: */
150: public void setHumanReadableDelay(String s) {
151: setMsDelay(masterTask.project.getDateOrganizer()
152: .getLapFromHumanReadable(s));
153: }
154:
155: }
|