use of com.liferay.ide.kaleo.core.model.WorkflowNode in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _handleConnectionBendpointChange.
private void _handleConnectionBendpointChange(Transition transition) {
ConnectionService connService = _part().service(ConnectionService.class);
DiagramConnectionPart connPart = _getConnectionPart(connService, transition);
if (connPart != null) {
List<Point> bendpoints = new ArrayList<>();
WorkflowNode wfNode = transition.nearest(WorkflowNode.class);
ElementHandle<WorkflowNodeMetadata> nodeMetadata = wfNode.getMetadata();
WorkflowNodeMetadata metadata = nodeMetadata.content(false);
TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, metadata);
for (ConnectionBendpoint bendpoint : transitionMetadata.getBendpoints()) {
bendpoints.add(new Point(bendpoint.getX().content(), bendpoint.getY().content()));
}
connPart.resetBendpoints(bendpoints);
}
}
use of com.liferay.ide.kaleo.core.model.WorkflowNode in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _writeTransitionBendPoints.
private void _writeTransitionBendPoints(Transition transition, DiagramConnectionPart connPart) {
WorkflowNode workflowNode = transition.nearest(WorkflowNode.class);
ElementHandle<WorkflowNodeMetadata> nodeMetadata = workflowNode.getMetadata();
WorkflowNodeMetadata metadata = nodeMetadata.content(true);
TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, metadata, true);
transitionMetadata.setName(transition.getName().content());
ElementList<ConnectionBendpoint> bendpointsInMetadataList = transitionMetadata.getBendpoints();
int bendpointsInMetadataSize = bendpointsInMetadataList.size();
List<Point> bendpointsInPartList = connPart.getBendpoints();
int bendpointsInPartSize = bendpointsInPartList.size();
for (int i = 0, n = min(bendpointsInMetadataSize, bendpointsInPartSize); i < n; i++) {
ConnectionBendpoint bendpointInMetadata = bendpointsInMetadataList.get(i);
Point bendpointInPart = bendpointsInPartList.get(i);
if (bendpointInMetadata.getX().content() != bendpointInPart.getX()) {
bendpointInMetadata.setX(bendpointInPart.getX());
}
if (bendpointInMetadata.getY().content() != bendpointInPart.getY()) {
bendpointInMetadata.setY(bendpointInPart.getY());
}
}
if (bendpointsInMetadataSize < bendpointsInPartSize) {
for (int i = bendpointsInMetadataSize; i < bendpointsInPartSize; i++) {
ConnectionBendpoint bendpointInMetadata = bendpointsInMetadataList.insert();
Point bendpointInPart = bendpointsInPartList.get(i);
bendpointInMetadata.setX(bendpointInPart.getX());
bendpointInMetadata.setY(bendpointInPart.getY());
}
} else if (bendpointsInMetadataSize > bendpointsInPartSize) {
for (int i = bendpointsInMetadataSize - 1; i >= bendpointsInPartSize; i--) {
bendpointsInMetadataList.remove(i);
}
}
if ((connPart.getLabelPosition() != null) && !connPart.getLabelPosition().equals(DEFAULT_POINT)) {
transitionMetadata.getLabelLocation().setX(connPart.getLabelPosition().getX());
transitionMetadata.getLabelLocation().setY(connPart.getLabelPosition().getY());
}
}
use of com.liferay.ide.kaleo.core.model.WorkflowNode in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _read.
private void _read(DiagramNodePart nodePart) {
WorkflowNode workflowNode = nodePart.getLocalModelElement().nearest(WorkflowNode.class);
if (!workflowNode.disposed()) {
WorkflowNodeMetadata metadata = workflowNode.getMetadata().content();
Position position = metadata.getPosition();
Value<Integer> valueX = position.getX();
Value<Integer> valueY = position.getY();
if ((valueX.content() != -1) && (valueY.content() != -1)) {
_writeWorkflowNodeMetaDataToBounds(metadata, nodePart);
}
String nodeId = nodePart.getId();
if (_nodeBounds.containsKey(nodeId) && (_nodeBounds.get(nodeId) != null)) {
nodePart.setNodeBounds(_nodeBounds.get(nodeId));
} else {
_nodeBounds.put(nodeId, nodePart.getNodeBounds());
}
}
/*
* handle the case where a transition is added and its target node
* hasn't been. keep the transitions in a map and every time a new node
* is added, check if it is a target of unconnected transitions,
* reconnect the DiagramConnectionPart
*/
SapphireDiagramEditorPagePart part = _part();
ConnectionService connService = part.service(ConnectionService.class);
if (workflowNode instanceof CanTransition) {
CanTransition canTransition = (CanTransition) workflowNode;
for (Transition transition : canTransition.getTransitions()) {
if (transition.getTarget().target() == null) {
if (!_unconnectedTransitions.containsKey(transition.getTarget().content())) {
_unconnectedTransitions.put(transition.getTarget().content(), new LinkedList<Transition>());
}
if (!transition.disposed()) {
_unconnectedTransitions.get(transition.getTarget().content()).add(transition);
}
}
}
}
if (_unconnectedTransitions.containsKey(workflowNode.getName().content())) {
List<Transition> transitions = _unconnectedTransitions.get(workflowNode.getName().content());
for (Transition transition : transitions) {
DiagramConnectionPart connPart = _getConnectionPart(connService, transition);
DiagramNodePart nodePart1 = part.getDiagramNodePart(transition.nearest(WorkflowNode.class));
DiagramNodePart nodePart2 = part.getDiagramNodePart(workflowNode);
connPart.reconnect(nodePart1, nodePart2);
/*
* sometimes the reconnect doesn't work, an alternative way is
* to remove it and create a new one if( connPart != null ) {
* connPart.remove(); }
*
* connService.connect( nodePart1, nodePart2, "Transition" );
*/
}
_unconnectedTransitions.remove(workflowNode.getName().content());
}
}
use of com.liferay.ide.kaleo.core.model.WorkflowNode in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _write.
private void _write(DiagramNodePart nodePart) {
WorkflowNode workflowNode = nodePart.getLocalModelElement().nearest(WorkflowNode.class);
if (!workflowNode.disposed()) {
if (_isNodeLayoutChanged(nodePart)) {
_removeWorkflowNodeListeners();
_writeWorkflowNodeBoundsToMetaData(workflowNode, nodePart);
_addWorkflowNodeListeners();
}
_refreshDirtyState();
}
}
use of com.liferay.ide.kaleo.core.model.WorkflowNode in project liferay-ide by liferay.
the class ChangeTaskAssignmentsActionHandler method run.
@Override
protected Object run(Presentation context) {
Task task = _task(context);
ChangeTaskAssignmentsOp op = ChangeTaskAssignmentsOp.TYPE.instantiate();
for (WorkflowNode node : task.nearest(WorkflowDefinition.class).getDiagramNodes()) {
Assignable assignable = node.nearest(Assignable.class);
if (assignable != null) {
for (Role role : assignable.getRoles()) {
String name = role.getName().content(false);
if (!isNullOrEmpty(name)) {
ElementList<RoleName> roleName = op.getRoleNames();
roleName.insert().setName(name);
}
}
}
}
User existingUser = task.getUser().content(false);
ElementList<Role> existingRoles = task.getRoles();
ElementList<ResourceAction> existingActions = task.getResourceActions();
Scriptable scriptedAssignment = task.getScriptedAssignment().content(false);
if (existingUser != null) {
op.getImpliedUser().copy(existingUser);
} else if (ListUtil.isNotEmpty(existingRoles)) {
op.getImpliedRole().copy(existingRoles.get(0));
for (Role role : existingRoles) {
Role newRole = op.getRoles().insert();
newRole.copy(role);
Boolean autoCreate = role.getAutoCreate().content(false);
if (autoCreate != null) {
newRole.setAutoCreate(role.getAutoCreate().content());
}
}
} else if (ListUtil.isNotEmpty(existingActions)) {
for (ResourceAction action : existingActions) {
ElementList<ResourceAction> resourceActions = op.getResourceActions();
ResourceAction resourceAction = resourceActions.insert();
resourceAction.copy(action);
}
} else if (scriptedAssignment != null) {
ElementHandle<Scriptable> scriptable = op.getScriptedAssignment();
Scriptable content = scriptable.content(true);
content.copy(scriptedAssignment);
}
DefinitionLoader loader = DefinitionLoader.context(NewWorkflowDefinitionWizard.class);
DefinitionLoader loaderSdef = loader.sdef("WorkflowDefinitionWizards");
SapphireWizard<ChangeTaskAssignmentsOp> wizard = new SapphireWizard<>(op, loaderSdef.wizard("changeTaskAssignmentsWizard"));
int returnCode = new WizardDialog(((SwtPresentation) context).shell(), wizard).open();
if (returnCode == IDialogConstants.OK_ID) {
KaleoModelUtil.changeTaskAssignments(_task(context), op);
}
return null;
}
Aggregations