Search in sources :

Example 16 with ApplicationComponent

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

the class MobileApplicationComponentTreeObject method activeEditor.

public ApplicationComponentEditor activeEditor(boolean autoLaunch) {
    ApplicationComponentEditor editorPart = null;
    ApplicationComponent application = (ApplicationComponent) getObject();
    synchronized (application) {
        String tpl = application.getTplProjectName();
        try {
            if (StringUtils.isBlank(tpl) || Engine.theApp.databaseObjectsManager.getOriginalProjectByName(tpl, false) == null) {
                throw new InvalidParameterException("The value '" + tpl + "' of the property 'Template project' from '" + application.getQName() + "' is incorrect.");
            }
            IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            if (activePage != null) {
                IEditorReference[] editorRefs = activePage.getEditorReferences();
                for (int i = 0; i < editorRefs.length; i++) {
                    IEditorReference editorRef = (IEditorReference) editorRefs[i];
                    try {
                        IEditorInput editorInput = editorRef.getEditorInput();
                        if ((editorInput != null) && (editorInput instanceof ApplicationComponentEditorInput)) {
                            if (((ApplicationComponentEditorInput) editorInput).is(application)) {
                                editorPart = (ApplicationComponentEditor) editorRef.getEditor(false);
                            }
                        }
                    } catch (PartInitException e) {
                    }
                }
                if (editorPart != null) {
                    activePage.activate(editorPart);
                } else {
                    IEditorPart editor = activePage.openEditor(new ApplicationComponentEditorInput(application, autoLaunch), "com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditor");
                    if (editor instanceof ApplicationComponentEditor) {
                        editorPart = (ApplicationComponentEditor) editor;
                    } else {
                        ConvertigoPlugin.logWarning("The Application Component Editor won't open, please see the error log.");
                    }
                }
            }
        } catch (Exception e) {
            ConvertigoPlugin.logException(e, "Error while loading the page editor '" + application.getName() + "'");
        }
    }
    return editorPart;
}
Also used : ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) ApplicationComponentEditor(com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditor) IEditorPart(org.eclipse.ui.IEditorPart) InvalidParameterException(java.security.InvalidParameterException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) InvalidParameterException(java.security.InvalidParameterException) IEditorReference(org.eclipse.ui.IEditorReference) ApplicationComponentEditorInput(com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 17 with ApplicationComponent

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

the class MobileApplicationComponentTreeObject method treeObjectPropertyChanged.

@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
    super.treeObjectPropertyChanged(treeObjectEvent);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    Set<Object> done = checkDone(treeObjectEvent);
    String propertyName = (String) treeObjectEvent.propertyName;
    propertyName = ((propertyName == null) ? "" : propertyName);
    Object oldValue = treeObjectEvent.oldValue;
    Object newValue = treeObjectEvent.newValue;
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
        DatabaseObject dbo = doto.getObject();
        try {
            ApplicationComponent ac = getObject();
            // for Page or Menu or Route
            if (ac.equals(dbo.getParent())) {
                markApplicationAsDirty(done);
            } else // for any component inside a route
            if (ac.equals(dbo.getParent().getParent())) {
                markApplicationAsDirty(done);
            } else // for any UI component inside a menu or a stack
            if (dbo instanceof UIComponent) {
                UIComponent uic = (UIComponent) dbo;
                UIDynamicMenu menu = uic.getMenu();
                if (menu != null) {
                    if (ac.equals(menu.getParent())) {
                        if (propertyName.equals("FormControlName") || uic.isFormControlAttribute()) {
                            if (!newValue.equals(oldValue)) {
                                try {
                                    String oldSmart = ((MobileSmartSourceType) oldValue).getSmartValue();
                                    String newSmart = ((MobileSmartSourceType) newValue).getSmartValue();
                                    if (uic.getUIForm() != null) {
                                        String form = uic.getUIForm().getFormGroupName();
                                        if (menu.updateSmartSource(form + "\\?\\.controls\\['" + oldSmart + "'\\]", form + "?.controls['" + newSmart + "']")) {
                                            this.viewer.refresh();
                                        }
                                    }
                                } catch (Exception e) {
                                }
                            }
                        }
                        markApplicationAsDirty(done);
                    }
                }
            } else // for this application
            if (this.equals(doto)) {
                if (propertyName.equals("isPWA")) {
                    if (!newValue.equals(oldValue)) {
                        markPwaAsDirty();
                    }
                } else if (propertyName.equals("componentScriptContent")) {
                    if (!newValue.equals(oldValue)) {
                        markComponentTsAsDirty();
                        markApplicationAsDirty(done);
                    }
                } else if (propertyName.equals("useClickForTap")) {
                    for (TreeObject to : this.getChildren()) {
                        if (to instanceof ObjectsFolderTreeObject) {
                            ObjectsFolderTreeObject ofto = (ObjectsFolderTreeObject) to;
                            if (ofto.folderType == ObjectsFolderTreeObject.FOLDER_TYPE_PAGES) {
                                for (TreeObject cto : ofto.getChildren()) {
                                    if (cto instanceof MobilePageComponentTreeObject) {
                                        ((MobilePageComponentTreeObject) cto).markPageAsDirty(done);
                                    }
                                }
                            }
                        }
                    }
                    markApplicationAsDirty(done);
                } else if (propertyName.equals("tplProjectName")) {
                    // close app editor and reinitialize builder
                    Project project = ac.getProject();
                    closeAllEditors(false);
                    MobileBuilder.releaseBuilder(project);
                    MobileBuilder.initBuilder(project);
                    IProject iproject = ConvertigoPlugin.getDefault().getProjectPluginResource(project.getName());
                    iproject.refreshLocal(IResource.DEPTH_INFINITE, null);
                    // force app sources regeneration
                    for (TreeObject to : this.getChildren()) {
                        if (to instanceof ObjectsFolderTreeObject) {
                            ObjectsFolderTreeObject ofto = (ObjectsFolderTreeObject) to;
                            if (ofto.folderType == ObjectsFolderTreeObject.FOLDER_TYPE_PAGES) {
                                for (TreeObject cto : ofto.getChildren()) {
                                    if (cto instanceof MobilePageComponentTreeObject) {
                                        ((MobilePageComponentTreeObject) cto).markPageAsDirty(done);
                                    }
                                }
                            }
                        }
                    }
                    markApplicationAsDirty(done);
                    // delete node modules and alert user
                    final File nodeModules = new File(project.getDirPath(), "/_private/ionic/node_modules");
                    if (nodeModules.exists()) {
                        ProgressMonitorDialog dialog = new ProgressMonitorDialog(ConvertigoPlugin.getMainShell());
                        dialog.open();
                        dialog.run(true, false, new IRunnableWithProgress() {

                            @Override
                            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                                monitor.beginTask("deleting node modules", IProgressMonitor.UNKNOWN);
                                String alert = "template changed!";
                                if (com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(nodeModules)) {
                                    alert = "You have just changed the template.\nPackages have been deleted and will be reinstalled next time you run your application again.";
                                } else {
                                    alert = "You have just changed the template: packages could not be deleted!\nDo not forget to reinstall the packages before running your application again, otherwise it may be corrupted!";
                                }
                                monitor.done();
                                ConvertigoPlugin.infoMessageBox(alert);
                            }
                        });
                    }
                } else {
                    markApplicationAsDirty(done);
                }
            }
        } catch (Exception e) {
        }
    }
}
Also used : ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) UIDynamicMenu(com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu) InvalidParameterException(java.security.InvalidParameterException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProject(org.eclipse.core.resources.IProject) Project(com.twinsoft.convertigo.beans.core.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 18 with ApplicationComponent

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

the class MobileApplicationTreeObject method treeObjectPropertyChanged.

@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
    super.treeObjectPropertyChanged(treeObjectEvent);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    String propertyName = (String) treeObjectEvent.propertyName;
    propertyName = ((propertyName == null) ? "" : propertyName);
    Object oldValue = treeObjectEvent.oldValue;
    Object newValue = treeObjectEvent.newValue;
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
        DatabaseObject dbo = doto.getObject();
        try {
            if (this.equals(doto)) {
                if (propertyName.equals("applicationName")) {
                    if (!newValue.equals(oldValue)) {
                        ApplicationComponent app = (ApplicationComponent) ((MobileApplication) dbo).getApplicationComponent();
                        app.markPwaAsDirty();
                    }
                }
            }
        } catch (Exception e) {
        }
    }
}
Also used : ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 19 with ApplicationComponent

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

