Search in sources :

Example 26 with PageComponent

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

the class Ionic3Builder method pageRenamed.

@Override
public void pageRenamed(final IPageComponent pageComponent, final String oldName) throws EngineException {
    PageComponent page = (PageComponent) pageComponent;
    if (page != null && page.isEnabled() && initDone) {
        synchronized (page) {
            MobileApplication mobileApplication = project.getMobileApplication();
            if (mobileApplication != null) {
                ApplicationComponent application = (ApplicationComponent) mobileApplication.getApplicationComponent();
                if (application != null) {
                    writePageSourceFiles(page);
                    writeAppSourceFiles(application);
                    deleteUselessDir(oldName);
                    moveFiles();
                    Engine.logEngine.trace("(MobileBuilder) Handled 'pageRenamed'");
                }
            }
        }
    }
}
Also used : MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) IApplicationComponent(com.twinsoft.convertigo.beans.core.IApplicationComponent) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent)

Example 27 with PageComponent

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

the class Ionic3Builder method getTempTsRelativePath.

@Override
public String getTempTsRelativePath(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);
            File tempTsFile = new File(pageDir, pageName.toLowerCase() + ".temp.ts");
            String filePath = tempTsFile.getPath().replace(projectDir.getPath(), File.separator);
            return filePath;
        }
    } catch (Exception e) {
        throw new EngineException("Unable to write page temp ts file", e);
    }
    return null;
}
Also used : 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 28 with PageComponent

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

the class Ionic3Builder method writeAppModuleTs.

