Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Detachable Composite
Detachable Composite [message #445489] Sun, 07 November 2004 20:04 Go to next message
Fabian Wolf is currently offline Fabian WolfFriend
Messages: 96
Registered: July 2009
Member
Hello,

I'm stuck with a problem that's really driving me crazy...

I'm trying to create a Class implementing composite which by default is
inside a CTabItem and which is supposed to hold other widgets.
It's creating a ViewForm which is supposed to offer a button that lets the
user detach or reattach the ViewForm from the CTabItem.

When detaching, it creates a new Shell and sets the ViewForm's parent to be
the shell (using setParent).
It then disposes the TabItem.
The problem is, that whenever I dispose the TabItem the ViewForm inside the
newly opened shell becomes invisible (but not disposed - as the
DisposeEvent tells me).

My second try was to dispose both the ViewForm and the TabItem and to create
a new ViewForm inside the shell - no luck as well, same problem.

The code looks like this:

public class DetachableView extends Composite {

private ViewForm viewForm;
private CTabItem tabItem;
private Composite parent;
private Control child;
private Shell shell;

public DetachableView(CTabFolder parent) {
super(parent, SWT.NONE);

this.parent = parent;

// Create a new CTabItem in the CTabFolder
tabItem = new CTabItem(parent, SWT.NONE);
createContent(tabItem.getParent());
tabItem.setControl(viewForm);
}


private void detach() {
shell = new Shell(Display.getCurrent());
shell.setSize(300, 600);
viewForm.setParent(shell);
//createContent(shell);

// This is when the ViewForm disappears as well...
tabItem.dispose();

shell.open();
}



private void attach() {
tabItem = new CTabItem((CTabFolder)this.parent, SWT.NONE);
viewForm.setParent(tabItem);
tabItem.setControl(viewForm);

shell.close();
shell.dispose();
}



private void createContent(Composite p) {

viewForm = new ViewForm(p, SWT.FLAT | SWT.BORDER);

final ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT);
final ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
toolItem.setImage(new
ResourceLoader().loadImageResource("de.test.resource", "down.png"));
final Menu menu = new Menu(toolBar);
MenuItem detach = new MenuItem(menu, SWT.NONE);
detach.setText(i18n.getLocalString("Detach"));
MenuItem attach = new MenuItem(menu, SWT.NONE);
attach.setText(i18n.getLocalString("Attach"));

toolItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Rectangle rect = toolItem.getBounds();
menu.setLocation(toolBar.toDisplay(rect.x, rect.y +
rect.height));
menu.setVisible(true);
}
});
detach.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
detach();
}
});
attach.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
attach();
}
});

viewForm.setTopRight(toolBar);
viewForm.setContent(this.child);
}

}




Any idea???
Any help is appreciated!!

Thanks,
Fabian
Re: Detachable Composite [message #445566 is a reply to message #445489] Mon, 08 November 2004 14:40 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Before disposing the CTabItem, call CTabItem.setControl(null).

"Fabian Wolf" <Fabian.Wolf@informatik.uni-ulm.de> wrote in message
news:cmlv3t$or4$1@eclipse.org...
> Hello,
>
> I'm stuck with a problem that's really driving me crazy...
>
> I'm trying to create a Class implementing composite which by default is
> inside a CTabItem and which is supposed to hold other widgets.
> It's creating a ViewForm which is supposed to offer a button that lets the
> user detach or reattach the ViewForm from the CTabItem.
>
> When detaching, it creates a new Shell and sets the ViewForm's parent to
> be
> the shell (using setParent).
> It then disposes the TabItem.
> The problem is, that whenever I dispose the TabItem the ViewForm inside
> the
> newly opened shell becomes invisible (but not disposed - as the
> DisposeEvent tells me).
>
> My second try was to dispose both the ViewForm and the TabItem and to
> create
> a new ViewForm inside the shell - no luck as well, same problem.
>
> The code looks like this:
>
> public class DetachableView extends Composite {
>
> private ViewForm viewForm;
> private CTabItem tabItem;
> private Composite parent;
> private Control child;
> private Shell shell;
>
> public DetachableView(CTabFolder parent) {
> super(parent, SWT.NONE);
>
> this.parent = parent;
>
> // Create a new CTabItem in the CTabFolder
> tabItem = new CTabItem(parent, SWT.NONE);
> createContent(tabItem.getParent());
> tabItem.setControl(viewForm);
> }
>
>
> private void detach() {
> shell = new Shell(Display.getCurrent());
> shell.setSize(300, 600);
> viewForm.setParent(shell);
> //createContent(shell);
>
> // This is when the ViewForm disappears as well...
> tabItem.dispose();
>
> shell.open();
> }
>
>
>
> private void attach() {
> tabItem = new CTabItem((CTabFolder)this.parent, SWT.NONE);
> viewForm.setParent(tabItem);
> tabItem.setControl(viewForm);
>
> shell.close();
> shell.dispose();
> }
>
>
>
> private void createContent(Composite p) {
>
> viewForm = new ViewForm(p, SWT.FLAT | SWT.BORDER);
>
> final ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT);
> final ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
> toolItem.setImage(new
> ResourceLoader().loadImageResource("de.test.resource", "down.png"));
> final Menu menu = new Menu(toolBar);
> MenuItem detach = new MenuItem(menu, SWT.NONE);
> detach.setText(i18n.getLocalString("Detach"));
> MenuItem attach = new MenuItem(menu, SWT.NONE);
> attach.setText(i18n.getLocalString("Attach"));
>
> toolItem.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> Rectangle rect = toolItem.getBounds();
> menu.setLocation(toolBar.toDisplay(rect.x, rect.y +
> rect.height));
> menu.setVisible(true);
> }
> });
> detach.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> detach();
> }
> });
> attach.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> attach();
> }
> });
>
> viewForm.setTopRight(toolBar);
> viewForm.setContent(this.child);
> }
>
> }
>
>
>
>
> Any idea???
> Any help is appreciated!!
>
> Thanks,
> Fabian
Previous Topic:Can I drag and drop a TreeItem with its children?
Next Topic:Scrollable List
Goto Forum:
  


Current Time: Tue Oct 20 03:25:12 GMT 2020

Powered by FUDForum. Page generated in 0.01962 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top