01: /*******************************************************************************
02: * Copyright (c) 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.examples.views.properties.tabbed.article.views;
11:
12: import org.eclipse.core.runtime.IAdaptable;
13: import org.eclipse.jface.resource.ImageDescriptor;
14: import org.eclipse.swt.widgets.Button;
15: import org.eclipse.ui.model.IWorkbenchAdapter;
16: import org.eclipse.ui.views.properties.IPropertySource;
17:
18: /**
19: * This class represents a Button Element in the Sample View
20: *
21: * TIP: By implementing the <code>IWorkbenchAdapter</code> interface, we can
22: * easily add objects of this type to viewers and parts in the workbench. When a
23: * viewer contains <code>IWorkbenchAdapter</code>, the generic
24: * <code>WorkbenchContentProvider</code> and
25: * <code>WorkbenchLabelProvider</code> can be used to provide navigation and
26: * display for that viewer.
27: */
28: public class ButtonElement implements IWorkbenchAdapter, IAdaptable {
29:
30: private String headingName;
31:
32: private Button ctl;
33:
34: /**
35: * Creates a new ButtonElement.
36: *
37: * @param initBtn
38: * the control of this element
39: * @param heading
40: * text corresponding to the heading
41: */
42: public ButtonElement(Button initBtn, String heading) {
43: this .headingName = heading;
44: this .ctl = initBtn;
45: }
46:
47: /*
48: * (non-Javadoc) Method declared on IAdaptable
49: */
50: public Object getAdapter(Class adapter) {
51: if (adapter == IWorkbenchAdapter.class)
52: return this ;
53: if (adapter == IPropertySource.class)
54: return new ButtonElementProperties(this );
55: return null;
56: }
57:
58: /*
59: * (non-Javadoc) Method declared on IWorkbenchAdapter
60: */
61: public ImageDescriptor getImageDescriptor(Object object) {
62: return null;
63: }
64:
65: /*
66: * (non-Javadoc) Method declared on IWorkbenchAdapter
67: */
68: public String getLabel(Object o) {
69: return headingName;
70: }
71:
72: /*
73: * (non-Javadoc) Method declared on IWorkbenchAdapter
74: */
75: public Object getParent(Object o) {
76: return null;
77: }
78:
79: /**
80: * Retrieve the control for this element.
81: *
82: * @return the control for this element.
83: */
84: public Button getControl() {
85: return ctl;
86: }
87:
88: /**
89: * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(Object)
90: */
91: public Object[] getChildren(Object o) {
92: return null;
93: }
94:
95: }
|