KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
17
18 public class ConditionalSubItem extends AbstractSubItem implements ISubItemItem {
19     private String JavaDoc condition;
20     private ArrayList JavaDoc subItems;
21     private SubItem selectedSubItem;
22
23     /**
24      * Constructor for ConditionalSubItem.
25      */

26     public ConditionalSubItem() {
27         super();
28     }
29     
30     public ConditionalSubItem(String JavaDoc condition) {
31         super();
32         this.condition = condition;
33     }
34     
35     /**
36      * Returns the condition.
37      * @return String
38      */

39     public String JavaDoc 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 JavaDoc 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 JavaDoc();
57         }
58         subItems.add(subItem);
59     }
60
61     /**
62      * @return Returns the subItems.
63      */

64     public ArrayList JavaDoc getSubItems() {
65         return subItems;
66     }
67
68     public SubItem getSelectedSubItem() {
69         return selectedSubItem;
70     }
71
72     public void setSelectedSubItem(CheatSheetManager csm) {
73         String JavaDoc conditionValue = csm.getVariableData(condition);
74
75         for (Iterator JavaDoc iter = subItems.iterator(); iter.hasNext();) {
76             SubItem subItem = (SubItem) iter.next();
77             if(subItem.getWhen() != null && subItem.getWhen().equals(conditionValue)) {
78                 selectedSubItem = subItem;
79                 break;
80             }
81         }
82     }
83 }
84
Popular Tags