Search in sources :

Example 1 with ScriptLanguageType

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

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

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

the class CodePropertyEditorRenderer method createContents.

@Override
protected void createContents(Composite parent) {
    PropertyEditorPart part = getPart();
    Composite scriptEditorParent = createMainComposite(parent, new CreateMainCompositeDelegate(part) {

        @Override
        public boolean canScaleVertically() {
            return true;
        }
    });
    context.adapt(scriptEditorParent);
    int textFieldParentColumns = 1;
    SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation(getActionPresentationManager());
    boolean actionsToolBarNeeded = toolBarActionsPresentation.hasActions();
    if (actionsToolBarNeeded || true)
        textFieldParentColumns++;
    scriptEditorParent.setLayout(glayout(textFieldParentColumns, 0, 0, 0, 0));
    Composite nestedComposite = new Composite(scriptEditorParent, SWT.NONE);
    nestedComposite.setLayoutData(gdfill());
    nestedComposite.setLayout(glspacing(glayout(2, 0, 0), 2));
    this.context.adapt(nestedComposite);
    PropertyEditorAssistDecorator decorator = createDecorator(nestedComposite);
    decorator.control().setLayoutData(gdvalign(gd(), SWT.TOP));
    decorator.addEditorControl(nestedComposite);
    /*
		 * scriptEditorParent.setLayout( new FillLayout( SWT.HORIZONTAL ) );
		 * scriptEditorParent.setLayoutData( gdhhint( gdfill(), 300 ) );
		 */
    PropertyEditorInput editorInput = new PropertyEditorInput(part.getLocalModelElement(), (ValueProperty) part.getProperty());
    try {
        ScriptLanguageType scriptLang = context.getPart().getLocalModelElement().nearest(IScriptable.class).getScriptLanguage().getContent(false);
        String fileName = scriptLang.getClass().getField(scriptLang.toString()).getAnnotation(DefaultValue.class).text();
        IContentDescription contentDescription = ContentTypeManager.getInstance().getDescriptionFor(editorInput.getStorage().getContents(), fileName, IContentDescription.ALL);
        EditorDescriptor defaultEditor = (EditorDescriptor) PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(editorInput.getName(), contentDescription.getContentType());
        _textEditor = (ITextEditor) defaultEditor.createEditor();
    } catch (Exception e1) {
    }
    IEditorReference ref = new ScriptEditorReference(_textEditor, editorInput);
    IEditorSite site = new ScriptEditorSite(ref, _textEditor, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage());
    try {
        _textEditor.init(site, editorInput);
        _textEditor.getDocumentProvider().getDocument(editorInput).addDocumentListener(new IDocumentListener() {

            public void documentAboutToBeChanged(DocumentEvent event) {
            }

            public void documentChanged(DocumentEvent event) {
                String content = event.getDocument().get();
                part.getLocalModelElement().write(((ValueProperty) part.getProperty()), content);
            }
        });
        ModelPropertyListener modelListener = new ModelPropertyListener() {

            @Override
            public void handlePropertyChangedEvent(ModelPropertyChangeEvent event) {
                CodePropertyEditorRenderer.this.textEditor.getDocumentProvider().getDocument(editorInput).set(part.getLocalModelElement().read(getProperty()).getText());
            }
        };
        part.getLocalModelElement().addListener(modelListener, part.getProperty().getName());
    } catch (PartInitException pie) {
        pie.printStackTrace();
    }
    Control[] prevChildren = scriptEditorParent.getChildren();
    // _textEditor.createPartControl( scriptEditorParent );
    new Label(scriptEditorParent, SWT.NONE);
    Control[] newChildren = scriptEditorParent.getChildren();
    decorator.addEditorControl(newChildren[prevChildren.length], true);
    if (actionsToolBarNeeded) {
        ToolBar toolbar = new ToolBar(scriptEditorParent, SWT.FLAT | SWT.HORIZONTAL);
        toolbar.setLayoutData(gdvfill());
        toolBarActionsPresentation.setToolBar(toolbar);
        toolBarActionsPresentation.render();
        context.adapt(toolbar);
        decorator.addEditorControl(toolbar);
    // relatedControls.add( toolbar );
    }
}
Also used : Label(org.eclipse.swt.widgets.Label) ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) PropertyEditorAssistDecorator(org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator) DefaultValue(org.eclipse.sapphire.modeling.annotations.DefaultValue) Control(org.eclipse.swt.widgets.Control) IEditorReference(org.eclipse.ui.IEditorReference) PartInitException(org.eclipse.ui.PartInitException) IContentDescription(org.eclipse.core.runtime.content.IContentDescription) PropertyEditorPart(org.eclipse.sapphire.ui.PropertyEditorPart) ModelPropertyChangeEvent(org.eclipse.sapphire.modeling.ModelPropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) IDocumentListener(org.eclipse.jface.text.IDocumentListener) DocumentEvent(org.eclipse.jface.text.DocumentEvent) EditorDescriptor(org.eclipse.ui.internal.registry.EditorDescriptor) PartInitException(org.eclipse.ui.PartInitException) SapphireToolBarActionPresentation(org.eclipse.sapphire.ui.swt.renderer.SapphireToolBarActionPresentation) ModelPropertyListener(org.eclipse.sapphire.modeling.ModelPropertyListener) ToolBar(org.eclipse.swt.widgets.ToolBar) IEditorSite(org.eclipse.ui.IEditorSite)

Example 4 with ScriptLanguageType

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

the class ScriptPropertyEditorCondition method evaluate.

@Override
protected boolean evaluate() {
    if (_paramType != null) {
        Scriptable scriptable = _scriptable();
        ScriptLanguageType scriptLanguageType = scriptable.getScriptLanguage().content(true);
        if (scriptLanguageType == null) {
            scriptLanguageType = ScriptLanguageType.valueOf(KaleoModelUtil.getDefaultValue(scriptable, KaleoCore.DEFAULT_SCRIPT_LANGUAGE_KEY, ScriptLanguageType.GROOVY));
        }
        if (_paramType.equals(scriptLanguageType)) {
            return true;
        }
    }
    return false;
}
Also used : ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable)

Example 5 with ScriptLanguageType

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

the class ScriptPropertyEditorInput method getScriptLanguage.

public String getScriptLanguage() {
    String retval = null;
    try {
        Scriptable scriptable = _modelElement.nearest(Scriptable.class);
        Value<ScriptLanguageType> languageType = scriptable.getScriptLanguage();
        ScriptLanguageType scriptType = languageType.content();
        Class<?> scriptTypeClass = scriptType.getClass();
        Field field = scriptTypeClass.getFields()[scriptType.ordinal()];
        EnumSerialization enumValue = field.getAnnotation(EnumSerialization.class);
        retval = enumValue.primary();
    } catch (Exception e) {
    }
    return retval;
}
Also used : Field(java.lang.reflect.Field) EnumSerialization(org.eclipse.sapphire.modeling.annotations.EnumSerialization) ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable)

Aggregations

ScriptLanguageType (com.liferay.ide.kaleo.core.model.ScriptLanguageType)7 Scriptable (com.liferay.ide.kaleo.core.model.Scriptable)5 ResourceAction (com.liferay.ide.kaleo.core.model.ResourceAction)2 Role (com.liferay.ide.kaleo.core.model.Role)2 User (com.liferay.ide.kaleo.core.model.User)2 DefaultValue (org.eclipse.sapphire.modeling.annotations.DefaultValue)2 Action (com.liferay.ide.kaleo.core.model.Action)1 Assignable (com.liferay.ide.kaleo.core.model.Assignable)1 Position (com.liferay.ide.kaleo.core.model.Position)1 RoleType (com.liferay.ide.kaleo.core.model.RoleType)1 State (com.liferay.ide.kaleo.core.model.State)1 Task (com.liferay.ide.kaleo.core.model.Task)1 TemplateLanguageType (com.liferay.ide.kaleo.core.model.TemplateLanguageType)1 Transition (com.liferay.ide.kaleo.core.model.Transition)1 TransitionMetadata (com.liferay.ide.kaleo.core.model.TransitionMetadata)1 WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)1 WorkflowNodeMetadata (com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Field (java.lang.reflect.Field)1 IContainer (org.eclipse.core.resources.IContainer)1