KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
16
17 public class PerformWhen implements IExecutableItem {
18     private String JavaDoc condition;
19     private ArrayList JavaDoc executables;
20     private AbstractExecutable selectedExecutable;
21
22     /**
23      * Constructor for PerformWhen.
24      */

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

38     public String JavaDoc getCondition() {
39         return condition;
40     }
41
42     /**
43      * Sets the condition.
44      * @param newCondition The new condition to set
45      */

46     public void setCondition(String JavaDoc newCondition) {
47         this.condition = newCondition;
48     }
49
50     /**
51      * @return Returns the executables.
52      */

53     public ArrayList JavaDoc getExecutables() {
54         return executables;
55     }
56     
57     /**
58      * @param executable the AbstractExecutable to add.
59      */

60     public void addExecutable(AbstractExecutable executable) {
61         if(executables == null) {
62             executables = new ArrayList JavaDoc();
63         }
64         executables.add(executable);
65     }
66
67
68     /**
69      * This method always returns <code>null</code>, it is only here aid in parsing.
70      * @return Returns the executables.
71      */

72     public AbstractExecutable getExecutable() {
73         return null;
74     }
75
76     /**
77      * Delegate to the addAbstractExecutable metod.
78      * @param executable the AbstractExecutable to add.
79      */

80     public void setExecutable(AbstractExecutable executable) {
81         addExecutable(executable);
82     }
83
84     public AbstractExecutable getSelectedExecutable() {
85         return selectedExecutable;
86     }
87
88     public void setSelectedExecutable(CheatSheetManager csm) {
89         String JavaDoc conditionValue = csm.getVariableData(condition);
90
91         for (Iterator JavaDoc iter = executables.iterator(); iter.hasNext();) {
92             AbstractExecutable executable = (AbstractExecutable) iter.next();
93             if(executable.getWhen() != null && executable.getWhen().equals(conditionValue)) {
94                 selectedExecutable = executable;
95                 break;
96             }
97         }
98     }
99
100 }
101
Popular Tags