Search in sources :

Example 1 with ElementHandle

use of org.eclipse.sapphire.ElementHandle 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)

Example 2 with ElementHandle

use of org.eclipse.sapphire.ElementHandle in project liferay-ide by liferay.

the class EmailAddressValidationService method _getSchemaVersion.

private Version _getSchemaVersion() {
    Version schemaVersion = new Version(KaleoCore.DEFAULT_KALEO_VERSION);
    if (context(WorkflowDefinition.class) != null) {
        WorkflowDefinition workflowDefinition = context(WorkflowDefinition.class);
        Value<Version> version = workflowDefinition.getSchemaVersion();
        schemaVersion = version.content();
    } else if (context(NewNodeOp.class) != null) {
        NewNodeOp newNodeOp = context(NewNodeOp.class);
        ElementHandle<WorkflowDefinition> workflowDef = newNodeOp.getWorkflowDefinition();
        WorkflowDefinition workflowDefinition = workflowDef.content();
        Value<Version> version = workflowDefinition.getSchemaVersion();
        schemaVersion = version.content();
    } else if (context(NewWorkflowDefinitionOp.class) != null) {
        NewWorkflowDefinitionOp newWorkflowDenitionOp = context(NewWorkflowDefinitionOp.class);
        ReferenceValue<String, IProject> opProject = newWorkflowDenitionOp.getProject();
        IProject project = opProject.target();
        ILiferayProject liferayProj = LiferayCore.create(project);
        ILiferayPortal portal = liferayProj.adapt(ILiferayPortal.class);
        if (portal != null) {
            schemaVersion = new Version(portal.getVersion());
        }
    }
    return schemaVersion;
}
Also used : Version(org.eclipse.sapphire.Version) ILiferayProject(com.liferay.ide.core.ILiferayProject) NewNodeOp(com.liferay.ide.kaleo.core.op.NewNodeOp) ReferenceValue(org.eclipse.sapphire.ReferenceValue) Value(org.eclipse.sapphire.Value) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) ElementHandle(org.eclipse.sapphire.ElementHandle) NewWorkflowDefinitionOp(com.liferay.ide.kaleo.core.op.NewWorkflowDefinitionOp) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) IProject(org.eclipse.core.resources.IProject)

Aggregations

WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)2 ElementHandle (org.eclipse.sapphire.ElementHandle)2 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)1 ILiferayProject (com.liferay.ide.core.ILiferayProject)1 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 WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)1 ChangeTaskAssignmentsOp (com.liferay.ide.kaleo.core.op.ChangeTaskAssignmentsOp)1 NewNodeOp (com.liferay.ide.kaleo.core.op.NewNodeOp)1 NewWorkflowDefinitionOp (com.liferay.ide.kaleo.core.op.NewWorkflowDefinitionOp)1 IProject (org.eclipse.core.resources.IProject)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 ReferenceValue (org.eclipse.sapphire.ReferenceValue)1 Value (org.eclipse.sapphire.Value)1 Version (org.eclipse.sapphire.Version)1