|
Link Here
|
| 13 |
package org.eclipse.mylyn.internal.tasks.ui.editors; |
13 |
package org.eclipse.mylyn.internal.tasks.ui.editors; |
| 14 |
|
14 |
|
| 15 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
|
|
16 |
import java.util.HashMap; |
| 16 |
import java.util.List; |
17 |
import java.util.List; |
|
|
18 |
import java.util.Map; |
| 17 |
|
19 |
|
| 18 |
import org.eclipse.jface.action.Action; |
20 |
import org.eclipse.jface.action.Action; |
| 19 |
import org.eclipse.jface.action.ToolBarManager; |
21 |
import org.eclipse.jface.action.ToolBarManager; |
|
Link Here
|
| 73 |
|
75 |
|
| 74 |
private boolean expandAllInProgress; |
76 |
private boolean expandAllInProgress; |
| 75 |
|
77 |
|
|
|
78 |
private final Map<Section, CommentGroup> subToCommentGroup = new HashMap<Section, CommentGroup>(); |
| 79 |
|
| 76 |
public TaskEditorCommentPart() { |
80 |
public TaskEditorCommentPart() { |
| 77 |
setPartName("Comments"); |
81 |
setPartName("Comments"); |
| 78 |
} |
82 |
} |
|
Link Here
|
| 153 |
}); |
157 |
}); |
| 154 |
} |
158 |
} |
| 155 |
} |
159 |
} |
|
|
160 |
|
| 156 |
setSection(toolkit, section); |
161 |
setSection(toolkit, section); |
| 157 |
} |
162 |
} |
| 158 |
|
163 |
|
|
Link Here
|
| 179 |
// last group is not rendered as subsection |
184 |
// last group is not rendered as subsection |
| 180 |
CommentGroup lastGroup = commentGroups.get(commentGroups.size() - 1); |
185 |
CommentGroup lastGroup = commentGroups.get(commentGroups.size() - 1); |
| 181 |
addComments(toolkit, composite, lastGroup.getCommentAttributes()); |
186 |
addComments(toolkit, composite, lastGroup.getCommentAttributes()); |
|
|
187 |
|
| 182 |
} |
188 |
} |
| 183 |
} |
189 |
} |
| 184 |
|
190 |
|
|
Link Here
|
| 376 |
expandAllInProgress = true; |
382 |
expandAllInProgress = true; |
| 377 |
getTaskEditorPage().setReflow(false); |
383 |
getTaskEditorPage().setReflow(false); |
| 378 |
|
384 |
|
|
|
385 |
boolean sectionExpanded = false; |
| 386 |
if (section != null && section.isExpanded()) { |
| 387 |
sectionExpanded = true; |
| 388 |
} |
| 389 |
|
| 390 |
// first expand the whole comments section |
| 379 |
if (section != null) { |
391 |
if (section != null) { |
| 380 |
EditorUtil.toggleExpandableComposite(true, section); |
392 |
EditorUtil.toggleExpandableComposite(true, section); |
| 381 |
} |
393 |
} |
| 382 |
|
394 |
|
| 383 |
if (subSections != null) { |
395 |
if (subSections != null) { |
| 384 |
// first toggle on all subSections |
396 |
int numberOfSectionsExpanded = getHighestExpandedSection(sectionExpanded); |
| 385 |
if (section != null) { |
|
|
| 386 |
EditorUtil.toggleExpandableComposite(true, section); |
| 387 |
} |
| 388 |
|
397 |
|
|
|
398 |
//add to the number of expanded sections by 1, from the bottom up |
| 399 |
int count = subSections.size(); |
| 389 |
for (Section subSection : subSections) { |
400 |
for (Section subSection : subSections) { |
| 390 |
if (subSection.isDisposed()) { |
401 |
if (subSection.isDisposed()) { |
|
|
402 |
count--; |
| 391 |
continue; |
403 |
continue; |
| 392 |
} |
404 |
} |
| 393 |
EditorUtil.toggleExpandableComposite(true, subSection); |
405 |
if (count - numberOfSectionsExpanded < 1) { |
|
|
406 |
changeExpansionStateOfSection(subSections.size() - count, true); |
| 407 |
} else { |
| 408 |
//this is a special case: |
| 409 |
//when the task is first opened in the task editor |
| 410 |
//if the whole section was not expanded then all subsections are in the expanded state |
| 411 |
if (sectionExpanded == false) { |
| 412 |
changeExpansionStateOfSection(subSections.size() - count, false); |
| 413 |
} |
| 414 |
} |
| 415 |
count--; |
| 394 |
} |
416 |
} |
| 395 |
} |
417 |
} |
| 396 |
|
418 |
|
| 397 |
for (ExpandableComposite composite : commentComposites) { |
419 |
//expand all current comments, which is not usually a comment group |
| 398 |
if (composite.isDisposed()) { |
420 |
changeExpansionStateOfSection(subSections.size(), true); |
| 399 |
continue; |
421 |
|
| 400 |
} |
|
|
| 401 |
if (!composite.isExpanded()) { |
| 402 |
EditorUtil.toggleExpandableComposite(true, composite); |
| 403 |
} |
| 404 |
} |
| 405 |
} finally { |
422 |
} finally { |
| 406 |
expandAllInProgress = false; |
423 |
expandAllInProgress = false; |
| 407 |
getTaskEditorPage().setReflow(true); |
424 |
getTaskEditorPage().setReflow(true); |
|
Link Here
|
| 409 |
getTaskEditorPage().reflow(); |
426 |
getTaskEditorPage().reflow(); |
| 410 |
} |
427 |
} |
| 411 |
|
428 |
|
| 412 |
// private static void toggleChildren(Composite composite, boolean expended) { |
429 |
/** |
| 413 |
// for (Control child : composite.getChildren()) { |
430 |
* |
| 414 |
// if (child instanceof ExpandableComposite && !child.isDisposed()) { |
431 |
* @param sectionNumber |
| 415 |
// EditorUtil.toggleExpandableComposite(expended, (ExpandableComposite) child); |
432 |
* - the number of the section to expand, counting from top to bottom, starting at 0 |
| 416 |
// } |
433 |
* @param expansionState |
| 417 |
// if (child instanceof Composite) { |
434 |
* - the expansion state |
| 418 |
// toggleChildren((Composite) child, expended); |
435 |
*/ |
| 419 |
// } |
436 |
private void changeExpansionStateOfSection(int sectionNumber, boolean expansionState) { |
| 420 |
// } |
437 |
if (subSections == null) { |
| 421 |
// } |
438 |
return; |
|
|
439 |
} |
| 440 |
int sectionCount = 0; |
| 441 |
for (Section subSection : subSections) { |
| 442 |
if (sectionCount == sectionNumber) { |
| 443 |
EditorUtil.toggleExpandableComposite(expansionState, subSection); |
| 444 |
} |
| 445 |
sectionCount++; |
| 446 |
} |
| 447 |
Range range = getRange(sectionNumber); |
| 448 |
int count = 0; |
| 449 |
for (ExpandableComposite composite : commentComposites) { |
| 450 |
if (composite.isDisposed()) { |
| 451 |
continue; |
| 452 |
} |
| 453 |
if (count >= range.getOffset() && count < range.getEnd()) { |
| 454 |
EditorUtil.toggleExpandableComposite(expansionState, composite); |
| 455 |
} |
| 456 |
count++; |
| 457 |
} |
| 458 |
|
| 459 |
} |
| 460 |
|
| 461 |
private int getHighestExpandedSection(boolean parentSectionExpanded) { |
| 462 |
if (!parentSectionExpanded) { |
| 463 |
return 0; |
| 464 |
} |
| 465 |
int highestExpandedSection = 0; |
| 466 |
if (subSections != null) { |
| 467 |
int sectionNumber = 0; |
| 468 |
for (Section subSection : subSections) { |
| 469 |
if (subSection.isExpanded() && allCommentsExpanded(sectionNumber)) { |
| 470 |
highestExpandedSection = Math.max(subSections.size() - sectionNumber, highestExpandedSection); |
| 471 |
} |
| 472 |
sectionNumber++; |
| 473 |
} |
| 474 |
|
| 475 |
if (highestExpandedSection > 0) { |
| 476 |
return highestExpandedSection + 1; |
| 477 |
} else { |
| 478 |
return allCommentsExpanded(subSections.size()) ? 1 : 0; |
| 479 |
} |
| 480 |
} |
| 481 |
return highestExpandedSection; |
| 482 |
} |
| 483 |
|
| 484 |
class Range { |
| 485 |
int offset = 0; |
| 486 |
|
| 487 |
int end = 0; |
| 488 |
|
| 489 |
public Range() { |
| 490 |
} |
| 491 |
|
| 492 |
public Range(int i, int j) { |
| 493 |
offset = i; |
| 494 |
end = j; |
| 495 |
} |
| 496 |
|
| 497 |
public int getOffset() { |
| 498 |
return offset; |
| 499 |
} |
| 500 |
|
| 501 |
public void setStart(int offset) { |
| 502 |
this.offset = offset; |
| 503 |
} |
| 504 |
|
| 505 |
public int getEnd() { |
| 506 |
return end; |
| 507 |
} |
| 508 |
|
| 509 |
public void setEnd(int end) { |
| 510 |
this.end = end; |
| 511 |
} |
| 512 |
|
| 513 |
} |
| 514 |
|
| 515 |
/** |
| 516 |
* |
| 517 |
* @param sectionNumber |
| 518 |
* - the section number, counting from top to bottom, starting at 0 |
| 519 |
* @return |
| 520 |
*/ |
| 521 |
private boolean allCommentsExpanded(int sectionNumber) { |
| 522 |
|
| 523 |
if (subSections != null) { |
| 524 |
Range commentsInGroup = getRange(sectionNumber); |
| 525 |
ExpandableComposite[] commentArray = commentComposites.toArray(new ExpandableComposite[commentComposites.size()]); |
| 526 |
for (int i = commentsInGroup.getOffset(); i >= commentsInGroup.getOffset() && i < commentArray.length; i++) { |
| 527 |
ExpandableComposite expandableComposite = commentArray[i]; |
| 528 |
if (i >= commentsInGroup.getOffset() && i < commentsInGroup.getEnd()) { |
| 529 |
if (!expandableComposite.isExpanded()) { |
| 530 |
return false; |
| 531 |
} |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
return true; |
| 536 |
} |
| 537 |
|
| 538 |
private Range getRange(int sectionNumber) { |
| 539 |
if (subSections == null) { |
| 540 |
return new Range(0, 0); |
| 541 |
} |
| 542 |
int count = 0; |
| 543 |
Range commentsInGroup = new Range(); |
| 544 |
for (Section subSection : subSections) { |
| 545 |
commentsInGroup.setStart(commentsInGroup.getEnd()); |
| 546 |
CommentGroup commentGroup = subToCommentGroup.get(subSection); |
| 547 |
if (commentGroup == null) { |
| 548 |
break; |
| 549 |
} else { |
| 550 |
commentsInGroup.setEnd(commentsInGroup.getEnd() + commentGroup.getCommentAttributes().size()); |
| 551 |
} |
| 552 |
if (count >= sectionNumber) { |
| 553 |
break; |
| 554 |
} |
| 555 |
count++; |
| 556 |
} |
| 557 |
//special case for the last section, as it is not broken into a subsection |
| 558 |
if (sectionNumber == subSections.size()) { |
| 559 |
commentsInGroup.setStart(commentsInGroup.getEnd()); |
| 560 |
commentsInGroup.setEnd(commentComposites.size()); |
| 561 |
} |
| 562 |
return commentsInGroup; |
| 563 |
} |
| 422 |
|
564 |
|
| 423 |
private TaskComment convertToTaskComment(TaskDataModel taskDataModel, TaskAttribute commentAttribute) { |
565 |
private TaskComment convertToTaskComment(TaskDataModel taskDataModel, TaskAttribute commentAttribute) { |
| 424 |
TaskComment taskComment = new TaskComment(taskDataModel.getTaskRepository(), taskDataModel.getTask(), |
566 |
TaskComment taskComment = new TaskComment(taskDataModel.getTaskRepository(), taskDataModel.getTask(), |
|
Link Here
|
| 517 |
} |
659 |
} |
| 518 |
|
660 |
|
| 519 |
subSections.add(groupSection); |
661 |
subSections.add(groupSection); |
|
|
662 |
//necessary for finding expansion state |
| 663 |
subToCommentGroup.put(groupSection, commentGroup); |
| 520 |
} |
664 |
} |
| 521 |
|
665 |
|
| 522 |
private void expandSubSection(final FormToolkit toolkit, CommentGroup commentGroup, Section subSection) { |
666 |
private void expandSubSection(final FormToolkit toolkit, CommentGroup commentGroup, Section subSection) { |