Search in sources :

Example 11 with ApplicationComponent

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

the class MobilePageSegmentValidator method isValid.

@Override
public String isValid(Object value) {
    if (page != null) {
        String segment = value.toString();
        if (segment.isEmpty()) {
            return "The segment must not be empty!";
        }
        if (segment.startsWith("/")) {
            return "The segment must not start with \"/\"!";
        }
        if (segment.endsWith("/")) {
            return "The segment must not end with \"/\"!";
        }
        Pattern pattern = Pattern.compile("\\$\\{(.*)\\}");
        Matcher matcher = pattern.matcher(segment);
        if (matcher.find()) {
            return "The segment must not contain symbols!";
        }
        try {
            new URI("http://example.com/" + segment);
        } catch (Exception e) {
            return "The segment is not valid!";
        }
        ApplicationComponent app = page.getApplication();
        if (app != null) {
            for (PageComponent p : app.getPageComponentList()) {
                if (!p.equals(page)) {
                    if (toParamPath(p.getSegment()).equals(toParamPath(segment))) {
                        if (p.getSegment().equals(segment))
                            return "Segment \"" + p.getSegment() + "\" already exists for the application!";
                        else
                            return "A similar segment \"" + p.getSegment() + "\" already exists for the application!";
                    }
                    if (p.getName().equals(segment)) {
                        return "Segment \"" + segment + "\" is invalid: It must not be the name of another page!";
                    }
                }
            }
        }
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) URI(java.net.URI) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent)

Example 12 with ApplicationComponent

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

the class ApplicationComponentEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);
    setInput(input);
    applicationEditorInput = (ApplicationComponentEditorInput) input;
    ApplicationComponent application = applicationEditorInput.application;
    Project project = application.getProject();
    datasetDir = new File(project.getDirPath() + "/dataset");
    datasetDir.mkdirs();
    devicePref = new File(Engine.USER_WORKSPACE_PATH, "studio/device-" + project.getName() + ".json");
    setPartName(project.getName() + " [A: " + application.getName() + "]");
    terminateNode();
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) File(java.io.File)

Example 13 with ApplicationComponent

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

the class MobileComponentImportVariablesAction 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();
            if (databaseObject != null) {
                if (databaseObject instanceof UIDynamicAction) {
                    UIDynamicAction dynAction = (UIDynamicAction) databaseObject;
                    IonBean ionBean = ((UIDynamicAction) dynAction).getIonBean();
                    if (ionBean != null) {
                        // Case of CallSequenceAction
                        if (ionBean.getName().equals("CallSequenceAction")) {
                            Object value = ionBean.getProperty("requestable").getValue();
                            if (!value.equals(false)) {
                                String target = value.toString();
                                if (!target.isEmpty()) {
                                    try {
                                        String projectName = target.substring(0, target.indexOf('.'));
                                        String sequenceName = target.substring(target.indexOf('.') + 1);
                                        Project p = Engine.theApp.databaseObjectsManager.getProjectByName(projectName);
                                        Sequence sequence = p.getSequenceByName(sequenceName);
                                        int size = sequence.numberOfVariables();
                                        for (int i = 0; i < size; i++) {
                                            RequestableVariable variable = (RequestableVariable) sequence.getVariable(i);
                                            if (variable != null) {
                                                String variableName = variable.getName();
                                                if (dynAction.getVariable(variableName) == null) {
                                                    if (!StringUtils.isNormalized(variableName))
                                                        throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
                                                    UIControlVariable uiVariable = new UIControlVariable();
                                                    uiVariable.setName(variableName);
                                                    uiVariable.setComment(variable.getDescription());
                                                    uiVariable.setVarSmartType(new MobileSmartSourceType(variable.getDefaultValue().toString()));
                                                    dynAction.addUIComponent(uiVariable);
                                                    uiVariable.bNew = true;
                                                    uiVariable.hasChanged = true;
                                                    dynAction.hasChanged = true;
                                                }
                                            }
                                        }
                                    } catch (Exception e) {
                                    }
                                }
                            }
                        } else // Case of InvokeAction
                        if (ionBean.getName().equals("InvokeAction")) {
                            UIDynamicInvoke dynInvoke = (UIDynamicInvoke) databaseObject;
                            UIActionStack stack = dynInvoke.getTargetSharedAction();
                            if (stack != null) {
                                for (UIStackVariable variable : stack.getVariables()) {
                                    String variableName = variable.getName();
                                    if (dynAction.getVariable(variableName) == null) {
                                        if (!StringUtils.isNormalized(variableName))
                                            throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
                                        UIControlVariable uiVariable = new UIControlVariable();
                                        uiVariable.setName(variableName);
                                        uiVariable.setComment(variable.getComment());
                                        MobileSmartSourceType msst = new MobileSmartSourceType();
                                        msst.setMode(MobileSmartSourceType.Mode.SCRIPT);
                                        msst.setSmartValue(variable.getVariableValue());
                                        uiVariable.setVarSmartType(msst);
                                        dynAction.addUIComponent(uiVariable);
                                        uiVariable.bNew = true;
                                        uiVariable.hasChanged = true;
                                        dynAction.hasChanged = true;
                                    }
                                }
                            }
                        }
                        if (dynAction.hasChanged) {
                            IScriptComponent main = dynAction.getMainScriptComponent();
                            if (main != null) {
                                if (main instanceof ApplicationComponent) {
                                    ((ApplicationComponent) main).markApplicationAsDirty();
                                }
                                if (main instanceof PageComponent) {
                                    ((PageComponent) main).markPageAsDirty();
                                }
                            }
                            explorerView.reloadTreeObject(treeObject);
                            StructuredSelection structuredSelection = new StructuredSelection(treeObject);
                            ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
                        }
                    }
                } else if (databaseObject instanceof UIUseShared) {
                    UIUseShared useShared = (UIUseShared) databaseObject;
                    UISharedComponent sharedComp = useShared.getTargetSharedComponent();
                    if (sharedComp != null) {
                        for (UICompVariable variable : sharedComp.getVariables()) {
                            String variableName = variable.getName();
                            if (useShared.getVariable(variableName) == null) {
                                if (!StringUtils.isNormalized(variableName))
                                    throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
                                UIControlVariable uiVariable = new UIControlVariable();
                                uiVariable.setName(variableName);
                                uiVariable.setComment(variable.getComment());
                                MobileSmartSourceType msst = new MobileSmartSourceType();
                                msst.setMode(MobileSmartSourceType.Mode.SCRIPT);
                                msst.setSmartValue(variable.getVariableValue());
                                uiVariable.setVarSmartType(msst);
                                useShared.addUIComponent(uiVariable);
                                uiVariable.bNew = true;
                                uiVariable.hasChanged = true;
                                useShared.hasChanged = true;
                            }
                        }
                        if (useShared.hasChanged) {
                            IScriptComponent main = useShared.getMainScriptComponent();
                            if (main != null) {
                                if (main instanceof ApplicationComponent) {
                                    ((ApplicationComponent) main).markApplicationAsDirty();
                                }
                                if (main instanceof PageComponent) {
                                    ((PageComponent) main).markPageAsDirty();
                                }
                            }
                            explorerView.reloadTreeObject(treeObject);
                            StructuredSelection structuredSelection = new StructuredSelection(treeObject);
                            ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to add variables to action !");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) UIUseShared(com.twinsoft.convertigo.beans.mobile.components.UIUseShared) EngineException(com.twinsoft.convertigo.engine.EngineException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UIControlVariable(com.twinsoft.convertigo.beans.mobile.components.UIControlVariable) Cursor(org.eclipse.swt.graphics.Cursor) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) UICompVariable(com.twinsoft.convertigo.beans.mobile.components.UICompVariable) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) IScriptComponent(com.twinsoft.convertigo.beans.mobile.components.IScriptComponent) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) UIStackVariable(com.twinsoft.convertigo.beans.mobile.components.UIStackVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) EngineException(com.twinsoft.convertigo.engine.EngineException) Project(com.twinsoft.convertigo.beans.core.Project) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) UIDynamicAction(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) UIDynamicInvoke(com.twinsoft.convertigo.beans.mobile.components.UIDynamicInvoke) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 14 with ApplicationComponent

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

the class SetMobileRootPageAction 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) {
            MobilePageComponentTreeObject pageTreeObject = (MobilePageComponentTreeObject) explorerView.getFirstSelectedTreeObject();
            PageComponent page = (PageComponent) pageTreeObject.getObject();
            ApplicationComponent application = (ApplicationComponent) page.getParent();
            MobilePageComponentTreeObject rootPageTreeObject = null;
            PageComponent rootPage = application.getRootPage();
            if (rootPage != null) {
                rootPageTreeObject = (MobilePageComponentTreeObject) explorerView.findTreeObjectByUserObject(rootPage);
            }
            application.setRootPage(page);
            application.markRootAsDirty();
            if (rootPageTreeObject != null) {
                rootPageTreeObject.isDefault = false;
                rootPageTreeObject.hasBeenModified(true);
            }
            pageTreeObject.isDefault = true;
            pageTreeObject.hasBeenModified(true);
            // Updating the tree
            explorerView.refreshTreeObject(pageTreeObject.getParentDatabaseObjectTreeObject());
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to set page to root one!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) MobilePageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePageComponentTreeObject) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) Cursor(org.eclipse.swt.graphics.Cursor) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) Display(org.eclipse.swt.widgets.Display)

Example 15 with ApplicationComponent

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

the class MobileApplicationComponentTreeObject method editAppComponentTsFile.

public void editAppComponentTsFile() {
    final ApplicationComponent application = getObject();
    try {
        // Refresh project resource
        String projectName = application.getProject().getName();
        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
        // Close editor
        String filePath = application.getProject().getMobileBuilder().getTempTsRelativePath(application);
        IFile file = project.getFile(filePath);
        closeComponentFileEditor(file);
        // Write temporary file
        application.getProject().getMobileBuilder().writeAppComponentTempTs(application);
        file.refreshLocal(IResource.DEPTH_ZERO, null);
        // Open file in editor
        if (file.exists()) {
            IEditorInput input = new ComponentFileEditorInput(file, application);
            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());
                                FormatedContent componentScriptContent = new FormatedContent(MobileBuilder.getMarkers(doc.get()));
                                MobileApplicationComponentTreeObject.this.setPropertyValue("componentScriptContent", componentScriptContent);
                            }
                        }
                    }
                });
            }
        }
    } catch (Exception e) {
        ConvertigoPlugin.logException(e, "Unable to open typescript file for page '" + application.getName() + "'!");
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.mobile.ComponentFileEditorInput) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IPropertyListener(org.eclipse.ui.IPropertyListener) InvalidParameterException(java.security.InvalidParameterException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) 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)

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