|
|
|
|
|
|
Re: How add restriction to add a new component [message #901846 is a reply to message #901843] |
Tue, 14 August 2012 18:36 |
Konstantin Scheglov Messages: 555 Registered: July 2009 |
Senior Member |
|
|
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>
Konstantin Scheglov,
Google, Inc.
[Updated on: Tue, 14 August 2012 18:37] Report message to a moderator
|
|
|
|
|
|
|
Re: How add restriction to add a new component [message #901862 is a reply to message #901859] |
Tue, 14 August 2012 19:22 |
Konstantin Scheglov Messages: 555 Registered: July 2009 |
Senior Member |
|
|
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.
Konstantin Scheglov,
Google, Inc.
[Updated on: Tue, 14 August 2012 19:23] 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 |
Arthur Fücher Messages: 59 Registered: August 2012 |
Member |
|
|
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] Report message to a moderator
|
|
|
|
|
|
|
|
Re: How add restriction to add a new component [message #902032 is a reply to message #902008] |
Wed, 15 August 2012 15:06 |
Konstantin Scheglov Messages: 555 Registered: July 2009 |
Senior Member |
|
|
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.
Konstantin Scheglov,
Google, Inc.
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04892 seconds