Search in sources :

Example 6 with WalkHelper

use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.

the class Get method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    String projectName = request.getParameter("projectName");
    Element root = document.getDocumentElement();
    root.setAttribute("name", projectName);
    ProjectUtils.getFullProjectDOM(document, projectName, new StreamSource(getClass().getResourceAsStream("cleanDOM.xsl")));
    final Map<String, DatabaseObject> map = getDatabaseObjectByQName(request);
    map.clear();
    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
    new WalkHelper() {

        @Override
        protected void walk(DatabaseObject databaseObject) throws Exception {
            map.put(databaseObject.getQName(), databaseObject);
            super.walk(databaseObject);
        }
    }.init(project);
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Element(org.w3c.dom.Element) StreamSource(javax.xml.transform.stream.StreamSource) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper)

Example 7 with WalkHelper

use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.

the class CreateNgxApplicationTranslationsFileAction method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            Object databaseObject = treeObject.getObject();
            List<String> textList = new ArrayList<String>();
            if ((databaseObject != null) && (databaseObject instanceof ApplicationComponent)) {
                ApplicationComponent application = (ApplicationComponent) databaseObject;
                new WalkHelper() {

                    @Override
                    protected void walk(DatabaseObject databaseObject) throws Exception {
                        String text = null;
                        if (databaseObject instanceof PageComponent) {
                            PageComponent page = (PageComponent) databaseObject;
                            text = page.getTitle();
                        } else if (databaseObject instanceof UIUseShared) {
                            UIUseShared uius = (UIUseShared) databaseObject;
                            UISharedComponent uisc = uius.getTargetSharedComponent();
                            if (uisc != null && !uius.isRecursive()) {
                                super.walk(uisc);
                            }
                        } else if (databaseObject instanceof UIText) {
                            UIText uiText = (UIText) databaseObject;
                            MobileSmartSourceType msst = uiText.getTextSmartType();
                            if (Mode.PLAIN.equals(msst.getMode())) {
                                text = msst.getValue();
                            }
                        }
                        if (text != null && !textList.contains(text)) {
                            textList.add(text);
                        }
                        super.walk(databaseObject);
                    }
                }.init(application);
                MobileApplicationTranslationsDialog dlg = new MobileApplicationTranslationsDialog(shell);
                int ret = dlg.open();
                if (ret != Window.OK) {
                    return;
                }
                Locale from = dlg.getLocaleFrom();
                Locale to = dlg.getLocaleTo();
                boolean auto = dlg.isAuto();
                File i18nDir = new File(application.getProject().getDirPath(), "DisplayObjects/mobile/assets/i18n");
                // store source file
                File source = new File(i18nDir, from.getLanguage() + ".json");
                TranslateUtils.storeTranslations(textList, source);
                ConvertigoPlugin.logDebug(source.getName() + " file successfully created or updated.");
                // store target file
                if (!to.equals(from)) {
                    File target = new File(i18nDir, to.getLanguage() + ".json");
                    // translate with google api
                    if (auto) {
                        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
                        dialog.run(true, false, new IRunnableWithProgress() {

                            @Override
                            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                                monitor.beginTask("translating", IProgressMonitor.UNKNOWN);
                                Translator translator = TranslateUtils.newTranslator();
                                try {
                                    translator.translate(from, source, to, target);
                                    ConvertigoPlugin.logDebug(target.getName() + " file successfully translated.");
                                } catch (Exception e) {
                                    ConvertigoPlugin.logError(e.getMessage(), false);
                                    try {
                                        TranslateUtils.storeTranslations(textList, target);
                                    } catch (Exception ex) {
                                    }
                                }
                                monitor.done();
                            }
                        });
                    } else // do not translate
                    {
                        TranslateUtils.storeTranslations(textList, target);
                    }
                    ConvertigoPlugin.logDebug(target.getName() + " file successfully created or updated.");
                }
                // regenerate app templates
                try {
                    application.markApplicationAsDirty();
                    for (PageComponent page : application.getPageComponentList()) {
                        if (page.isEnabled()) {
                            page.markPageAsDirty();
                        }
                    }
                } catch (Throwable t) {
                }
                ConvertigoPlugin.logInfo("Translations file(s) successfully created or updated.", true);
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to create the Mobile application translations file(s)!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Locale(java.util.Locale) MobileApplicationTranslationsDialog(com.twinsoft.convertigo.eclipse.dialogs.MobileApplicationTranslationsDialog) MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) ArrayList(java.util.ArrayList) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Cursor(org.eclipse.swt.graphics.Cursor) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) Translator(com.twinsoft.convertigo.engine.mobile.TranslateUtils.Translator) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UIText(com.twinsoft.convertigo.beans.ngx.components.UIText) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Example 8 with WalkHelper

