Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7543a35e7be1342017daab6f2226331150f237b5 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*******************************************************************************
 * Copyright (c) 2002, 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.ui.internal.cheatsheets.data;

import java.util.ArrayList;
import java.util.Iterator;

public class Item extends Intro implements IExecutableItem, IPerformWhenItem, ISubItemItem {
	private String title;
	private boolean skip;
	private boolean dialog;
	private ArrayList itemExtensions;
	
	private AbstractExecutable executable;
	private PerformWhen performWhen;
	
	private ArrayList subItems;
	private String completionMessage;

	/**
	 * Constructor for Item.
	 */
	public Item() {
		super();
	}
	
	public Item(String title, String description, String href, String contextId, boolean skip, boolean dialog) {
		super(description, href, contextId);
		this.title = title;
		this.skip = skip;
		this.dialog = dialog;
	}
	
	/**
	 * Returns the title.
	 * @return String
	 */
	public String getTitle() {
		return this.title;
	}

	/**
	 * Returns whether this item is dynamic. An item is dynamic if it
	 * has performWhen condition, conditionalSubItems or repeatedSubItems.
	 *
	 * @return <code>true</code> if this item is dynamic, and
	 *  <code>false</code> for normal items
	 */
	public boolean isDynamic() {
		if( performWhen != null || hasDynamicSubItems()) {
			return true;
		}

		return false;
	}

	/**
	 * Returns whether or not this item requires opening a dialog.
	 * @return whether the item requires opening a dialog
	 */
	public boolean isDialog() {
		return this.dialog;
	}
	
	/**
	 * Returns the skip.
	 * @return boolean
	 */
	public boolean isSkip() {
		return this.skip;
	}

	/**
	 * Sets whether or not this item requires opening a dialog.
	 * @param dialog whether the item requires opening a dialog
	 */
	public void setDialog(boolean dialog) {
		this.dialog = dialog;
	}
	
	/**
	 * @param skip The skip to set.
	 */
	public void setSkip(boolean skip) {
		this.skip = skip;
	}

	/**
	 * Sets the title.
	 * @param title The title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * Sets the item extensions for this item.
	 * @param exts the extensions to set
	 */
	public void setItemExtensions(ArrayList exts){
		this.itemExtensions = exts;	
	}
	
	/**
	 * Returns the item extensions, if any, for this item,.
	 * @return list of the extensions or <code>null</code>
	 */
	public ArrayList getItemExtensions(){
		return itemExtensions;
	}
	
	/**
	 * @return Returns the performWhen.
	 */
	public PerformWhen getPerformWhen() {
		return performWhen;
	}
	
	/**
	 * @param performWhen The performWhen to set.
	 */
	public void setPerformWhen(PerformWhen performWhen) {
		this.performWhen = performWhen;
	}
	
	/**
	 * @param subItem the SubItem to add.
	 */
	public void addSubItem(AbstractSubItem subItem) {
		if(subItems == null) {
			subItems = new ArrayList();
		}
		subItems.add(subItem);
	}

	/**
	 * @return Returns the subItems.
	 */
	public ArrayList getSubItems() {
		return subItems;
	}
	
	private boolean hasDynamicSubItems() {
		if( subItems != null) {
			for (Iterator iter = subItems.iterator(); iter.hasNext();) {
				AbstractSubItem subItem = (AbstractSubItem)iter.next();
				if( subItem instanceof RepeatedSubItem ||
					subItem instanceof ConditionalSubItem ||
					subItem instanceof SubItem && ((SubItem)subItem).getPerformWhen() != null ) {
					return true;
				}
			}
		}

		return false;
	}

	public AbstractExecutable getExecutable() {
		return executable;
	}

	public void setExecutable(AbstractExecutable executable) {
		this.executable = executable;	
	}

	public void setCompletionMessage(String message) {
		this.completionMessage = message;	
	}
	
	public String getCompletionMessage() {
		return completionMessage;
	}
}

Back to the top