Java Code Examples for org.eclipse.swt.custom.CTabFolder#getItemCount()

The following examples show how to use org.eclipse.swt.custom.CTabFolder#getItemCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TLAEditorAndPDFViewer.java    From tlaplus with MIT License 6 votes vote down vote up
@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;
}
 
Example 2
Source File: CodeSelectorFactory.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
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);
	}
}
 
Example 3
Source File: TLAEditorAndPDFViewer.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
protected void addPages()
{
    try
    {

        // This code moves the tabs to the top of the page.
        // This makes them more obvious to the user.
        if (getContainer() instanceof CTabFolder)
        {
            final CTabFolder cTabFolder = (CTabFolder) getContainer();
cTabFolder.setTabPosition(SWT.TOP);

// 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);
}
        }

        tlaEditor = new TLAEditor();

        addPage(tlaEditorIndex, tlaEditor, tlaEditorInput);
        setPageText(tlaEditorIndex, "TLA Module");

    } catch (PartInitException e)
    {
    	// I hope you don't choke swallowing all those exceptions...
        e.printStackTrace();
    }
}
 
Example 4
Source File: TLAEditorAndPDFViewer.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
public void removePage(int pageIndex) {
	super.removePage(pageIndex);
	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);
		}
	}
}
 
Example 5
Source File: RelPanel.java    From Rel with Apache License 2.0 5 votes vote down vote up
private static int getTabIndex(CTabFolder tabFolder, CTabItem item) {
	if (item == null)
		return -1;
	for (int index = 0; index < tabFolder.getItemCount(); index++)
		if (tabFolder.getItem(index) == item)
			return index;
	return -1;
}
 
Example 6
Source File: ModelEditor.java    From tlaplus with MIT License 4 votes vote down vote up
/**
    * Overrides the method in {@link FormEditor}. Calls this method in the superclass
    * and then makes some changes if the input is a tla file.
    * 
    * This is done so that when read-only editor pages are added to this model editor,
    * we can make the following changes:
    * 
    * 1.) Set the title of the tabs of those pages to the name of the module being shown.
    *    If this is not done, the title of those tabs would be the empty string.
    *    
    * 2.) Set those pages to be closeable. This makes it possible to click on the tab
    *     to close it.
    */
public void addPage(int index, IEditorPart editor, IEditorInput input) throws PartInitException {
       super.addPage(index, editor, input);
       //TODO This method screams to be refactored and simplified, but sadly life is short.
       /*
        * Do stuff if the input is a tla file.
        * 
        * 1.) Set the title of the page to be the
        * name of the file.
        * 
        * 2.) Set the page to be closeable.
        */
       if (editor instanceof TLACoverageEditor) {
		// ... just add another special case to this supposed-to-be generic method. We
		// want the tab for the TLACoverageEditor to show not just the file name and an
		// icon indicating the editor type.
       	this.setPageText(index, editor.getTitle());
       	this.setPageImage(index, editor.getTitleImage());
		((CTabFolder) getContainer()).getItem(index).setShowClose(true);
       } else if (input instanceof FileEditorInput
			&& ((FileEditorInput) input).getFile().getFileExtension().equals(ResourceHelper.TLA_EXTENSION)) {
           setPageText(index, input.getName());

		((CTabFolder) getContainer()).getItem(index).setShowClose(true);
           // setPageImage(pageIndex, image);
	} else if (input instanceof FileEditorInput && "pdf".equals(((FileEditorInput) input).getFile().getFileExtension())) {
		setPageText(index, "State Graph");
	} else if (editor instanceof Closeable) {
		final CTabFolder tabFolder = (CTabFolder)getContainer();
		
		tabFolder.getItem(index).setShowClose(true);

		final int tabCount = tabFolder.getItemCount();
		for (int i = tabCount - 2; i >= index; i--) {
			final Closeable c = indexCloseableMap.remove(new Integer(i));
			
			if (c != null) {
				indexCloseableMap.put(new Integer(i + 1), c);
			}
		}

		indexCloseableMap.put(new Integer(index), (Closeable)editor);
	}
   }
 
Example 7
Source File: LamiReportView.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void createPartControl(@Nullable Composite parent) {
    LamiAnalysisReport report = fReport;
    if (report == null || parent == null) {
        return;
    }

    setPartName(report.getName());

    fTabFolder = new CTabFolder(parent, SWT.NONE);
    fTabFolder.setSimple(false);

    for (LamiResultTable table : report.getTables()) {
        String name = table.getTableClass().getTableTitle();

        CTabItem tabItem = new CTabItem(fTabFolder, SWT.NULL);
        tabItem.setText(name);

        SashForm sf = new SashForm(fTabFolder, SWT.NONE);
        fTabPages.add(new LamiReportViewTabPage(sf, table));
        tabItem.setControl(sf);
    }

    /* Add toolbar buttons */
    Action toggleTableAction = new ToggleTableAction();
    toggleTableAction.setText(Messages.LamiReportView_ActivateTableAction_ButtonName);
    toggleTableAction.setToolTipText(Messages.LamiReportView_ActivateTableAction_ButtonTooltip);
    toggleTableAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath("icons/table.gif")); //$NON-NLS-1$

    IActionBars actionBars = getViewSite().getActionBars();
    IToolBarManager toolbarMgr = actionBars.getToolBarManager();
    toolbarMgr.add(toggleTableAction);

    fNewChartAction.setText(Messages.LamiReportView_NewCustomChart);

    fClearCustomViewsAction.setText(Messages.LamiReportView_ClearAllCustomViews);
    IMenuManager menuMgr = actionBars.getMenuManager();
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener((@Nullable IMenuManager manager) -> {
        if (manager != null) {
            populateMenu(manager);
        }
    });
    populateMenu(menuMgr);

    /* Select the first tab initially */
    CTabFolder tf = checkNotNull(fTabFolder);
    if (tf.getItemCount() > 0) {
        tf.setSelection(0);
    }

}
 
Example 8
Source File: ArtikelView.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void createPartControl(Composite parent){
	parent.setLayout(new FillLayout());
	ctab = new CTabFolder(parent, SWT.NONE);
	importers = new Hashtable<String, ImporterPage>();
	
	new FavoritenCTabItem(ctab, SWT.None);
	addPagesFor(ExtensionPointConstantsUi.VERRECHNUNGSCODE);
	
	if (ctab.getItemCount() > 0) {
		ctab.setSelection(0);
	}
	ctab.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e){
			CTabItem selected = ctab.getSelection();
			
			if (selected instanceof FavoritenCTabItem)
				return;
			
			if (selected != null) {
				String t = selected.getText();
				
				MasterDetailsPage page = (MasterDetailsPage) selected.getControl();
				if (page == null) {
					try {
						IDetailDisplay det = (IDetailDisplay) selected.getData(KEY_DETAIL);
						IConfigurationElement ce =
							(IConfigurationElement) selected.getData(KEY_CE);
						CodeSelectorFactory cs =
							(CodeSelectorFactory) ce
								.createExecutableExtension(ExtensionPointConstantsUi.VERRECHNUNGSCODE_CSF);
						String a = ce.getAttribute(ExtensionPointConstantsUi.VERRECHNUNGSCODE_IMPC);
						ImporterPage ip = null;
						if (a != null) {
							ip = (ImporterPage) ce.createExecutableExtension(ExtensionPointConstantsUi.VERRECHNUNGSCODE_IMPC);
							if (ip != null) {
								importers.put(det.getTitle(), ip);
							}
						}
						
						page = new MasterDetailsPage(ctab, cs, det);
						selected.setControl(page);
						selected.setData(det);
					} catch (Exception ex) {
						LoggerFactory.getLogger(getClass()).error("Error creating pages", ex);
						return;
					}
				}
				importAction.setEnabled(importers.get(t) != null);
				ViewerConfigurer vc = page.cv.getConfigurer();
				vc.getControlFieldProvider().setFocus();
			}
		}
		
	});
	makeActions();
	viewmenus = new ViewMenus(getViewSite());
	viewmenus.createMenu(importAction /* ,deleteAction */);
	GlobalEventDispatcher.addActivationListener(this, this);
	
}