blob: 44491de417467ae08b97b39b03f49bc5f1fb423f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/*******************************************************************************
* Copyright (c) 2001, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.ws.internal.explorer.platform.perspective;
import java.util.Vector;
// A class representing a Vector of breadcrumbs. A position index is used
// to navigate through the data structure.
public class History
{
private Vector items_;
private int position_;
public History()
{
items_ = new Vector();
position_ = -1;
}
// Add a new breadcrumb to the history list. When adding a new breadcrumb
// within the current list, all breadcrumbs after the newly added one are
// removed.
public boolean addBreadCrumb(BreadCrumb b)
{
int numberOfItems = items_.size();
if (numberOfItems == 0)
{
position_++;
items_.addElement(b);
return true;
}
else
{
BreadCrumb currentBreadCrumb = (BreadCrumb)items_.elementAt(position_);
if (!currentBreadCrumb.equals(b))
{
position_++;
items_.insertElementAt(b,position_);
for (int i=items_.size()-1;i>position_;i--)
items_.removeElementAt(i);
return true;
}
}
return false;
}
// Move forward within the history list and obtain the breadcrumb.
public BreadCrumb forward()
{
if (position_ < items_.size()-1)
{
position_++;
BreadCrumb b = (BreadCrumb)items_.elementAt(position_);
return b;
}
return null;
}
// Move back within the history list and obtain the breadcrumb.
public BreadCrumb back()
{
if (position_ > 0)
{
position_--;
BreadCrumb b = (BreadCrumb)items_.elementAt(position_);
return b;
}
return null;
}
public void removeCurrentBreadCrumb()
{
items_.removeElementAt(position_);
if (position_ > items_.size()-1)
position_--;
}
public void dump()
{
for (int i=0;i<items_.size();i++)
{
items_.elementAt(i);
}
}
}
|