Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » Using a custom layout manager
Using a custom layout manager [message #677440] Wed, 08 June 2011 14:32 Go to next message
Dan Hentschel is currently offline Dan HentschelFriend
Messages: 10
Registered: April 2011
Junior Member
Is it possible to use my own custom layout with WB? I haven't found any way to add one to the palette yet, but beyond that, if I edit the source code on my shell to set the layout explicitly, then it does not seem to be running through my code in the design view.

- dan
Re: Using a custom layout manager [message #677442 is a reply to message #677440] Wed, 08 June 2011 14:39 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
WindowBuilder should in general render custom layout, if it uses same code patterns as standard ones. If you don't observe this, please post test case or open bug.

You can add your layout (or any other component, such as widget) using several ways. See http://code.google.com/javadevtools/wbpro/NewComponentsTutorial.pdf


Konstantin Scheglov,
Google, Inc.
Re: Using a custom layout manager [message #677456 is a reply to message #677440] Wed, 08 June 2011 15:12 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 886
Registered: July 2009
Location: Boston, MA
Senior Member
Also keep in mind that custom layout managers are not simple components like widgets. There is no Java Bean model for layout managers that will tell a UI tool how to represent them at design time. You will need to create a design time model for it and register that with WB just as we have done for all of the other layout managers. Fortunately, WB is now open source, so there are lots and lots of layout manager examples that you can look at and copy from. If your custom layout manager is a simple derivative of one of the existing items on the palette, this should be quite easy. If it is unique or complex and not derived from an existing layout manager, then you will have a lot of work to do (for which the existing examples should give you guidance).
Re: Using a custom layout manager [message #677552 is a reply to message #677456] Wed, 08 June 2011 19:51 Go to previous messageGo to next message
Dan Hentschel is currently offline Dan HentschelFriend
Messages: 10
Registered: April 2011
Junior Member
I tried creating a very simple project in which I created a layout manager named SomeLayout. I copied into it the exact code from FillLayout, and I also created a SomeLayoutInfo class with helper classes, which I modeled exactly after the FillLayoutInfo and associated from the WB source tree. It doesn't seem to be working the way I expected. I have attached a very simple sample Eclipse project that highlights the problem that I am seeing (note that the classpath will need to be massaged a bit to point to your local SWT version and WB installation directory).

In the sample project I have psoted, when I click on the Design tab for MainWindow.java, I get a "WindowBuilder was not able to show the GUI" message. If I comment out line 47:

// shell.setLayout(new SomeLayout(SWT.HORIZONTAL));


Then the Design tab loads fine, but clicking the "SomeLayout" button in the palette doesn't do anything. Any pointers would be appreciated. I'm a bit stuck right now.

- dan
Re: Using a custom layout manager [message #678806 is a reply to message #677552] Thu, 09 June 2011 14:59 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
Try to read error message a little further than just "WindowBuilder was not able to show the GUI".

You will see that problem is caused by loading *.wbp-component.xml, which was caused by impossibility to load SomeLayoutInfo class, because you put it into your Eclipse with UI. If you want to expend WindowBuilder, you should create new plugin and _run_ Eclipse with this plugin, not just _have_ this plugin in sources in Eclipse. This is general plugin development knowledge.


Konstantin Scheglov,
Google, Inc.
Re: Using a custom layout manager [message #681729 is a reply to message #678806] Thu, 09 June 2011 18:17 Go to previous messageGo to next message
Dan Hentschel is currently offline Dan HentschelFriend
Messages: 10
Registered: April 2011
Junior Member
Yes, thank you for that. I suspected that something like this was what was happening, but my initial attempts at making it a plugin didn't show any promising results.

I have now made some progress, though. I now have a plugin project that seems to have no problem with the SomeLayoutInfo model specified in the meta file. However, it still doesn't work correctly. I can add my layout to a shell, but once my layout is active, the designer won't allow me to add any widgets to the shell. I can add widgets to the shell if I set the layout to Absolute layout, and then the widgets are positioned correctly if I set the layout to SomeLayout after the widgets are placed.

I don't completely understand the interactions with the SomeLayoutInfo class yet, so I put some breakpoints in each of the three methods (including the constructor). None of my breakpoints were hit. I see no evidence that the model class is even being constructed.

Another thing I didn't understand was the "Code generation" section of the ToolkitDescription. For now, I'm just returning null from getGenerationSettings(), on the assumption that it is unrelated to anything that I am doing right now. I'm not sure if that is a valid assumption, though.

I will continue to look into it, but please let me know if I am doing anything obviously wrong. I have posted two projects this time. One is the plugin project, and the second is the project that I test with when I launch Eclipse from within the plugin project.

Re: Using a custom layout manager [message #681746 is a reply to message #681729] Thu, 09 June 2011 18:36 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
1. You don't need ToolkitDescription and ToolkitProvider, you work just in normal RCP toolkit.

2. I think that SomeLayout itself should not be in plugin, because in this case you will have to add this plugin into project classpath to use it in this project. While this will work, this will pollute classpath with design-time classes. Create separate project and jar it.

3. So, in <extension point="org.eclipse.wb.core.toolkits"> contribute to <toolkit id="org.eclipse.wb.rcp"> not to your toolkit (which is not used in any case). By doing this you will tell WindowBuilder that this plugin has models for components, so your SomeLayoutInfo.java will be used and constructor hit.

4. If you contribute component (layout in your case) to palette using plugin.xml, then you don't need org.eclipse.wb.rcp.wbp-palette.xml in project. In same way, it is better to have SomeLayout.wbp-component.xml in plugin.

5. Yes, you will not able to drop new widgets because WindowBuilder does not know what feedback to show. In general you should also contribute to <extension point="org.eclipse.wb.core.editPolicyFactories"> (and org.eclipse.wb.core.treeEditPolicyFactories for components tree) and provide LayoutEditPolicy. If your layout is simple flow-based layout, you can use just descriptions is wbp-component.xml file. See RowLayout.wbp-component.xml as example.
	<!-- PARAMETERS -->
	<parameters>
		<parameter name="layout-data.has">true</parameter>
		<parameter name="layout-data.class">org.eclipse.swt.layout.RowData</parameter>
		<!-- flow container -->
		<parameter name="flowContainer">true</parameter>
		<parameter name="flowContainer.horizontal">isHorizontal()</parameter>
	</parameters>


At same time rendering after absolute layout works because WindowBuilder just interprets code.


Konstantin Scheglov,
Google, Inc.

[Updated on: Thu, 09 June 2011 18:37]

Report message to a moderator

Re: Using a custom layout manager [message #682184 is a reply to message #681746] Fri, 10 June 2011 15:06 Go to previous message
Dan Hentschel is currently offline Dan HentschelFriend
Messages: 10
Registered: April 2011
Junior Member
Thank you very much for your patience and your in-depth response. I am making very good progress now.

- dan
Previous Topic:Window Builder 3.7RC4 available
Next Topic:Deploy WindowBuilder application
Goto Forum:
  


Current Time: Mon Nov 24 22:59:18 GMT 2014

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

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