Tabris: Is it planned to support CTabFolder? - swt

Tabris-Experts,
currently I want to use CTabFolder to have the ability to close CTabItems. Is it correct that CTabFolder is not supported in Tabris until now?
Using following code ...
public class TabFolderExample extends Shell {
public TabFolderExample(Display display) {
super(display, SWT.NO_TRIM);
createContents();
}
private void createContents() {
setMaximized(true);
setLayout(new FillLayout(SWT.VERTICAL));
createTabFolder();
createCTabFolder();
}
private void createTabFolder() {
final TabFolder tabFolder = new TabFolder(this, SWT.NONE);
final TabItem tab0 = new TabItem(tabFolder, SWT.NONE);
tab0.setText("Tab0");
Text text0 = new Text(tabFolder, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
text0.setText("Content Tab0");
tab0.setControl(text0);
final TabItem tab1 = new TabItem(tabFolder, SWT.NONE);
tab1.setText("Tab1");
Text text1 = new Text(tabFolder, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
text1.setText("Content Tab1");
tab1.setControl(text1);
}
private void createCTabFolder() {
final CTabFolder tabFolder = new CTabFolder(this, SWT.NONE);
final CTabItem tab0 = new CTabItem(tabFolder, SWT.NONE);
tab0.setText("Tab0");
Text text0 = new Text(tabFolder, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
text0.setText("Content Tab0");
tab0.setControl(text0);
final CTabItem tab1 = new CTabItem(tabFolder, SWT.NONE);
tab1.setText("Tab1");
Text text1 = new Text(tabFolder, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
text1.setText("Content Tab1");
tab1.setControl(text1);
}
#Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
I get this result on the iPad. The CTabFolder in the bottom is empty.
What do you suggest to work around this at the moment? I was thinking about StackLayout and Labels?
Best regards.

On the Tabris client for iOS, CTabFolder and TabFolder are (currently) the same.
The "extended functionalities" of CTabFolder are not really applicable to the iOS default Tab/TabFolder UI. So to close a Tab you might want to rethink your user workflow for now.
We will have a look at the CTabFolder again, and see if we might implement it like Tabs are implemented on Safari for iPad. But that will definitely be farther along the roadmap.

Related

How to create a text box when click on button in swt?

I have created 2 composite in swt. 1 button created inside 1st composite. I want to create one text box when I will click on the button. But I am unable to do that functionality.
Assuming you are using layouts for your code you just need to create the Text control and then redo the layout.
For example, using GridLayout:
shell.setLayout(new GridLayout());
final Composite buttonComposite = new Composite(shell, SWT.NONE);
buttonComposite.setLayout(new GridLayout());
final Button button = new Button(buttonComposite, SWT.PUSH);
button.setText("Create Text");
final Composite textComposite = new Composite(shell, SWT.NONE);
textComposite.setLayout(new GridLayout());
button.addSelectionListener(new SelectionAdapter()
{
#Override
public void widgetSelected(final SelectionEvent e)
{
final Text newText = new Text(textComposite, SWT.SINGLE | SWT.BORDER);
newText.setText("New text control");
newText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
// Update the layout
shell.layout(true);
}
});
Alternatively you can create the Text control at the beginning but make it not visible and exclude it from the layout:
shell.setLayout(new GridLayout());
final Composite buttonComposite = new Composite(shell, SWT.NONE);
buttonComposite.setLayout(new GridLayout());
final Button button = new Button(buttonComposite, SWT.PUSH);
button.setText("Create Text");
final Composite textComposite = new Composite(shell, SWT.NONE);
textComposite.setLayout(new GridLayout());
final Text newText = new Text(textComposite, SWT.SINGLE | SWT.BORDER);
newText.setText("New text control");
// Not visible
newText.setVisible(false);
// Exclude from layout
final GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
data.exclude = true;
newText.setLayoutData(data);
button.addSelectionListener(new SelectionAdapter()
{
#Override
public void widgetSelected(final SelectionEvent e)
{
// Include in layout
final GridData data = (GridData)newText.getLayoutData();
data.exclude = false;
// Make visible
newText.setVisible(true);
// Redo layout
shell.layout(true);
}
});

How to replace a button and re position it dynamically?

I have a text box and a add button next to it, when I click on add button I am able to add a text box and delete button next to it. Now I want the add button on the first row to be changed to delete and the add button should be re-positioned below two rows, when the second row delete button is clicked (the second row is deleted )the add button should go back to the first row and replace delete button. It should look like following.
How do I achieve this?
If you create a Composite as a container of sorts, you can add and remove from it allowing everything outside to remain in the correct order. By reserving the space, the delete button is always below the contents of the container.
I have a text box and a add button next to it, when I click on add button I am able to add a text box and delete button next to it
For example, if we have a small Shell with an add Button as you mentioned, and an empty space to add the Text widgets to:
final Composite baseComposite = new Composite(shell, SWT.BORDER);
baseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
baseComposite.setLayout(new GridLayout());
final Composite rowsContainerComposite = new Composite(baseComposite, SWT.BORDER);
rowsContainerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
rowsContainerComposite.setLayout(new GridLayout());
final Button addButton = new Button(baseComposite, SWT.PUSH);
addButton.setText("Add");
(For now the empty space is grabbing all available space, but you can change that as needed)
When adding rows, you can add to the rowsContainerComposite:
addButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(final SelectionEvent e) {
new Row(rowsContainerComposite);
rowsContainerComposite.layout();
}
});
A sample Row class:
public class Row {
final Composite baseComposite;
public Row(final Composite parent) {
baseComposite = new Composite(parent, SWT.BORDER);
baseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
baseComposite.setLayout(new GridLayout(2, false));
final Text text = new Text(baseComposite, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final Button deleteButton = new Button(baseComposite, SWT.PUSH);
deleteButton.setText("Delete");
deleteButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(final SelectionEvent e) {
baseComposite.dispose();
parent.layout();
}
});
}
}
when the second row delete button is clicked (the second row is deleted )the add button should go back to the first row
Then when deleted, rows will shift back appropriately:
the add button should be re-positioned below two rows
The idea is that by using the "container" composite, you're reserving that space to add and remove the rows from. The delete button will always be below the rows as they are added and removed.
Full example:
public class AddDeleteButtonTest {
private static class Row {
final Composite baseComposite;
public Row(final Composite parent) {
baseComposite = new Composite(parent, SWT.BORDER);
baseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
baseComposite.setLayout(new GridLayout(2, false));
final Text text = new Text(baseComposite, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final Button deleteButton = new Button(baseComposite, SWT.PUSH);
deleteButton.setText("Delete");
deleteButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(final SelectionEvent e) {
baseComposite.dispose();
parent.layout();
}
});
}
}
private final Display display;
private final Shell shell;
public AddDeleteButtonTest() {
display = new Display();
shell = new Shell(display);
shell.setLayout(new FillLayout());
final Composite baseComposite = new Composite(shell, SWT.BORDER);
baseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
baseComposite.setLayout(new GridLayout());
final Composite rowsContainerComposite = new Composite(baseComposite, SWT.BORDER);
rowsContainerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
rowsContainerComposite.setLayout(new GridLayout());
final Button addButton = new Button(baseComposite, SWT.PUSH);
addButton.setText("Add");
addButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(final SelectionEvent e) {
new Row(rowsContainerComposite);
rowsContainerComposite.layout();
}
});
}
public void run() {
shell.setSize(200, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(final String... args) {
new AddDeleteButtonTest().run();
}
}
I did the same in one of my project. The code is bit complicated to do in Jface/SWT. Adding and removing widgets on composite will be bit heavy task. This will reduce UI performance.
If you use Jface tableviewer instead of creating composite, you will get better UI performance and good look as well. In table viewer in one column you can show textboxes and in one column you can show buttons. You can write table column Editing support/label providers to show the buttons.
With this approach you will be able show buttons for all rows or when you click on any cell you want to add or delete.
I can't share the code snippet right now, due to some reasons, but if you need I will share it on weekends

Eclipse e4: creating a 3 part window trim without resizing text in tool control

I created a Window Trim - Top
now I add 3 Tool Control
first only should contain a SWT-Text and not resize ever...
however, when I type some text and resize my window, it automatically resizes the SWT-Text to fit the text, which it should not.
So how can I give that Tool Control, or the Composite, or the Text the right Size and tell it, NOT to resize!?
public class TrimBarSearch {
#Inject
ISearchService searchService;
private Text txtSearch;
private Composite composite;
#Inject
public TrimBarSearch() {
}
#PostConstruct
public void createGui(final Composite parent) {
parent.setLayoutData(new GridLayout(3, false));
composite = new Composite(parent, SWT.NONE);
Point xy = new Point(300, 15);
Point sizeComposite = new Point(310, 25);
composite.setLayout(new GridLayout(1, false));
composite.setSize(sizeComposite);
txtSearch = new Text(composite, SWT.FILL);
txtSearch.setSize(xy);
txtSearch.setText("");
// TODO fix resizing-problem
parent.getShell().addListener(SWT.Resize, e -> {
//maybe here?!
});}
Never try and mix Layouts with setSize - it does not work, the layout will override your size.
Instead you can specify a width hint for the text in the GridData for the text. Instead of:
txtSearch.setSize(xy);
use:
GridData data = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
data.widthHint = 300;
txtSize.setLayoutData(data);

Avoid Tree Resize after Section expand

I've got a question I couldn't resolve myself for quite a while now.
I have a RCP ViewPage containing two sections. The sections are inside a SashForm so that the user is able to resize the expanded sections. In the bottom section there is a Tree which is empty after initialization. Through user interaction (i.e. removing a filter) the tree gets filled and has a lot of data in it. If the user now collapses the bottom view and expands it again the tree gets resized which causes ScrollBars in my form. What I want is scrollbars in the tree view.
Here is how the view is build:
- ScrolledForm
- Form Body
- Sash
- Section 1
- Composite
- Some View
- Section 2
- Composite
- Tree
I hope you understand what I'm trying to achieve.
UPDATE: Here is some source code to play with. It uses a Table instead of a tree but produces the same issue.
public class MyPersonPageEditor extends FormPage {
public static final String ID = "some.ID";
TableViewer tableViewer;
public MyPersonPageEditor(FormEditor editor) {
super(editor, ID, "Some Title");
}
#Override
protected void createFormContent(IManagedForm managedForm) {
FormToolkit toolkit = managedForm.getToolkit();
ScrolledForm form = managedForm.getForm();
Composite formBody = form.getBody();
formBody.setLayout(new GridLayout());
form.setText("Some Title");
toolkit.decorateFormHeading(form.getForm());
SashForm sfForm = new SashForm(formBody, SWT.VERTICAL);
sfForm.setLayout(new GridLayout());
sfForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Section topSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE);
topSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
topSection.setText("Section 1 Title");
Composite topSectionComposite = toolkit.createComposite(topSection);
topSectionComposite.setLayout(new GridLayout());
toolkit.createLabel(topSectionComposite, "Just some content. Doesn't need to be much");
Button btn = toolkit.createButton(topSectionComposite, "Create Table Content", SWT.PUSH);
btn.addSelectionListener(new SelectionListener() {
#Override
public void widgetSelected(SelectionEvent e) {
for (int i = 0 ; i < 10 ; i++) {
tableViewer.add("Element " + i);
}
}
#Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
topSection.setClient(topSectionComposite);
Section bottomSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE);
bottomSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
bottomSection.setText("Section 2 Title");
Composite bottomSectionComposite = toolkit.createComposite(bottomSection);
bottomSectionComposite.setLayout(new GridLayout());
bottomSectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
bottomSection.setClient(bottomSectionComposite);
Table table = toolkit.createTable(bottomSectionComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION |
SWT.V_SCROLL | SWT.H_SCROLL | SWT.RESIZE);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
table.setHeaderVisible(true);
tableViewer = new TableViewer(table);
tableViewer.add("New Element");
new TableColumn(table, SWT.LEFT).setText("Spalte 1");
TableLayout layoutDefault = new TableLayout();
layoutDefault.addColumnData(new ColumnWeightData(1));
table.setLayout(layoutDefault);
form.reflow(true);
}
}
If you click the button after start the table looks like the left picture. After you collapse and expand the second section it looks like the right one.
Here is the code that works: you just have to tweak the size of the Tree/Table and make sure it will not span across the vertical space:
public void createPartControl(Composite parent) {
FormToolkit toolkit = new FormToolkit(parent.getDisplay());
final ScrolledForm form = toolkit.createScrolledForm(parent);
Composite formBody = form.getBody();
formBody.setLayout(new GridLayout());
form.setText("Some Title");
toolkit.decorateFormHeading(form.getForm());
SashForm sfForm = new SashForm(formBody, SWT.VERTICAL);
sfForm.setLayout(new GridLayout());
sfForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
//top section
Section topSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE);
topSection.setLayout(new GridLayout());
topSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
topSection.setText("Section 1 Title");
Composite topSectionComposite = toolkit.createComposite(topSection);
topSectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
topSectionComposite.setLayout(new TableWrapLayout());
toolkit.createLabel(topSectionComposite, "Just some content. Doesn't need to be much");
Button btn = toolkit.createButton(topSectionComposite, "Create Table Content", SWT.PUSH);
btn.addSelectionListener(new SelectionListener() {
#Override
public void widgetSelected(SelectionEvent e) {
for (int i = 0 ; i < 10 ; i++) {
tableViewer.add("Element " + i);
}
form.reflow(true);
}
#Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
topSection.setClient(topSectionComposite);
//bottom section
Section bottomSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE);
bottomSection.setLayout(new GridLayout());
bottomSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
bottomSection.setText("Section 2 Title");
Composite bottomSectionComposite = toolkit.createComposite(bottomSection);
bottomSectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
bottomSectionComposite.setLayout(new TableWrapLayout());
Table table = toolkit.createTable(bottomSectionComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION |
SWT.V_SCROLL | SWT.H_SCROLL | SWT.RESIZE);
TableWrapData ttd222 = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB);
ttd222.maxHeight =200;
table.setLayoutData(ttd222);
table.setHeaderVisible(true);
tableViewer = new TableViewer(table);
tableViewer.add("New Element");
new TableColumn(table, SWT.LEFT).setText("Spalte 1");
TableLayout layoutDefault = new TableLayout();
layoutDefault.addColumnData(new ColumnWeightData(1));
table.setLayout(layoutDefault);
bottomSection.setClient(bottomSectionComposite);
form.reflow(true);
}
-make sure the Tree has the SWT.H_SCROLL style (if I remember correctly), that is has a minimum size (for example with GridLayout and GridData set the minHeight to X or with TableWrapLayout and TableData heightHint to X)
-if you don't manage to make it work just tell me and I'll try to make the code; also, a picture with the layout would be great

ExpandBar in Eclipse View Part

I am trying to add an expand bar to an Eclipse viewpart. When I click the expand button I would like the viewpart to move items below the expand bar down and show the expanded items. What currently happens is the expand bar items just disappear below the items below the expand bar. Any thoughts?
final ExpandBar expandBar = new ExpandBar(parent, SWT.NONE);
expandBar.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
expandBar.setSpacing(0);
fd_toolBar.top = new FormAttachment(expandBar, 6);
FormData fd_expandBar = new FormData();
fd_expandBar.top = new FormAttachment(0, 62);
fd_expandBar.left = new FormAttachment(0, 3);
expandBar.setLayoutData(fd_expandBar);
formToolkit.paintBordersFor(expandBar);
final ExpandItem xpndtmWarningDetails = new ExpandItem(expandBar, SWT.NONE);
xpndtmWarningDetails.setExpanded(true);
xpndtmWarningDetails.setText("Warning Details");
final Composite composite_1 = new Composite(expandBar, SWT.NONE);
composite_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
xpndtmWarningDetails.setControl(composite_1);
formToolkit.paintBordersFor(composite_1);
xpndtmWarningDetails.setHeight(xpndtmWarningDetails.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
Label lblTest = new Label(composite_1, SWT.NONE);
lblTest.setBounds(10, 10, 55, 15);
lblTest.setText("Test");
expandBar.addExpandListener(new ExpandListener(){
#Override
public void itemCollapsed(ExpandEvent e) {
expandBar.setSize(expandBar.getSize().x, xpndtmWarningDetails.getHeaderHeight());
parent.layout(true);
}
#Override
public void itemExpanded(ExpandEvent e) {
expandBar.setSize(expandBar.getSize().x, 300);
expandBar.layout(true);
parent.layout(true);
}
});
I think the ExpandBar works best when used like it is in this example...
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet343.java
... with several expand bars stacked on top of each other, and nothing else mixed in.
I think the functionality your looking for can be accomplished with an ExpandableComposite object. It depends on what else is going on in your ViewPart.
Here's a quick example of an ExpandableComposite.
package com.amx.designsuite.rcp;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
public class ExpandableCompositeExample extends Composite {
/**
* Create the composite.
* #param parent
* #param style
*/
public ExpandableCompositeExample(final Composite parent, int style) {
super(parent, style);
FormToolkit toolkit;
toolkit = new FormToolkit(parent.getDisplay());
final ScrolledForm form = toolkit.createScrolledForm(parent);
form.setText("Title for Form holding Expandable Composite (optional)");
TableWrapLayout layout = new TableWrapLayout();
form.getBody().setLayout(layout);
ExpandableComposite expandableCompsite = toolkit.createExpandableComposite(form.getBody(), ExpandableComposite.TREE_NODE | ExpandableComposite.SHORT_TITLE_BAR);
toolkit.paintBordersFor(expandableCompsite);
expandableCompsite.setText("Expandable Composite Title (Optional)");
expandableCompsite.setExpanded(true);
Text txtMyNewText = toolkit.createText(expandableCompsite, "Text to show when composite is expanded", SWT.NONE);
expandableCompsite.setClient(txtMyNewText);
}
#Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}