use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.

the class CreateMobileApplicationTranslationsFileAction method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            Object databaseObject = treeObject.getObject();
            List<String> textList = new ArrayList<String>();
            if ((databaseObject != null) && (databaseObject instanceof ApplicationComponent)) {
                ApplicationComponent application = (ApplicationComponent) databaseObject;
                new WalkHelper() {

                    @Override
                    protected void walk(DatabaseObject databaseObject) throws Exception {
                        String text = null;
                        if (databaseObject instanceof PageComponent) {
                            PageComponent page = (PageComponent) databaseObject;
                            text = page.getTitle();
                        } else if (databaseObject instanceof UIUseShared) {
                            UIUseShared uius = (UIUseShared) databaseObject;
                            UISharedComponent uisc = uius.getTargetSharedComponent();
                            if (uisc != null && !uius.isRecursive()) {
                                super.walk(uisc);
                            }
                        } else if (databaseObject instanceof UIText) {
                            UIText uiText = (UIText) databaseObject;
                            MobileSmartSourceType msst = uiText.getTextSmartType();
                            if (Mode.PLAIN.equals(msst.getMode())) {
                                text = msst.getValue();
                            }
                        }
                        if (text != null && !textList.contains(text)) {
                            textList.add(text);
                        }
                        super.walk(databaseObject);
                    }
                }.init(application);
                MobileApplicationTranslationsDialog dlg = new MobileApplicationTranslationsDialog(shell);
                int ret = dlg.open();
                if (ret != Window.OK) {
                    return;
                }
                Locale from = dlg.getLocaleFrom();
                Locale to = dlg.getLocaleTo();
                boolean auto = dlg.isAuto();
                File i18nDir = new File(application.getProject().getDirPath(), "DisplayObjects/mobile/assets/i18n");
                // store source file
                File source = new File(i18nDir, from.getLanguage() + ".json");
                TranslateUtils.storeTranslations(textList, source);
                ConvertigoPlugin.logDebug(source.getName() + " file successfully created or updated.");
                // store target file
                if (!to.equals(from)) {
                    File target = new File(i18nDir, to.getLanguage() + ".json");
                    // translate with google api
                    if (auto) {
                        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
                        dialog.run(true, false, new IRunnableWithProgress() {

                            @Override
                            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                                monitor.beginTask("translating", IProgressMonitor.UNKNOWN);
                                Translator translator = TranslateUtils.newTranslator();
                                try {
                                    translator.translate(from, source, to, target);
                                    ConvertigoPlugin.logDebug(target.getName() + " file successfully translated.");
                                } catch (Exception e) {
                                    ConvertigoPlugin.logError(e.getMessage(), false);
                                    try {
                                        TranslateUtils.storeTranslations(textList, target);
                                    } catch (Exception ex) {
                                    }
                                }
                                monitor.done();
                            }
                        });
                    } else // do not translate
                    {
                        TranslateUtils.storeTranslations(textList, target);
                    }
                    ConvertigoPlugin.logDebug(target.getName() + " file successfully created or updated.");
                }
                // regenerate app templates
                try {
                    application.markApplicationAsDirty();
                    for (PageComponent page : application.getPageComponentList()) {
                        if (page.isEnabled()) {
                            page.markPageAsDirty();
                        }
                    }
                } catch (Throwable t) {
                }
                ConvertigoPlugin.logInfo("Translations file(s) successfully created or updated.", true);
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to create the Mobile application translations file(s)!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Locale(java.util.Locale) MobileApplicationTranslationsDialog(com.twinsoft.convertigo.eclipse.dialogs.MobileApplicationTranslationsDialog) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) UIUseShared(com.twinsoft.convertigo.beans.mobile.components.UIUseShared) ArrayList(java.util.ArrayList) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Cursor(org.eclipse.swt.graphics.Cursor) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) Translator(com.twinsoft.convertigo.engine.mobile.TranslateUtils.Translator) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UIText(com.twinsoft.convertigo.beans.mobile.components.UIText) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Example 9 with WalkHelper

