001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.examples.views.properties.tabbed.article.views;
011:
012: import java.util.ArrayList;
013:
014: import org.eclipse.jface.viewers.ArrayContentProvider;
015: import org.eclipse.jface.viewers.ListViewer;
016: import org.eclipse.swt.SWT;
017: import org.eclipse.swt.layout.RowLayout;
018: import org.eclipse.swt.widgets.Button;
019: import org.eclipse.swt.widgets.Composite;
020: import org.eclipse.swt.widgets.Group;
021: import org.eclipse.ui.model.WorkbenchLabelProvider;
022: import org.eclipse.ui.part.ViewPart;
023: import org.eclipse.ui.views.properties.IPropertySheetPage;
024: import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
025: import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
026:
027: /**
028: * Sample view for the example.
029: *
030: * @author Anthony Hunter
031: *
032: */
033: public class SampleView extends ViewPart implements
034: ITabbedPropertySheetPageContributor {
035:
036: private ListViewer viewer;
037:
038: private Group grp1;
039:
040: /**
041: * The constructor.
042: */
043: public SampleView() {
044: //
045: }
046:
047: /**
048: * This is a callback that will allow us to create the viewer and initialize
049: * it.
050: */
051: public void createPartControl(Composite parent) {
052: // create all the GUI controls
053: // create two groups
054: viewer = new ListViewer(parent, SWT.SINGLE);
055:
056: grp1 = new Group(parent, SWT.NONE);
057: grp1.setText("Preview");//$NON-NLS-1$
058: RowLayout rowLayout = new RowLayout();
059: grp1.setLayout(rowLayout);
060:
061: Button btn = new Button(grp1, SWT.PUSH);
062: btn.setText("Hello");//$NON-NLS-1$
063:
064: // fill in the element
065: ArrayList ctlList = new ArrayList();
066: ButtonElement btnEl = new ButtonElement(btn, "Button");//$NON-NLS-1$
067: ctlList.add(btnEl);
068:
069: viewer.setContentProvider(new ArrayContentProvider());
070: viewer.setLabelProvider(new WorkbenchLabelProvider());
071: viewer.setInput(ctlList);
072: getSite().setSelectionProvider(viewer);
073:
074: }
075:
076: /**
077: * Passing the focus request to the viewer's control.
078: */
079: public void setFocus() {
080: viewer.getControl().setFocus();
081: }
082:
083: /**
084: * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
085: */
086: public Object getAdapter(Class adapter) {
087: if (adapter == IPropertySheetPage.class)
088: return new TabbedPropertySheetPage(this );
089: return super .getAdapter(adapter);
090: }
091:
092: /**
093: * @see org.eclipse.ui.IWorkbenchPart#dispose()
094: */
095: public void dispose() {
096: super .dispose();
097: }
098:
099: public String getContributorId() {
100: return getSite().getId();
101: }
102:
103: }
|