the class ApplicationComponentEditor method launchBuilder.

public void launchBuilder(boolean forceInstall, boolean forceClean) {
    final MobileBuilderBuildMode buildMode = this.buildMode;
    final int buildCount = ++this.buildCount;
    final boolean isDark = SwtUtils.isDark();
    // Close editors (*.temp.ts) to avoid npm error at build launch
    ConvertigoPlugin.getDisplay().syncExec(new Runnable() {

        public void run() {
            try {
                ApplicationComponent mc = applicationEditorInput.application;
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                if (activePage != null) {
                    IEditorReference[] editorRefs = activePage.getEditorReferences();
                    for (int i = 0; i < editorRefs.length; i++) {
                        IEditorReference editorRef = (IEditorReference) editorRefs[i];
                        try {
                            IEditorInput editorInput = editorRef.getEditorInput();
                            if (editorInput != null && editorInput instanceof ComponentFileEditorInput) {
                                if (((ComponentFileEditorInput) editorInput).is(mc) || ((ComponentFileEditorInput) editorInput).isChildOf(mc)) {
                                    activePage.closeEditor(editorRef.getEditor(false), false);
                                }
                            }
                        } catch (Exception e) {
                        }
                    }
                }
            } catch (Throwable t) {
            }
        }
    });
    // Launch build
    Engine.execute(() -> {
        try {
            String loader = IOUtils.toString(getClass().getResourceAsStream("loader.html"), "UTF-8");
            if (isDark) {
                loader = loader.replace("lightblue", "rgb(47,47,47); color: white");
            }
            c8oBrowser.setText(loader);
        } catch (Exception e1) {
            throw new RuntimeException(e1);
        }
        Project project = applicationEditorInput.application.getProject();
        File ionicDir = new File(project.getDirPath(), "_private/ionic");
        File nodeModules = new File(ionicDir, "node_modules");
        String nodeVersion = ProcessUtils.getNodeVersion(project);
        File nodeDir = ProcessUtils.getDefaultNodeDir();
        try {
            nodeDir = ProcessUtils.getNodeDir(nodeVersion, (r, t, x) -> {
                appendOutput("Downloading nodejs " + nodeVersion + ": " + Math.round((r * 100f) / t) + "%");
            });
        } catch (Exception e1) {
        }
        {
            String versions = "Will use nodejs " + ProcessUtils.getNodeVersion(nodeDir) + " and npm " + ProcessUtils.getNpmVersion(nodeDir);
            appendOutput(versions);
            Engine.logStudio.info(versions);
        }
        String path = nodeDir.getAbsolutePath();
        terminateNode();
        MobileBuilder mb = project.getMobileBuilder();
        if (forceInstall || !nodeModules.exists() || mb.getNeedPkgUpdate()) {
            boolean[] running = { true };
            try {
                new File(ionicDir, "package-lock.json").delete();
                if (forceClean) {
                    appendOutput("...", "...", "Removing existing node_modules... This can take several seconds...");
                    Engine.logStudio.info("Removing existing node_modules... This can take several seconds...");
                    com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(nodeModules);
                }
                appendOutput("Installing node_modules... This can take several minutes depending on your network connection speed...");
                Engine.logStudio.info("Installing node_modules... This can take several minutes depending on your network connection speed...");
                long start = System.currentTimeMillis();
                ProcessBuilder pb = ProcessUtils.getNpmProcessBuilder(path, "npm", "install", ionicDir.toString(), "--no-shrinkwrap", "--no-package-lock");
                pb.redirectErrorStream(true);
                pb.directory(ionicDir);
                Process p = pb.start();
                Engine.execute(() -> {
                    try {
                        File staging = new File(nodeModules, ".staging");
                        while (running[0] && !staging.exists()) {
                            appendOutput("Resolving dependencies … (" + Math.round(System.currentTimeMillis() - start) / 1000 + " sec)");
                            Thread.sleep(1000);
                        }
                        while (running[0] && staging.exists()) {
                            appendOutput("Collecting node_modules: " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfAsBigInteger(nodeModules)) + " (" + Math.round(System.currentTimeMillis() - start) / 1000 + " sec)");
                            Engine.logStudio.info("Installing, node_module size is now : " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfAsBigInteger(nodeModules)));
                            Thread.sleep(1000);
                        }
                    } catch (Exception e) {
                        appendOutput("Something wrong during the install: " + e);
                    }
                });
                processes.add(p);
                BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) {
                    line = pRemoveEchap.matcher(line).replaceAll("");
                    if (StringUtils.isNotBlank(line)) {
                        Engine.logStudio.info(line);
                        appendOutput(line);
                    }
                }
                Engine.logStudio.info(line);
                appendOutput("\\o/");
            } catch (Exception e) {
                appendOutput(":( " + e);
            }
            running[0] = false;
        }
        mb.setNeedPkgUpdate(false);
        Object mutex = new Object();
        mb.setBuildMutex(mutex);
        mb.setAppBuildMode(buildMode);
        try {
            ConvertigoPlugin.getDefault().getProjectPluginResource(project.getName()).refreshLocal(IResource.DEPTH_INFINITE, null);
        } catch (CoreException ce) {
        }
        try {
            mb.startBuild();
            File displayObjectsMobile = new File(project.getDirPath(), "DisplayObjects/mobile");
            displayObjectsMobile.mkdirs();
            appendOutput("removing previous build directory");
            for (File f : displayObjectsMobile.listFiles()) {
                if (!f.getName().equals("assets")) {
                    com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(f);
                }
            }
            appendOutput("previous build directory removed");
            this.applicationEditorInput.application.checkFolder();
            try {
                File watchJS = new File(project.getDirPath(), "_private/ionic/node_modules/@ionic/app-scripts/dist/watch.js");
                if (watchJS.exists()) {
                    int ms = ConvertigoPlugin.getMobileBuilderThreshold();
                    String txt = FileUtils.readFileToString(watchJS, "UTF-8");
                    String ntxt = txt.replaceAll("var BUILD_UPDATE_DEBOUNCE_MS = \\d+;", "var BUILD_UPDATE_DEBOUNCE_MS = " + ms + ";");
                    if (!txt.equals(ntxt))
                        ;
                    {
                        FileUtils.writeStringToFile(watchJS, ntxt, "UTF-8");
                    }
                }
            } catch (Exception e) {
                Engine.logStudio.warn("Failed to update DEBOUNCE", e);
            }
            File assets = new File(displayObjectsMobile, "assets");
            if (assets.exists() && assets.isDirectory()) {
                appendOutput("Handle application assets");
                Engine.logStudio.info("Handle application assets");
                File privAssets = new File(ionicDir, "src/assets");
                FileUtils.deleteDirectory(privAssets);
                FileUtils.copyDirectory(assets, privAssets);
            }
            ProcessBuilder pb = ProcessUtils.getNpmProcessBuilder(path, "npm", "run", buildMode.command(), "--nobrowser");
            if (!MobileBuilderBuildMode.production.equals(buildMode)) {
                List<String> cmd = pb.command();
                synchronized (usedPort) {
                    cmd.add("--port");
                    cmd.add("" + (portNode = NetworkUtils.nextAvailable(8100, usedPort)));
                    cmd.add("--livereload-port");
                    cmd.add("" + (portReload = NetworkUtils.nextAvailable(35729, usedPort)));
                    cmd.add("--dev-logger-port");
                    cmd.add("" + (portLogger = NetworkUtils.nextAvailable(53703, usedPort)));
                }
            }
            pb.redirectErrorStream(true);
            pb.directory(ionicDir);
            Process p = pb.start();
            processes.add(p);
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = br.readLine()) != null) {
                line = pRemoveEchap.matcher(line).replaceAll("");
                if (StringUtils.isNotBlank(line)) {
                    Engine.logStudio.info(line);
                    appendOutput(line);
                    if (line.matches(".*build .*finished.*")) {
                        synchronized (mutex) {
                            mutex.notify();
                        }
                        mb.buildFinished();
                    }
                    Matcher m = pIsServerRunning.matcher(line);
                    if (m.matches()) {
                        JSONObject envJSON = new JSONObject();
                        envJSON.put("remoteBase", EnginePropertiesManager.getProperty(PropertyName.APPLICATION_SERVER_CONVERTIGO_URL) + "/projects/" + project.getName() + "/_private");
                        FileUtils.write(new File(displayObjectsMobile, "env.json"), envJSON.toString(4), "UTF-8");
                        baseUrl = m.group(1);
                        synchronized (mutex) {
                            mutex.notify();
                        }
                        mb.buildFinished();
                        doLoad();
                    }
                }
            }
            if (buildCount == this.buildCount) {
                if (MobileBuilderBuildMode.production.equals(buildMode)) {
                    String SERVER_C8O_URL = EnginePropertiesManager.getProperty(PropertyName.APPLICATION_SERVER_CONVERTIGO_URL);
                    baseUrl = SERVER_C8O_URL + "/projects/" + project.getName() + "/DisplayObjects/mobile/index.html";
                    doLoad();
                    toast("Application in production mode");
                }
                appendOutput("\\o/");
            } else {
                appendOutput("previous build canceled !");
            }
        } catch (Exception e) {
            appendOutput(":( " + e);
        } finally {
            synchronized (mutex) {
                mutex.notify();
            }
            mb.setBuildMutex(null);
            mb.buildFinished();
            try {
                ConvertigoPlugin.getDefault().getProjectPluginResource(project.getName()).refreshLocal(IResource.DEPTH_INFINITE, null);
            } catch (CoreException ce) {
            }
        }
    });
}
Also used : Element(com.teamdev.jxbrowser.dom.Element) CoreException(org.eclipse.core.runtime.CoreException) FocusEvent(org.eclipse.swt.events.FocusEvent) StringUtils(org.apache.commons.lang3.StringUtils) Point(org.eclipse.swt.graphics.Point) Matcher(java.util.regex.Matcher) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) UIUseShared(com.twinsoft.convertigo.beans.mobile.components.UIUseShared) KeyEvent(org.eclipse.swt.events.KeyEvent) UIDynamicElement(com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IEditorPart(org.eclipse.ui.IEditorPart) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) Set(java.util.Set) ToolItem(org.eclipse.swt.widgets.ToolItem) IOUtils(org.apache.commons.io.IOUtils) MenuItem(org.eclipse.swt.widgets.MenuItem) SWT(org.eclipse.swt.SWT) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) JsAccessible(com.teamdev.jxbrowser.js.JsAccessible) MobileComponent(com.twinsoft.convertigo.beans.mobile.components.MobileComponent) EditorPart(org.eclipse.ui.part.EditorPart) SwtUtils(com.twinsoft.convertigo.eclipse.swt.SwtUtils) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) SelectionListener(org.eclipse.swt.events.SelectionListener) JFaceResources(org.eclipse.jface.resource.JFaceResources) IEditorSite(org.eclipse.ui.IEditorSite) RequestPermissionCallback(com.teamdev.jxbrowser.permission.callback.RequestPermissionCallback) GridData(org.eclipse.swt.layout.GridData) RowData(org.eclipse.swt.layout.RowData) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UIDynamicInvoke(com.twinsoft.convertigo.beans.mobile.components.UIDynamicInvoke) Engine(com.twinsoft.convertigo.engine.Engine) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) MobileDebugView(com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView) MobileBuilderBuildMode(com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode) JsObject(com.teamdev.jxbrowser.js.JsObject) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Node(com.teamdev.jxbrowser.dom.Node) Project(com.twinsoft.convertigo.beans.core.Project) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) JSONException(org.codehaus.jettison.json.JSONException) ModifyListener(org.eclipse.swt.events.ModifyListener) FileUtils(com.twinsoft.convertigo.engine.util.FileUtils) IEditorReference(org.eclipse.ui.IEditorReference) BufferedReader(java.io.BufferedReader) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ProcessUtils(com.twinsoft.convertigo.engine.util.ProcessUtils) GridLayout(org.eclipse.swt.layout.GridLayout) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) ClipboardAction(com.twinsoft.convertigo.eclipse.popup.actions.ClipboardAction) ToolBar(org.eclipse.swt.widgets.ToolBar) VerifyListener(org.eclipse.swt.events.VerifyListener) MobileEventListener(com.twinsoft.convertigo.engine.mobile.MobileEventListener) EnginePropertiesManager(com.twinsoft.convertigo.engine.EnginePropertiesManager) InjectJsCallback(com.teamdev.jxbrowser.browser.callback.InjectJsCallback) NetworkUtils(com.twinsoft.convertigo.engine.util.NetworkUtils) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Collection(java.util.Collection) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) UIControlEvent(com.twinsoft.convertigo.beans.mobile.components.UIControlEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConvertigoPlugin(com.twinsoft.convertigo.eclipse.ConvertigoPlugin) PropertyName(com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyName) List(java.util.List) Pattern(java.util.regex.Pattern) ShowContextMenuCallback(com.teamdev.jxbrowser.browser.callback.ShowContextMenuCallback) Label(org.eclipse.swt.widgets.Label) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Document(com.teamdev.jxbrowser.dom.Document) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) FocusListener(org.eclipse.swt.events.FocusListener) Event(org.eclipse.swt.widgets.Event) Frame(com.teamdev.jxbrowser.frame.Frame) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) HashSet(java.util.HashSet) PaletteSourceTransfer(com.twinsoft.convertigo.eclipse.dnd.PaletteSourceTransfer) BatchOperationHelper(com.twinsoft.convertigo.engine.helpers.BatchOperationHelper) Charset(java.nio.charset.Charset) Browser(com.teamdev.jxbrowser.browser.Browser) LinkedList(java.util.LinkedList) UIDynamicAction(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) Response(com.teamdev.jxbrowser.browser.callback.InjectJsCallback.Response) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RowLayout(org.eclipse.swt.layout.RowLayout) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) IResource(org.eclipse.core.resources.IResource) NumberUtils(org.apache.commons.lang3.math.NumberUtils) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) KeyListener(org.eclipse.swt.events.KeyListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) FocusAdapter(org.eclipse.swt.events.FocusAdapter) C8oBrowser(com.twinsoft.convertigo.eclipse.swt.C8oBrowser) Control(org.eclipse.swt.widgets.Control) Matcher(java.util.regex.Matcher) IEditorReference(org.eclipse.ui.IEditorReference) InputStreamReader(java.io.InputStreamReader) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) MobileBuilderBuildMode(com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode) Point(org.eclipse.swt.graphics.Point) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) JSONException(org.codehaus.jettison.json.JSONException) Project(com.twinsoft.convertigo.beans.core.Project) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) CoreException(org.eclipse.core.runtime.CoreException) JSONObject(org.codehaus.jettison.json.JSONObject) BufferedReader(java.io.BufferedReader) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject) JsObject(com.teamdev.jxbrowser.js.JsObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput)

