Disposing a StructureView

I am opening a customised StructureView like this:

StructureView view = builder.createStructureView(editor, project);
SwitchBrowserDialog dialog = new SwitchBrowserDialog(view.getComponent());
dialog.setVisible(true);

The problem is that when IDEA exits, I receive the following error message:

      • The following objects were not disposed:


com.intellij.ide.structureView.newStructureView.StructureViewComponent[.....] of class class com.intellij.ide.structureView.newStructureView.StructureViewComponent

If I call Disposer.dispose(view) after the dialog closes, the error goes away but the StructureView fails to operate on subsequent openings (perhaps the object returned is a singleton).

If I try to link the StructureView with a parent, I can find no implementers of Disposable that make sense in this context.

Any ideas?

Darren

3 comments

Hello Darren,

DG> I am opening a customised StructureView like this:
DG>
DG> StructureView view = builder.createStructureView(editor, project);
DG> SwitchBrowserDialog dialog = new
DG> SwitchBrowserDialog(view.getComponent()); dialog.setVisible(true);
DG>
DG> The problem is that when IDEA exits, I receive the following error
DG> message:
DG>
DG> *** The following objects were not disposed:
DG>
DG> com.intellij.ide.structureView.newStructureView.StructureViewCompone
DG> nt[.....] of class class
DG> com.intellij.ide.structureView.newStructureView.StructureViewCompone
DG> nt
DG>
DG> If I call Disposer.dispose(view) after the dialog closes, the error
DG> goes away but the StructureView fails to operate on subsequent
DG> openings (perhaps the object returned is a singleton).
DG>
DG> If I try to link the StructureView with a parent, I can find no
DG> implementers of Disposable that make sense in this context.
DG>
DG> Any ideas?

Indeed, you need to dispose the StructureView instance with Disposer.dispose(),
and get a new instance from the builder every time the dialog is opened again.
If you do that and it doesn't work, could you please clarify what exactly
"fails to operate" means? A larger snipppet of your code can also help.

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

'Fails to operate' means that the children of the root element are not added to the tree on subsequent openings of the dialog (see first.png and second.png).

As you can see, my plugin is an attempt to make a switch-structure popup, so to allow navigating to the different case labels in a switch structure. (Specifically, I hope to find this useful in at least j2me, where jar size and speed limitations often lead to a rather contrived structure of overly long switch statements and so on).

My StructureViewTreeElement (SwitchTreeElement) getChildren() method looks like this:

 res = new LinkedList();

	for (PsiElement child : block.getChildren())
	{
		if (child instanceof PsiSwitchLabelStatement)
			res.add(new SwitchTreeElement(child, child.getText()));
	}

	return res.toArray(new StructureViewTreeElement[res.size()]);
}
]]>

The AnAction uses this code to create the popup:



Attachment(s):
second.PNG
first.PNG
0

er, scrap that... the root node was just collapsed :)

No idea why though!

0

Please sign in to leave a comment.