-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Hi Ralph, The fact that the node provides resize handles suggests that it is already defined as "resizable". What you need to check first is:
With the updated layouts, I would expect:
|
Beta Was this translation helpful? Give feedback.
-
Hi, The "prefWidth/height" layout options are not to be defined in the Node Builder; they are the variable that you manipulate when resizing the node via the resize handle. They shouldn't be hardcoded. They need to be set by the (BPMN)ChangeBoundsOperationHandler. Here's how it's done for the default GLSP implementation: public class ChangeBoundsOperationHandler extends AbstractOperationHandler<ChangeBoundsOperation> {
[...]
protected void changeElementBounds(final String elementId, final GPoint newPosition, final GDimension newSize) {
[...]
if (nodeToUpdate.getLayout() != null) {
nodeToUpdate.getLayoutOptions().put(GLayoutOptions.KEY_PREF_WIDTH, newSize.getWidth());
nodeToUpdate.getLayoutOptions().put(GLayoutOptions.KEY_PREF_HEIGHT, newSize.getHeight());
}
nodeToUpdate.setSize(newSize);
nodeToUpdate.setPosition(positionToSet);
}
} |
Beta Was this translation helpful? Give feedback.
-
Ok, everything is now working and I just want to provide a complete code example here (if someone finds this discussion helpful) The Builder Class In the Builder Class the method public class TaskNodeBuilder extends AbstractGNodeBuilder<TaskNode, TaskNodeBuilder> {
private final String name;
public TaskNodeBuilder(final String type, final String name) {
super(type);
this.name = name;
}
.....
@Override
public void setProperties(final TaskNode node) {
super.setProperties(node);
node.setName(name);
node.setLayout(GConstants.Layout.HBOX);
// Set min width/height defaults
node.getLayoutOptions().put(GLayoutOptions.KEY_MIN_WIDTH, BPMNActivity.DEFAULT_WIDTH);
node.getLayoutOptions().put(GLayoutOptions.KEY_MIN_HEIGHT, BPMNActivity.DEFAULT_HEIGHT);
// Set actual width/height
node.getLayoutOptions().put(GLayoutOptions.KEY_PREF_WIDTH, size.getWidth());
node.getLayoutOptions().put(GLayoutOptions.KEY_PREF_HEIGHT, size.getHeight());
...
}
....
} The Model Factory In the public class BPMNGModelFactory implements GModelFactory {
private static Logger logger = Logger.getLogger(BPMNGModelFactory.class.getName());
@Inject
protected BPMNGModelState modelState;
@Override
public void createGModel() {
...
// compute position....
BPMNPoint bpmnPoint = activity.getBounds().getPosition();
GPoint point = GraphUtil.point(bpmnPoint.getX(), bpmnPoint.getY());
// compute the dimension...
GDimension dimension = GraphUtil.dimension(activity.getBounds().getDimension().getWidth(),
activity.getBounds().getDimension().getHeight());
// call the builder..
TaskNodeBuilder builder = new TaskNodeBuilder(activity.getType(), activity.getName());
// Build the GLSP Node....
TaskNode taskNode = builder //
.id(activity.getId()) //
.position(point) //
.size(dimension) // the size is used by the builder to adjust prevWidth/height
.build();
.....
} The BPMNChangeBoundsOperationHandler And finally we use a public class BPMNChangeBoundsOperationHandler extends AbstractOperationHandler<ChangeBoundsOperation> {
@Inject
protected BPMNGModelState modelState;
@Override
public void executeOperation(final ChangeBoundsOperation operation) {
BPMNProcess context = modelState.getBpmnModel().getContext();
// iterate over all new Bounds...
try {
List<ElementAndBounds> elementBounds = operation.getNewBounds();
for (ElementAndBounds elementBound : elementBounds) {
String id = elementBound.getElementId();
GPoint newPoint = elementBound.getNewPosition();
GDimension newSize = elementBound.getNewSize();
// find the corresponding BPMN source element and GNode element
BPMNFlowElement bpmnFlowElement = context.findBPMNFlowElementById(id);
if (bpmnFlowElement != null) {
GNode gNode = null;
Optional<GNode> _node = modelState.getIndex().findElementByClass(id, GNode.class);
if (_node.isPresent()) {
gNode = _node.get();
} else {
// this case should not happen!
logger.warning("Node Element '" + id + "' not found in current modelState!");
continue;
}
// update BPMNElement position....
BPMNBounds bpmnBounds = bpmnFlowElement.getBounds();
bpmnBounds.updateLocation(newPoint.getX(), newPoint.getY());
// update GNode position....
gNode.setPosition(newPoint);
// update BPMNElement dimension....
bpmnBounds.updateDimension(newSize.getWidth(), newSize.getHeight());
// Update GNode dimension....
gNode.getLayoutOptions().put(GLayoutOptions.KEY_PREF_WIDTH, newSize.getWidth());
gNode.getLayoutOptions().put(GLayoutOptions.KEY_PREF_HEIGHT, newSize.getHeight());
gNode.setSize(newSize); // has no effect for VBox/HBox
}
}
} catch (BPMNMissingElementException e) {
e.printStackTrace();
}
// no more action - the GModel is now up to date
}
} |
Beta Was this translation helpful? Give feedback.
Ok, everything is now working and I just want to provide a complete code example here (if someone finds this discussion helpful)
The Builder Class
In the Builder Class the method
setProperties
is used to set the prevWidth/height for the node given by thesize
object: