Search in sources :

Example 1 with UICustomAction

use of com.twinsoft.convertigo.beans.mobile.components.UICustomAction in project convertigo by convertigo.

the class MobilePickerComposite method lookupModelData.

private Map<String, Object> lookupModelData(TVObject tvObject) {
    Map<String, Object> data = new HashMap<String, Object>();
    Map<String, String> params = new HashMap<String, String>();
    DatabaseObject dbo = null;
    String searchPath = "";
    Object object = tvObject.getObject();
    JSONObject infos = tvObject.getInfos();
    if (object != null) {
        try {
            if (object instanceof RequestableObject) {
                dbo = (RequestableObject) object;
                searchPath = "";
            } else if (object instanceof DesignDocument) {
                dbo = (DesignDocument) object;
                DesignDocument dd = (DesignDocument) dbo;
                params.put("ddoc", dd.getName());
                params.put("view", tvObject.getParent().getName());
                params.put("include_docs", infos.has("include_docs") ? infos.getString("include_docs") : "false");
                searchPath = tvObject.getName().startsWith("get") ? ".rows.value" : "";
            } else if (object instanceof UIControlDirective) {
                dbo = (UIControlDirective) object;
                do {
                    UIControlDirective directive = (UIControlDirective) dbo;
                    String rootDboName = "";
                    if (directive.getPage() != null) {
                        rootDboName = directive.getPage().getName();
                    } else if (directive.getMenu() != null) {
                        rootDboName = directive.getMenu().getName();
                    }
                    MobileSmartSourceType msst = directive.getSourceSmartType();
                    MobileSmartSource mss = msst.getSmartSource();
                    if (mss != null) {
                        dbo = mss.getDatabaseObject(rootDboName);
                        params.putAll(mss.getParameters());
                        searchPath = mss.getModelPath().replaceAll("\\?\\.", ".") + searchPath;
                    } else {
                        dbo = null;
                    }
                } while (dbo != null && dbo instanceof UIControlDirective);
            } else if (object instanceof UIForm) {
                dbo = (UIForm) object;
                searchPath = "";
            } else if (object instanceof ApplicationComponent) {
                dbo = (ApplicationComponent) object;
                params.put("json", infos.toString());
                searchPath = "";
            } else if (object instanceof UIActionStack) {
                dbo = (UIActionStack) object;
                searchPath = "";
            } else if (object instanceof IAction) {
                if (object instanceof UIDynamicAction) {
                    dbo = (UIDynamicAction) object;
                    searchPath = "";
                } else if (object instanceof UICustomAction) {
                    dbo = (UICustomAction) object;
                    searchPath = "";
                }
            } else if (object instanceof UISharedComponent) {
                dbo = (UISharedComponent) object;
                searchPath = "";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    data.put("databaseObject", dbo);
    data.put("params", params);
    data.put("searchPath", searchPath);
    return data;
}
Also used : RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) IAction(com.twinsoft.convertigo.beans.mobile.components.IAction) HashMap(java.util.HashMap) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) UIControlDirective(com.twinsoft.convertigo.beans.mobile.components.UIControlDirective) UIForm(com.twinsoft.convertigo.beans.mobile.components.UIForm) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) PartInitException(org.eclipse.ui.PartInitException) JSONException(org.codehaus.jettison.json.JSONException) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) MobileSmartSource(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource) UIDynamicAction(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) JSONObject(org.codehaus.jettison.json.JSONObject) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UICustomAction(com.twinsoft.convertigo.beans.mobile.components.UICustomAction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject) TVObject(com.twinsoft.convertigo.eclipse.views.mobile.MobilePickerContentProvider.TVObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) MobilePageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePageComponentTreeObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject)

Example 2 with UICustomAction

use of com.twinsoft.convertigo.beans.mobile.components.UICustomAction in project convertigo by convertigo.

the class MobileUIComponentTreeObject method editFunction.

