01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.part;
11:
12: import java.util.Stack;
13:
14: /* (non-Javadoc)
15: * A <code>DrillStack</code> manages a stack of DrillFrames.
16: * This class is not intended for use beyond the package.
17: */
18: /* package */class DrillStack {
19: Stack fStack = null;
20:
21: /**
22: * Allocates a new DrillStack.
23: */
24: public DrillStack() {
25: reset();
26: }
27:
28: /**
29: * Adds a drill frame to the stack.
30: *
31: * @param oRecord the new drill frame
32: */
33: public DrillFrame add(DrillFrame oRecord) {
34: fStack.push(oRecord);
35: return oRecord;
36: }
37:
38: /**
39: * Returns true if backward navigation is possible. This is only true
40: * if the stack size is greater than 0.
41: *
42: * @return true if backward navigation is possible
43: */
44: public boolean canGoBack() {
45: return (fStack.size() > 0);
46: }
47:
48: /**
49: * Returns true if "go home" is possible. This is only true
50: * if the stack size is greater than 0.
51: *
52: * @return true if "go home" is possible
53: */
54: public boolean canGoHome() {
55: return (fStack.size() > 0);
56: }
57:
58: /**
59: * Navigate backwards one record.
60: */
61: public DrillFrame goBack() {
62: DrillFrame aFrame = (DrillFrame) fStack.pop();
63: return aFrame;
64: }
65:
66: /**
67: * Navigate to the home record.
68: */
69: public DrillFrame goHome() {
70: DrillFrame aFrame = (DrillFrame) fStack.elementAt(0);
71: reset();
72: return aFrame;
73: }
74:
75: /**
76: * Clears the navigation stack.
77: */
78: public void reset() {
79: fStack = new Stack();
80: }
81:
82: /**
83: * Returns the stack size.
84: *
85: * @return the stack size
86: */
87: public int size() {
88: return fStack.size();
89: }
90:
91: /**
92: * Returns the top element on the stack.
93: *
94: * @return the top element on the stack
95: */
96: public DrillFrame top() {
97: return (DrillFrame) fStack.peek();
98: }
99: }
|