Search in sources :

Example 11 with PageComponent

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

the class Ionic3Builder method pageAdded.

@Override
public void pageAdded(final IPageComponent pageComponent) throws EngineException {
    PageComponent page = (PageComponent) pageComponent;
    if (page != null && page.isEnabled() && page.bNew && initDone) {
        synchronized (page) {
            addPage(page);
            moveFiles();
            Engine.logEngine.trace("(MobileBuilder) Handled 'pageAdded'");
        }
    }
}
Also used : IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent)

Example 12 with PageComponent

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

the class Ionic3Builder method writePageTempTs.

@Override
public void writePageTempTs(final IPageComponent pageComponent) throws EngineException {
    PageComponent page = (PageComponent) pageComponent;
    try {
        if (page != null) {
            String pageName = page.getName();
            File pageDir = new File(ionicWorkDir, "src/pages/" + pageName);
            String tsContent;
            if (page.isEnabled()) {
                File pageTsFile = new File(pageDir, 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_function:XXX, End_c8o_function:XXX
            Pattern pattern = Pattern.compile("/\\*Begin_c8o_function:(.+)\\*/");
            Matcher matcher = pattern.matcher(tsContent);
            while (matcher.find()) {
                String markerId = matcher.group(1);
                String beginMarker = "/*Begin_c8o_function:" + markerId + "*/";
                String endMarker = "/*End_c8o_function:" + markerId + "*/";
                tsContent = tsContent.replace(beginMarker, "//---" + markerId + "---");
                tsContent = tsContent.replace(endMarker, "//---" + markerId + "---");
            }
            // Remove all CTSXXX
            int index = tsContent.indexOf("/*End_c8o_PageFunction*/");
            if (index != -1) {
                tsContent = tsContent.substring(0, index) + "/*End_c8o_PageFunction*/" + System.lineSeparator() + "}";
            }
            // Write file (do not need delay)
            tsContent = LsPattern.matcher(tsContent).replaceAll(System.lineSeparator());
            File tempTsFile = new File(pageDir, pageName.toLowerCase() + ".temp.ts");
            FileUtils.write(tempTsFile, tsContent, "UTF-8");
        }
    } catch (Exception e) {
        throw new EngineException("Unable to write ionic page temp ts file", e);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) EngineException(com.twinsoft.convertigo.engine.EngineException) File(java.io.File) 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)

Example 13 with PageComponent

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

the class Ionic3Builder method getAppComponentTsContent.

private String getAppComponentTsContent(ApplicationComponent app) throws IOException {
    String c8o_AppProdMode = "";
    String c8o_PagesImport = "";
    String c8o_PagesVariables = "";
    String c8o_PagesVariablesKeyValue = "";
    String c8o_RootPage = "null";
    String c8o_PageArrayDef = "";
    String c8o_Version = app.getC8oVersion();
    String c8o_AppComponentMarkers = app.getComponentScriptContent().getString();
    String c8o_AppImports = app.getComputedImports();
    String c8o_AppDeclarations = app.getComputedDeclarations();
    String c8o_AppConstructors = app.getComputedConstructors();
    String c8o_AppFunctions = app.getComputedFunctions();
    int i = 1;
    if (app.compareToTplVersion("7.7.0.6") < 0) {
        c8o_PageArrayDef = "Array<{title: string, icon: string, iconPos: string, component: any, name: string, includedInAutoMenu?: boolean}>";
    } else {
        c8o_PageArrayDef = "Array<{title: string, titleKey: string, icon: string, iconPos: string, component: any, name: string, includedInAutoMenu?: boolean}>";
    }
    List<PageComponent> pages = getEnabledPages(app);
    for (PageComponent page : pages) {
        synchronized (page) {
            String pageName = page.getName();
            String pageIcon = page.getIcon();
            String pageIconPos = page.getIconPosition();
            String pageTitle = page.getTitle();
            String pageTitleKey = TranslateUtils.getComputedKey(project, page.getTitle());
            boolean isRootPage = page.isRoot;
            boolean isMenuPage = page.isInAutoMenu();
            boolean isLastPage = i == pages.size();
            if (isRootPage) {
                c8o_RootPage = pageName;
            }
            if (app.compareToTplVersion("7.7.0.2") < 0) {
                c8o_PagesImport += "import { " + pageName + " } from \"../pages/" + pageName + "/" + pageName.toLowerCase() + "\";" + System.lineSeparator();
                if (app.compareToTplVersion("7.5.2.1") < 0) {
                    c8o_PagesVariables += " { title: \"" + pageTitle + "\", icon: \"" + pageIcon + "\", component: " + pageName + ", includedInAutoMenu: " + isMenuPage + "}" + (isLastPage ? "" : ",");
                } else {
                    c8o_PagesVariables += " { title: \"" + pageTitle + "\", icon: \"" + pageIcon + "\", iconPos: \"" + pageIconPos + "\", component: " + pageName + ", includedInAutoMenu: " + isMenuPage + "}" + (isLastPage ? "" : ",");
                }
                c8o_PagesVariablesKeyValue += pageName + ":" + pageName + (isLastPage ? "" : ",");
            } else if (app.compareToTplVersion("7.7.0.6") < 0) {
                if (isRootPage) {
                    c8o_RootPage = "'" + c8o_RootPage + "'";
                    c8o_PagesVariables += " { title: \"" + pageTitle + "\", icon: \"" + pageIcon + "\", iconPos: \"" + pageIconPos + "\", component: " + "this.rootPage" + ", name: \"" + pageName + "\", includedInAutoMenu: " + isMenuPage + "}" + (isLastPage ? "" : ",");
                    c8o_PagesVariablesKeyValue += pageName + ":" + "this.rootPage" + (isLastPage ? "" : ",");
                } else {
                    c8o_PagesVariables += " { title: \"" + pageTitle + "\", icon: \"" + pageIcon + "\", iconPos: \"" + pageIconPos + "\", component: \"" + pageName + "\", name: \"" + pageName + "\", includedInAutoMenu: " + isMenuPage + "}" + (isLastPage ? "" : ",");
                    c8o_PagesVariablesKeyValue += pageName + ":" + "null" + (isLastPage ? "" : ",");
                }
            } else {
                if (isRootPage) {
                    c8o_RootPage = "'" + c8o_RootPage + "'";
                    c8o_PagesVariables += " { title: \"" + pageTitle + "\", titleKey: \"" + pageTitleKey + "\", icon: \"" + pageIcon + "\", iconPos: \"" + pageIconPos + "\", component: " + "this.rootPage" + ", name: \"" + pageName + "\", includedInAutoMenu: " + isMenuPage + "}" + (isLastPage ? "" : ",");
                    c8o_PagesVariablesKeyValue += pageName + ":" + "this.rootPage" + (isLastPage ? "" : ",");
                } else {
                    c8o_PagesVariables += " { title: \"" + pageTitle + "\", titleKey: \"" + pageTitleKey + "\", icon: \"" + pageIcon + "\", iconPos: \"" + pageIconPos + "\", component: \"" + pageName + "\", name: \"" + pageName + "\", includedInAutoMenu: " + isMenuPage + "}" + (isLastPage ? "" : ",");
                    c8o_PagesVariablesKeyValue += pageName + ":" + "null" + (isLastPage ? "" : ",");
                }
            }
            i++;
        }
    }
    String computedRoute = app.getComputedRoute();
    File appComponentTpl = new File(ionicTplDir, "src/app/app.component.ts");
    String cContent = FileUtils.readFileToString(appComponentTpl, "UTF-8");
    if (app.compareToTplVersion("7.7.0.2") >= 0) {
        c8o_AppProdMode = MobileBuilderBuildMode.production.equals(buildMode) ? "enableProdMode();" : "";
    }
    cContent = cContent.replaceAll("/\\*\\=c8o_PagesImport\\*/", c8o_PagesImport);
    cContent = cContent.replaceAll("/\\*\\=c8o_RootPage\\*/", c8o_RootPage);
    cContent = cContent.replaceAll("/\\*\\=c8o_PageArrayDef\\*/", c8o_PageArrayDef);
    cContent = cContent.replaceAll("/\\*\\=c8o_PagesVariables\\*/", c8o_PagesVariables);
    cContent = cContent.replaceAll("/\\*\\=c8o_PagesVariablesKeyValue\\*/", c8o_PagesVariablesKeyValue);
    cContent = cContent.replaceAll("/\\*\\=c8o_RoutingTable\\*/", computedRoute);
    cContent = cContent.replaceAll("/\\*\\=c8o_AppImports\\*/", c8o_AppImports);
    cContent = cContent.replaceAll("/\\*\\=c8o_AppDeclarations\\*/", c8o_AppDeclarations);
    cContent = cContent.replaceAll("/\\*\\=c8o_AppConstructors\\*/", c8o_AppConstructors);
    cContent = cContent.replaceAll("/\\*\\=c8o_AppProdMode\\*/", c8o_AppProdMode);
    String c8oInit = "settings.addHeader(\"x-convertigo-mb\", \"" + c8o_Version + "\");\n\t\tthis.c8o.init(";
    cContent = cContent.replaceFirst("this\\.c8o\\.init\\(", c8oInit);
    // begin c8o marker
    Pattern pattern = Pattern.compile("/\\*Begin_c8o_(.+)\\*/");
    Matcher matcher = pattern.matcher(cContent);
    while (matcher.find()) {
        String markerId = matcher.group(1);
        String tplMarker = getMarker(cContent, markerId);
        String customMarker = getMarker(c8o_AppComponentMarkers, markerId);
        if (!customMarker.isEmpty()) {
            cContent = cContent.replace(tplMarker, customMarker);
        }
    }
    cContent = cContent.replaceAll("/\\*\\=c8o_AppFunctions\\*/", Matcher.quoteReplacement(c8o_AppFunctions));
    return cContent;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) File(java.io.File) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent)

Example 14 with PageComponent

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

the class MobilePickerContentProvider method addIterations.

private void addIterations(TVObject tvi, Object object) {
    if (object != null) {
        List<UIComponent> list = null;
        if (object instanceof PageComponent) {
            list = ((PageComponent) object).getUIComponentList();
        } else if (object instanceof UIComponent) {
            list = ((UIComponent) object).getUIComponentList();
        }
        if (list != null) {
            for (UIComponent uic : list) {
                if (uic instanceof UIControlDirective) {
                    // do not add to prevent selection on itself or children
                    if (uic.equals(selected)) {
                        return;
                    }
                    // do not add if not parent of selected (popped picker only)
                    boolean showInPicker = true;
                    if (selected != null && selected instanceof UIComponent) {
                        String selectedQName = ((UIComponent) selected).getQName();
                        String uicQName = uic.getQName() + ".";
                        if (!selectedQName.startsWith(uicQName)) {
                            showInPicker = false;
                        }
                    }
                    UIControlDirective uicd = (UIControlDirective) uic;
                    if (showInPicker && AttrDirective.ForEach.equals(AttrDirective.getDirective(uicd.getDirectiveName()))) {
                        SourceData sd = null;
                        try {
                            sd = Filter.Iteration.toSourceData(new JSONObject().put("priority", uic.priority));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        TVObject tuic = tvi.add(new TVObject(uic.toString(), uic, sd));
                        addIterations(tuic, uic);
                    } else {
                        addIterations(tvi, uic);
                    }
                } else {
                    addIterations(tvi, uic);
                }
            }
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) UIControlDirective(com.twinsoft.convertigo.beans.mobile.components.UIControlDirective) JSONException(org.codehaus.jettison.json.JSONException) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) SourceData(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData)

Example 15 with PageComponent

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

the class MobilePickerContentProvider method addForms.

private void addForms(TVObject tvi, Object object) {
    if (object != null) {
        List<UIComponent> list = null;
        if (object instanceof PageComponent) {
            list = ((PageComponent) object).getUIComponentList();
        } else if (object instanceof UIComponent) {
            list = ((UIComponent) object).getUIComponentList();
        }
        if (list != null) {
            for (UIComponent uic : list) {
                if (uic instanceof UIForm) {
                    // do not add to prevent selection on itself or children
                    if (uic.equals(selected)) {
                        return;
                    }
                    SourceData sd = null;
                    try {
                        sd = Filter.Form.toSourceData(new JSONObject().put("priority", uic.priority));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    TVObject tuic = tvi.add(new TVObject(uic.toString(), uic, sd));
                    addForms(tuic, uic);
                } else {
                    addForms(tvi, uic);
                }
            }
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) JSONException(org.codehaus.jettison.json.JSONException) UIForm(com.twinsoft.convertigo.beans.mobile.components.UIForm) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) SourceData(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData)

Aggregations

PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)41 IPageComponent (com.twinsoft.convertigo.beans.core.IPageComponent)20 EngineException (com.twinsoft.convertigo.engine.EngineException)16 File (java.io.File)15 ApplicationComponent (com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent)14 IOException (java.io.IOException)11 UIComponent (com.twinsoft.convertigo.beans.mobile.components.UIComponent)9 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)8 UISharedComponent (com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)6 UIUseShared (com.twinsoft.convertigo.beans.mobile.components.UIUseShared)6 ArrayList (java.util.ArrayList)6 IApplicationComponent (com.twinsoft.convertigo.beans.core.IApplicationComponent)5 Project (com.twinsoft.convertigo.beans.core.Project)4 Contributor (com.twinsoft.convertigo.beans.mobile.components.Contributor)4 UIActionStack (com.twinsoft.convertigo.beans.mobile.components.UIActionStack)4 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)4 TreeObjectEvent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent)4 HashMap (java.util.HashMap)4 JSONObject (org.codehaus.jettison.json.JSONObject)4 Cursor (org.eclipse.swt.graphics.Cursor)4