How add restriction to add a new component [message #901832] |
Tue, 14 August 2012 17:37  |
Eclipse User |
|
|
|
Hi,
I made a new component extending a SashForm, just to start to work with toolkit and window builder. My component just make a new SashForm, but it always do a HORIZONTAL style in the constructor. The component is working!
Now, I want to do some validations when the user try to add a new component in my "SashForm".
How I do that? When the user is trying to add a new component, in the icon of the mouse stay a green or red icon, how can I intercept this?
[]'s
|
|
|
Re: How add restriction to add a new component [message #901838 is a reply to message #901832] |
Tue, 14 August 2012 18:02   |
Eclipse User |
|
|
|
SashForm is done as "flow container".
<!-- flow container -->
<parameter name="flowContainer">true</parameter>
<parameter name="flowContainer.horizontal">isHorizontal()</parameter>
<parameter name="flowContainer.component">org.eclipse.swt.widgets.Control</parameter>
So, your component description file (*.wbp-component.xml) could provide "component-validator" to check component better than just "component" (which checks just type).
There are examples of this in org.eclipse.wb.rcp plugin.
|
|
|
Re: How add restriction to add a new component [message #901839 is a reply to message #901838] |
Tue, 14 August 2012 18:14   |
Eclipse User |
|
|
|
Hi Konstantin,
I do this implementation just to test:
<parameter name="flowContainer.component-validator">false</parameter>
If I understand what you say, it will always return false and I could't add a new component to my "SashForm".
But doesn't work... I don't understand what you say, or I implemented wrong?
<!-- PARAMETERS -->
<parameters>
<parameter name="layout.has">false</parameter>
<!-- border -->
<parameter name="shouldDrawBorder">true</parameter>
<!-- flow container -->
<parameter name="flowContainer">true</parameter>
<parameter name="flowContainer.horizontal">isHorizontal()</parameter>
<parameter name="flowContainer.component">org.eclipse.swt.widgets.Control</parameter>
<parameter name="flowContainer.component-validator">false</parameter>
</parameters>
Thanks!
|
|
|
|
Re: How add restriction to add a new component [message #901843 is a reply to message #901841] |
Tue, 14 August 2012 18:26   |
Eclipse User |
|
|
|
Sorry...I make a mistake, and it's working!!
Thank you..
just one more question, there is a way to I do this restriction in the object that I'm adding?
For example, a item menu just can be added in a menu..is the same parameter?
And, there is any place that have a complete documentation about all the parameters that could I use in de *.wbp-component.xml?
|
|
|
Re: How add restriction to add a new component [message #901845 is a reply to message #901843] |
Tue, 14 August 2012 18:35   |
Eclipse User |
|
|
|
Konstatin,
How can I call a method of my class to validate this?
<parameter name="flowContainer.component-validator">canAdd()</parameter>
I do that, but this generate this error in console:
[Error: unable to access property (null parent): canAdd]
|
|
|
Re: How add restriction to add a new component [message #901846 is a reply to message #901843] |
Tue, 14 August 2012 18:36   |
Eclipse User |
|
|
|
These are advanced topics, they are not covered by any documentation.
There is some internal documentation (also may be not 100% complete, but most things are covered) for *.wbp-component.xml files
http://dev.eclipse.org/svnroot/tools/org.eclipse.windowbuilder/trunk/org.eclipse.wb.core/development_doc/
You need Designer_2.0_descriptions.pdf
See
org.eclipse.wb.core.gef.policy.validator.LayoutRequestValidators.mixWithMandatory(ILayoutRequestValidator)
org.eclipse.wb.core.gef.policy.validator.CompatibleLayoutRequestValidator.areCompatible(EditPart, Object)
org.eclipse.wb.core.gef.policy.validator.CompatibleLayoutRequestValidator.childAgreeToBeDroppedOnParent(Object, Object)
i.e. "GEF.requestValidator.child" is *.wbp-component.xml
For example
<!-- GEF validators -->
<parameter name="GEF.requestValidator.child"><![CDATA[
def existChildrenByType(type) {
foreach(child : parent.getChildren()){
if(isComponentType(child,type)){
return true;
}
}
return false;
}
existChildrenByType("org.eclipse.jface.viewers.Viewer")
]]></parameter>
</parameters>
[Updated on: Tue, 14 August 2012 18:37] by Moderator Report message to a moderator
|
|
|
Re: How add restriction to add a new component [message #901848 is a reply to message #901845] |
Tue, 14 August 2012 18:39   |
Eclipse User |
|
|
|
You have "parent" and "child" variables in these scripts.
Probably you need "child.canAdd()" in this case.
Arthur Fücher wrote on Tue, 14 August 2012 14:35Konstatin,
How can I call a method of my class to validate this?
<parameter name="flowContainer.component-validator">canAdd()</parameter>
I do that, but this generate this error in console:
[Error: unable to access property (null parent): canAdd]
|
|
|
|
Re: How add restriction to add a new component [message #901854 is a reply to message #901851] |
Tue, 14 August 2012 19:00   |
Eclipse User |
|
|
|
Ah... Yes, this method should be in the Info class.
And at the time of creation infoInstance.getObject() will return null.
So, you can not call method of the class.
But if you create it and you provided *.wbp-component.xml for it, you could set parameters for creation to check if this creation is valid to be added to the container.
|
|
|
Re: How add restriction to add a new component [message #901859 is a reply to message #901854] |
Tue, 14 August 2012 19:12   |
Eclipse User |
|
|
|
Ok,
To explain what I'm doing: I have 2 classes extends SashForm: HorizontalBox and VertivalBox. To start, I want to allow the user just add a Horizontal in a Vertical, and a Vertical in a Horizontal...
For this I do this implementation:
<parameter name="flowContainer.component-validator"><![CDATA[!isComponentType('com.test.fw.wb.mvc.core.HorizontalBox')]]>
But I want to do more...I want to allow the user just add 2 children for each "Box", to do this I need to access a method...right? Or can I do it otherwise?
|
|
|
Re: How add restriction to add a new component [message #901862 is a reply to message #901859] |
Tue, 14 August 2012 19:22   |
Eclipse User |
|
|
|
If you want to limit number of children, this is actually "component-validator", not "GEF.requestValidator.child", because this is parent imposed limitation, not children.
And parent is actually always accessible, both Info and its toolkit Object.
Here is part of Nebula CompositeTable.
<parameter name="flowContainer.component-validator"><![CDATA[ReflectionUtils.getFullyQualifiedName(component.description.componentClass,false) == 'org.eclipse.swt.widgets.Composite' && container.getChildren().size() < 2]]></parameter>
So, something like "container.getChildren().size() < 2" could work.
Only trick is if we move same component inside, we should not include moving component into these "2" components.
But again, if this is creation, then "component.object === null", i.e. we don't have object yet.
Note that for flow containers "container" and "component" variables are available.
Not "parent" and "child".
Also, "ReflectionUtils.getFullyQualifiedName" is not the best way to check type.
[Updated on: Tue, 14 August 2012 19:23] by Moderator Report message to a moderator
|
|
|
Re: How add restriction to add a new component [message #901870 is a reply to message #901862] |
Tue, 14 August 2012 20:50   |
Eclipse User |
|
|
|
I do what you say, and it's is working, but when I'm adding the second component into the Box the component-validator allows because I have only one. But, the validation is called one more time in:
FlowContainerLayoutEditPolicy [line: 58] - decorateChild(EditPart)
(m_container.validateComponent(child.getModel()))
This time, it's not more valid because I have 2 childrens, and they don't install my SelectionEditPolicy.
The parameter in *.wbp-component.xml is like this:
<parameter name="flowContainer.component-validator"><![CDATA[
!isComponentType('com.test.fw.wb.mvc.core.HorizontalBox') && container.getChildren().size() < 2]]>
</parameter>
I'm doing something wrong? Or missing something?
[Updated on: Tue, 14 August 2012 20:51] by Moderator Report message to a moderator
|
|
|
|
Re: How add restriction to add a new component [message #901878 is a reply to message #901874] |
Tue, 14 August 2012 21:14   |
Eclipse User |
|
|
|
I try to do this, using component.parent() == container, but it cause this error:
unable to resolve method: org.eclipse.wb.internal.swt.model.widgets.ButtonInfo.parent() [arglength=0]
It's wrong this method? Or it's the problem that the object in the first time we don't have the object?
*I'm trying to add a button!
|
|
|
|
|
Re: How add restriction to add a new component [message #902008 is a reply to message #901976] |
Wed, 15 August 2012 13:21   |
Eclipse User |
|
|
|
Another question...
When I need to do a restriction in "SashForm" I've used flowContainer.component-validator because as you say 'SashForm is done as "flow container"'.. but if I need to do a restriction in a class that extend for example "Shell", how can I know what I need to use in the place of flow container?
|
|
|
Re: How add restriction to add a new component [message #902032 is a reply to message #902008] |
Wed, 15 August 2012 15:06   |
Eclipse User |
|
|
|
Each container has LayoutEditPolicy, which decides which components to accept, how to show feedback and what command to execute to add/move component.
"Flow container" means just special kind of LayoutEditPolicy which is description-driven, uses information specified in *.wbp-component.xml files, so users can easily configure such often cases.
Some LayoutEditPolicy implementations are very specific, for example for GridLayout or BorderLayout.
So, if you have specific Layout manager, you may be will need to create plugin with LayoutEditPolicy.
But may be "GEF.requestValidator.parent" parameter can be used for your task.
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.11879 seconds