下面列出了org.eclipse.swt.widgets.Layout#org.eclipse.swt.custom.CTabFolder 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* PDI-14411 NPE on Ctrl-W
*/
@Test
public void testCloseFirstTabOfTwo() {
final CTabFolder cTabFolder = mock( CTabFolder.class );
final TabSet tabSet = createTabSet( cTabFolder );
final CTabItem cTabItem1 = mock( CTabItem.class );
TabItem firstItem = createItem( tabSet, "first", "1st", cTabItem1 );
final CTabItem cTabItem2 = mock( CTabItem.class );
TabItem secondItem = createItem( tabSet, "second", "2nd", cTabItem2 );
assertEquals( 0, tabSet.indexOf( firstItem ) );
assertEquals( 1, tabSet.indexOf( secondItem ) );
tabSet.setSelected( firstItem );
assertEquals( 0, tabSet.getSelectedIndex() );
wireDisposalSelection( cTabFolder, tabSet, cTabItem1, cTabItem2 );
firstItem.dispose();
assertEquals( -1, tabSet.indexOf( firstItem ) );
assertNotNull( "selected is null", tabSet.getSelected() );
}
private void addMouseListenerToTabFolder() {
CTabFolder tabFolder = (CTabFolder) this.getContainer();
tabFolder.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent mouseevent) {
Category category = getCurrentPageCategory();
if (category != null) {
CategoryNameChangeDialog dialog = new CategoryNameChangeDialog(
PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell(),
category);
if (dialog.open() == IDialogConstants.OK_ID) {
ChangeCategoryNameCommand command = new ChangeCategoryNameCommand(
diagram, category, dialog.getCategoryName());
execute(command);
}
}
super.mouseDoubleClick(mouseevent);
}
});
}
public static CTabFolder createTabFolder( Composite composite, FormData fd, String... titles ) {
Composite container = new Composite( composite, SWT.NONE );
WidgetUtils.setFormLayout( container, 0 );
container.setLayoutData( fd );
CTabFolder tabFolder = new CTabFolder( container, SWT.NONE );
tabFolder.setLayoutData( new FormDataBuilder().fullSize().result() );
for ( String title : titles ) {
if ( title.length() < 8 ) {
title = StringUtils.rightPad( title, 8 );
}
Composite tab = new Composite( tabFolder, SWT.NONE );
WidgetUtils.setFormLayout( tab, ConstUi.MEDUIM_MARGIN );
CTabItem tabItem = new CTabItem( tabFolder, SWT.NONE );
tabItem.setText( title );
tabItem.setControl( tab );
}
tabFolder.setSelection( 0 );
return tabFolder;
}
public void updateModified(){
CTabFolder folder = (CTabFolder)getParent();
Object loc;
if( file.isLocal())
loc = file.getDir();
else
loc = file.getSym();
for( CTabItem cur : folder.getItems())
if( cur.getData("file") != null && ((SymitarFile)cur.getData("file")).equals(file) && cur.getData("loc").equals(loc) )
if( modified && ( cur.getData("modified") == null || !((Boolean)cur.getData("modified")))){
cur.setData("modified", true);
cur.setText(cur.getText() + " *");
}
else if( !modified && ( cur.getData("modified") == null || ((Boolean)cur.getData("modified")))){
cur.setData("modified", false);
cur.setText(cur.getText().substring(0,cur.getText().length() - 2));
}
}
private void addLogTableTabs() {
// Create a nested tab folder in the tab item, on the history composite...
//
tabFolder = new CTabFolder( jobHistoryComposite, SWT.MULTI );
spoon.props.setLook( tabFolder, Props.WIDGET_STYLE_TAB );
FormData fdTabFolder = new FormData();
fdTabFolder.left = new FormAttachment( 0, 0 ); // First one in the left top corner
fdTabFolder.top = new FormAttachment( (Control) toolbar.getManagedObject(), 0 );
fdTabFolder.right = new FormAttachment( 100, 0 );
fdTabFolder.bottom = new FormAttachment( 100, 0 );
tabFolder.setLayoutData( fdTabFolder );
models = new JobHistoryLogTab[jobMeta.getLogTables().size()];
for ( int i = 0; i < models.length; i++ ) {
models[i] = new JobHistoryLogTab( tabFolder, jobMeta.getLogTables().get( i ) );
}
}
/**
* Ctrl-W on first and second in succession would close first and third
*/
@Test
public void testCloseFirstTabOfThree() {
final CTabFolder cTabFolder = mock( CTabFolder.class );
final TabSet tabSet = createTabSet( cTabFolder );
final CTabItem cTabItem1 = mock( CTabItem.class );
TabItem firstItem = createItem( tabSet, "first", "1st", cTabItem1 );
final CTabItem cTabItem2 = mock( CTabItem.class );
TabItem secondItem = createItem( tabSet, "second", "2nd", cTabItem2 );
TabItem thirdItem = createItem( tabSet, "third", "3rd", mock( CTabItem.class ) );
assertEquals( 0, tabSet.indexOf( firstItem ) );
assertEquals( 1, tabSet.indexOf( secondItem ) );
assertEquals( 2, tabSet.indexOf( thirdItem ) );
wireDisposalSelection( cTabFolder, tabSet, cTabItem1, cTabItem2 );
tabSet.setSelected( firstItem );
assertEquals( 0, tabSet.getSelectedIndex() );
firstItem.dispose();
assertEquals( "should select second", secondItem, tabSet.getSelected() );
}
private void configureTabFolder(final Composite compo) {
Composite c = compo;
while (c != null) {
if (c instanceof CTabFolder) {
break;
}
c = c.getParent();
}
if (c != null) {
final CTabFolder folder = (CTabFolder) c;
folder.setMaximizeVisible(true);
folder.setMinimizeVisible(true);
folder.setMinimumCharacters(10);
folder.setMRUVisible(true);
folder.setTabHeight(16);
}
}
private void addLogTableTabs() {
// Create a nested tab folder in the tab item, on the history composite...
//
tabFolder = new CTabFolder( transHistoryComposite, SWT.MULTI );
spoon.props.setLook( tabFolder, Props.WIDGET_STYLE_TAB );
FormData fdTabFolder = new FormData();
fdTabFolder.left = new FormAttachment( 0, 0 ); // First one in the left top corner
fdTabFolder.top = new FormAttachment( (Control) toolbar.getManagedObject(), 0 );
fdTabFolder.right = new FormAttachment( 100, 0 );
fdTabFolder.bottom = new FormAttachment( 100, 0 );
tabFolder.setLayoutData( fdTabFolder );
models = new TransHistoryLogTab[transMeta.getLogTables().size()];
for ( int i = 0; i < models.length; i++ ) {
models[i] = new TransHistoryLogTab( tabFolder, transMeta.getLogTables().get( i ) );
}
}
@Override
public void createPartControl(Composite parent) {
Composite p = new Composite(parent, SWT.NONE);
p.setLayout(new GridLayout());
p.setLayoutData(new GridData(GridData.FILL_BOTH));
folder = new CTabFolder(p, SWT.NONE);
folder.setFont(parent.getFont());
folder.setLayout(new GridLayout());
folder.setLayoutData(new GridData(GridData.FILL_BOTH));
// Text tab
terminalText = addTab(folder, "Text");
// ANSI tab
terminalANSI = addTab(folder, "ANSI");
}
/**
* Setup the Disk window and display (open) it.
*/
public void open() {
shell = new Shell(parentShell, SWT.SHELL_TRIM);
shell.setLayout(new FillLayout());
shell.setImage(imageManager.get(ImageManager.ICON_DISK));
setStandardWindowTitle();
shell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
dispose(event);
}
});
CTabFolder tabFolder = new CTabFolder(shell, SWT.BOTTOM);
new DiskExplorerTab(tabFolder, disks, imageManager, this);
diskMapTabs = new DiskMapTab[disks.length];
for (int i=0; i<disks.length; i++) {
if (disks[i].supportsDiskMap()) {
diskMapTabs[i] = new DiskMapTab(tabFolder, disks[i]);
}
}
diskInfoTab = new DiskInfoTab(tabFolder, disks);
tabFolder.setSelection(tabFolder.getItems()[0]);
shell.open();
}
private void initialize(Composite composite) {
parent = composite;
registerPluginViews();
tabbedMDI = new TabbedMDI(null, VIEW_ID, VIEW_ID, swtView, dataSource);
tabbedMDI.setDestroyEntriesOnDeactivate(true);
tabbedMDI.buildMDI(composite);
CTabFolder folder = tabbedMDI.getTabFolder();
Label lblClose = new Label(folder, SWT.WRAP);
lblClose.setText("x");
lblClose.addListener(SWT.MouseUp, new Listener() {
@Override
public void handleEvent(Event event) {
delete();
}
});
folder.setTopRight(lblClose);
updateThread = new UpdateThread();
updateThread.setDaemon(true);
updateThread.start();
dataSourceChanged(dataSource);
}
private void buildContents() {
tabFolder = new CTabFolder(shell, SWT.TOP | SWT.NO_TRIM);
tabFolder.setBorderVisible(true);
tabFolder.setBackgroundMode(SWT.INHERIT_DEFAULT);
tabFolder.setMRUVisible(true);
tabFolder.setSimple(false); // rounded tabs
tabFolder.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));
final Map<String, Map<String, List<Pref>>> prefs = GamaPreferences.organizePrefs();
for (final String tabName : prefs.keySet()) {
final CTabItem item = new CTabItem(tabFolder, SWT.NONE);
item.setFont(GamaFonts.getNavigHeaderFont());
item.setText(tabName);
item.setImage(prefs_images.get(tabName));
item.setShowClose(false);
buildContentsFor(item, prefs.get(tabName));
}
buildButtons();
shell.layout();
}
public static void makeTabs(CTabFolder ctab, IViewSite site, String point){
String settings = null;
if (point.equals(ExtensionPointConstantsUi.VERRECHNUNGSCODE)) {
settings = CoreHub.userCfg.get(Preferences.USR_SERVICES_DIAGNOSES_SRV, null);
} else if (point.equals(ExtensionPointConstantsUi.DIAGNOSECODE)) {
settings = CoreHub.userCfg.get(Preferences.USR_SERVICES_DIAGNOSES_DIAGNOSE, null);
}
java.util.List<IConfigurationElement> list = Extensions.getExtensions(point);
if (settings == null) {
addAllTabs(list, ctab, point);
} else {
addUserSpecifiedTabs(list, settings, ctab, point);
}
if (ctab.getItemCount() > 0) {
ctab.setSelection(0);
}
}
private void addMouseListenerToTabFolder() {
final CTabFolder tabFolder = (CTabFolder) getContainer();
tabFolder.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(final MouseEvent mouseevent) {
final Category category = getPageCategory(getActivePage());
if (category != null) {
final CategoryNameChangeDialog dialog = new CategoryNameChangeDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), category);
if (dialog.open() == IDialogConstants.OK_ID) {
final ChangeCategoryNameCommand command = new ChangeCategoryNameCommand(diagram, category, dialog.getCategoryName());
execute(command);
}
}
super.mouseDoubleClick(mouseevent);
}
});
}
@Override
public int addPage(IFormPage page) throws PartInitException {
final int idx = super.addPage(page);
if (getContainer() instanceof CTabFolder) {
final CTabFolder cTabFolder = (CTabFolder) getContainer();
// If there is only the editor but no PDF shown next to it, the tab bar of the
// ctabfolder just wastes screen estate.
if (cTabFolder.getItemCount() <= 1) {
cTabFolder.setTabHeight(0);
} else {
cTabFolder.setTabHeight(-1);
}
}
return idx;
}
public PulseDistributionTab(RawProtocolMessage message, CTabFolder chartFolder) {
distributionData = createPulseDistributionPlot(message.m_PulseLengths);
selectedIntervalSeries = new XYSeries("Selected Interval");
distributionData.addSeries(selectedIntervalSeries);
CTabItem distributionTab = new CTabItem(chartFolder, SWT.NONE);
distributionTab.setText("Pulse length Distribution");
// Create a Chart and a panel for pulse length distribution
JFreeChart distributionChart = ChartFactory.createXYLineChart("Pulse Length Distribution", "Pulse Length (us)", "# Pulses", distributionData, PlotOrientation.VERTICAL, true, false, false);
ChartPanel distributionChartPanel = new ChartPanel(distributionChart);
RawSignalWindow.configurePanelLooks(distributionChart, 2);
distributionChartPanel.setPreferredSize(new Dimension(700, 270));// 270
// Make the mark line dashed, so we can see the space line when they overlap
float pattern[] = {5.0f, 5.0f};
BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, pattern, 0.0f);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) distributionChart.getXYPlot().getRenderer();
renderer.setSeriesStroke(0, stroke);
// Create a ChartComposite on our tab for pulse distribution
ChartComposite distributionFrame = new ChartComposite(chartFolder, SWT.NONE, distributionChart, true);
distributionFrame.setHorizontalAxisTrace(false);
distributionFrame.setVerticalAxisTrace(false);
distributionFrame.setDisplayToolTips(true);
GridData distributionGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
distributionGridData.grabExcessHorizontalSpace = true;
distributionGridData.grabExcessVerticalSpace = false;
distributionGridData.heightHint = 270;
distributionFrame.setLayoutData(distributionGridData);
distributionTab.setControl(distributionFrame);
}
@Override
protected void createPages() {
createPage0();
createPage1();
createPage2();
if (getPageCount() == 1) {
Composite container = getContainer();
if (container instanceof CTabFolder) {
((CTabFolder) container).setTabHeight(0);
}
}
}
/**
* If there is just one page in the multi-page editor part,
* this hides the single tab at the bottom.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void hideTabs ()
{
if ( getPageCount () <= 1 )
{
setPageText ( 0, "" ); //$NON-NLS-1$
if ( getContainer () instanceof CTabFolder )
{
( (CTabFolder)getContainer () ).setTabHeight ( 1 );
Point point = getContainer ().getSize ();
getContainer ().setSize ( point.x, point.y + 6 );
}
}
}
/**
* If there is more than one page in the multi-page editor part,
* this shows the tabs at the bottom.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void showTabs ()
{
if ( getPageCount () > 1 )
{
setPageText ( 0, getString ( "_UI_SelectionPage_label" ) ); //$NON-NLS-1$
if ( getContainer () instanceof CTabFolder )
{
( (CTabFolder)getContainer () ).setTabHeight ( SWT.DEFAULT );
Point point = getContainer ().getSize ();
getContainer ().setSize ( point.x, point.y - 6 );
}
}
}
/**
* If there is more than one page in the multi-page editor part,
* this shows the tabs at the bottom.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
protected void showTabs ()
{
if ( getPageCount () > 1 )
{
setPageText ( 0, getString ( "_UI_SelectionPage_label" ) ); //$NON-NLS-1$
if ( getContainer () instanceof CTabFolder )
{
( (CTabFolder)getContainer () ).setTabHeight ( SWT.DEFAULT );
final Point point = getContainer ().getSize ();
getContainer ().setSize ( point.x, point.y - 6 );
}
}
}
/**
* Testcase for test createTabItems() method
*/
public void testCreateTabItems( )
{
Shell shell = new Shell( );
TabPageGenerator generator = new TabPageGenerator( );
generator.createControl( shell, new ArrayList( ) );
Control control = generator.getControl( );
if(control instanceof CTabFolder)
assertEquals( 0, ((CTabFolder)control).getItemCount( ) );
shell.dispose( );
}
/**
* If there is just one page in the multi-page editor part,
* this hides the single tab at the bottom.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void hideTabs ()
{
if ( getPageCount () <= 1 )
{
setPageText ( 0, "" ); //$NON-NLS-1$
if ( getContainer () instanceof CTabFolder )
{
( (CTabFolder)getContainer () ).setTabHeight ( 1 );
Point point = getContainer ().getSize ();
getContainer ().setSize ( point.x, point.y + 6 );
}
}
}
private CTabFolder createTabFolder(Shell shell1) {
CTabFolder chartFolder = new CTabFolder(shell1, SWT.NONE);
GridData folderGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
folderGridData.grabExcessHorizontalSpace = true;
folderGridData.grabExcessVerticalSpace = false;
folderGridData.heightHint = 280;
chartFolder.setLayoutData(folderGridData);
return chartFolder;
}
/**
* If there is just one page in the multi-page editor part,
* this hides the single tab at the bottom.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void hideTabs() {
if (getPageCount() <= 1) {
setPageText(0, "");
if (getContainer() instanceof CTabFolder) {
((CTabFolder)getContainer()).setTabHeight(1);
Point point = getContainer().getSize();
getContainer().setSize(point.x, point.y + 6);
}
}
}
/**
* If there is just one page in the multi-page editor part,
* this hides the single tab at the bottom.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void hideTabs ()
{
if ( getPageCount () <= 1 )
{
setPageText ( 0, "" ); //$NON-NLS-1$
if ( getContainer () instanceof CTabFolder )
{
( (CTabFolder)getContainer () ).setTabHeight ( 1 );
Point point = getContainer ().getSize ();
getContainer ().setSize ( point.x, point.y + 6 );
}
}
}
/**
* Create a tab.
*
* @param tabFolder
*/
private void createRangeTab(CTabFolder tabFolder) {
CTabItem tabItem4 = new CTabItem(tabFolder, SWT.NULL);
tabItem4.setText(Resources.getMessage("HierarchyWizardEditor.3")); //$NON-NLS-1$
Composite parent = new Composite(tabFolder, SWT.NULL);
parent.setLayout(SWTUtil.createGridLayout(2, false));
new HierarchyWizardEditorRange<T>(parent, model, true);
new HierarchyWizardEditorRange<T>(parent, model, false);
tabItem4.setControl(parent);
}
protected void createTabToolButtons( CTabFolder tabFolder )
{
List<IButtonHandler> buttons = wizardBase.getTabToolButtons( );
if ( buttons.size( ) == 0 )
{
return;
}
ToolBar toolbar = new ToolBar( tabFolder, SWT.FLAT | SWT.WRAP );
tabFolder.setTopRight( toolbar );
for ( IButtonHandler btnHandler : buttons )
{
ToolItem btn = new ToolItem( toolbar, SWT.NONE );
btn.addSelectionListener( this );
btn.setData( btnHandler );
if ( btnHandler.getLabel( ) != null )
{
btn.setText( btnHandler.getLabel( ) );
}
if ( btnHandler.getTooltip( ) != null )
{
btn.setToolTipText( btnHandler.getTooltip( ) );
}
if ( btnHandler.getIcon( ) != null )
{
btn.setImage( btnHandler.getIcon( ) );
}
}
}
/**
* If there is just one page in the multi-page editor part,
* this hides the single tab at the bottom.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void hideTabs ()
{
if ( getPageCount () <= 1 )
{
setPageText ( 0, "" ); //$NON-NLS-1$
if ( getContainer () instanceof CTabFolder )
{
( (CTabFolder)getContainer () ).setTabHeight ( 1 );
Point point = getContainer ().getSize ();
getContainer ().setSize ( point.x, point.y + 6 );
}
}
}
/**
* If there is more than one page in the multi-page editor part,
* this shows the tabs at the bottom.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void showTabs ()
{
if ( getPageCount () > 1 )
{
setPageText ( 0, getString ( "_UI_SelectionPage_label" ) ); //$NON-NLS-1$
if ( getContainer () instanceof CTabFolder )
{
( (CTabFolder)getContainer () ).setTabHeight ( SWT.DEFAULT );
Point point = getContainer ().getSize ();
getContainer ().setSize ( point.x, point.y - 6 );
}
}
}
/**
* If there is just one page in the multi-page editor part,
* this hides the single tab at the bottom.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void hideTabs ()
{
if ( getPageCount () <= 1 )
{
setPageText ( 0, "" ); //$NON-NLS-1$
if ( getContainer () instanceof CTabFolder )
{
( (CTabFolder)getContainer () ).setTabHeight ( 1 );
Point point = getContainer ().getSize ();
getContainer ().setSize ( point.x, point.y + 6 );
}
}
}