[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [ve-dev] Read/Write of complex LayoutManager values
|
Rich -
Not sure my question was clear. The form of enumeration is not
really the point of my problem, but rather, once I do get a IJavaInstance
(or something) representing a constraint object, how do I then get the
constraint
constructor parameter values. Swing BoxLayout
does retrieve the individual constraint objects, but merely types
them. I do not see an example of actually extracting constructor
parameter values.
That is, given only the (prior generated) source:
jPanel.add(jLabel,
new
CellConstraints(2, 2));
jPanel.add(getJButton(),
new
CellConstraints(4, 2));
how do I subsquently read back just the int pair values 2, 2 and
4, 2? Hopefully, the following routine will give a better picture
of what I am trying to do -- just need to understand how to fill in the
"???????".
Thanks,
Gerald
/**
*
Retrieves
a
map
of
constraint
values
for
some
set
of
components
present
in
a
*
container
managed
by
a
FormLayout.
Required
to
determine
the
existing
constraint
*
values
as a precondition
to
computing
revised
constraints.
*
<p>
*
The
set
of
components
may
be
a
subset
of
all
components
in
the
container.
*
<p>
*
The
returned
map
must
contain
sufficient
information
to
allow
component/constraint
*
tuples
to
be
subsequently
identified
and
revised
with
new
constraint
values.
*
Example:
*
*
<pre>
*
Map
workMap
=
getConstraintMap(children);
*
workMap
=
shiftRightByOne(workMap);
*
updateConstraintsFromMap(children,
workMap);
*
</pre>
*
*
@param
children
*
a
List
of
components
in
a
container.
*
*
@return
a
Map
containing
component
keys
and
corresponding
cell
addresses.
*
*/
public Map
getConstraintsMap(List children) {
- ResourceSet rset =
JavaEditDomainHelper.getResourceSet(
policy.getEditDomain());
EReference sfConstraintConstraint =
JavaInstantiation.getReference(rset,
JFCConstants.SF_CONSTRAINT_CONSTRAINT);
EReference sfConstraintComponent =
JavaInstantiation.getReference(rset,
JFCConstants.SF_CONSTRAINT_COMPONENT);
EReference sfComponents = JavaInstantiation.getReference(rset,
JFCConstants.SF_CONTAINER_COMPONENTS);
// formlayout is defined by a column/row grid
Point p =
null;
// for each grid cell, p.x is the
column and p.y is the row
LinkedHashMap<IJavaInstance, Point> map =
new
LinkedHashMap<IJavaInstance, Point>();
Iterator childs =
children.iterator();
while (childs.hasNext()) {
- EObject constraintComponent =
InverseMaintenanceAdapter.getIntermediateReference((EObject)
getContainerBean(), sfComponents, sfConstraintComponent,(EObject)
childs.next());
if
(constraintComponent.eIsSet(sfConstraintComponent) && constraintComponent.eIsSet(sfConstraintConstraint)) {
- // get the component
- IJavaInstance constraintComponentAttributeValue = (IJavaInstance) constraintComponent.eGet(sfConstraintComponent);
- // then get the constraint
- IJavaInstance constraintConstraintAttributeValue = (IJavaInstance) constraintComponent.eGet(sfConstraintConstraint);
- // given that constraintAttributeValue represents a constraint object in source of the form:
- // new CellConstraints(int col, int row)
- // pull out the constructor parameter values
- int
col = ?????????(constraintConstraintAttributeValue, 0); // <<<< unknown part; get first parameter
- int
row = ?????????(constraintConstraintAttributeValue, 1); // <<<< unknown part; get second parameter
- p =
new Point(col, row);
- map.put(constraintComponentAttributeValue, p);
}
}
return map;
}
At 10:47 AM 6/5/2006, you wrote:
Third question is you don't need to use the inverse maintenance adapter to get the constraints. The Panel's (the parent container) "components" feature points to an intermidiate object that contains both the constraint and the child. Take a look at ContainerProxyAdapter.addComponentWithConstraint() method and where it was called from. It is called with the intermediate object (called a ConstraintComponent). The constraint components are the true value of the "components" setting on the parent. From the constraint component there are two other settings, one is the constraint and the other is the child control.
The call in addComponentWithConstraint:
if (constraintComponent.eIsSet(sfConstraintConstraint)) {
constraintAttributeValue = (IJavaInstance) constraintComponent.eGet(sfConstraintConstraint);
constraintIsSet = true;
}
is how you retrieve the constraint out of the constraint component. Do a search on where sfConstraintConstraint is is set to see how to get it.
PS: sfContainerComponents is the feature for getting the cooresponding child out of the constraint component.