01: /*******************************************************************************
02: * Copyright (c) 2000, 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.readmetool;
11:
12: import org.eclipse.jface.viewers.ISelection;
13: import org.eclipse.jface.viewers.ListViewer;
14: import org.eclipse.swt.widgets.Composite;
15: import org.eclipse.ui.ISelectionListener;
16: import org.eclipse.ui.IWorkbenchPart;
17: import org.eclipse.ui.PlatformUI;
18: import org.eclipse.ui.model.WorkbenchContentProvider;
19: import org.eclipse.ui.model.WorkbenchLabelProvider;
20: import org.eclipse.ui.part.ViewPart;
21:
22: /**
23: * This class demonstrates a simple view containing a single viewer.
24: */
25: public class ReadmeSectionsView extends ViewPart implements
26: ISelectionListener {
27: ListViewer viewer;
28:
29: /**
30: * Creates a new ReadmeSectionsView .
31: */
32: public ReadmeSectionsView() {
33: super ();
34: }
35:
36: /* (non-Javadoc)
37: * Method declared on IWorkbenchPart
38: */
39: public void createPartControl(Composite parent) {
40: viewer = new ListViewer(parent);
41:
42: PlatformUI.getWorkbench().getHelpSystem().setHelp(
43: viewer.getControl(),
44: IReadmeConstants.SECTIONS_VIEW_CONTEXT);
45:
46: // if the objects in the viewer implement IWorkbenchAdapter,
47: // these generic content and label providers can be used.
48: viewer.setContentProvider(new WorkbenchContentProvider());
49: viewer.setLabelProvider(new WorkbenchLabelProvider());
50:
51: // add myself as a global selection listener
52: getSite().getPage().addSelectionListener(this );
53:
54: // prime the selection
55: selectionChanged(null, getSite().getPage().getSelection());
56: }
57:
58: /**
59: * The <code>ReadmeSectionView</code> implementation of this
60: * <code>IWorkbenchPart</code> method runs super
61: * and removes itself from the global selection listener.
62: */
63: public void dispose() {
64: super .dispose();
65: getSite().getPage().removeSelectionListener(this );
66: }
67:
68: /* (non-Javadoc)
69: * Method declared on ISelectionListener
70: */
71: public void selectionChanged(IWorkbenchPart part, ISelection sel) {
72: //if the selection is a readme file, get its sections.
73: AdaptableList input = ReadmeModelFactory.getInstance()
74: .getSections(sel);
75: viewer.setInput(input);
76: }
77:
78: /* (non-Javadoc)
79: * Method declared on IWorkbenchPart
80: */
81: public void setFocus() {
82: viewer.getControl().setFocus();
83: }
84: }
|