private void writeAppModuleTs(ApplicationComponent app) throws EngineException {
    try {
        if (app != null) {
            String c8o_PagesImport = "";
            String c8o_PagesLinks = "";
            String c8o_PagesDeclarations = "";
            int i = 1;
            Map<String, File> comp_beans_dirs = new HashMap<>();
            Map<String, String> module_ts_imports = new HashMap<>();
            Set<String> module_ng_imports = new HashSet<String>();
            Set<String> module_ng_providers = new HashSet<String>();
            Set<String> module_ng_declarations = new HashSet<String>();
            Set<String> module_ng_components = new HashSet<String>();
            // App contributors
            for (Contributor contributor : app.getContributors()) {
                comp_beans_dirs.putAll(contributor.getCompBeanDir());
                module_ts_imports.putAll(contributor.getModuleTsImports());
                module_ng_imports.addAll(contributor.getModuleNgImports());
                module_ng_providers.addAll(contributor.getModuleNgProviders());
                module_ng_declarations.addAll(contributor.getModuleNgDeclarations());
                module_ng_components.addAll(contributor.getModuleNgComponents());
            }
            // Pages contributors
            List<PageComponent> pages = getEnabledPages(app);
            for (PageComponent page : pages) {
                synchronized (page) {
                    String pageName = page.getName();
                    String pageSegment = page.getSegment();
                    boolean isLastPage = i == pages.size();
                    if (app.compareToTplVersion("7.7.0.2") < 0) {
                        c8o_PagesImport += "import { " + pageName + " } from \"../pages/" + pageName + "/" + pageName.toLowerCase() + "\";" + System.lineSeparator();
                        c8o_PagesLinks += " { component: " + pageName + ", name: \"" + pageName + "\", segment: \"" + pageSegment + "\" }" + (isLastPage ? "" : ",");
                        c8o_PagesDeclarations += " " + pageName + (isLastPage ? "" : ",");
                        List<Contributor> contributors = page.getContributors();
                        for (Contributor contributor : contributors) {
                            comp_beans_dirs.putAll(contributor.getCompBeanDir());
                            module_ts_imports.putAll(contributor.getModuleTsImports());
                            module_ng_imports.addAll(contributor.getModuleNgImports());
                            module_ng_providers.addAll(contributor.getModuleNgProviders());
                            module_ng_declarations.addAll(contributor.getModuleNgDeclarations());
                            module_ng_components.addAll(contributor.getModuleNgComponents());
                        }
                    } else {
                        List<Contributor> contributors = page.getContributors();
                        for (Contributor contributor : contributors) {
                            if (contributor.isNgModuleForApp()) {
                                comp_beans_dirs.putAll(contributor.getCompBeanDir());
                                module_ts_imports.putAll(contributor.getModuleTsImports());
                                module_ng_imports.addAll(contributor.getModuleNgImports());
                                module_ng_providers.addAll(contributor.getModuleNgProviders());
                                module_ng_declarations.addAll(contributor.getModuleNgDeclarations());
                                module_ng_components.addAll(contributor.getModuleNgComponents());
                            }
                        }
                        writePageModuleTs(page);
                    }
                    i++;
                }
            }
            String c8o_ModuleTsImports = "";
            Map<String, String> tpl_ts_imports = getTplAppModuleTsImports();
            if (!module_ts_imports.isEmpty()) {
                for (String comp : module_ts_imports.keySet()) {
                    if (!tpl_ts_imports.containsKey(comp)) {
                        if (comp.indexOf(" as ") != -1) {
                            c8o_ModuleTsImports += "import " + comp + " from '" + module_ts_imports.get(comp) + "';" + System.lineSeparator();
                        } else {
                            c8o_ModuleTsImports += "import { " + comp + " } from '" + module_ts_imports.get(comp) + "';" + System.lineSeparator();
                        }
                    }
                }
            }
            String c8o_ModuleNgImports = "";
            String tpl_ng_imports = getTplAppModuleNgImports();
            if (!module_ng_imports.isEmpty()) {
                for (String module : module_ng_imports) {
                    if (!tpl_ng_imports.contains(module)) {
                        c8o_ModuleNgImports += "\t" + module + "," + System.lineSeparator();
                    }
                }
                if (!c8o_ModuleNgImports.isEmpty()) {
                    c8o_ModuleNgImports = System.lineSeparator() + c8o_ModuleNgImports;
                }
            }
            String c8o_ModuleNgProviders = "";
            String tpl_ng_providers = getTplAppModuleNgProviders();
            if (!module_ng_providers.isEmpty()) {
                for (String provider : module_ng_providers) {
                    if (!tpl_ng_providers.contains(provider)) {
                        c8o_ModuleNgProviders += "\t" + provider + "," + System.lineSeparator();
                    }
                }
                if (!c8o_ModuleNgProviders.isEmpty()) {
                    c8o_ModuleNgProviders = System.lineSeparator() + c8o_ModuleNgProviders;
                }
            }
            String c8o_ModuleNgDeclarations = "";
            String tpl_ng_declarations = getTplAppModuleNgDeclarations();
            if (!module_ng_declarations.isEmpty()) {
                for (String declaration : module_ng_declarations) {
                    if (!tpl_ng_declarations.contains(declaration)) {
                        c8o_ModuleNgDeclarations += "\t" + declaration + "," + System.lineSeparator();
                    }
                }
                if (!c8o_ModuleNgDeclarations.isEmpty()) {
                    c8o_ModuleNgDeclarations = System.lineSeparator() + c8o_ModuleNgDeclarations;
                }
            }
            String c8o_ModuleNgComponents = "";
            String tpl_ng_components = getTplAppModuleNgComponents();
            if (!module_ng_components.isEmpty()) {
                for (String component : module_ng_components) {
                    if (!tpl_ng_components.contains(component)) {
                        c8o_ModuleNgComponents += "\t" + component + "," + System.lineSeparator();
                    }
                }
                if (!c8o_ModuleNgComponents.isEmpty()) {
                    c8o_ModuleNgComponents = System.lineSeparator() + c8o_ModuleNgComponents;
                }
            }
            boolean c8o_RegisterWorker = isAppPwaAble() && isBuildProdMode();
            File appModuleTpl = new File(ionicTplDir, "src/app/app.module.ts");
            String mContent = FileUtils.readFileToString(appModuleTpl, "UTF-8");
            mContent = mContent.replaceAll("/\\*\\=c8o_RegisterWorker\\*/", String.valueOf(c8o_RegisterWorker));
            mContent = mContent.replaceAll("/\\*\\=c8o_ModuleTsImports\\*/", c8o_ModuleTsImports);
            mContent = mContent.replaceAll("/\\*\\=c8o_PagesImport\\*/", c8o_PagesImport);
            mContent = mContent.replaceAll("/\\*\\=c8o_PagesLinks\\*/", c8o_PagesLinks);
            mContent = mContent.replaceAll("/\\*\\=c8o_PagesDeclarations\\*/", c8o_PagesDeclarations);
            mContent = mContent.replaceAll("/\\*Begin_c8o_NgModules\\*/", c8o_ModuleNgImports);
            mContent = mContent.replaceAll("/\\*End_c8o_NgModules\\*/", "");
            mContent = mContent.replaceAll("/\\*Begin_c8o_NgProviders\\*/", c8o_ModuleNgProviders);
            mContent = mContent.replaceAll("/\\*End_c8o_NgProviders\\*/", "");
            mContent = mContent.replaceAll("/\\*Begin_c8o_NgDeclarations\\*/", c8o_ModuleNgDeclarations);
            mContent = mContent.replaceAll("/\\*End_c8o_NgDeclarations\\*/", "");
            mContent = mContent.replaceAll("/\\*Begin_c8o_NgComponents\\*/", c8o_ModuleNgComponents);
            mContent = mContent.replaceAll("/\\*End_c8o_NgComponents\\*/", "");
            File appModuleTsFile = new File(ionicWorkDir, "src/app/app.module.ts");
            writeFile(appModuleTsFile, mContent, "UTF-8");
            for (String compbean : comp_beans_dirs.keySet()) {
                File srcDir = comp_beans_dirs.get(compbean);
                for (File f : srcDir.listFiles()) {
                    String fContent = FileUtils.readFileToString(f, "UTF-8");
                    File destFile = new File(ionicWorkDir, "src/components/" + compbean + "/" + f.getName());
                    writeFile(destFile, fContent, "UTF-8");
                }
            }
            if (initDone) {
                Engine.logEngine.trace("(MobileBuilder) Ionic module ts file generated for 'app'");
            }
        }
    } catch (Exception e) {
        throw new EngineException("Unable to write ionic app module ts file", e);
    }
}
Also used : HashMap(java.util.HashMap) EngineException(com.twinsoft.convertigo.engine.EngineException) Contributor(com.twinsoft.convertigo.beans.mobile.components.Contributor) 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) File(java.io.File) HashSet(java.util.HashSet)

Example 29 with PageComponent

use of com.twinsoft.convertigo.beans.mobile.components.PageComponent 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 30 with PageComponent

use of com.twinsoft.convertigo.beans.mobile.components.PageComponent 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)

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