use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.

the class MobileSmartSource method findDatabaseObject.

private DatabaseObject findDatabaseObject(final String dboName, final long priority) throws Exception {
    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(getProjectName());
    DatabaseObject root = null;
    if (dboName != null) {
        ApplicationComponent app = (ApplicationComponent) project.getMobileApplication().getApplicationComponent();
        try {
            root = app.getPageComponentByName(dboName);
        } catch (Exception e1) {
            try {
                root = app.getMenuComponentByName(dboName);
            } catch (Exception e2) {
                try {
                    root = app;
                } catch (Exception e3) {
                    ;
                }
            }
        }
    }
    if (root == null) {
        root = project;
    }
    final List<DatabaseObject> list = new ArrayList<DatabaseObject>();
    new WalkHelper() {

        @Override
        protected void walk(DatabaseObject databaseObject) throws Exception {
            if (databaseObject.priority == priority) {
                list.add(databaseObject);
            }
            if (list.isEmpty()) {
                super.walk(databaseObject);
            }
        }
    }.init(root);
    return list.isEmpty() ? null : list.get(0);
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) ArrayList(java.util.ArrayList) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) JSONException(org.codehaus.jettison.json.JSONException)

Example 10 with WalkHelper

use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.

the class UIDynamicAnimate method getAnimatableId.

private String getAnimatableId() {
    if (!identifiable.isEmpty()) {
        String p_name = identifiable.substring(0, identifiable.indexOf('.'));
        Project project = this.getProject();
        if (project != null) {
            Project p = null;
            try {
                // p = p_name.equals(project.getName()) ? project: Engine.theApp.databaseObjectsManager.getOriginalProjectByName(p_name);
                p = Engine.theApp.referencedProjectManager.importProjectFrom(project, p_name);
            } catch (Exception e) {
                Engine.logBeans.warn("(UIDynamicAnimate) For \"" + this.toString() + "\", targeted project \"" + p_name + "\" is missing !");
            }
            if (p != null) {
                Map<String, DatabaseObject> map = new HashMap<String, DatabaseObject>();
                try {
                    new WalkHelper() {

                        @Override
                        protected void walk(DatabaseObject databaseObject) throws Exception {
                            map.put(databaseObject.getQName(), databaseObject);
                            super.walk(databaseObject);
                        }
                    }.init(p);
                    DatabaseObject animatable = map.get(identifiable);
                    if (animatable != null && animatable instanceof UIElement) {
                        return ((UIElement) animatable).getIdentifier();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return "";
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) HashMap(java.util.HashMap) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper)

Aggregations

WalkHelper (com.twinsoft.convertigo.engine.helpers.WalkHelper)26 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)25 Project (com.twinsoft.convertigo.beans.core.Project)14 EngineException (com.twinsoft.convertigo.engine.EngineException)10 IOException (java.io.IOException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 CoreException (org.eclipse.core.runtime.CoreException)9 ArrayList (java.util.ArrayList)8 Transaction (com.twinsoft.convertigo.beans.core.Transaction)7 Step (com.twinsoft.convertigo.beans.core.Step)6 JSONException (org.codehaus.jettison.json.JSONException)6 Connector (com.twinsoft.convertigo.beans.core.Connector)5 Criteria (com.twinsoft.convertigo.beans.core.Criteria)5 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)5 Sequence (com.twinsoft.convertigo.beans.core.Sequence)5 Sheet (com.twinsoft.convertigo.beans.core.Sheet)5 Statement (com.twinsoft.convertigo.beans.core.Statement)5 TestCase (com.twinsoft.convertigo.beans.core.TestCase)5 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)5 HashMap (java.util.HashMap)5