Пример #1
0
 private void addCompanion(CompanionFacade companion, boolean silently) {
   companion.getNameRef().addReferenceListener(this);
   CompanionNode child = new CompanionNode(companion);
   if (children == null) {
     children = new Vector();
   }
   @SuppressWarnings("unchecked")
   int insertIndex =
       Collections.binarySearch(children, child, Comparators.toStringIgnoreCaseCollator());
   if (insertIndex < 0) {
     if (silently) {
       insert(child, -(insertIndex + 1));
     } else {
       insertNodeInto(child, this, -(insertIndex + 1));
     }
   } else {
     if (silently) {
       insert(child, insertIndex);
     } else {
       insertNodeInto(child, this, insertIndex);
     }
   }
   if (!silently) {
     nodeChanged(this);
   }
 }
Пример #2
0
 @Override
 public void elementRemoved(ListEvent<CompanionFacade> e) {
   String type = e.getElement().getCompanionType();
   int index = Collections.binarySearch(types, type, Comparators.toStringIgnoreCaseCollator());
   CompanionTypeNode child = (CompanionTypeNode) getChildAt(index);
   child.removeCompanion(e.getElement());
 }
Пример #3
0
 @Override
 @SuppressWarnings("unchecked")
 public void referenceChanged(ReferenceEvent<String> e) {
   Collections.sort(children, Comparators.toStringIgnoreCaseCollator());
   int[] indexes = new int[getChildCount()];
   for (int i = 0; i < indexes.length; i++) {
     indexes[i] = i;
   }
   nodesChanged(this, indexes);
 }
Пример #4
0
 private void removeCompanion(CompanionFacade companion) {
   companion.getNameRef().removeReferenceListener(this);
   // we create a dummy child for comparison
   CompanionNode child = new CompanionNode(companion);
   @SuppressWarnings("unchecked")
   int index =
       Collections.binarySearch(children, child, Comparators.toStringIgnoreCaseCollator());
   removeNodeFromParent((CompanionNode) getChildAt(index));
   nodeChanged(this);
 }
Пример #5
0
 @Override
 public void keyAdded(MapEvent<String, Integer> e) {
   int insertIndex =
       Collections.binarySearch(types, e.getKey(), Comparators.toStringIgnoreCaseCollator());
   if (insertIndex < 0) {
     insertIndex = -(insertIndex + 1);
   }
   types.add(insertIndex, e.getKey());
   CompanionTypeNode child = new CompanionTypeNode(e.getKey());
   insertNodeInto(child, this, insertIndex);
 }
Пример #6
0
 private void initChildren() {
   types.clear();
   types.addAll(maxMap.getKeys());
   Collections.sort(types, Comparators.toStringIgnoreCaseCollator());
   removeAllChildren();
   for (String key : types) {
     CompanionTypeNode child = new CompanionTypeNode(key);
     add(child);
   }
   for (CompanionFacade companion : companions) {
     addCompanion(companion, true);
   }
 }
Пример #7
0
 private void addCompanion(CompanionFacade companion, boolean silently) {
   String type = companion.getCompanionType();
   int index = Collections.binarySearch(types, type, Comparators.toStringIgnoreCaseCollator());
   if (index < 0) {
     Logging.errorPrint(
         "Unable to add companion "
             + companion
             + " as the type "
             + type
             + " could not be found.");
     return;
   }
   CompanionTypeNode child = (CompanionTypeNode) getChildAt(index);
   child.addCompanion(companion, silently);
 }