01: /*******************************************************************************
02: * Copyright (c) 2002, 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.internal.cheatsheets.data;
11:
12: import java.util.ArrayList;
13: import java.util.Iterator;
14:
15: import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
16:
17: public class ConditionalSubItem extends AbstractSubItem implements
18: ISubItemItem {
19: private String condition;
20: private ArrayList subItems;
21: private SubItem selectedSubItem;
22:
23: /**
24: * Constructor for ConditionalSubItem.
25: */
26: public ConditionalSubItem() {
27: super ();
28: }
29:
30: public ConditionalSubItem(String condition) {
31: super ();
32: this .condition = condition;
33: }
34:
35: /**
36: * Returns the condition.
37: * @return String
38: */
39: public String getCondition() {
40: return condition;
41: }
42:
43: /**
44: * Sets the condition.
45: * @param newCondition The new condition to set
46: */
47: public void setCondition(String newCondition) {
48: this .condition = newCondition;
49: }
50:
51: /**
52: * @param subItem the SubItem to add.
53: */
54: public void addSubItem(AbstractSubItem subItem) {
55: if (subItems == null) {
56: subItems = new ArrayList();
57: }
58: subItems.add(subItem);
59: }
60:
61: /**
62: * @return Returns the subItems.
63: */
64: public ArrayList getSubItems() {
65: return subItems;
66: }
67:
68: public SubItem getSelectedSubItem() {
69: return selectedSubItem;
70: }
71:
72: public void setSelectedSubItem(CheatSheetManager csm) {
73: String conditionValue = csm.getVariableData(condition);
74:
75: for (Iterator iter = subItems.iterator(); iter.hasNext();) {
76: SubItem subItem = (SubItem) iter.next();
77: if (subItem.getWhen() != null
78: && subItem.getWhen().equals(conditionValue)) {
79: selectedSubItem = subItem;
80: break;
81: }
82: }
83: }
84: }
|