Skip to main content
summaryrefslogtreecommitdiffstats
blob: d000ee26a3f72bf955d1cbd45aae090239570fea (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
/*******************************************************************************
 * Copyright (c) 2009 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
 *******************************************************************************/
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2007 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 implementation
//------------------------------------------------------------------------------
package org.eclipse.epf.richtext.actions;

import java.util.Collection;

import org.eclipse.epf.common.ui.actions.CComboContributionItem;
import org.eclipse.epf.richtext.IRichText;
import org.eclipse.swt.SWT;

/**
 * The abstract implementation of a rich text combo action.
 * 
 * @author Kelvin Low
 * @author Jeff Hardy
 * @since 1.0
 */
public abstract class RichTextComboAction extends CComboContributionItem {
	
	protected IRichText richText;
	
	protected String toolTipText;

	protected boolean enabled = true;
	
	protected boolean notifyListeners = false;

	
	/**
	 * Creates a new instance.
	 * 
	 * @param richText
	 *            a rich text control
	 */
	public RichTextComboAction(IRichText richText) {
		super(SWT.READ_ONLY | SWT.FLAT | SWT.BORDER);
		this.richText = richText;
	}

	/**
	 * Creates a new instance.
	 * 
	 * @param richText
	 *            a rich text control
	 */
	public RichTextComboAction(IRichText richText, int style) {
		super(SWT.READ_ONLY | SWT.FLAT | SWT.BORDER | style);
		this.richText = richText;
	}


	/**
	 * Executes the action.
	 * 
	 * @param richText
	 *            a rich text control
	 * @param index
	 *            the index of the selected item
	 */
	public abstract void execute(IRichText richText);
	
	public abstract Collection<String> getInput();
	
	public void init() {
		setInput(getInput());
		setNotifyListeners(true);
	}
	
	protected String getCComboSelection() {
		if (getCCombo() != null) {
			int index = getSelectionIndex();
			return getCCombo().getItem(index);
		}
		return null;
	}
	
	/**
	 * Returns the tool tip for the action.
	 * 
	 * @return the tool tip text
	 */
	public String getToolTipText() {
		return toolTipText;
	}

	/**
	 * Sets the tool tip for the action.
	 * 
	 * @param toolTipText
	 *            the tool tip text
	 */
	public void setToolTipText(String toolTipText) {
		this.toolTipText = toolTipText;
	}

	/**
	 * Returns the enabled status of the action.
	 * 
	 * @return <code>true</code> if enabled, <code>false</code> if not
	 */
	public boolean getEnabled() {
		return enabled;
	}

	/**
	 * Enables or disables the action.
	 * 
	 * @param enabled
	 *            if <code>true</code>, enable the action. if
	 *            <code>false</code>, disable it.
	 */
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	
	@Override
	protected void performSelectionChanged() {
		if (notifyListeners) {
			execute(richText);
		}
	}

	public boolean isNotifyListeners() {
		return notifyListeners;
	}

	public void setNotifyListeners(boolean notifyListeners) {
		this.notifyListeners = notifyListeners;
	}
}

Back to the top