Exemplo n.º 1
0
 public void printActivities() {
   // clear table
   int currentRow = 0;
   view.getTableModel().setRowCount(currentRow);
   Iterator<Activity> iter = activities.iterator();
   while (iter.hasNext()) {
     Activity a = iter.next();
     // print succ's and pred's
     Iterator<Activity> relationsIter = a.getPredecessors().iterator();
     String predecessors = "";
     while (relationsIter.hasNext()) {
       predecessors += relationsIter.next().getName() + " ";
     }
     // get start and end
     Calendar calStart = a.getStartDate();
     Calendar calEnd = a.getEndDate();
     String start, end;
     if (calStart == null || calEnd == null) {
       start = "-";
       end = "-";
     } else {
       start =
           calStart.get(Calendar.DAY_OF_MONTH)
               + "/"
               + (calStart.get(Calendar.MONTH) + 1)
               + "/"
               + calStart.get(Calendar.YEAR);
       end =
           calEnd.get(Calendar.DAY_OF_MONTH)
               + "/"
               + (calEnd.get(Calendar.MONTH) + 1)
               + "/"
               + calEnd.get(Calendar.YEAR);
     }
     // build Gantt for current activity
     String ganttLine = "";
     if ("START".equals(a.getName())) {
       for (int t = 1; t <= this.length; t++) {
         if (t % 5 == 0) ganttLine += "'";
         else ganttLine += " ";
       }
     } else {
       for (int t = 0; t < this.length; t++) {
         if (t >= a.getStartDay() && t < a.getStartDay() + a.getDuration()) ganttLine += "X";
         else ganttLine += " ";
       }
     }
     // print row
     view.getTableModel()
         .addRow(new Object[] {a.getName(), a.getDuration(), start, end, predecessors, ganttLine});
     for (int i = 0;
         i < this.getMaxNumOfResources()
             && (i + view.getColumnOffset()) < view.getTableModel().getColumnCount();
         i++) {
       view.getTableModel().setValueAt(a.getResource(i), currentRow, i + view.getColumnOffset());
     }
     currentRow++;
   }
 }
Exemplo n.º 2
0
 public void deleteActivityByName(String activityName) {
   Activity current = getActivityByName(activityName);
   if (current != null) {
     // delete successor references
     Iterator<Activity> predIter = current.getPredecessors().iterator();
     while (predIter.hasNext()) {
       predIter.next().getSuccessors().remove(current);
     }
     // delete predecessor references
     Iterator<Activity> succIter = current.getSuccessors().iterator();
     while (succIter.hasNext()) {
       succIter.next().getPredecessors().remove(current);
     }
     // delete element
     activities.remove(current);
   }
 }
Exemplo n.º 3
0
 public void updatePredecessors(Activity a, String[] newPreds) {
   List<Activity> oldPreds = new ArrayList<Activity>(a.getPredecessors());
   for (int i = 0; i < newPreds.length; i++) {
     if (a.inList(oldPreds, newPreds[i])) {
       // no update
       oldPreds.remove(this.getActivityByName(newPreds[i]));
     } else {
       // add new arcs
       addArc(newPreds[i], a.getName());
     }
   }
   Iterator<Activity> it = oldPreds.iterator();
   while (it.hasNext()) {
     // delete old arcs
     removeArc(it.next().getName(), a.getName());
   }
   // if no predecessors entered then add START
   if (newPreds.length == 0 && !a.getName().equals("START")) {
     addArc("START", a.getName());
   }
 }