01: /*******************************************************************************
02: * Copyright (c) 2004, 2005 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.components.views.comparisons;
11:
12: import org.eclipse.core.runtime.IStatus;
13: import org.eclipse.swt.SWT;
14: import org.eclipse.swt.events.SelectionAdapter;
15: import org.eclipse.swt.events.SelectionEvent;
16: import org.eclipse.swt.widgets.Button;
17: import org.eclipse.swt.widgets.Composite;
18: import org.eclipse.ui.internal.part.components.services.IUserMessages;
19: import org.eclipse.ui.part.ViewPart;
20:
21: /**
22: * Demonstrates how to use component dependencies in an old-style view
23: *
24: * @since 3.1
25: */
26: public class DependenciesViewOld extends ViewPart {
27: // Dependencies
28: private IUserMessages dialogs;
29:
30: // Main widget
31: private Composite parent;
32:
33: /* (non-Javadoc)
34: * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
35: */
36: public void createPartControl(Composite parent) {
37: this .parent = parent;
38: this .dialogs = (IUserMessages) getSite().getAdapter(
39: IUserMessages.class);
40:
41: Button testButton = new Button(parent, SWT.PUSH);
42: testButton.setText("Open a dialog");
43: testButton.addSelectionListener(new SelectionAdapter() {
44: /* (non-Javadoc)
45: * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
46: */
47: public void widgetSelected(SelectionEvent e) {
48: openADialog();
49: }
50: });
51: }
52:
53: private void openADialog() {
54: if (dialogs != null) {
55: dialogs.show(IStatus.INFO, "This is a message");
56: }
57: }
58:
59: /* (non-Javadoc)
60: * @see org.eclipse.ui.IWorkbenchPart#setFocus()
61: */
62: public void setFocus() {
63: parent.setFocus();
64: }
65:
66: }
|