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();
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations