KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > data > Item


1 /*******************************************************************************
2  * Copyright (c) 2002, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.cheatsheets.data;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15
16 public class Item extends Intro implements IExecutableItem, IPerformWhenItem, ISubItemItem {
17     private String JavaDoc title;
18     private boolean skip;
19     private boolean dialog;
20     private ArrayList JavaDoc itemExtensions;
21     
22     private AbstractExecutable executable;
23     private PerformWhen performWhen;
24     
25     private ArrayList JavaDoc subItems;
26     private String JavaDoc completionMessage;
27
28     /**
29      * Constructor for Item.
30      */

31     public Item() {
32         super();
33     }
34     
35     public Item(String JavaDoc title, String JavaDoc description, String JavaDoc href, String JavaDoc contextId, boolean skip, boolean dialog) {
36         super(description, href, contextId);
37         this.title = title;
38         this.skip = skip;
39         this.dialog = dialog;
40     }
41     
42     /**
43      * Returns the title.
44      * @return String
45      */

46     public String JavaDoc getTitle() {
47         return this.title;
48     }
49
50     /**
51      * Returns whether this item is dynamic. An item is dynamic if it
52      * has performWhen condition, conditionalSubItems or repeatedSubItems.
53      *
54      * @return <code>true</code> if this item is dynamic, and
55      * <code>false</code> for normal items
56      */

57     public boolean isDynamic() {
58         if( performWhen != null || hasDynamicSubItems()) {
59             return true;
60         }
61
62         return false;
63     }
64
65     /**
66      * Returns whether or not this item requires opening a dialog.
67      * @return whether the item requires opening a dialog
68      */

69     public boolean isDialog() {
70         return this.dialog;
71     }
72     
73     /**
74      * Returns the skip.
75      * @return boolean
76      */

77     public boolean isSkip() {
78         return this.skip;
79     }
80
81     /**
82      * Sets whether or not this item requires opening a dialog.
83      * @param dialog whether the item requires opening a dialog
84      */

85     public void setDialog(boolean dialog) {
86         this.dialog = dialog;
87     }
88     
89     /**
90      * @param skip The skip to set.
91      */

92     public void setSkip(boolean skip) {
93         this.skip = skip;
94     }
95
96     /**
97      * Sets the title.
98      * @param title The title to set
99      */

100     public void setTitle(String JavaDoc title) {
101         this.title = title;
102     }
103
104     /**
105      * Sets the item extensions for this item.
106      * @param exts the extensions to set
107      */

108     public void setItemExtensions(ArrayList JavaDoc exts){
109         this.itemExtensions = exts;
110     }
111     
112     /**
113      * Returns the item extensions, if any, for this item,.
114      * @return list of the extensions or <code>null</code>
115      */

116     public ArrayList JavaDoc getItemExtensions(){
117         return itemExtensions;
118     }
119     
120     /**
121      * @return Returns the performWhen.
122      */

123     public PerformWhen getPerformWhen() {
124         return performWhen;
125     }
126     
127     /**
128      * @param performWhen The performWhen to set.
129      */

130     public void setPerformWhen(PerformWhen performWhen) {
131         this.performWhen = performWhen;
132     }
133     
134     /**
135      * @param subItem the SubItem to add.
136      */

137     public void addSubItem(AbstractSubItem subItem) {
138         if(subItems == null) {
139             subItems = new ArrayList JavaDoc();
140         }
141         subItems.add(subItem);
142     }
143
144     /**
145      * @return Returns the subItems.
146      */

147     public ArrayList JavaDoc getSubItems() {
148         return subItems;
149     }
150     
151     private boolean hasDynamicSubItems() {
152         if( subItems != null) {
153             for (Iterator JavaDoc iter = subItems.iterator(); iter.hasNext();) {
154                 AbstractSubItem subItem = (AbstractSubItem)iter.next();
155                 if( subItem instanceof RepeatedSubItem ||
156                     subItem instanceof ConditionalSubItem ||
157                     subItem instanceof SubItem && ((SubItem)subItem).getPerformWhen() != null ) {
158                     return true;
159                 }
160             }
161         }
162
163         return false;
164     }
165
166     public AbstractExecutable getExecutable() {
167         return executable;
168     }
169
170     public void setExecutable(AbstractExecutable executable) {
171         this.executable = executable;
172     }
173
174     public void setCompletionMessage(String JavaDoc message) {
175         this.completionMessage = message;
176     }
177     
178     public String JavaDoc getCompletionMessage() {
179         return completionMessage;
180     }
181 }
182
Popular Tags