1 11 package org.eclipse.ui.views.framelist; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.commands.common.EventManager; 17 import org.eclipse.core.runtime.Assert; 18 import org.eclipse.jface.util.IPropertyChangeListener; 19 import org.eclipse.jface.util.PropertyChangeEvent; 20 21 33 public class FrameList extends EventManager { 34 35 36 public static final String P_CURRENT_FRAME = "currentFrame"; 38 private IFrameSource source; 39 40 private List frames; 41 42 private int current; 43 44 49 public FrameList(IFrameSource source) { 50 this.source = source; 51 Frame frame = source.getFrame(IFrameSource.CURRENT_FRAME, 0); 52 frame.setParent(this); 53 frame.setIndex(0); 54 frames = new ArrayList (); 55 frames.add(frame); 56 current = 0; 57 } 58 59 65 public void addPropertyChangeListener(IPropertyChangeListener listener) { 66 addListenerObject(listener); 67 } 68 69 74 public void back() { 75 if (current > 0) { 76 setCurrent(current - 1); 77 } 78 } 79 80 88 protected void firePropertyChange(PropertyChangeEvent event) { 89 Object [] listeners = getListeners(); 90 for (int i = 0; i < listeners.length; ++i) { 91 ((IPropertyChangeListener) listeners[i]).propertyChange(event); 92 } 93 } 94 95 100 public void forward() { 101 if (current < frames.size() - 1) { 102 setCurrent(current + 1); 103 } 104 } 105 106 112 public Frame getCurrentFrame() { 113 return getFrame(current); 114 } 115 116 121 public int getCurrentIndex() { 122 return current; 123 } 124 125 132 public Frame getFrame(int index) { 133 if (index < 0 || index >= frames.size()) { 134 return null; 135 } 136 return (Frame) frames.get(index); 137 } 138 139 142 public IFrameSource getSource() { 143 return source; 144 } 145 146 154 public void gotoFrame(Frame frame) { 155 for (int i = frames.size(); --i > current;) { 156 frames.remove(i); 157 } 158 frame.setParent(this); 159 int index = frames.size(); 160 frame.setIndex(index); 161 frames.add(frame); 162 setCurrent(index); 163 } 164 165 171 public void removePropertyChangeListener(IPropertyChangeListener listener) { 172 removeListenerObject(listener); 173 } 174 175 182 void setCurrent(int newCurrent) { 183 Assert.isTrue(newCurrent >= 0 && newCurrent < frames.size()); 184 int oldCurrent = this.current; 185 if (oldCurrent != newCurrent) { 186 updateCurrentFrame(); 187 this.current = newCurrent; 188 firePropertyChange(new PropertyChangeEvent(this, P_CURRENT_FRAME, 189 getFrame(oldCurrent), getFrame(newCurrent))); 190 } 191 } 192 193 198 public void setCurrentIndex(int index) { 199 if (index != -1 && index != current) { 200 setCurrent(index); 201 } 202 } 203 204 207 public int size() { 208 return frames.size(); 209 } 210 211 215 public void updateCurrentFrame() { 216 Assert.isTrue(current >= 0); 217 Frame frame = source.getFrame(IFrameSource.CURRENT_FRAME, 218 IFrameSource.FULL_CONTEXT); 219 frame.setParent(this); 220 frame.setIndex(current); 221 frames.set(current, frame); 222 } 223 } 224 | Popular Tags |