Search in sources :

Example 6 with UIActionStack

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

Example 7 with UIActionStack

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

the class MobileUIComponentTreeObject method handleSharedActionChanged.

protected void handleSharedActionChanged(UIActionStack sharedAction, Set<Object> done) {
    if (sharedAction != null) {
        // a uic has changed/added/removed from a shared action referenced by this UIDynamicInvoke
        if (getObject() instanceof UIDynamicInvoke) {
            UIDynamicInvoke udi = (UIDynamicInvoke) getObject();
            if (udi.getSharedActionQName().equals(sharedAction.getQName())) {
                UIActionStack uisa = udi.getSharedAction();
                UISharedComponent uisc = udi.getSharedComponent();
                // udi inside a shared action
                if (uisa != null && !uisa.equals(sharedAction)) {
                    notifyDataseObjectPropertyChanged(uisa, "", null, null, done);
                } else // udi inside a shared component
                if (uisc != null) {
                    notifyDataseObjectPropertyChanged(uisc, "", null, null, done);
                } else // udi inside a page or menu
                {
                    try {
                        markMainAsDirty(udi, done);
                    } catch (EngineException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
Also used : UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) UIDynamicInvoke(com.twinsoft.convertigo.beans.mobile.components.UIDynamicInvoke) EngineException(com.twinsoft.convertigo.engine.EngineException) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)

Example 8 with UIActionStack

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

the class MobileUIComponentTreeObject method getNamedSourceSelector.

@Override
public NamedSourceSelector getNamedSourceSelector() {
    return new NamedSourceSelector() {

        @Override
        Object thisTreeObject() {
            return MobileUIComponentTreeObject.this;
        }

        @Override
        protected List<String> getPropertyNamesForSource(Class<?> c) {
            List<String> list = new ArrayList<String>();
            UIComponent object = getObject();
            if (object instanceof UIDynamicTab) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobilePageComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("tabpage");
                }
            } else if (object instanceof UIDynamicMenuItem) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobilePageComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("itempage");
                }
            } else if (object instanceof UIDynamicAnimate) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobilePageComponentTreeObject.class.isAssignableFrom(c) || MobileUIComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("identifiable");
                }
            } else if (object instanceof UIDynamicInvoke) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobileUIComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("stack");
                }
            } else if (object instanceof UIUseShared) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobileUIComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("sharedcomponent");
                }
            } else if (object instanceof UIDynamicInfiniteScroll) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobilePageComponentTreeObject.class.isAssignableFrom(c) || MobileUIComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("scrollaction");
                }
            } else if (object instanceof UIDynamicElement) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || SequenceTreeObject.class.isAssignableFrom(c) || ConnectorTreeObject.class.isAssignableFrom(c)) {
                    list.add("requestable");
                }
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobilePageComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("page");
                }
                if (ProjectTreeObject.class.isAssignableFrom(c) || ConnectorTreeObject.class.isAssignableFrom(c) || DesignDocumentTreeObject.class.isAssignableFrom(c) || DesignDocumentViewTreeObject.class.isAssignableFrom(c)) {
                    list.add("fsview");
                }
            }
            return list;
        }

        @Override
        protected boolean isNamedSource(String propertyName) {
            UIComponent object = getObject();
            if (object instanceof UIDynamicTab) {
                return "tabpage".equals(propertyName);
            } else if (object instanceof UIDynamicMenuItem) {
                return "itempage".equals(propertyName);
            } else if (object instanceof UIDynamicAnimate) {
                return "identifiable".equals(propertyName);
            } else if (object instanceof UIDynamicInvoke) {
                return "stack".equals(propertyName);
            } else if (object instanceof UIUseShared) {
                return "sharedcomponent".equals(propertyName);
            } else if (object instanceof UIDynamicInfiniteScroll) {
                return "scrollaction".equals(propertyName);
            } else if (object instanceof UIDynamicElement) {
                return "requestable".equals(propertyName) || "fsview".equals(propertyName) || "page".equals(propertyName);
            }
            return false;
        }

        @Override
        public boolean isSelectable(String propertyName, Object nsObject) {
            UIComponent object = getObject();
            if (object instanceof UIDynamicTab) {
                if ("tabpage".equals(propertyName)) {
                    if (nsObject instanceof PageComponent) {
                        return (((PageComponent) nsObject).getProject().equals(object.getProject()));
                    }
                }
            } else if (object instanceof UIDynamicMenuItem) {
                if ("itempage".equals(propertyName)) {
                    if (nsObject instanceof PageComponent) {
                        return (((PageComponent) nsObject).getProject().equals(object.getProject()));
                    }
                }
            } else if (object instanceof UIDynamicAnimate) {
                if ("identifiable".equals(propertyName)) {
                    UIDynamicAnimate uda = (UIDynamicAnimate) object;
                    if (nsObject instanceof UIElement) {
                        UIElement ue = (UIElement) nsObject;
                        if (hasSameScriptComponent(uda, ue)) {
                            return !ue.getIdentifier().isEmpty();
                        }
                    }
                }
            } else if (object instanceof UIDynamicInvoke) {
                if ("stack".equals(propertyName)) {
                    return nsObject instanceof UIActionStack;
                }
            } else if (object instanceof UIUseShared) {
                if ("sharedcomponent".equals(propertyName)) {
                    return nsObject instanceof UISharedComponent;
                }
            } else if (object instanceof UIDynamicInfiniteScroll) {
                if ("scrollaction".equals(propertyName)) {
                    if (nsObject instanceof UIDynamicAction) {
                        UIDynamicAction uida = (UIDynamicAction) nsObject;
                        if (uida.getProject().equals(object.getProject())) {
                            if (uida.getIonBean().getName().equals("CallSequenceAction")) {
                                return true;
                            }
                            if (uida.getIonBean().getName().equals("FullSyncViewAction")) {
                                return true;
                            }
                        }
                    }
                }
            } else if (object instanceof UIDynamicElement) {
                if ("requestable".equals(propertyName)) {
                    UIDynamicElement cc = (UIDynamicElement) object;
                    if (cc.getIonBean().getName().equals("CallSequenceAction")) {
                        return nsObject instanceof Sequence;
                    }
                    if (cc.getIonBean().getName().equals("CallFullSyncAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncSyncAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncViewAction")) {
                        return nsObject instanceof DesignDocument;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncPostAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncGetAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncDeleteAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncPutAttachmentAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncDeleteAttachmentAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FSImage")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("AutoScrollComponent")) {
                        return nsObject instanceof Sequence;
                    }
                }
                if ("fsview".equals(propertyName)) {
                    UIDynamicElement cc = (UIDynamicElement) object;
                    if (cc.getIonBean().getName().equals("FullSyncViewAction")) {
                        return nsObject instanceof String;
                    }
                    if (cc.getIonBean().getName().equals("AutoScrollComponent")) {
                        return nsObject instanceof DesignDocument || nsObject instanceof String;
                    }
                }
                if ("page".equals(propertyName)) {
                    if (nsObject instanceof PageComponent) {
                        return (((PageComponent) nsObject).getProject().equals(object.getProject()));
                    }
                }
            }
            return false;
        }

        @Override
        protected void handleSourceCleared(String propertyName) {
        // nothing to do
        }

        @Override
        protected void handleSourceRenamed(String propertyName, String oldName, String newName) {
            if (isNamedSource(propertyName)) {
                boolean hasBeenRenamed = false;
                Object oValue = getPropertyValue(propertyName);
                String pValue;
                if (oValue instanceof MobileSmartSourceType) {
                    MobileSmartSourceType sst = (MobileSmartSourceType) oValue;
                    pValue = sst.getSmartValue();
                } else {
                    pValue = (String) oValue;
                }
                String _pValue = pValue;
                if (pValue != null && (pValue.startsWith(oldName + ".") || pValue.equals(oldName))) {
                    _pValue = newName + pValue.substring(oldName.length());
                    if (!pValue.equals(_pValue)) {
                        UIComponent object = getObject();
                        if (object instanceof UIDynamicTab) {
                            if ("tabpage".equals(propertyName)) {
                                ((UIDynamicTab) object).setTabPage(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIDynamicMenuItem) {
                            if ("itempage".equals(propertyName)) {
                                ((UIDynamicMenuItem) object).setItemPage(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIDynamicAnimate) {
                            if ("identifiable".equals(propertyName)) {
                                ((UIDynamicAnimate) object).setIdentifiable(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIDynamicInvoke) {
                            if ("stack".equals(propertyName)) {
                                ((UIDynamicInvoke) object).setSharedActionQName(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIUseShared) {
                            if ("sharedcomponent".equals(propertyName)) {
                                ((UIUseShared) object).setSharedComponentQName(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIDynamicInfiniteScroll) {
                            if ("scrollaction".equals(propertyName)) {
                                ((UIDynamicInfiniteScroll) object).setScrollAction(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIDynamicElement) {
                            if ("requestable".equals(propertyName)) {
                                ((UIDynamicElement) object).getIonBean().setPropertyValue("requestable", new MobileSmartSourceType(_pValue));
                                hasBeenRenamed = true;
                            }
                            if ("fsview".equals(propertyName)) {
                                ((UIDynamicElement) object).getIonBean().setPropertyValue("fsview", new MobileSmartSourceType(_pValue));
                                hasBeenRenamed = true;
                            }
                            if ("page".equals(propertyName)) {
                                ((UIDynamicElement) object).getIonBean().setPropertyValue("page", new MobileSmartSourceType(_pValue));
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIText) {
                            if ("textValue".equals(propertyName)) {
                                ((UIText) object).setTextSmartType(new MobileSmartSourceType(_pValue));
                                hasBeenRenamed = true;
                            }
                        }
                    }
                }
                if (hasBeenRenamed) {
                    hasBeenModified(true);
                    viewer.refresh();
                    ConvertigoPlugin.projectManager.getProjectExplorerView().updateTreeObject(MobileUIComponentTreeObject.this);
                    // refresh editors (e.g labels in combobox)
                    getDescriptors();
                    TreeObjectEvent treeObjectEvent = new TreeObjectEvent(MobileUIComponentTreeObject.this, propertyName, pValue, _pValue);
                    ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectPropertyChanged(treeObjectEvent);
                }
            }
        }

        @Override
        protected void refactorSmartSources(Class<?> c, String oldName, String newName) {
            try {
                // A project has been renamed
                if (ProjectTreeObject.class.isAssignableFrom(c)) {
                    UIComponent object = getObject();
                    for (java.beans.PropertyDescriptor pd : CachedIntrospector.getBeanInfo(object).getPropertyDescriptors()) {
                        if (pd.getPropertyType().equals(MobileSmartSourceType.class)) {
                            String propertyName = pd.getName();
                            Object oValue = getPropertyValue(propertyName);
                            MobileSmartSourceType msst = (MobileSmartSourceType) oValue;
                            MobileSmartSource mss = msst.getSmartSource();
                            boolean hasBeenChanged = false;
                            if (mss != null) {
                                if (oldName.equals(mss.getProjectName())) {
                                    mss.setProjectName(newName);
                                    msst.setSmartValue(mss.toJsonString());
                                    hasBeenChanged = true;
                                }
                            }
                            if (hasBeenChanged) {
                                Object nValue = getPropertyValue(propertyName);
                                hasBeenModified(true);
                                viewer.refresh();
                                ConvertigoPlugin.projectManager.getProjectExplorerView().updateTreeObject(MobileUIComponentTreeObject.this);
                                // refresh editors (e.g labels in combobox)
                                getDescriptors();
                                TreeObjectEvent treeObjectEvent = new TreeObjectEvent(MobileUIComponentTreeObject.this, propertyName, oValue, nValue);
                                ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectPropertyChanged(treeObjectEvent);
                            }
                        }
                    }
                }
            } catch (Exception e) {
            // TODO: handle exception
            }
        }
    };
}
Also used : UIElement(com.twinsoft.convertigo.beans.mobile.components.UIElement) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) UIUseShared(com.twinsoft.convertigo.beans.mobile.components.UIUseShared) ArrayList(java.util.ArrayList) UIDynamicTab(com.twinsoft.convertigo.beans.mobile.components.UIDynamicTab) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) UIDynamicInfiniteScroll(com.twinsoft.convertigo.beans.mobile.components.UIDynamicInfiniteScroll) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) UIText(com.twinsoft.convertigo.beans.mobile.components.UIText) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) UIDynamicElement(com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement) Sequence(com.twinsoft.convertigo.beans.core.Sequence) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) UIDynamicAnimate(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAnimate) UIDynamicAction(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) MobileSmartSource(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource) UIDynamicInvoke(com.twinsoft.convertigo.beans.mobile.components.UIDynamicInvoke) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) UIDynamicMenuItem(com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenuItem) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 9 with UIActionStack

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

the class MobileUIComponentTreeObject method treeObjectAdded.

@Override
public void treeObjectAdded(TreeObjectEvent treeObjectEvent) {
    super.treeObjectAdded(treeObjectEvent);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    Set<Object> done = checkDone(treeObjectEvent);
    String propertyName = (String) treeObjectEvent.propertyName;
    propertyName = ((propertyName == null) ? "" : propertyName);
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
        DatabaseObject dbo = doto.getObject();
        try {
            if (this.equals(treeObject)) {
                UIActionStack uisa = ((UIComponent) dbo).getSharedAction();
                UISharedComponent uisc = ((UIComponent) dbo).getSharedComponent();
                if (uisa != null && !uisa.equals(getObject())) {
                    notifyDataseObjectPropertyChanged(uisa, "", null, null, done);
                }
                if (uisc != null && !uisc.equals(getObject())) {
                    notifyDataseObjectPropertyChanged(uisc, "", null, null, done);
                }
            } else {
                if (dbo instanceof UIActionStack) {
                    handleSharedActionChanged((UIActionStack) dbo, done);
                } else if (dbo instanceof UISharedComponent) {
                    handleSharedComponentChanged((UISharedComponent) dbo, done);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 10 with UIActionStack

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

Aggregations

UIActionStack (com.twinsoft.convertigo.beans.mobile.components.UIActionStack)13 UISharedComponent (com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)11 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)9 UIComponent (com.twinsoft.convertigo.beans.mobile.components.UIComponent)8 EngineException (com.twinsoft.convertigo.engine.EngineException)8 ApplicationComponent (com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent)6 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)5 UIDynamicAction (com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction)5 UIDynamicInvoke (com.twinsoft.convertigo.beans.mobile.components.UIDynamicInvoke)5 CoreException (org.eclipse.core.runtime.CoreException)5 UICustomAction (com.twinsoft.convertigo.beans.mobile.components.UICustomAction)4 JSONException (org.codehaus.jettison.json.JSONException)4 DesignDocument (com.twinsoft.convertigo.beans.couchdb.DesignDocument)3 IAction (com.twinsoft.convertigo.beans.mobile.components.IAction)3 IScriptComponent (com.twinsoft.convertigo.beans.mobile.components.IScriptComponent)3 MobileSmartSourceType (com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType)3 UIUseShared (com.twinsoft.convertigo.beans.mobile.components.UIUseShared)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 IApplicationComponent (com.twinsoft.convertigo.beans.core.IApplicationComponent)2 IPageComponent (com.twinsoft.convertigo.beans.core.IPageComponent)2