Search in sources :

Example 1 with Scriptable

use of com.liferay.ide.kaleo.core.model.Scriptable in project liferay-ide by liferay.

the class ScriptPropertyStorage method getName.

@Override
public String getName() {
    Scriptable scriptable = element().nearest(Scriptable.class);
    Value<ScriptLanguageType> languageType = scriptable.getScriptLanguage();
    ScriptLanguageType scriptLanguageType = languageType.content(true);
    if (scriptLanguageType == null) {
        scriptLanguageType = ScriptLanguageType.valueOf(KaleoModelUtil.getDefaultValue(element(), KaleoCore.DEFAULT_SCRIPT_LANGUAGE_KEY, ScriptLanguageType.GROOVY));
    }
    DefaultValue defaultValue = ScriptLanguageType.class.getFields()[scriptLanguageType.ordinal()].getAnnotation(DefaultValue.class);
    return defaultValue.text();
}
Also used : DefaultValue(org.eclipse.sapphire.modeling.annotations.DefaultValue) ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable)

Example 2 with Scriptable

use of com.liferay.ide.kaleo.core.model.Scriptable in project liferay-ide by liferay.

the class KaleoModelUtil method changeTaskAssignments.

public static void changeTaskAssignments(Task task, AssignableOp op) {
    if ((task == null) || (op == null)) {
        return;
    }
    ElementHandle<User> user = task.getUser();
    user.clear();
    ElementHandle<Scriptable> scripteAssignment = task.getScriptedAssignment();
    scripteAssignment.clear();
    ElementList<ResourceAction> resourceAction = task.getResourceActions();
    resourceAction.clear();
    ElementList<Role> taskRole = task.getRoles();
    taskRole.clear();
    switch(op.getAssignmentType().content(true)) {
        case CREATOR:
            user.content(true);
            break;
        case USER:
            User content = user.content(true);
            content.copy(op.getImpliedUser());
            break;
        case ROLE:
            final Role newRole = taskRole.insert();
            newRole.copy(op.getImpliedRole());
            break;
        case ROLE_TYPE:
            for (Role role : op.getRoles()) {
                Role newRoleType = taskRole.insert();
                newRoleType.copy(role);
                Value<RoleType> roleType = role.getRoleType();
                newRoleType.setRoleType(roleType.content(true));
                Value<Boolean> autoCreate = role.getAutoCreate();
                if (autoCreate.content() != null) {
                    newRoleType.setAutoCreate(autoCreate.content());
                }
            }
            break;
        case SCRIPTED_ASSIGNMENT:
            Scriptable scriptable = scripteAssignment.content(true);
            Scriptable impliedScriptable = op.getImpliedScriptable();
            Value<ScriptLanguageType> scriptLanguageType = impliedScriptable.getScriptLanguage();
            scriptable.setScriptLanguage(scriptLanguageType.content(true));
            scriptable.setScript("/*specify script assignment */");
            break;
        case RESOURCE_ACTIONS:
            for (ResourceAction ra : op.getResourceActions()) {
                ResourceAction newResourceAction = resourceAction.insert();
                newResourceAction.copy(ra);
            }
            break;
    }
}
Also used : User(com.liferay.ide.kaleo.core.model.User) RoleType(com.liferay.ide.kaleo.core.model.RoleType) ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable) Role(com.liferay.ide.kaleo.core.model.Role) ResourceAction(com.liferay.ide.kaleo.core.model.ResourceAction)

Example 3 with Scriptable

use of com.liferay.ide.kaleo.core.model.Scriptable 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 4 with Scriptable

use of com.liferay.ide.kaleo.core.model.Scriptable in project liferay-ide by liferay.

the class EditScriptActionHandler method edit.

@Override
public Object edit(Element modelElement, Presentation context) {
    Scriptable scriptable = modelElement.nearest(Scriptable.class);
    IKaleoEditorHelper kaleoEditorHelper = KaleoUI.getKaleoEditorHelper(scriptable.getScriptLanguage().text(true));
    kaleoEditorHelper.openEditor(context.part(), scriptable, Action.PROP_SCRIPT);
    return null;
}
Also used : IKaleoEditorHelper(com.liferay.ide.kaleo.ui.IKaleoEditorHelper) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable)

Example 5 with Scriptable

use of com.liferay.ide.kaleo.core.model.Scriptable in project liferay-ide by liferay.

the class ScriptableOpenActionHandler method scriptable.

protected Scriptable scriptable(Presentation context) {
    Scriptable retval = null;
    ISapphirePart part = context.part();
    if (part instanceof DetailSectionPart) {
        DetailSectionPart pageBook = part.nearest(DetailSectionPart.class);
        FormPart currentPage = pageBook.getCurrentPage();
        Element element = currentPage.getLocalModelElement();
        retval = element.nearest(Scriptable.class);
    } else {
        Element modelElement = context.part().getLocalModelElement();
        if (modelElement instanceof Task) {
            Task task = modelElement.nearest(Task.class);
            ElementHandle<Scriptable> scriptable = task.getScriptedAssignment();
            retval = scriptable.content(false);
        } else {
            retval = modelElement.nearest(Scriptable.class);
        }
    }
    return retval;
}
Also used : Task(com.liferay.ide.kaleo.core.model.Task) FormPart(org.eclipse.sapphire.ui.forms.FormPart) Element(org.eclipse.sapphire.Element) ISapphirePart(org.eclipse.sapphire.ui.ISapphirePart) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable) DetailSectionPart(org.eclipse.sapphire.ui.forms.DetailSectionPart)

Aggregations

Scriptable (com.liferay.ide.kaleo.core.model.Scriptable)11 ScriptLanguageType (com.liferay.ide.kaleo.core.model.ScriptLanguageType)5 ResourceAction (com.liferay.ide.kaleo.core.model.ResourceAction)3 Role (com.liferay.ide.kaleo.core.model.Role)3 User (com.liferay.ide.kaleo.core.model.User)3 Assignable (com.liferay.ide.kaleo.core.model.Assignable)2 Task (com.liferay.ide.kaleo.core.model.Task)2 IKaleoEditorHelper (com.liferay.ide.kaleo.ui.IKaleoEditorHelper)2 Element (org.eclipse.sapphire.Element)2 Action (com.liferay.ide.kaleo.core.model.Action)1 RoleName (com.liferay.ide.kaleo.core.model.RoleName)1 RoleType (com.liferay.ide.kaleo.core.model.RoleType)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 Field (java.lang.reflect.Field)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 ElementHandle (org.eclipse.sapphire.ElementHandle)1 Event (org.eclipse.sapphire.Event)1 FilteredListener (org.eclipse.sapphire.FilteredListener)1