KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > views > ComboPart


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 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.help.ui.internal.views;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.custom.CCombo;
15 import org.eclipse.swt.events.KeyListener;
16 import org.eclipse.swt.events.ModifyListener;
17 import org.eclipse.swt.events.SelectionListener;
18 import org.eclipse.swt.widgets.*;
19 import org.eclipse.ui.forms.widgets.FormToolkit;
20
21 public class ComboPart {
22     private Control combo;
23
24     public ComboPart() {
25     }
26     
27     public ComboPart(Composite parent, FormToolkit toolkit, int style) {
28         createControl(parent, toolkit, style);
29     }
30
31     public void addSelectionListener(SelectionListener listener) {
32         if (combo instanceof Combo)
33             ((Combo) combo).addSelectionListener(listener);
34         else
35             ((CCombo) combo).addSelectionListener(listener);
36     }
37     
38     public void addModifyListener(ModifyListener listener) {
39         if (combo instanceof Combo)
40             ((Combo) combo).addModifyListener(listener);
41         else
42             ((CCombo) combo).addModifyListener(listener);
43     }
44     
45     public void addKeyListener(KeyListener listener) {
46         if (combo instanceof Combo)
47             ((Combo) combo).addKeyListener(listener);
48         else
49             ((CCombo) combo).addKeyListener(listener);
50     }
51
52     public void createControl(Composite parent, FormToolkit toolkit, int style) {
53         if (toolkit.getBorderStyle() == SWT.BORDER)
54             combo = new Combo(parent, style | SWT.BORDER);
55         else
56             combo = new CCombo(parent, style | SWT.FLAT);
57         toolkit.adapt(combo, true, true);
58     }
59
60     public Control getControl() {
61         return combo;
62     }
63
64     public int getSelectionIndex() {
65         if (combo instanceof Combo)
66             return ((Combo) combo).getSelectionIndex();
67         return ((CCombo) combo).getSelectionIndex();
68     }
69
70     public void add(String JavaDoc item, int index) {
71         if (combo instanceof Combo)
72             ((Combo) combo).add(item, index);
73         else
74             ((CCombo) combo).add(item, index);
75     }
76
77     public void add(String JavaDoc item) {
78         if (combo instanceof Combo)
79             ((Combo) combo).add(item);
80         else
81             ((CCombo) combo).add(item);
82     }
83
84     public void select(int index) {
85         if (combo instanceof Combo)
86             ((Combo) combo).select(index);
87         else
88             ((CCombo) combo).select(index);
89     }
90
91     public String JavaDoc getSelection() {
92         if (combo instanceof Combo)
93             return ((Combo) combo).getItem(getSelectionIndex());
94         return ((CCombo) combo).getItem(getSelectionIndex());
95     }
96
97     public void setText(String JavaDoc text) {
98         if (combo instanceof Combo)
99             ((Combo) combo).setText(text);
100         else
101             ((CCombo) combo).setText(text);
102     }
103     public String JavaDoc getText() {
104         if (combo instanceof Combo)
105             return ((Combo) combo).getText();
106         return ((CCombo) combo).getText();
107     }
108
109     public void setItems(String JavaDoc[] items) {
110         if (combo instanceof Combo)
111             ((Combo) combo).setItems(items);
112         else
113             ((CCombo) combo).setItems(items);
114     }
115 }
116
Popular Tags