Example 20 with ApplicationComponent

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

the class MobilePickerContentProvider method addActions.

private void addActions(TVObject tvi, Object object) {
    if (object != null) {
        List<? extends UIComponent> list = null;
        if (object instanceof ApplicationComponent) {
            ApplicationComponent app = (ApplicationComponent) object;
            list = app.getUIAppEventList();
            list.addAll(GenericUtils.cast(app.getUIEventSubscriberList()));
            list.addAll(GenericUtils.cast(app.getSharedActionList()));
        } else if (object instanceof UIActionStack) {
            if (tvi != null && "actions".equals(tvi.getName())) {
                list = new ArrayList<>(Arrays.asList((UIActionStack) object));
            } else {
                list = ((UIActionStack) object).getUIComponentList();
            }
        } else if (object instanceof UISharedComponent) {
            list = ((UISharedComponent) object).getUIComponentList();
        } else if (object instanceof PageComponent) {
            list = ((PageComponent) object).getUIComponentList();
        } else if (object instanceof UIComponent) {
            list = ((UIComponent) object).getUIComponentList();
        }
        if (list != null) {
            TVObject tvEvents = null, tvControls = null;
            if (tvi != null && "actions".equals(tvi.getName())) {
                tvEvents = tvi.children.get(0);
                tvControls = tvi.children.get(1);
            }
            for (UIComponent uic : list) {
                // 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;
                    }
                }
                if (showInPicker) {
                    if (uic instanceof UIAppEvent || uic instanceof UIPageEvent || uic instanceof UIEventSubscriber) {
                        TVObject tve = tvEvents == null ? tvi.add(new TVObject(uic.toString(), uic, null)) : tvEvents.add(new TVObject(uic.toString(), uic, null));
                        addActions(tve, uic);
                    } else if (uic instanceof UIActionEvent || uic instanceof UIControlEvent) {
                        TVObject tve = tvControls == null ? tvi.add(new TVObject(uic.toString(), uic, null)) : tvControls.add(new TVObject(uic.toString(), uic, null));
                        addActions(tve, uic);
                    } else if (uic instanceof IAction || uic instanceof UIActionStack) {
                        SourceData sd = null;
                        try {
                            sd = Filter.Action.toSourceData(new JSONObject().put("priority", uic.priority));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        TVObject tuic = tvi.add(new TVObject(uic.toString(), uic, sd));
                        addActions(tuic, uic);
                    } else {
                        addActions(tvi, uic);
                    }
                // } else {
                // addActions(tvi, uic);
                }
            }
        }
    }
}
Also used : UIAppEvent(com.twinsoft.convertigo.beans.mobile.components.UIAppEvent) UIPageEvent(com.twinsoft.convertigo.beans.mobile.components.UIPageEvent) IAction(com.twinsoft.convertigo.beans.mobile.components.IAction) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) ArrayList(java.util.ArrayList) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) JSONException(org.codehaus.jettison.json.JSONException) UIEventSubscriber(com.twinsoft.convertigo.beans.mobile.components.UIEventSubscriber) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) SourceData(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) UIControlEvent(com.twinsoft.convertigo.beans.mobile.components.UIControlEvent) JSONObject(org.codehaus.jettison.json.JSONObject) UIActionEvent(com.twinsoft.convertigo.beans.mobile.components.UIActionEvent)

Aggregations

ApplicationComponent (com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent)42 IApplicationComponent (com.twinsoft.convertigo.beans.core.IApplicationComponent)20 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)16 File (java.io.File)14 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)13 EngineException (com.twinsoft.convertigo.engine.EngineException)12 UISharedComponent (com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)10 UIComponent (com.twinsoft.convertigo.beans.mobile.components.UIComponent)9 UIActionStack (com.twinsoft.convertigo.beans.mobile.components.UIActionStack)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 JSONObject (org.codehaus.jettison.json.JSONObject)8 JSONException (org.codehaus.jettison.json.JSONException)7 PartInitException (org.eclipse.ui.PartInitException)7 MobileApplication (com.twinsoft.convertigo.beans.core.MobileApplication)6 Project (com.twinsoft.convertigo.beans.core.Project)6 UIUseShared (com.twinsoft.convertigo.beans.mobile.components.UIUseShared)6 IOException (java.io.IOException)6 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)6 IPageComponent (com.twinsoft.convertigo.beans.core.IPageComponent)5 UICustomAction (com.twinsoft.convertigo.beans.mobile.components.UICustomAction)5