• R/O
  • SSH
  • HTTPS

freegantt: Commit


Commit MetaInfo

Révision129 (tree)
l'heure2012-09-18 16:56:26
Auteurmonolith52

Message de Log

リファクタリング途中まで

Change Summary

Modification

--- trunk/src/jp/sourceforge/freegantt/swing/TaskLineDataPane.java (revision 128)
+++ trunk/src/jp/sourceforge/freegantt/swing/TaskLineDataPane.java (revision 129)
@@ -527,7 +527,7 @@
527527 if (dragOperation == OPERATION_TASK_SLIDE) {
528528 floatingTask
529529 .setStartDate(getLateBusinessDayAtPoint(e.getPoint()));
530- project.updateChildrenPeriod(floatingTask);
530+ project.updateChildrenPeriod(floatingTask, true);
531531 repaint();
532532 return true;
533533 } else if (dragOperation == OPERATION_TASK_PERIOD) {
@@ -535,7 +535,7 @@
535535 int count = getBusinessDayCount(floatingTask.getStartDate(),
536536 toCalendar);
537537 floatingTask.setPeriod(count);
538- project.updateChildrenPeriod(floatingTask);
538+ project.updateChildrenPeriod(floatingTask, true);
539539 repaint();
540540 return true;
541541 } else if (dragOperation == OPERATION_TASK_COMPLETION) {
@@ -551,28 +551,18 @@
551551 }
552552
553553 public boolean mouseReleased(MouseEvent e) {
554+ if (dragOperation != OPERATION_TASK_SLIDE &&
555+ dragOperation != OPERATION_TASK_PERIOD &&
556+ dragOperation != OPERATION_TASK_COMPLETION) return false;
557+
554558 if (dragOperation == OPERATION_TASK_SLIDE) {
555559 floatingTask.setStartDate(getLateBusinessDayAtPoint(e.getPoint()));
556-
557- project.getController().setTaskAtRow(floatingTask, project.getRowByTask(targetTask));
558-
559- dragOperation = OPERATION_NONE;
560- floatingTask = null;
561- repaintProject();
562- return true;
563- } else if (dragOperation == OPERATION_TASK_PERIOD) {
560+ } else if (dragOperation == OPERATION_TASK_PERIOD) {
564561 Calendar toCalendar = getLateBusinessDayAtPoint(e.getPoint());
565562 int count = getBusinessDayCount(floatingTask.getStartDate(),
566563 toCalendar);
567564 floatingTask.setStartDate(floatingTask.getStartDate());
568565 floatingTask.setPeriod(count);
569-
570- project.getController().setTaskAtRow(floatingTask, project.getRowByTask(targetTask));
571-
572- dragOperation = OPERATION_NONE;
573- floatingTask = null;
574- repaintProject();
575- return true;
576566 } else if (dragOperation == OPERATION_TASK_COMPLETION) {
577567 int offset = e.getX();
578568 Rectangle rect = getTaskRect(targetTask);
@@ -579,15 +569,21 @@
579569 int completion = ((offset - rect.x) * 100 / rect.width / 5) * 5;
580570 completion = Math.min(Math.max(completion, 0), 100);
581571 floatingTask.setCompletion(completion);
582-
572+ }
573+
574+ CompoundEdit compound = new CompoundEdit();
575+ project.getUndoManager().addEdit(compound);
576+ try {
583577 project.getController().setTaskAtRow(floatingTask, project.getRowByTask(targetTask));
584-
585- dragOperation = OPERATION_NONE;
586- floatingTask = null;
587- repaintProject();
588- return true;
578+ project.update();
579+ } finally {
580+ compound.end();
589581 }
590- return false;
582+
583+ dragOperation = OPERATION_NONE;
584+ floatingTask = null;
585+ repaintProject();
586+ return true;
591587 }
592588
593589 public Pair<Integer, Task> getOperation(MouseEvent e) {
--- trunk/src/jp/sourceforge/freegantt/data/controller/ProjectController.java (revision 128)
+++ trunk/src/jp/sourceforge/freegantt/data/controller/ProjectController.java (revision 129)
@@ -31,6 +31,7 @@
3131 import jp.sourceforge.freegantt.data.undo.UpdateProjectNameEdit;
3232 import jp.sourceforge.freegantt.data.undo.UpdateProjectSummaryEdit;
3333 import jp.sourceforge.freegantt.data.undo.UpdateTaskEdit;
34+import jp.sourceforge.freegantt.data.undo.UpdateTaskGroupEdit;
3435 import jp.sourceforge.freegantt.data.undo.UpdateTaskTableWidthEdit;
3536 import jp.sourceforge.freegantt.data.undo.UpdateViewTaskTableColumnsEdit;
3637 import jp.sourceforge.freegantt.util.CalendarUtil;
@@ -108,7 +109,7 @@
108109 * @param task
109110 * @param row
110111 */
111- public void setTaskAtRow(Task newTask, int row, boolean isOnUpdate) {
112+ public void setTaskAtRow(Task newTask, int row) {
112113 if (newTask == null) newTask = new Task();
113114 CompoundEdit compound = new CompoundEdit();
114115 getUndoManager().addEdit(compound);
@@ -130,15 +131,11 @@
130131 newTask,
131132 row));
132133 project.getTasks().set(index, newTask);
133- if (!isOnUpdate) project.update();
134134 } finally {
135135 compound.end();
136+ project.getTaskTableModel().fireTableChanged();
136137 }
137138 }
138-
139- public void setTaskAtRow(Task newTask, int row) {
140- setTaskAtRow(newTask, row, false);
141- }
142139
143140 /**
144141 * 指定行まで空タスクで埋める
@@ -267,6 +264,8 @@
267264 newTask.setLevel(task.getLevel() + 1);
268265
269266 setTaskAtRow(newTask, row);
267+
268+ project.update();
270269 } finally {
271270 compound.end();
272271 }
@@ -617,4 +616,26 @@
617616 project.getProjectViewModel().fireProjectViewChangedEvent();
618617 }
619618 }
619+
620+ /**
621+ * 指定行のタスクにグループフラグを設定する
622+ * @param b
623+ * @param rowByTask
624+ */
625+ public void setTaskGroup(boolean group, int row) {
626+ Task task = project.getTaskAtRow(row);
627+ if (task == null) return;
628+ if (task.isGroup() == group) return;
629+
630+ CompoundEdit compound = new CompoundEdit();
631+ getUndoManager().addEdit(compound);
632+ try {
633+ setModified(true);
634+
635+ compound.addEdit(new UpdateTaskGroupEdit(project, group, row));
636+ task.setGroup(group);
637+ } finally {
638+ compound.end();
639+ }
640+ }
620641 }
--- trunk/src/jp/sourceforge/freegantt/data/undo/UpdateTaskEdit.java (revision 128)
+++ trunk/src/jp/sourceforge/freegantt/data/undo/UpdateTaskEdit.java (revision 129)
@@ -55,8 +55,6 @@
5555 super.undo();
5656 oldTask.setRestrictions(collectTasksAtRows(oldRestrictionRows));
5757 project.getController().setTaskAtRow(oldTask, row);
58- project.update();
59- project.getTaskTableModel().fireTableChanged();
6058 }
6159
6260 @Override
@@ -64,8 +62,6 @@
6462 super.redo();
6563 newTask.setRestrictions(collectTasksAtRows(newRestrictionRows));
6664 project.getController().setTaskAtRow(newTask, row);
67- project.update();
68- project.getTaskTableModel().fireTableChanged();
6965 }
7066
7167 @Override
--- trunk/src/jp/sourceforge/freegantt/data/undo/UpdateTaskGroupEdit.java (nonexistent)
+++ trunk/src/jp/sourceforge/freegantt/data/undo/UpdateTaskGroupEdit.java (revision 129)
@@ -0,0 +1,41 @@
1+package jp.sourceforge.freegantt.data.undo;
2+
3+import javax.swing.undo.AbstractUndoableEdit;
4+import javax.swing.undo.CannotRedoException;
5+import javax.swing.undo.CannotUndoException;
6+
7+import jp.sourceforge.freegantt.data.Project;
8+
9+public class UpdateTaskGroupEdit extends AbstractUndoableEdit {
10+ private static final long serialVersionUID = 2433458560313634203L;
11+
12+ Project project;
13+ boolean oldGroup;
14+ boolean newGroup;
15+ int row;
16+
17+ public UpdateTaskGroupEdit(Project project, boolean newGroup, int row) {
18+ this.project = project;
19+ this.oldGroup = project.getTaskAtRow(row).isGroup();
20+ this.newGroup = newGroup;
21+ this.row = row;
22+ }
23+
24+ @Override
25+ public void undo() throws CannotUndoException {
26+ super.undo();
27+ project.getController().setTaskGroup(oldGroup, row);
28+ }
29+
30+ @Override
31+ public void redo() throws CannotRedoException {
32+ super.redo();
33+ project.getController().setTaskGroup(newGroup, row);
34+ }
35+
36+ @Override
37+ public void die() {
38+ super.die();
39+ project = null;
40+ }
41+}
--- trunk/src/jp/sourceforge/freegantt/data/Project.java (revision 128)
+++ trunk/src/jp/sourceforge/freegantt/data/Project.java (revision 129)
@@ -48,8 +48,6 @@
4848 Print print = new Print();
4949
5050 // 以下は自動計算される
51- /** タスクレベル */
52- int maxLevel;
5351 /** データ範囲開始日 */
5452 Calendar chartFromDate;
5553 /** データ範囲終了日 */
@@ -166,9 +164,6 @@
166164 public void setAdditionalHolidays(List<Calendar> additionalHolidays) {
167165 this.additionalHolidays = additionalHolidays;
168166 }
169- public int getMaxLevel() {
170- return maxLevel;
171- }
172167 public TaskListTableModel getTaskTableModel() {
173168 return taskTableModel;
174169 }
@@ -230,9 +225,46 @@
230225 return result;
231226 }
232227
228+ /**
229+ * 子タスクを集めて返す
230+ * @param targetTask
231+ */
232+ public List<Task> getChildTasks(Task targetTask) {
233+ List<Task> childTasks = new ArrayList<Task>();
234+ int index = getIndexByTask(targetTask);
235+ index ++;
236+
237+ while (index < tasks.size()) {
238+ Task task = getTaskAtIndex(index);
239+ if (task.getLevel() <= targetTask.getLevel()) return childTasks;
240+ childTasks.add(task);
241+ index++;
242+ }
243+ return childTasks;
244+ }
245+
246+ /**
247+ * 親タスクを返す
248+ * @param targetTask 見つからなければnull
249+ * @return
250+ */
251+ private Task getParentTask(Task targetTask) {
252+ if (targetTask.getLevel() == 0) return null;
253+
254+ int index = getIndexByTask(targetTask);
255+ index--;
256+ while (index >= 0) {
257+ Task task = getTaskAtIndex(index);
258+ if (task.getLevel() < targetTask.getLevel()) return task;
259+ index--;
260+ }
261+
262+ return null;
263+ }
264+
233265 public void update() {
234266
235- // タスクを階層順にソートする
267+ // タスクをlevelの降順にソートする
236268 List<Task> sortedTasks = new ArrayList<Task>(tasks);
237269 Collections.sort(sortedTasks, new Comparator<Task>() {
238270 @Override
@@ -246,22 +278,16 @@
246278
247279 // 階層の深いものから実質工期を求める
248280 for (Task task: sortedTasks) {
249- task.setGroup(!getChildTasks(task).isEmpty());
281+ getController().setTaskGroup(!getChildTasks(task).isEmpty(), getRowByTask(task));
250282 if (task.isGroup()) {
251283 updateParentPeriod(task);
252284 } else if (task.isMilestone()) {
253285 updateMilestone(task);
254286 } else {
255- updateChildrenPeriod(task);
287+ updateChildrenPeriod(task, false);
256288 }
257289 }
258290
259- // 最深階層を更新する
260- maxLevel = 0;
261- if (!sortedTasks.isEmpty()) {
262- maxLevel = sortedTasks.get(sortedTasks.size()-1).getLevel();
263- }
264-
265291 // クリティカルパスを計算する
266292 updateCliticalPath();
267293
@@ -270,30 +296,35 @@
270296 }
271297
272298 public void updateMilestone(Task task) {
273- task.setRealPeriod(0);
299+ Task updateTask = task.clone();
274300
301+ updateTask.setRealPeriod(0);
302+
275303 List<Task> srcs = getRestrictionSrcTasks(task);
276304 if (srcs.size() == 0) {
277- task.setCompletion(100);
278- return;
305+ updateTask.setCompletion(100);
306+ } else {
307+ int completeTaskCount = 0;
308+ for (Task src: srcs) {
309+ if (src.getCompletion() == 100) completeTaskCount++;
310+ }
311+ updateTask.setCompletion(completeTaskCount * 100 / srcs.size());
279312 }
280313
281- int completeTaskCount = 0;
282- for (Task src: srcs) {
283- if (src.getCompletion() == 100) completeTaskCount++;
314+ if (!updateTask.equals(task)) {
315+ getController().setTaskAtRow(updateTask, getRowByTask(task));
284316 }
285- task.setCompletion(completeTaskCount * 100 / srcs.size());
286317 }
287318
288- public void updateChildrenPeriod(Task task) {
319+ public void updateChildrenPeriod(Task task, boolean isFloating) {
289320 if (task.isGroup()) return;
290-
291321 if (task.getStartDate() == null) return;
292322 if (task.getPeriod() == null) task.setPeriod(0);
323+ Task updateTask = (isFloating ? task : task.clone());
293324
294- int leftPeriod = task.getPeriod();
325+ int leftPeriod = updateTask.getPeriod();
295326 int realPeriod = 0;
296- Calendar now = (Calendar)task.getStartDate().clone();
327+ Calendar now = (Calendar)updateTask.getStartDate().clone();
297328
298329 // 無限ループを防ぐためにリミッタを使用する
299330 for (int i=0; i<365 && leftPeriod > 0.0; i++) {
@@ -304,46 +335,13 @@
304335 now.add(Calendar.DATE, 1);
305336 }
306337
307- task.setRealPeriod(realPeriod);
308- }
309-
310-
311- /**
312- * 子タスクを集めて返す
313- * @param targetTask
314- */
315- public List<Task> getChildTasks(Task targetTask) {
316- List<Task> childTasks = new ArrayList<Task>();
317- int index = getIndexByTask(targetTask);
318- index ++;
319-
320- while (index < tasks.size()) {
321- Task task = getTaskAtIndex(index);
322- if (task.getLevel() <= targetTask.getLevel()) return childTasks;
323- childTasks.add(task);
324- index++;
325- }
326- return childTasks;
327- }
328-
329- /**
330- * 親タスクを返す
331- * @param targetTask 見つからなければnull
332- * @return
333- */
334- private Task getParentTask(Task targetTask) {
335- if (targetTask.getLevel() == 0) return null;
338+ updateTask.setRealPeriod(realPeriod);
336339
337- int index = getIndexByTask(targetTask);
338- index--;
339- while (index >= 0) {
340- Task task = getTaskAtIndex(index);
341- if (task.getLevel() < targetTask.getLevel()) return task;
342- index--;
340+ if (!isFloating && !updateTask.equals(task)) {
341+ getController().setTaskAtRow(updateTask, getRowByTask(task));
343342 }
344-
345- return null;
346343 }
344+
347345
348346 /**
349347 * 親タスクの開始日と工期は子タスクの全日程を含む長さとする。
@@ -400,7 +398,7 @@
400398 if (!updateTask.equals(task)) {
401399 System.out.println("Group Task updated: " + updateTask.getName());
402400 // この仲ではupdateが呼ばれない
403- getController().setTaskAtRow(updateTask, getRowByTask(task), true);
401+ getController().setTaskAtRow(updateTask, getRowByTask(task));
404402 }
405403 }
406404
Afficher sur ancien navigateur de dépôt.