I am trying to add a search field in the toolbar after my buttons of my Eclipse RCP Application from the Application.e4xmi , but it doesn't work. I created a ToolControl with a handler :
#Execute
public void execute(Shell shell)
{
shell.setLayout(new GridLayout());
final Composite comp = new Composite(shell, SWT.NONE);
comp.setLayout(new GridLayout());
Text text = new Text(comp, SWT.BORDER);
text.setMessage("Search");
text.setToolTipText("search");
System.out.println("i am in SearchToolItem ");
GridData lGridData = new GridData(GridData.FILL, GridData.FILL, true, true);
lGridData.widthHint = 200;
text.setLayoutData(lGridData);
}
How should I do this?
I assume you are specifying this class as a ToolControl in the e4xmi.
ToolControls don't use #Execute and they aren't given a Shell.
Instead use #PostConstruct and specify a Composite:
#PostConstruct
public void postConstruct(Composite parent)
{
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout());
....
}
Note: Do not change the layout for the parent composite.
Related
I have a composite, which has 3 UI controls - SWT Group, SWT TabFolder, and a child composite that has a label and a link. In some use-cases the SWT Group is hidden, and I would like that the blank space is not seen instead the composite has to be redrawn and show only the SWT TabFolder and the child composite, without any space.
I'm using composite.layout(true), but still there is blank space of the SWT Group when it is made hidden.
Could someone help me solve this issue
TestComposite extends Composite{
private Label childlabel;
private Group group;
private TabFolder tabFolder;
private Button button;
TestComposite(Compossite parent){
super(parent, SWT.NONE);
setLayout(new GridLayout(1, true));
setFont(parent.getFont());
setBackground(parent.getBackground());
GridDataFactory.fillDefaults().grab(true, true).applyTo(this);
createControl();
}
public void createControl() {
this.group = new Group(this, SWT.SHADOW_IN);
this.group.setSize(this.getDisplay().getActiveShell().getSize());
this.button = new Button(this.group, SWT.PUSH);
GridDataFactory.swtDefaults().applyTo(this.button);
this.tabFolder = new TabFolder(this, SWT.TOP);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true,
true).applyTo(this.tabFolder);
Composite childComposite = new Composite(this, SWT.NONE);
childComposite .setLayout(new GridLayout(2, false));
GridDataFactory.swtDefaults().grab(true, false).align(SWT.LEFT,
SWT.TOP).applyTo(childComposite );
this.childLabel = new Label(childComposite, SWT.NONE);
GridDataFactory.swtDefaults().grab(true, false).applyTo(childlabel);
setInput(abc);
enableVisibilityOfGroup(false);
}
public void enableVisibilityOfGroup(Boolean visible){
this.group.setVisible(visible);
// this shoudl redraw the UI and shown only tabFolder and label in the
// whole wizard page, but there is blank space in place of group
this.layout(true);
}
}
Set GridData on the Group
GridDataFactory.swtDefaults().applyTo(this.group);
Use GridData.exclude to exclude/include the group in the layout:
public void enableVisibilityOfGroup(boolean visible) {
this.group.setVisible(visible);
GridData gridData = (GridData)this.group.getLayoutData();
gridData.exclude = !visible;
this.layout(true);
}
I'm developing a plugin for eclipse and I'm struggling to use ScrolledComposite as well as making it take up the remaining space.
The parent layout is a 2-column Grid:
#Override
public void createPartControl(Composite parent) {
parent.setLayout(new GridLayout(2, false));
// other views etc
}
The ScrolledComposite is created like so (slightly abbreviated):
private void fillScroll() {
if (scroll != null) {
scroll.dispose();
}
scroll = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
GridData gd = new GridData();
gd.horizontalSpan = 2;
scroll.setLayoutData(gd);
Composite innerContainer = new Composite(scroll, 0);
innerContainer.setLayout(new GridLayout(1, false));
// for loop that adds widgets to innerContainer
scroll.setExpandHorizontal(true);
scroll.setExpandVertical(true);
scroll.setContent(innerContainer);
scroll.setSize(innerContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT));
parent.layout(true);
}
The list of questions are the widgets added in the for loop and are contained by innerContainer.
Expectation: Since innerContainer is too large to fit in the parent, there should be scroll bars.
What actually happens: There are no scroll bars.
How do I fix this problem?
The GridData on the ScrolledComposite needs to have grabExcessVerticalSpace set to true. I suggest you to use the extended constructor in order to clearly define how it should be displayed, for example:
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
Option A: change scroll.setSize to scroll.setMinSize:
scroll.setMinSize(innerContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT));
or, Option B: remove scroll.setExpandHorizontal and scroll.setExpandVertical and change scroll.setSize to innerContainer.setSize:
innerContainer.setSize(innerContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT));
In my Eclipse plugin editor there is a button called "Add Graph" which adds a composite with a graph on another already created composite with "Grid Layout", but the created composite is not appearing until resizing the Editor manually or switch to another editor and go back
i have also used
parentComposite.pack();
parentComposite.layout();
but the added composite is shown up with a small size, and it`s adjusted also after resizing the Editor manually or switch to another editor and go back.
So my Question is how to call the same handler which runs while resizing the Editor manually or switch to another editor and go back. to adjust my view after adding the new composite.
Adding the Example:
public class MyEditor extends EditorPart {
private Composite compGraphesArea;
#Override
public void createPartControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout(2, false));
Button btnAddGraph = new Button(container, SWT.NONE);
btnAddGraph.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
createGraph(compGraphesArea);
}
});
btnAddGraph.setText("Add Graph");
compGraphesArea = new Composite(container, SWT.NONE);
compGraphesArea.setLayout(new GridLayout(1, true));
compGraphesArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
createGraph(compGraphesArea);
}
private void createGraph(Composite compGraphArea) {
JFreeChart chart = chartHandler.getChart();
compGraphPlot = new Composite(compGraphArea, SWT.BORDER | SWT.EMBEDDED);
compGraphPlot.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
Frame chartFrame = SWT_AWT.new_Frame(compGraphPlot);
ChartPanel label = new ChartPanel(chart);
chartFrame.add(label);
chartFrame.pack();
chartFrame.setVisible(true);
XYPlot plot = chart.getXYPlot();
ValueAxis axis = plot.getDomainAxis();
axis.setFixedAutoRange(1000000 + slider.getMaximum() / 2);
}
And this what i got after pressing "Add Graph":
and this what i am expecting and what i got after making any change on the Editor manually:
I have a wizard with table and button components. When I click to the add button I choose from dialog window what items should be added to the table. I confirm items, and then this ones appears in the table with scrollbar. But if I resize the wizard, the table size is changed. How to fix it?
Table before resize:
Table after wizard resize
Composite compositeArea = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
compositeArea.setLayout(layout);
Table table = new Table(compositeArea, SWT.BORDER | SWT.V_SCROLL);
new TableColumn(someList, SWT.NULL);
table.setLayoutData(new GridData(HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL));
** Please note that the use of HORIZONTAL_ALIGN_FILL and GRAB_HORIZONTAL is discouraged. Instead, you should be using the public GridData(int, int, boolean, boolean) constructor. **
To slighly simplify your code snippet (only one column on the composite, and only one default table column - see full code below):
// ...
final Composite compositeArea = new Composite(parent, SWT.NONE);
compositeArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
compositeArea.setLayout(new GridLayout());
final Table table = new Table(compositeArea, SWT.BORDER | SWT.V_SCROLL);
table.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
// ...
...and we see that the Table isn't fitting in the available space or showing the scrollbar as expected, and the same occurs when the Shell is resized.
In answer to your question, this is because the layout data of the Table doesn't know how to layout vertically - you've only specified two horizontal style attributes.
If we instead use the suggested constructor:
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
...the Table takes the available space correct, shows the scrollbar, and updates correctly when the Shell is resized. Using the layout data, we've told the Table to fill the available horizontal space, and the Table will display the scrollbar if necessary.
Full example:
public class TableResizeTest {
private final Display display;
private final Shell shell;
public TableResizeTest() {
display = new Display();
shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setMaximized(true);
final Composite parent = new Composite(shell, SWT.NONE);
parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
parent.setLayout(new GridLayout());
// -- snippet --
final Composite compositeArea = new Composite(parent, SWT.NONE);
compositeArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
compositeArea.setLayout(new GridLayout());
final Table table = new Table(compositeArea, SWT.BORDER | SWT.V_SCROLL);
// table.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// -------------
for (int i = 0; i < 20; ++i) {
new TableItem(table, SWT.NONE).setText(String.valueOf(i));
}
}
public void run() {
shell.setSize(300, 300);
shell.open();
while (!shell.isDisposed()) {
if (display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(final String... args) {
new TableResizeTest().run();
}
}
I am trying to embed a JFace TableViewer in a SWT TabFolder, but when I do so, the table does not show up. The current (working code) in my GitToDo code looks like (see this Git repos):
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Git ToDo");
FillLayout layout = new FillLayout();
shell.setLayout(layout);
final GitToDoTree tableViewer = new GitToDoTree(shell);
Where the latter GitToDoTree extends TableViewer, with this constructor:
super(parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.FILL);
this.shell = parent;
table = this.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
So, when I construct the TableViewer-extending GitToDoTree from a Shell it works, but as soon as I try to build it from a TabFolder or (tried that too) a Composite, nothing shows up anymore.
How can I get my TableViewer to show up in the TabFolder?
If your TableViewer class isn't showing up when you add it to a Composite I would say that chances are that you are not setting a layout for the nested Composite.
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Git ToDo");
FillLayout layout = new FillLayout();
shell.setLayout(layout);
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new FillLayout()); // Possible missing layout?
final GitToDoTree tableViewer = new GitToDoTree(composite);
And as for the TabFolder that may be that you are not setting the client control on the TabItem
TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
TabItem item = new TabItem(tabFolder, SWT.NONE);
item.setText("Table");
GitToDoTree viewer = new GitToDoTree(tabFolder);
item.setControl(viewer.getTable()); // Possible setControl call?
TabItem item2= new TabItem(tabFolder, SWT.NONE);
item2.setText("Empty");