Creates a tabbed display in Eclipse RCP application
step-----------
1. Create View in the project.
2. Assign the view Id in the perspective addView(4 parameter...); method and add the this(Member View);
package com.magnus.tabbedpane;
import org.eclipse.swt.SWT;
import java.io.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.part.ViewPart;
public class MemberTabView extends ViewPart {
public static final String MEM_VIEW_ID="com.magnus.tabbedPane.MemberTab";
public MemberTabView() {
// TODO Auto-generated constructor stub
}
@Override
public void createPartControl(Composite parent) {
// Create the containing tab folder
final TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
// Create each tab and set its text, tool tip text,
// image, and control
TabItem one = new TabItem(tabFolder, SWT.NONE);
one.setText("General Info");
one.setToolTipText("Member General Informaion");
one.setControl(getTabOneControl(tabFolder));
TabItem two = new TabItem(tabFolder, SWT.NONE);
two.setText("Financial Info");
two.setToolTipText("Enter Financial Information");
two.setControl(getTabTwoControl(tabFolder));
TabItem three = new TabItem(tabFolder, SWT.NONE);
three.setText("Education Info");
three.setToolTipText("Edutaion Information");
three.setControl(getTabThreeControl(tabFolder));
// Select the third tab (index is zero-based)
tabFolder.setSelection(0);
// Add an event listener to write the selected tab to stdout
tabFolder.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) {
System.out.println(tabFolder.getSelection()[0].getText() + " selected");
}
});
}
/**
* Gets the control for tab one
*
* @param tabFolder the parent tab folder
* @return Control
*/
private Control getTabOneControl(TabFolder tabFolder) {
// Create some labels and text fields
Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayout(new RowLayout());
new Label(composite, SWT.LEFT).setText("Label One:");
new Text(composite, SWT.BORDER);
new Label(composite, SWT.RIGHT).setText("Label Two:");
new Text(composite, SWT.BORDER);
return composite;
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
/**
* Gets the control for tab two
*
* @param tabFolder the parent tab folder
* @return Control
*/
private Control getTabTwoControl(TabFolder tabFolder) {
// Create a multi-line text field
return new Text(tabFolder, SWT.BORDER | SWT.MULTI | SWT.WRAP);
}
/**
* Gets the control for tab three
*
* @param tabFolder the parent tab folder
* @return Control
*/
private Control getTabThreeControl(TabFolder tabFolder) {
// Create a composite and add four buttons to it
Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayout(new FillLayout(SWT.VERTICAL));
new Button(composite, SWT.PUSH).setText("Button one");
new Button(composite, SWT.PUSH).setText("Button two");
new Button(composite, SWT.PUSH).setText("Button three");
new Button(composite, SWT.PUSH).setText("Button four");
return composite;
}
}
No comments:
Post a Comment