Can I put a view into CTabFolder SWT? - java

As the title, I want to know that is there any way to put a view that extend ViewPart into a CtabFolder?
I have did some google search but there is nothing can help. So I decided to bring my question to here.
Thanks.

After tried more research I have found how to show a ViewPart in a CTabFolder as CTabItem. Here is it:
// create a container for the View part with tabFolder as a parent CTabFolder
Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayout(new FillLayout());
CTabItem item = null;
item = new CTabItem(tabFolder, SWT.NONE);
// Create the one of the ViewPart I want to show in my CTabFolder
ProjectVersionDriversView myTestViewer = new ProjectVersionDriversView();
// call the init method on the ViewPart with the current ViewSite
try {
myTestViewer.init(this.getViewSite());
} catch (PartInitException e) {
e.printStackTrace();
}
// Build the ViewPart within our composite container.
myTestViewer.createPartControl(composite);
item.setText("Your Title");
// set the composite containing the view part as the control for tabItem2.
item.setControl(composite);
It's from here.

Related

java composite with an scrolling image

I am newbie with swt and I have a Dialog that contains an image but if the image is too big is not possible to see the complete image. It is cut. So I decided to create a Dialog with scrolling. I have done but the scroll doesn't work. It appears and you can clic over and move it but I can't move over the image. I have tried several things but none of them work :(
protected Control createDialogArea(Composite parent) {
//getShell().setText(Messages.labelTitle);
//setTitleImage(image); // Image to be displayed in your Dialog
//return parent;
Composite container = new Composite(getShell(), SWT.H_SCROLL | SWT.V_SCROLL);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
container.setLayout(new GridLayout());
Label preview = new Label(container, SWT.NONE);
GridData layoutData = new GridData(GridData.FILL_BOTH);
preview.setLayoutData(layoutData);
preview.setImage(image);
return parent;
}

Composite position and size - SWT

I need your help... I attached an image, I want that the right grid appears at the bottom, below of Estadisticas1, Estadisticas2, Estadisticas3, Estadisticas4
I tried a lot of ways, with GridData, FormLayout and no way!
Also, I tried with setSize and setBounds and in no cases the size or position change, I donĀ“t know why!
There are many ways to do this depending on exactly what you want which you haven't really specified. For example:
public void createPartControl(final Composite parent)
{
Composite body = new Composite(parent, SWT.NONE);
body.setLayout(new FillLayout(SWT.VERTICAL));
Composite topArea = new Composite(body, SWT.BORDER);
// TODO add your 'EstadisticasX' controls to 'topArea'
Composite bottomArea = new Composite(body, SWT.BORDER);
// TODO add bottom grid to 'bottomArea'
}

No Scroll on View in Eclipse RCP

I am supposed to create a scroll bar in my Eclipse RCP view and I referred to the ScrolledComposite javadoc and taking help from this.
private void createComposite2(final Composite parent,final String text, int compositeNumber)
{
final ScrolledComposite rightScrolled = new ScrolledComposite(parent, SWT.V_SCROLL|SWT.H_SCROLL|SWT.BORDER);
group=GUIToolkit.newGroup(rightScrolled, SWT.NONE, text, null);
rightScrolled.setContent(group);
group.setLayout(new FillLayout());
rightScrolled.setExpandHorizontal(true);
rightScrolled.setExpandVertical(true);
group.setSize(group.computeSize(SWT.DEFAULT, SWT.DEFAULT));
group.setBackground(white);
createPartControl(group,compositeNumber);
}
But instead the scroll is absent. Can anybody tell me what exactly is the problem? In one of the online resources I saw addControlListner. Will that help? If yes, how can I use it?
After some research and hit and trial, i came up with this code,
private void createComposite2(final Composite parent,final String text, int compositeNumber)
{
final ScrolledComposite rightScrolled = new ScrolledComposite(parent, SWT.V_SCROLL|SWT.H_SCROLL);
group=GUIToolkit.newGroup(rightScrolled, SWT.NONE, text, null);
rightScrolled.setContent(group);
rightScrolled.setExpandHorizontal(true);
rightScrolled.setExpandVertical(true);
rightScrolled.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
org.eclipse.swt.graphics.Rectangle r = rightScrolled.getClientArea();
rightScrolled.setMinSize(group.computeSize(r.width, SWT.DEFAULT));
}
});
group.setLayout(new FillLayout());
group.setBackground(white);
createPartControl(group,compositeNumber);
}
which resulted in scroll coming but it would not readjust to show the window.
Have a look at the first composite with name SOAD. It's the normal size.
and now this is when i push it on left side, the scroll should have been activated, and it is not... It is cropping the content.
How do i fix this

createForm() of FormToolKit creates scroll bars

I am trying to create a multipage editor looking similar to the manifest editor using the wizard for multipage editors provided by eclipse. The first page is created as follows:
void createPage0() {
Composite composite = new Composite(getContainer(), SWT.DEFAULT);
composite.setLayout(new FillLayout());
FormToolkit toolkit = new FormToolkit(composite.getDisplay());
Form form = toolkit.createForm(composite);
form.setText("Test Viewer");
toolkit.decorateFormHeading(form);
int index = addPage(composite);
setPageText(index, "editor1");
}
When ran with eclipse, the created form has two scroll activ scroll bar, although there is obviously nothing to scroll.
I tried cleaning and refreshing the project. Nothing changed. Help?
I found out the problem. The composite surrounding form somehow makes the scroll bars. The following code solves the problem.
void createPage0() {
FormToolkit toolkit = new FormToolkit(composite.getDisplay());
Form form = toolkit.createForm(composite);
form.setText("Test Viewer");
toolkit.decorateFormHeading(form);
int index = addPage(composite);
setPageText(index, "editor1");
}

How can i get a balloon in my custom tool tip?

I am creating a custom tooltip where i have a textbox.I am able to do that but i could not get balloon like icon as in the attached picture .Can anyone help me regarding this.
Mytooltip class:
public class MyToolTip extends ToolTip {
private Shell parentShell;
public MyToolTip(Control control) {
super(control,SWT.BALLOON,false);
this.parentShell = control.getShell();
}
#Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
// TODO Auto-generated method stub
Composite comp = new Composite(parent,SWT.NONE);
comp.setLayout(new FillLayout());
Text text = new Text(comp,SWT.BORDER);
text.setText("");
return comp;
}
}
Class using tooltip:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new RowLayout(SWT.VERTICAL));
Text text = new Text(shell, SWT.BORDER);
text.setText("sample text field");
MyToolTip myTooltipLabel = new MyToolTip(text);
myTooltipLabel.setShift(new Point(-5, -5));
myTooltipLabel.setHideOnMouseDown(false);
myTooltipLabel.activate();
myTooltipLabel.setRespectDisplayBounds(false);
myTooltipLabel.setRespectMonitorBounds(false);
The problem is, that you are using org.eclipse.jface.window.ToolTip whereas the code that was used to create that screenshot uses org.eclipse.swt.widgets.ToolTip.
The SWT tooltip can have the balloon look by passing SWT.BALLOON as the style bit.
The JFace tooltip does not support SWT.BALLOON, only ToolTip.NO_RECREATE and ToolTip.RECREATE.
So here is the conclusion: You can't subclass the swt tooltip to make it editable. You can't make the JFace tooltip look the way you want it to look. The only solution that is left is creating your own Widget based on Composite or Canvas that does what you want.

Categories