Search in sources :

Example 1 with ApplicationComponent

use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent 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 2 with ApplicationComponent

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

the class NgxUIComponentTreeObject 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);
                                NgxUIComponentTreeObject.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.ngx.components.IScriptComponent) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.ngx.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.ngx.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 ApplicationComponent

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

the class NgxBuilder method pageDisabled.

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

Example 4 with ApplicationComponent

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

the class NgxBuilder method setAppBuildMode.

@Override
public void setAppBuildMode(MobileBuilderBuildMode buildMode) {
    super.setAppBuildMode(buildMode);
    if (project != null) {
        try {
            ApplicationComponent app = (ApplicationComponent) project.getMobileApplication().getApplicationComponent();
            app.markComponentTsAsDirty();
        } catch (Exception e) {
            Engine.logEngine.warn("(MobileBuilder) enabled to change build mode");
        }
    }
}
Also used : ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) IApplicationComponent(com.twinsoft.convertigo.beans.core.IApplicationComponent) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 5 with ApplicationComponent

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

the class NgxBuilder method appThemeChanged.

@Override
public synchronized void appThemeChanged(final IApplicationComponent appComponent) throws EngineException {
    ApplicationComponent app = (ApplicationComponent) appComponent;
    if (app != null && initDone) {
        writeAppTheme(app);
        moveFiles();
        Engine.logEngine.trace("(MobileBuilder) Handled 'appThemeChanged'");
    }
}
Also used : ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) IApplicationComponent(com.twinsoft.convertigo.beans.core.IApplicationComponent)

Aggregations

ApplicationComponent (com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent)38 IApplicationComponent (com.twinsoft.convertigo.beans.core.IApplicationComponent)21 PageComponent (com.twinsoft.convertigo.beans.ngx.components.PageComponent)13 EngineException (com.twinsoft.convertigo.engine.EngineException)12 File (java.io.File)12 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)9 UIActionStack (com.twinsoft.convertigo.beans.ngx.components.UIActionStack)8 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)8 UIComponent (com.twinsoft.convertigo.beans.ngx.components.UIComponent)7 JSONException (org.codehaus.jettison.json.JSONException)7 JSONObject (org.codehaus.jettison.json.JSONObject)7 PartInitException (org.eclipse.ui.PartInitException)7 UICustomAction (com.twinsoft.convertigo.beans.ngx.components.UICustomAction)6 IPageComponent (com.twinsoft.convertigo.beans.core.IPageComponent)5 MobileApplication (com.twinsoft.convertigo.beans.core.MobileApplication)5 Project (com.twinsoft.convertigo.beans.core.Project)5 UIDynamicAction (com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)5 IAction (com.twinsoft.convertigo.beans.ngx.components.IAction)4