1 11 package org.eclipse.ui.internal.menus; 12 13 import java.util.ArrayList ; 14 import java.util.Collections ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.core.commands.common.IIdentifiable; 19 20 43 final class OrderNode implements IIdentifiable { 44 45 50 private List after; 51 52 57 private List before; 58 59 63 private final LayoutNode layoutNode; 64 65 72 OrderNode(final LayoutNode layoutNode) { 73 if (layoutNode == null) { 74 throw new NullPointerException ("The layout node cannot be null"); } 76 77 this.layoutNode = layoutNode; 78 } 79 80 87 public final void addAfterNode(final OrderNode orderNode) { 88 if (after == null) { 89 after = new ArrayList (1); 90 after.add(orderNode); 91 return; 92 } 93 94 LayoutNode.sortedInsert(after, orderNode); 95 } 96 97 104 public final void addBeforeNode(final OrderNode orderNode) { 105 if (before == null) { 106 before = new ArrayList (1); 107 before.add(orderNode); 108 return; 109 } 110 111 LayoutNode.sortedInsert(before, orderNode); 112 } 113 114 117 public final void addTo(final ArrayList sortedChildren) { 118 Iterator itr; 119 120 if (before != null) { 121 itr = before.iterator(); 122 while (itr.hasNext()) { 123 final OrderNode node = (OrderNode) itr.next(); 124 node.addTo(sortedChildren); 125 } 126 } 127 128 sortedChildren.add(getLayoutNode()); 129 130 if (after != null) { 131 itr = after.iterator(); 132 while (itr.hasNext()) { 133 final OrderNode node = (OrderNode) itr.next(); 134 node.addTo(sortedChildren); 135 } 136 } 137 } 138 139 146 public final List getAfterNodes() { 147 if (after == null) { 148 return Collections.EMPTY_LIST; 149 } 150 151 return after; 152 } 153 154 161 public final List getBeforeNodes() { 162 if (before == null) { 163 return Collections.EMPTY_LIST; 164 } 165 166 return before; 167 } 168 169 public final String getId() { 170 return layoutNode.getId(); 171 } 172 173 178 public final Object getLayoutNode() { 179 return layoutNode; 180 } 181 182 public final String toString() { 183 final StringBuffer buffer = new StringBuffer (); 184 buffer.append("OrderNode("); buffer.append(layoutNode); 186 buffer.append(')'); 187 return buffer.toString(); 188 } 189 } | Popular Tags |