Search in sources :

Example 1 with SapphireWizard

use of org.eclipse.sapphire.ui.forms.swt.SapphireWizard 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;
}
Also used : SapphireWizard(org.eclipse.sapphire.ui.forms.swt.SapphireWizard) Task(com.liferay.ide.kaleo.core.model.Task) User(com.liferay.ide.kaleo.core.model.User) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) Role(com.liferay.ide.kaleo.core.model.Role) RoleName(com.liferay.ide.kaleo.core.model.RoleName) DefinitionLoader(org.eclipse.sapphire.ui.def.DefinitionLoader) ElementHandle(org.eclipse.sapphire.ElementHandle) SwtPresentation(org.eclipse.sapphire.ui.forms.swt.SwtPresentation) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ChangeTaskAssignmentsOp(com.liferay.ide.kaleo.core.op.ChangeTaskAssignmentsOp) Assignable(com.liferay.ide.kaleo.core.model.Assignable) ResourceAction(com.liferay.ide.kaleo.core.model.ResourceAction)

Aggregations

Assignable (com.liferay.ide.kaleo.core.model.Assignable)1 ResourceAction (com.liferay.ide.kaleo.core.model.ResourceAction)1 Role (com.liferay.ide.kaleo.core.model.Role)1 RoleName (com.liferay.ide.kaleo.core.model.RoleName)1 Scriptable (com.liferay.ide.kaleo.core.model.Scriptable)1 Task (com.liferay.ide.kaleo.core.model.Task)1 User (com.liferay.ide.kaleo.core.model.User)1 WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)1 WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)1 ChangeTaskAssignmentsOp (com.liferay.ide.kaleo.core.op.ChangeTaskAssignmentsOp)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 ElementHandle (org.eclipse.sapphire.ElementHandle)1 DefinitionLoader (org.eclipse.sapphire.ui.def.DefinitionLoader)1 SapphireWizard (org.eclipse.sapphire.ui.forms.swt.SapphireWizard)1 SwtPresentation (org.eclipse.sapphire.ui.forms.swt.SwtPresentation)1