private void editFunction(final UIComponent uic, final String functionMarker, final String propertyName) {
    try {
        IScriptComponent main = uic.getMainScriptComponent();
        if (main == null) {
            return;
        }
        // Refresh project resources for editor
        String projectName = uic.getProject().getName();
        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
        // Close editor and Reopen it after file has been rewritten
        String relativePath = uic.getProject().getMobileBuilder().getFunctionTempTsRelativePath(uic);
        IFile file = project.getFile(relativePath);
        if (!(uic instanceof UICustomAction)) {
            closeComponentFileEditor(file);
        }
        if (main instanceof ApplicationComponent) {
            if (uic.compareToTplVersion("7.5.2.0") < 0) {
                ConvertigoPlugin.logError("The ability to use forms or actions inside a menu is avalaible since 7.5.2 version." + "\nPlease change your Template project for the 'mobilebuilder_tpl_7_5_2' template.", true);
                return;
            }
        }
        uic.getProject().getMobileBuilder().writeFunctionTempTsFile(uic, functionMarker);
        file.refreshLocal(IResource.DEPTH_ZERO, null);
        // Open file in editor
        if (file.exists()) {
            IEditorInput input = new ComponentFileEditorInput(file, uic);
            if (input != null) {
                IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                String editorId = desc.getId();
                IEditorPart editorPart = activePage.openEditor(input, editorId);
                addMarkers(file, editorPart);
                editorPart.addPropertyListener(new IPropertyListener() {

                    boolean isFirstChange = false;

                    @Override
                    public void propertyChanged(Object source, int propId) {
                        if (source instanceof ITextEditor) {
                            if (propId == IEditorPart.PROP_DIRTY) {
                                if (!isFirstChange) {
                                    isFirstChange = true;
                                    return;
                                }
                                isFirstChange = false;
                                ITextEditor editor = (ITextEditor) source;
                                IDocumentProvider dp = editor.getDocumentProvider();
                                IDocument doc = dp.getDocument(editor.getEditorInput());
                                String marker = MobileBuilder.getMarker(doc.get(), functionMarker);
                                String content = MobileBuilder.getFormatedContent(marker, functionMarker);
                                FormatedContent formated = new FormatedContent(content);
                                MobileUIComponentTreeObject.this.setPropertyValue(propertyName, formated);
                            }
                        }
                    }
                });
            }
        }
    } catch (Exception e) {
        ConvertigoPlugin.logException(e, "Unable to edit function for '" + uic.getName() + "' component!");
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IScriptComponent(com.twinsoft.convertigo.beans.mobile.components.IScriptComponent) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.mobile.ComponentFileEditorInput) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IPropertyListener(org.eclipse.ui.IPropertyListener) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) UICustomAction(com.twinsoft.convertigo.beans.mobile.components.UICustomAction) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FormatedContent(com.twinsoft.convertigo.beans.common.FormatedContent) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with UICustomAction

use of com.twinsoft.convertigo.beans.mobile.components.UICustomAction in project convertigo by convertigo.

the class Ionic3Builder method writeFunctionTempTsFile.

@Override
public void writeFunctionTempTsFile(final IUIComponent uiComponent, String functionMarker) throws EngineException {
    UIComponent uic = (UIComponent) uiComponent;
    try {
        IScriptComponent main = uic.getMainScriptComponent();
        if (main != null) {
            String tempTsFileName = null, tsContent = null;
            File tempTsDir = null;
            if (main instanceof ApplicationComponent) {
                UIActionStack sharedAction = uic.getSharedAction();
                tempTsDir = sharedAction == null ? new File(ionicWorkDir, "src/app") : new File(ionicWorkDir, "src/services");
                tempTsFileName = sharedAction == null ? "app.component.function.temp.ts" : "actionbeans.service.function.temp.ts";
                File appTsFile = sharedAction == null ? new File(ionicWorkDir, "src/app/app.component.ts") : new File(ionicWorkDir, "src/services/actionbeans.service.ts");
                synchronized (writtenFiles) {
                    if (writtenFiles.contains(appTsFile)) {
                        File appTsFileTmp = toTmpFile(appTsFile);
                        if (appTsFileTmp.exists()) {
                            appTsFile = appTsFileTmp;
                        }
                    }
                }
                tsContent = FileUtils.readFileToString(appTsFile, "UTF-8");
            }
            if (main instanceof PageComponent) {
                PageComponent page = (PageComponent) main;
                String pageName = page.getName();
                tempTsDir = new File(ionicWorkDir, "src/pages/" + pageName);
                tempTsFileName = pageName.toLowerCase() + ".function.temp.ts";
                if (page.isEnabled()) {
                    File pageTsFile = new File(tempTsDir, pageName.toLowerCase() + ".ts");
                    synchronized (writtenFiles) {
                        if (writtenFiles.contains(pageTsFile)) {
                            File pageTsFileTmp = toTmpFile(pageTsFile);
                            if (pageTsFileTmp.exists()) {
                                pageTsFile = pageTsFileTmp;
                            }
                        }
                    }
                    tsContent = FileUtils.readFileToString(pageTsFile, "UTF-8");
                } else {
                    tsContent = getPageTsContent(page);
                }
            }
            // Replace all Begin_c8o_XXX, End_c8o_XXX except for functionMarker
            Pattern pattern = Pattern.compile("/\\*Begin_c8o_(.+)\\*/");
            Matcher matcher = pattern.matcher(tsContent);
            while (matcher.find()) {
                String markerId = matcher.group(1);
                if (!markerId.equals(functionMarker)) {
                    String beginMarker = "/*Begin_c8o_" + markerId + "*/";
                    String endMarker = "/*End_c8o_" + markerId + "*/";
                    tsContent = tsContent.replace(beginMarker, "//---" + markerId + "---");
                    tsContent = tsContent.replace(endMarker, "//---" + markerId + "---");
                }
            }
            // CustomAction : reduce code lines (action's function only)
            if (tempTsDir != null && tempTsFileName != null) {
                if (uiComponent instanceof UICustomAction) {
                    UICustomAction uica = (UICustomAction) uic;
                    tempTsFileName = "CTS" + uica.priority + ".temp.ts";
                    int index = tsContent.indexOf("export class ");
                    if (index != -1) {
                        int i = tsContent.indexOf("{", index);
                        tsContent = tsContent.substring(0, i + 1) + System.lineSeparator() + uica.getActionCode() + System.lineSeparator() + "}" + System.lineSeparator();
                    }
                }
            }
            // Write file (do not need delay)
            tsContent = LsPattern.matcher(tsContent).replaceAll(System.lineSeparator());
            File tempTsFile = new File(tempTsDir, tempTsFileName);
            FileUtils.write(tempTsFile, tsContent, "UTF-8");
        }
    } catch (Exception e) {
        throw new EngineException("Unable to write function temp ts file", e);
    }
}
Also used : Pattern(java.util.regex.Pattern) IScriptComponent(com.twinsoft.convertigo.beans.mobile.components.IScriptComponent) Matcher(java.util.regex.Matcher) IApplicationComponent(com.twinsoft.convertigo.beans.core.IApplicationComponent) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) IUIComponent(com.twinsoft.convertigo.beans.core.IUIComponent) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) EngineException(com.twinsoft.convertigo.engine.EngineException) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) UICustomAction(com.twinsoft.convertigo.beans.mobile.components.UICustomAction) File(java.io.File)

Example 4 with UICustomAction

use of com.twinsoft.convertigo.beans.mobile.components.UICustomAction in project convertigo by convertigo.

the class Ionic3Builder method getFunctionTempTsRelativePath.

@Override
public String getFunctionTempTsRelativePath(final IUIComponent uiComponent) throws EngineException {
    UIComponent uic = (UIComponent) uiComponent;
    IScriptComponent main = uic.getMainScriptComponent();
    if (main != null) {
        File tempTsDir = null;
        String tempTsFileName = null;
        if (main instanceof ApplicationComponent) {
            UIActionStack stack = uic.getSharedAction();
            tempTsDir = stack == null ? new File(ionicWorkDir, "src/app") : new File(ionicWorkDir, "src/services");
            tempTsFileName = stack == null ? "app.component.function.temp.ts" : "actionbeans.service.function.temp.ts";
        }
        if (main instanceof PageComponent) {
            PageComponent page = (PageComponent) main;
            String pageName = page.getName();
            tempTsDir = new File(ionicWorkDir, "src/pages/" + pageName);
            tempTsFileName = pageName.toLowerCase() + ".function.temp.ts";
        }
        if (tempTsDir != null && tempTsFileName != null) {
            if (uiComponent instanceof UICustomAction) {
                tempTsFileName = "CTS" + ((UICustomAction) uiComponent).priority + ".temp.ts";
            }
            File tempTsFile = new File(tempTsDir, tempTsFileName);
            return tempTsFile.getPath().replace(projectDir.getPath(), File.separator);
        }
    }
    return null;
}
Also used : UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) IScriptComponent(com.twinsoft.convertigo.beans.mobile.components.IScriptComponent) IApplicationComponent(com.twinsoft.convertigo.beans.core.IApplicationComponent) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) IUIComponent(com.twinsoft.convertigo.beans.core.IUIComponent) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) UICustomAction(com.twinsoft.convertigo.beans.mobile.components.UICustomAction) File(java.io.File) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent)

Example 5 with UICustomAction

use of com.twinsoft.convertigo.beans.mobile.components.UICustomAction in project convertigo by convertigo.

the class MobileUIComponentTreeObject method launchEditor.

@Override
public void launchEditor(String editorType) {
    UIComponent uic = getObject();
    if (uic instanceof UICustom) {
        openHtmlFileEditor();
    } else if (uic instanceof UIStyle) {
        openCssFileEditor();
    } else if (uic instanceof UICustomAction) {
        String functionMarker = "function:" + ((UICustomAction) uic).getActionName();
        editFunction(uic, functionMarker, "actionValue");
    } else if (uic instanceof UIFormCustomValidator) {
        String functionMarker = "function:" + ((UIFormCustomValidator) uic).getValidatorName();
        editFunction(uic, functionMarker, "validatorValue");
    } else {
        super.launchEditor(editorType);
    }
}
Also used : UICustom(com.twinsoft.convertigo.beans.mobile.components.UICustom) UIStyle(com.twinsoft.convertigo.beans.mobile.components.UIStyle) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) UICustomAction(com.twinsoft.convertigo.beans.mobile.components.UICustomAction) UIFormCustomValidator(com.twinsoft.convertigo.beans.mobile.components.UIFormCustomValidator)

Aggregations

UICustomAction (com.twinsoft.convertigo.beans.mobile.components.UICustomAction)6 ApplicationComponent (com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent)5 UIActionStack (com.twinsoft.convertigo.beans.mobile.components.UIActionStack)4 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)3 IScriptComponent (com.twinsoft.convertigo.beans.mobile.components.IScriptComponent)3 UIComponent (com.twinsoft.convertigo.beans.mobile.components.UIComponent)3 IApplicationComponent (com.twinsoft.convertigo.beans.core.IApplicationComponent)2 IPageComponent (com.twinsoft.convertigo.beans.core.IPageComponent)2 IUIComponent (com.twinsoft.convertigo.beans.core.IUIComponent)2 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)2 DesignDocument (com.twinsoft.convertigo.beans.couchdb.DesignDocument)2 IAction (com.twinsoft.convertigo.beans.mobile.components.IAction)2 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)2 UIDynamicAction (com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction)2 UIForm (com.twinsoft.convertigo.beans.mobile.components.UIForm)2 UISharedComponent (com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)2 EngineException (com.twinsoft.convertigo.engine.EngineException)2 File (java.io.File)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 FormatedContent (com.twinsoft.convertigo.beans.common.FormatedContent)1