Search in sources :

Example 1 with ContextValue

use of org.jboss.ide.eclipse.freemarker.configuration.ContextValue in project liferay-ide by liferay.

the class FreemarkerEditorHelper method openEditor.

@Override
public void openEditor(ISapphirePart sapphirePart, Element modelElement, ValueProperty valueProperty) {
    IProject project = sapphirePart.adapt(IProject.class);
    ConfigurationManager configManager = ConfigurationManager.getInstance(project);
    ContextValue[] contextValues = { new ContextValue(WorkflowContextConstants.SERVICE_CONTEXT, Map.class, Map.class), new ContextValue(WorkflowContextConstants.WORKFLOW_CONTEXT, Map.class, Map.class), new ContextValue(WorkflowContextConstants.ENTRY_CLASS_NAME, String.class, String.class), new ContextValue(WorkflowContextConstants.GROUP_ID, Long.class, Long.class), new ContextValue(WorkflowContextConstants.ENTRY_TYPE, String.class, String.class), new ContextValue(WorkflowContextConstants.USER_ID, Long.class, Long.class), new ContextValue(WorkflowContextConstants.TASK_COMMENTS, String.class, String.class), new ContextValue(WorkflowContextConstants.COMPANY_ID, Long.class, Long.class), new ContextValue(WorkflowContextConstants.ENTRY_CLASS_PK, Long.class, Long.class), new ContextValue(WorkflowContextConstants.TRANSITION_NAME, String.class, String.class), new ContextValue(WorkflowContextConstants.WORKFLOW_TASK_ASSIGNEES, List.class, List.class) };
    for (ContextValue cv : contextValues) {
        configManager.addContextValue(cv, project);
    }
    super.openEditor(sapphirePart, modelElement, valueProperty);
}
Also used : ContextValue(org.jboss.ide.eclipse.freemarker.configuration.ContextValue) List(java.util.List) ConfigurationManager(org.jboss.ide.eclipse.freemarker.configuration.ConfigurationManager) Map(java.util.Map) IProject(org.eclipse.core.resources.IProject)

Example 2 with ContextValue

use of org.jboss.ide.eclipse.freemarker.configuration.ContextValue in project liferay-ide by liferay.

the class NameFragment method getSingularReturnClass.

public Class getSingularReturnClass(Class parentClass, List fragments, Map context, IResource resource, IProject project) {
    if (null == singulaReturnClass) {
        String content = getContent();
        if (isStartFragment()) {
            ContextValue contextValue = ConfigurationManager.getInstance(project).getContextValue(content, resource, true);
            if (null == contextValue || null == contextValue.singularClass)
                singulaReturnClass = Object.class;
            else
                singulaReturnClass = contextValue.singularClass;
        } else {
            if (null == parentClass) {
                singulaReturnClass = Object.class;
            } else {
                content = Character.toUpperCase(content.charAt(1)) + content.substring(2, getContent().length());
                // $NON-NLS-1$
                String getcontent = "get" + content;
                for (int i = 0; i < parentClass.getMethods().length; i++) {
                    Method m = parentClass.getMethods()[i];
                    if (m.getName().equals(content) || m.getName().equals(getcontent)) {
                        Type type = m.getGenericReturnType();
                        if (type instanceof ParameterizedType) {
                            ParameterizedType pType = (ParameterizedType) type;
                            if (pType.getActualTypeArguments().length > 0) {
                                singulaReturnClass = (Class) pType.getActualTypeArguments()[0];
                                break;
                            }
                        }
                        singulaReturnClass = Object.class;
                        break;
                    }
                }
            }
        }
    }
    return singulaReturnClass;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ContextValue(org.jboss.ide.eclipse.freemarker.configuration.ContextValue) Method(java.lang.reflect.Method)

Example 3 with ContextValue

use of org.jboss.ide.eclipse.freemarker.configuration.ContextValue in project liferay-ide by liferay.

the class ContextValueDialog method okPressed.

protected void okPressed() {
    try {
        String name = keyText.getText().trim();
        // $NON-NLS-1$
        while (name.startsWith("$")) name = name.substring(1, name.length());
        if (name.length() == 0)
            MessageDialog.openError(getShell(), Messages.ContextValueDialog_ERROR, Messages.ContextValueDialog_MUST_CHOOSE_REFERENCE);
        String className = valueText.getText().trim();
        if (className.length() == 0)
            MessageDialog.openError(getShell(), Messages.ContextValueDialog_ERROR, Messages.ContextValueDialog_MUST_CHOOSE_CLASS);
        String singularClassName = singleValueText.getText().trim();
        Class singularClass = null;
        if (null != singularClassName && singularClassName.trim().length() > 0)
            singularClass = ConfigurationManager.getInstance(resource.getProject()).getClass(singularClassName);
        if (className.length() == 0)
            singularClassName = null;
        contextValue = new ContextValue(name, ConfigurationManager.getInstance(resource.getProject()).getClass(className), singularClass);
        ConfigurationManager.getInstance(resource.getProject()).addContextValue(contextValue, resource);
    } catch (Exception e) {
        MessageDialog.openError(getShell(), Messages.ContextValueDialog_ERROR, e.getMessage());
    }
    super.okPressed();
}
Also used : ContextValue(org.jboss.ide.eclipse.freemarker.configuration.ContextValue) JavaModelException(org.eclipse.jdt.core.JavaModelException)

Example 4 with ContextValue

use of org.jboss.ide.eclipse.freemarker.configuration.ContextValue in project liferay-ide by liferay.

the class CompletionProcessor method computeCompletionProposals.

public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    try {
        ItemSet directiveSet = editor.getItemSet();
        Map context = new HashMap();
        ContextValue[] values = ConfigurationManager.getInstance(editor.getProject()).getContextValues(editor.getFile(), true);
        for (int i = 0; i < values.length; i++) {
            context.put(values[i].name, values[i].objClass);
        }
        Item directive = directiveSet.getSelectedItem(offset);
        if (null != directive) {
            return directive.getCompletionProposals(offset, context);
        } else {
            // we might be starting something
            Item item = editor.getItemSet().getPreviousItem(offset);
            int topOffset = 0;
            if (null != item)
                topOffset = item.getRegion().getOffset() + item.getRegion().getLength();
            // check for directives and macro calls
            try {
                for (int i = offset - 1; i >= topOffset; i--) {
                    char c = editor.getDocument().getChar(i);
                    if (c == '>' || c == ']')
                        break;
                    if (c == '<' || c == '[') {
                        if (editor.getDocument().getLength() > i) {
                            char c2 = editor.getDocument().getChar(i + 1);
                            if (c2 == '#') {
                                CompletionDirective completionDirective = new CompletionDirective(i, offset - i, editor.getItemSet(), (ISourceViewer) viewer, (IResource) editor.getFile());
                                completionDirective.setItemSet(editor.getItemSet());
                                return completionDirective.getCompletionProposals(offset, context);
                            } else if (c2 == '@') {
                                CompletionMacroInstance completionMacroInstance = new CompletionMacroInstance(editor.getDocument().get(i, offset - i), i, editor.getItemSet(), editor.getFile());
                                completionMacroInstance.setItemSet(editor.getItemSet());
                                return completionMacroInstance.getCompletionProposals(offset, context);
                            } else if (c2 == '/') {
                                if (editor.getDocument().getLength() < i + 3 || editor.getDocument().getChar(i + 2) == ' ' || editor.getDocument().getChar(i + 2) == '\r' || editor.getDocument().getChar(i + 2) == '\n') {
                                    Item stackItem = editor.getItemSet().getPreviousStartItem(offset);
                                    StringBuffer value = new StringBuffer();
                                    if (null != stackItem && stackItem instanceof MacroInstance)
                                        // $NON-NLS-1$
                                        value.append("@");
                                    else
                                        // $NON-NLS-1$
                                        value.append("#");
                                    String name = null;
                                    if (null != stackItem)
                                        name = stackItem.getFirstToken();
                                    if (null != name)
                                        value.append(name);
                                    if (c == '<')
                                        value.append('>');
                                    else
                                        value.append(']');
                                    ICompletionProposal completionProposal = new CompletionProposal(value.toString(), offset, 0, offset + value.toString().length());
                                    return new ICompletionProposal[] { completionProposal };
                                }
                            } else {
                                return NO_COMPLETIONS;
                            }
                        }
                    }
                }
            } catch (BadLocationException e) {
                return NO_COMPLETIONS;
            }
            // check for interpolations
            try {
                for (int i = offset - 1; i >= topOffset; i--) {
                    char c = editor.getDocument().getChar(i);
                    if (c == '\n')
                        break;
                    else if (c == '$') {
                        if (editor.getDocument().getLength() > i) {
                            char c2 = editor.getDocument().getChar(i + 1);
                            if (c2 == '{') {
                                int j = offset;
                                while (editor.getDocument().getLength() > j) {
                                    char c3 = editor.getDocument().getChar(j);
                                    if (Character.isWhitespace(c3) || c3 == '(' || c3 == '.' || c3 == ')' || c3 == '}' || c3 == '?') {
                                        // j = j-1;
                                        break;
                                    }
                                    j++;
                                }
                                CompletionInterpolation interpolation = new CompletionInterpolation(editor.getDocument().get(i, j - i), i, editor.getItemSet(), editor.getFile());
                                interpolation.setParentItem(editor.getItemSet().getPreviousStartItem(offset));
                                return interpolation.getCompletionProposals(offset, context);
                            }
                        }
                    }
                }
            } catch (BadLocationException e) {
                return NO_COMPLETIONS;
            }
        }
    } catch (Exception e) {
        Plugin.log(e);
    }
    return NO_COMPLETIONS;
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) HashMap(java.util.HashMap) CompletionDirective(org.jboss.ide.eclipse.freemarker.model.CompletionDirective) CompletionMacroInstance(org.jboss.ide.eclipse.freemarker.model.CompletionMacroInstance) BadLocationException(org.eclipse.jface.text.BadLocationException) CompletionInterpolation(org.jboss.ide.eclipse.freemarker.model.CompletionInterpolation) Item(org.jboss.ide.eclipse.freemarker.model.Item) ItemSet(org.jboss.ide.eclipse.freemarker.model.ItemSet) ContextValue(org.jboss.ide.eclipse.freemarker.configuration.ContextValue) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionMacroInstance(org.jboss.ide.eclipse.freemarker.model.CompletionMacroInstance) MacroInstance(org.jboss.ide.eclipse.freemarker.model.MacroInstance) HashMap(java.util.HashMap) Map(java.util.Map) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 5 with ContextValue

use of org.jboss.ide.eclipse.freemarker.configuration.ContextValue in project liferay-ide by liferay.

the class ContextProperties method reloadContextValues.

public void reloadContextValues() {
    try {
        contextValuesTable.removeAll();
        ContextValue[] values = ConfigurationManager.getInstance(getResource().getProject()).getContextValues(getResource(), false);
        for (int i = 0; i < values.length; i++) {
            TableItem item = new TableItem(contextValuesTable, SWT.NULL);
            String[] arr = { values[i].name, values[i].objClass.getName() };
            item.setText(arr);
        }
        editContextValueButton.setEnabled(false);
        deleteContextValueButton.setEnabled(false);
    } catch (Exception e) {
        Plugin.log(e);
    }
    contextValuesTable.redraw();
}
Also used : ContextValue(org.jboss.ide.eclipse.freemarker.configuration.ContextValue) TableItem(org.eclipse.swt.widgets.TableItem)

Aggregations

ContextValue (org.jboss.ide.eclipse.freemarker.configuration.ContextValue)6 Map (java.util.Map)2 TableItem (org.eclipse.swt.widgets.TableItem)2 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IProject (org.eclipse.core.resources.IProject)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 PartInitException (org.eclipse.ui.PartInitException)1 ConfigurationManager (org.jboss.ide.eclipse.freemarker.configuration.ConfigurationManager)1 CompletionDirective (org.jboss.ide.eclipse.freemarker.model.CompletionDirective)1 CompletionInterpolation (org.jboss.ide.eclipse.freemarker.model.CompletionInterpolation)1 CompletionMacroInstance (org.jboss.ide.eclipse.freemarker.model.CompletionMacroInstance)1 Item (org.jboss.ide.eclipse.freemarker.model.Item)1 ItemSet (org.jboss.ide.eclipse.freemarker.model.ItemSet)1