Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » Restrict usage of few Palette objects from dropping onto ViewPart canvas
Restrict usage of few Palette objects from dropping onto ViewPart canvas [message #1097905] Fri, 30 August 2013 10:09 Go to next message
Tilak Sharma is currently offline Tilak Sharma
Messages: 48
Registered: July 2009
Member
Hi,

We are extending WindowBuilder to contribute our custom UI components (like, CustomCanvas, CustomComboBox, CustomTextBox, CustomRadioButton, etc) into the Palette.

We will be having our CustomCanvas on the ViewPart by default. Now we want to restrict Users from dropping any other existing UI components (Composite, Button, Tree, etc) onto our canvas.

How can we achieve that?

I tried extending the extension point ("org.eclipse.wb.core.editPolicyFactories"), but org.eclipse.wb.core.gef.policy.layout.LayoutPolicyUtils.createLayoutEditPolicy() method returns another LayoutEditPolicy object even before it loops till editPolicyFactory I contributed.

Thanks in anticipation,
Tilak
Re: Restrict usage of few Palette objects from dropping onto ViewPart canvas [message #1098173 is a reply to message #1097905] Fri, 30 August 2013 18:27 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin Scheglov
Messages: 555
Registered: July 2009
Senior Member
1. You probably want to rise priority for your layout factory.

<!-- ======================================================== -->
<!-- GEF factories -->
<!-- ======================================================== -->
<extension point="org.eclipse.wb.core.editPartFactories">
<factory class="org.eclipse.wb.internal.rcp.nebula.gef.EditPartFactory" priority="1"/>
</extension>

2. Also take a look at Designer_2.0_descriptions.pdf and GEF validators - you can put validation script into wbp-component.xml descriptor. So, you can use standard layouts, but custom limitations.

<parameter name="GEF.requestValidator.parent">true</parameter>

<parameter name="GEF.requestValidator.child"><![CDATA[
isComponentType(parent, 'org.eclipse.swt.widgets.Table') &&
parent.object.itemCount <= 2
]]></parameter>


Konstantin Scheglov,
Google, Inc.
Re: Restrict usage of few Palette objects from dropping onto ViewPart canvas [message #1098799 is a reply to message #1098173] Sat, 31 August 2013 18:13 Go to previous messageGo to next message
Tilak Sharma is currently offline Tilak Sharma
Messages: 48
Registered: July 2009
Member
Thanks for the reply , Konstantin.

After adding the priority as 1 for my extension as:
<extension
point="org.eclipse.wb.core.editPolicyFactories">
<factory
class="com.sample.policy.MyLayoutEditPolicyFactory"
priority="1">
</factory>
</extension>

I now get a callback to my MyLayoutEditPolicyFactory.createLayoutEditPolicy() method.

I understand that I need to return a class that extens LayoutEditPolicy. But it requires me to extend getCreateCommand(), getPasteCommand() and three other get*Command() methods.

What is the contract I should define for these methods? I just need a call back to the RequestValidator I return from this EditPolicy object, so that I can restrict the user from dropping any existing component based on a condition check.



Please suggest.

Thanks,
Tilak
Re: Restrict usage of few Palette objects from dropping onto ViewPart canvas [message #1098911 is a reply to message #1098799] Sat, 31 August 2013 22:14 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin Scheglov
Messages: 555
Registered: July 2009
Senior Member
If you return null command, container with your LayoutEditPolicy will not accept this request, i.e. component.

Konstantin Scheglov,
Google, Inc.
Re: Restrict usage of few Palette objects from dropping onto ViewPart canvas [message #1099266 is a reply to message #1098911] Sun, 01 September 2013 11:59 Go to previous messageGo to next message
Tilak Sharma is currently offline Tilak Sharma
Messages: 48
Registered: July 2009
Member
Hi Konstantin,

In the class MyLayoutEditPolicyFactory, I am creating an anonymous ILayoutRequestValidator like:

ILayoutRequestValidator validator = new ILayoutRequestValidator() {

@Override
public boolean validateCreateRequest(EditPart host, CreateRequest request) {
if (((JavaInfo) request.getSelectObject()).toString().contains("com.sample.custom"))
return true;
return false;
}

.
.
.
}

When I drag any existing component onto ViewPart canvas, it is now showing Red marker on the cursor for existing components and Green marker for my custom components.

Now, when I click on the ViewPart canvas to drop the component (ex, my customComboBox), it gives me a callback to MyLayoutEditPolicyFactory.getCreateCommand(CreateRequest request).
Here I want to return a command that handles this drop and adds it to the Canvas.
That is, I want to reuse existing code or class which does that already.


I see that without my extension point definition, the drop is being handled by FlowContainerLayoutEditPolicy or AbsoluteLayoutEditPolicy. I cannot extend them as they are marked final.

Please suggest.

Thanks,
Tilak

Re: Restrict usage of few Palette objects from dropping onto ViewPart canvas [message #1099403 is a reply to message #1099266] Sun, 01 September 2013 17:05 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin Scheglov
Messages: 555
Registered: July 2009
Senior Member
You can always use delegation instead of inheritance.

Konstantin Scheglov,
Google, Inc.
Re: Restrict usage of few Palette objects from dropping onto ViewPart canvas [message #1110662 is a reply to message #1099403] Tue, 17 September 2013 06:43 Go to previous message
Tilak Sharma is currently offline Tilak Sharma
Messages: 48
Registered: July 2009
Member
Hi Konstantin,

I am able to show only my Custom components in the Palette now. I achieved that by having a file org.eclipse.wb.rcp.wbp-palette-commands.xml under wbp-meta folder apart from org.eclipse.wb.rcp.wbp-palette.xml.

In this file (org.eclipse.wb.rcp.wbp-palette-commands.xml), I have the the commands to remove the existing categories, so that everytime I launch the WindowBuilder editor, I will see only the category of custom components I contributed.

Thanks,
Tilak

Previous Topic:WB uses wrong Classpath
Next Topic:WB tutorial
Goto Forum:
  


Current Time: Fri Oct 24 13:32:42 GMT 2014

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

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