📄 taskimpl.java
字号:
package net.sourceforge.ganttproject.task;import java.awt.Color;import java.util.ArrayList;import java.util.Date;import java.util.List;import java.lang.Long;import net.sourceforge.ganttproject.GanttCalendar;import net.sourceforge.ganttproject.GanttTaskRelationship;import net.sourceforge.ganttproject.calendar.AlwaysWorkingTimeCalendarImpl;import net.sourceforge.ganttproject.calendar.GPCalendar;import net.sourceforge.ganttproject.calendar.GPCalendarActivity;import net.sourceforge.ganttproject.shape.ShapePaint;import net.sourceforge.ganttproject.task.algorithm.AlgorithmCollection;import net.sourceforge.ganttproject.task.dependency.TaskDependencyException;import net.sourceforge.ganttproject.task.dependency.TaskDependencySlice;import net.sourceforge.ganttproject.task.dependency.TaskDependencySliceAsDependant;import net.sourceforge.ganttproject.task.dependency.TaskDependencySliceAsDependee;import net.sourceforge.ganttproject.task.dependency.TaskDependencySliceImpl;import net.sourceforge.ganttproject.task.hierarchy.TaskHierarchyItem;import net.sourceforge.ganttproject.time.TimeUnit;/** * Created by IntelliJ IDEA. * * @author bard Date: 31.01.2004 */public class TaskImpl implements Task { private int myID; private final TaskManagerImpl myManager; private String myName; private String myWebLink = new String("http://"); private boolean isMilestone; boolean isProjectTask; private int myPriority; private GanttCalendar myStart; private GanttCalendar myEnd; private GanttCalendar myThird; private int myThirdDateConstraint; private int myCompletionPercentage; private TaskLength myLength; private List myActivities = new ArrayList();// private boolean isStartFixed;// private boolean isFinishFixed; private boolean bExpand; // private final TaskDependencyCollection myDependencies = new // TaskDependencyCollectionImpl(); private ResourceAssignmentCollectionImpl myAssignments; private TaskDependencySlice myDependencySlice; private TaskDependencySlice myDependencySliceAsDependant; private TaskDependencySlice myDependencySliceAsDependee; private boolean myEventsEnabled; private final TaskHierarchyItem myTaskHierarchyItem; private ShapePaint myShape; private Color myColor; private String myNotes; private MutatorImpl myMutator; private final CustomColumnsValues customValues; private boolean critical; public final static int NONE = 0; public final static int EARLIESTBEGIN = 1; protected TaskImpl(TaskManager taskManager, int taskID) { myManager = (TaskManagerImpl) taskManager; if (taskID == -1) { myID = myManager.getMaxID(); myManager.increaseMaxID(); } else { if (myManager.getTask(taskID) != null) { throw new IllegalArgumentException("There is a task with ID=" + taskID + " already"); } myID = taskID; } myAssignments = new ResourceAssignmentCollectionImpl(this, myManager .getConfig().getResourceManager()); myDependencySlice = new TaskDependencySliceImpl(this, myManager .getDependencyCollection()); myDependencySliceAsDependant = new TaskDependencySliceAsDependant(this, myManager.getDependencyCollection()); myDependencySliceAsDependee = new TaskDependencySliceAsDependee(this, myManager.getDependencyCollection()); myPriority = 1; myTaskHierarchyItem = myManager.getHierarchyManager().createItem(this); myNotes = ""; bExpand = true; myColor = null; customValues = new CustomColumnsValues(); } protected TaskImpl(TaskImpl copy, boolean isUnplugged) { myManager = copy.myManager; if (!isUnplugged) { myTaskHierarchyItem = myManager.getHierarchyManager().createItem( this); } else { myTaskHierarchyItem = null; } myAssignments = new ResourceAssignmentCollectionImpl(this, myManager .getConfig().getResourceManager()); myAssignments.importData(copy.getAssignmentCollection()); myID = copy.myID; myName = copy.myName; myWebLink = copy.myWebLink; isMilestone = copy.isMilestone; isProjectTask = copy.isProjectTask; myPriority = copy.myPriority; myStart = copy.myStart; myEnd = copy.myEnd; myThird = copy.myThird; myThirdDateConstraint = copy.myThirdDateConstraint; myCompletionPercentage = copy.myCompletionPercentage; myLength = copy.myLength; myShape = copy.myShape; myColor = copy.myColor; myNotes = copy.myNotes; bExpand = copy.bExpand; // myDependencySlice = new TaskDependencySliceImpl(this, myManager .getDependencyCollection()); myDependencySliceAsDependant = new TaskDependencySliceAsDependant(this, myManager.getDependencyCollection()); myDependencySliceAsDependee = new TaskDependencySliceAsDependee(this, myManager.getDependencyCollection()); customValues = (CustomColumnsValues) copy.getCustomValues().clone(); recalculateActivities(); } public Task unpluggedClone() { TaskImpl result = new TaskImpl(this, true) { public boolean isSupertask() { return false; } }; return result; } public TaskMutator createMutator() { if (myMutator != null) { throw new RuntimeException("Two mutators have been requested for task="+getName(), myException); } myMutator = new MutatorImpl(); myException = new Exception(); return myMutator; } public TaskMutator createMutatorFixingDuration() { if (myMutator != null) { throw new RuntimeException("Two mutators have been requested for task="+getName(), myException); } myMutator = new MutatorImpl() { @Override public void setStart(GanttCalendar start) { super.setStart(start); TaskImpl.this.myEnd = null; } @Override public void setEnd(GanttCalendar end) { final Date newEndDate = end.getTime(); final Date newStartDate = shiftDate(newEndDate, getDuration().getTimeUnit(), -getDuration().getLength(), myManager.getCalendar()); setStart(new GanttCalendar(newStartDate)); } }; myException = new Exception(); return myMutator; } private Exception myException; // main properties public int getTaskID() { return myID; } public String getName() { return myName; } public String getWebLink() { return myWebLink; } public boolean isMilestone() { return isMilestone; } public int getPriority() { return myPriority; } public GanttCalendar getStart() { if (myMutator != null && myMutator.myIsolationLevel == TaskMutator.READ_UNCOMMITED) { return myMutator.getStart(); } else { return myStart; } } public GanttCalendar getEnd() { GanttCalendar result = null; if (myMutator != null && myMutator.myIsolationLevel == TaskMutator.READ_UNCOMMITED) { result = myMutator.getEnd(); } if (result==null) { if (myEnd == null) { myEnd = calculateEnd(); } result = myEnd; } return result; } GanttCalendar calculateEnd() { GanttCalendar result = getStart().Clone(); Date newEnd = shiftDate(result.getTime(), getDuration().getTimeUnit(), getDuration().getLength()); result.setTime(newEnd); return result; } public GanttCalendar getThird() { if (myMutator != null && myMutator.myIsolationLevel == TaskMutator.READ_UNCOMMITED) { return myMutator.getThird(); } else { return myThird; } } public int getThirdDateConstraint() { return myThirdDateConstraint; } public TaskActivity[] getActivities() { List activities = myMutator == null ? null : myMutator.getActivities(); if (activities == null) { activities = myActivities; } return (TaskActivity[]) activities.toArray(new TaskActivity[activities .size()]); } public TaskLength getDuration() { return (myMutator != null && myMutator.myIsolationLevel == TaskMutator.READ_UNCOMMITED) ? myMutator .getDuration() : myLength; } public int getCompletionPercentage() { return (myMutator != null && myMutator.myIsolationLevel == TaskMutator.READ_UNCOMMITED) ? myMutator .getCompletionPercentage() : myCompletionPercentage; } public boolean getExpand() { return bExpand; } public ShapePaint getShape() { return myShape; } public Color getColor() { Color result = myColor; if (result == null) { if (isMilestone() || getNestedTasks().length > 0) { result = Color.BLACK; } else { result = myManager.getConfig().getDefaultColor(); } } return result; } public String getNotes() { return myNotes; } public GanttTaskRelationship[] getPredecessors() { return new GanttTaskRelationship[0]; // To change body of implemented // methods use Options | File // Templates. } public GanttTaskRelationship[] getSuccessors() { return new GanttTaskRelationship[0]; // To change body of implemented // methods use Options | File // Templates. } public ResourceAssignment[] getAssignments() { return myAssignments.getAssignments(); } public ResourceAssignmentCollection getAssignmentCollection() { return myAssignments; } // public Task getSupertask() { TaskHierarchyItem container = myTaskHierarchyItem.getContainerItem(); return container.getTask(); } public Task[] getNestedTasks() { TaskHierarchyItem[] nestedItems = myTaskHierarchyItem.getNestedItems(); Task[] result = new Task[nestedItems.length]; for (int i = 0; i < nestedItems.length; i++) { result[i] = nestedItems[i].getTask(); } return result; } public void move(Task targetSupertask) { TaskImpl supertaskImpl = (TaskImpl) targetSupertask; TaskHierarchyItem targetItem = supertaskImpl.myTaskHierarchyItem; myTaskHierarchyItem.delete(); targetItem.addNestedItem(myTaskHierarchyItem); myManager.onTaskMoved(this); } public void delete() { getDependencies().clear(); getAssignmentCollection().clear(); } public TaskDependencySlice getDependencies() { return myDependencySlice; } public TaskDependencySlice getDependenciesAsDependant() { return myDependencySliceAsDependant; } public TaskDependencySlice getDependenciesAsDependee() { return myDependencySliceAsDependee; } public TaskManager getManager() { return myManager; } // TODO: remove this hack. ID must never be changed protected void setTaskIDHack(int taskID) { myID = taskID; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -