Search in sources :

Example 6 with PageComponent

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

the class NgxBuilder 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 = pageDir(page);
            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.ngx.components.PageComponent) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 7 with PageComponent

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

the class NgxBuilder method removeUselessPages.

private void removeUselessPages(ApplicationComponent application) {
    if (application != null) {
        File ionicPagesDir = pagesDir;
        List<String> pageDirectories = new ArrayList<String>();
        pageDirectories.add(ionicPagesDir.getAbsolutePath());
        List<PageComponent> pages = application.getPageComponentList();
        for (PageComponent page : pages) {
            File pageDir = pageDir(page);
            pageDirectories.add(pageDir.getAbsolutePath());
        }
        for (File dir : FileUtils.listFilesAndDirs(ionicPagesDir, FalseFileFilter.INSTANCE, DirectoryFileFilter.DIRECTORY)) {
            if (!pageDirectories.contains(dir.getAbsolutePath())) {
                try {
                    FileUtils.deleteDirectory(dir);
                } catch (Exception e) {
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 8 with PageComponent

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

the class NgxBuilder 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 = pageDir(page);
            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.ngx.components.PageComponent) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 9 with PageComponent

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

the class NgxBuilder method writeAppPluginsConfig.

private void writeAppPluginsConfig(ApplicationComponent app) throws EngineException {
    try {
        if (app != null) {
            Map<String, String> cfg_plugins = new HashMap<>();
            // Menus contributors
            for (Contributor contributor : app.getContributors()) {
                cfg_plugins.putAll(contributor.getConfigPlugins());
            }
            // Pages contributors
            List<PageComponent> pages = forceEnable ? app.getPageComponentList() : getEnabledPages(app);
            for (PageComponent page : pages) {
                List<Contributor> contributors = page.getContributors();
                for (Contributor contributor : contributors) {
                    cfg_plugins.putAll(contributor.getConfigPlugins());
                }
            }
            String mandatoryPlugins = "";
            for (String plugin : cfg_plugins.keySet()) {
                try {
                    JSONObject json = new JSONObject(cfg_plugins.get(plugin));
                    String version = json.getString("version");
                    mandatoryPlugins += "\t<plugin name=\"" + plugin + "\" spec=\"" + version + "\">" + System.lineSeparator();
                    if (json.has("variables")) {
                        JSONObject jsonVars = json.getJSONObject("variables");
                        @SuppressWarnings("unchecked") Iterator<String> it = jsonVars.keys();
                        while (it.hasNext()) {
                            String variable = it.next();
                            if (!variable.isEmpty()) {
                                String value = jsonVars.getString(variable);
                                mandatoryPlugins += "\t\t<variable name=\"" + variable + "\" value=\"" + value + "\" />" + System.lineSeparator();
                            }
                        }
                    }
                    mandatoryPlugins += "\t</plugin>" + System.lineSeparator();
                } catch (Exception e) {
                }
            }
            File appPlgConfig = new File(srcDir, "plugins.txt");
            writeFile(appPlgConfig, mandatoryPlugins, "UTF-8");
            if (initDone) {
                Engine.logEngine.trace("(MobileBuilder) App plugins config file generated");
            }
        }
    } catch (Exception e) {
        throw new EngineException("Unable to write app plugins config file", e);
    }
}
Also used : HashMap(java.util.HashMap) EngineException(com.twinsoft.convertigo.engine.EngineException) Contributor(com.twinsoft.convertigo.beans.ngx.components.Contributor) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException) JSONObject(org.codehaus.jettison.json.JSONObject) File(java.io.File)

Example 10 with PageComponent

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

the class NgxBuilder method pageTsChanged.

@Override
public synchronized void pageTsChanged(final IPageComponent pageComponent, boolean forceTemp) throws EngineException {
    PageComponent page = (PageComponent) pageComponent;
    if (page != null && page.isEnabled() && initDone) {
        writePageTs(page);
        moveFiles();
        File pageDir = pageDir(page);
        File tempTsFile = new File(pageDir, page.getName().toLowerCase() + ".temp.ts");
        if (forceTemp && tempTsFile.exists()) {
            writePageTempTs(page);
        }
        Engine.logEngine.trace("(MobileBuilder) Handled 'pageTsChanged'");
    }
}
Also used : File(java.io.File) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent)

Aggregations

PageComponent (com.twinsoft.convertigo.beans.ngx.components.PageComponent)36 IPageComponent (com.twinsoft.convertigo.beans.core.IPageComponent)21 EngineException (com.twinsoft.convertigo.engine.EngineException)14 File (java.io.File)13 ApplicationComponent (com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent)11 IOException (java.io.IOException)10 UIComponent (com.twinsoft.convertigo.beans.ngx.components.UIComponent)7 IApplicationComponent (com.twinsoft.convertigo.beans.core.IApplicationComponent)6 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)5 UIActionStack (com.twinsoft.convertigo.beans.ngx.components.UIActionStack)5 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)5 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)5 ArrayList (java.util.ArrayList)5 Cursor (org.eclipse.swt.graphics.Cursor)5 Display (org.eclipse.swt.widgets.Display)5 Shell (org.eclipse.swt.widgets.Shell)5 MobileApplication (com.twinsoft.convertigo.beans.core.MobileApplication)4 Contributor (com.twinsoft.convertigo.beans.ngx.components.Contributor)4 UIUseShared (com.twinsoft.convertigo.beans.ngx.components.UIUseShared)4 TreeObjectEvent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent)4