Search in sources :

Example 11 with WalkHelper

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

the class DatabaseObjectsManager method symbolsProjectCheckUndefined.

public boolean symbolsProjectCheckUndefined(String projectName) throws Exception {
    final Project project = getOriginalProjectByName(projectName, false);
    if (project == null) {
        return false;
    }
    if (project.undefinedGlobalSymbols) {
        project.undefinedGlobalSymbols = false;
        new WalkHelper() {

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                if (databaseObject.isSymbolError()) {
                    project.undefinedGlobalSymbols = true;
                } else {
                    super.walk(databaseObject);
                }
            }
        }.init(project);
    }
    return project.undefinedGlobalSymbols;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 12 with WalkHelper

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

the class ApplicationComponentEditor method highlightPoint.

private void highlightPoint(int x, int y) {
    x = c8oBrowser.fixDPI(x);
    y = c8oBrowser.fixDPI(y);
    Node node = browser.mainFrame().get().inspect(x, y).node().orElse(null);
    while (!(node == null || node instanceof Element)) {
        node = node.parent().orElse(null);
    }
    while (node != null) {
        Element element = (Element) node;
        if (element.equals(exHighlightElement)) {
            return;
        }
        exHighlightElement = element;
        String classes = element.attributeValue("class");
        Matcher mPriority = pPriority.matcher(classes);
        if (mPriority.find()) {
            try {
                node = null;
                long priority = Long.parseLong(mPriority.group(1));
                new WalkHelper() {

                    @Override
                    protected void walk(DatabaseObject databaseObject) throws Exception {
                        if (databaseObject instanceof UIUseShared) {
                            UISharedComponent uisc = ((UIUseShared) databaseObject).getTargetSharedComponent();
                            if (uisc != null) {
                                databaseObject = uisc;
                            }
                        } else if (databaseObject instanceof UIDynamicInvoke) {
                            UIDynamicInvoke uidi = (UIDynamicInvoke) databaseObject;
                            UIActionStack uisa = uidi.getTargetSharedAction();
                            if (uisa != null) {
                                if (!uidi.isRecursive()) {
                                    databaseObject = uisa;
                                }
                            }
                        }
                        if (databaseObject.priority == priority) {
                            throw new DatabaseObjectFoundException(databaseObject);
                        }
                        super.walk(databaseObject);
                    }
                }.init(applicationEditorInput.application);
            } catch (DatabaseObjectFoundException e) {
                DatabaseObject databaseObject = e.getDatabaseObject();
                c8oBrowser.getDisplay().asyncExec(() -> ConvertigoPlugin.getDefault().getProjectExplorerView().objectSelected(new CompositeEvent(databaseObject)));
                if (databaseObject instanceof MobileComponent && !databaseObject.equals(exHighlightMobileComponent)) {
                    highlightComponent(exHighlightMobileComponent = (MobileComponent) databaseObject, false);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            node = node.parent().orElse(null);
            while (!(node == null || node instanceof Element)) {
                node = node.parent().orElse(null);
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) Node(com.teamdev.jxbrowser.dom.Node) Element(com.teamdev.jxbrowser.dom.Element) UIDynamicElement(com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement) UIUseShared(com.twinsoft.convertigo.beans.mobile.components.UIUseShared) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) JSONException(org.codehaus.jettison.json.JSONException) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) UIDynamicInvoke(com.twinsoft.convertigo.beans.mobile.components.UIDynamicInvoke) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) MobileComponent(com.twinsoft.convertigo.beans.mobile.components.MobileComponent)

Example 13 with WalkHelper

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

the class ApplicationComponentEditor method highlightPoint.

private void highlightPoint(int x, int y) {
    x = c8oBrowser.fixDPI(x);
    y = c8oBrowser.fixDPI(y);
    Node node = browser.mainFrame().get().inspect(x, y).node().orElse(null);
    while (!(node == null || node instanceof Element)) {
        node = node.parent().orElse(null);
    }
    if (node == null) {
        return;
    }
    Object shadowHost = c8oBrowser.executeFunctionAndReturnValue("_c8o_getShadowHost", node);
    if (shadowHost != null && shadowHost instanceof Element) {
        node = (Element) shadowHost;
    }
    while (node != null) {
        Element element = (Element) node;
        if (element.equals(exHighlightElement)) {
            return;
        }
        exHighlightElement = element;
        String classes = element.attributeValue("class");
        Matcher mPriority = pPriority.matcher(classes);
        if (mPriority.find()) {
            try {
                node = null;
                long priority = Long.parseLong(mPriority.group(1));
                new WalkHelper() {

                    @Override
                    protected void walk(DatabaseObject databaseObject) throws Exception {
                        if (databaseObject instanceof UISharedComponent) {
                            UISharedComponent uisc = (UISharedComponent) databaseObject;
                            if (uisc != null) {
                                databaseObject = uisc;
                            }
                        } else if (databaseObject instanceof UIUseShared) {
                            UISharedComponent uisc = ((UIUseShared) databaseObject).getTargetSharedComponent();
                            if (uisc != null) {
                                databaseObject = uisc;
                            }
                        } else if (databaseObject instanceof UIDynamicInvoke) {
                            UIDynamicInvoke uidi = (UIDynamicInvoke) databaseObject;
                            UIActionStack uisa = uidi.getTargetSharedAction();
                            if (uisa != null) {
                                if (!uidi.isRecursive()) {
                                    databaseObject = uisa;
                                }
                            }
                        }
                        if (databaseObject.priority == priority) {
                            throw new DatabaseObjectFoundException(databaseObject);
                        }
                        super.walk(databaseObject);
                    }
                }.init(applicationEditorInput.application);
            } catch (DatabaseObjectFoundException e) {
                DatabaseObject databaseObject = e.getDatabaseObject();
                if (databaseObject instanceof MobileComponent && !databaseObject.equals(exHighlightMobileComponent)) {
                    if (dragStartMobileComponent != null) {
                        DatabaseObject ancestor = databaseObject;
                        while (dragStartMobileComponent != ancestor && ancestor != null) {
                            ancestor = ancestor.getParent();
                        }
                        if (dragStartMobileComponent == ancestor) {
                            return;
                        }
                    }
                    c8oBrowser.getDisplay().asyncExec(() -> ConvertigoPlugin.getDefault().getProjectExplorerView().objectSelected(new CompositeEvent(databaseObject)));
                    highlightComponent(exHighlightMobileComponent = (MobileComponent) databaseObject, false);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            node = node.parent().orElse(null);
            while (!(node == null || node instanceof Element)) {
                node = node.parent().orElse(null);
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) Node(com.teamdev.jxbrowser.dom.Node) Element(com.teamdev.jxbrowser.dom.Element) UIDynamicElement(com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) JSONException(org.codehaus.jettison.json.JSONException) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) UIDynamicInvoke(com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) 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) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) MobileComponent(com.twinsoft.convertigo.beans.ngx.components.MobileComponent)

Example 14 with WalkHelper

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

the class UIDynamicAnimate method getAnimatableId.

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

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

Example 15 with WalkHelper

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

the class ClipboardManager method cutAndPaste.

public void cutAndPaste(final DatabaseObject object, DatabaseObject parentDatabaseObject) throws ConvertigoException {
    // Verifying if a sheet with the same browser does not already exist
    if (object instanceof Sheet) {
        String browser = ((Sheet) object).getBrowser();
        Sheet sheet = null;
        if (parentDatabaseObject instanceof ScreenClass) {
            sheet = ((ScreenClass) parentDatabaseObject).getLocalSheet(browser);
        } else if (parentDatabaseObject instanceof RequestableObject) {
            sheet = ((RequestableObject) parentDatabaseObject).getSheet(browser);
        }
        if (sheet != null) {
            throw new EngineException("You cannot cut and paste the sheet because a sheet is already defined for the browser \"" + browser + "\" in the screen class \"" + parentDatabaseObject.getName() + "\".");
        }
    }
    if (object instanceof Step) {
        if (object instanceof ThenStep) {
            throw new EngineException("You cannot cut the \"Then\" step");
        }
        if (object instanceof ElseStep) {
            throw new EngineException("You cannot cut the \"Else\" step");
        }
    }
    if (object instanceof Statement) {
        if (object instanceof ThenStatement)
            throw new EngineException("You cannot cut the \"Then\" statement");
        if (object instanceof ElseStatement)
            throw new EngineException("You cannot cut the \"Else\" statement");
    }
    // Verify object is accepted for paste
    if (!DatabaseObjectsManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
        throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
    }
    if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
        if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
            throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
        }
        if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
            String tplVersion = com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.getTplRequired(object);
            throw new EngineException("Template project " + tplVersion + " compatibility required");
        }
    } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
        if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
            throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
        }
        if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
            String tplVersion = com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.getTplRequired(object);
            throw new EngineException("Template project " + tplVersion + " compatibility required");
        }
    }
    // Verify if a child object with same name exist
    boolean bContinue = true;
    boolean bIncName = false;
    String dboName = object.getName();
    while (bContinue) {
        try {
            if (bIncName) {
                dboName = DatabaseObject.incrementName(dboName);
                object.setName(dboName);
            }
            new WalkHelper() {

                boolean root = true;

                boolean find = false;

                @Override
                protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
                    boolean isInstance = dboClass.isInstance(object);
                    find |= isInstance;
                    return isInstance;
                }

                @Override
                protected void walk(DatabaseObject databaseObject) throws Exception {
                    if (root) {
                        root = false;
                        if (databaseObject instanceof Project) {
                            if (object instanceof Connector && ((Connector) object).isDefault) {
                                throw new EngineException("You cannot cut the default connector to another project");
                            }
                        } else if (databaseObject instanceof Connector) {
                            if (object instanceof ScreenClass) {
                                throw new EngineException("You cannot cut the default screen class to another connector");
                            } else if (object instanceof Transaction && ((Transaction) object).isDefault) {
                                throw new EngineException("You cannot cut the default transaction to another connector");
                            }
                        } else if (databaseObject instanceof ScreenClass) {
                            if (object instanceof Criteria && databaseObject.getParent() instanceof Connector) {
                                throw new EngineException("You cannot cut the criterion of default screen class");
                            }
                        } else if (databaseObject instanceof MobileObject) {
                            if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
                                if (object instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
                                    com.twinsoft.convertigo.beans.mobile.components.PageComponent pc = GenericUtils.cast(object);
                                    if (pc.isRoot) {
                                        throw new EngineException("You cannot cut the root page to another application");
                                    }
                                }
                            } else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
                                if (object instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
                                    com.twinsoft.convertigo.beans.ngx.components.PageComponent pc = GenericUtils.cast(object);
                                    if (pc.isRoot) {
                                        throw new EngineException("You cannot cut the root page to another application");
                                    }
                                }
                            }
                        }
                        super.walk(databaseObject);
                        if (!find) {
                            throw new EngineException("You cannot cut and paste to a " + databaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
                        }
                    } else {
                        if (object != databaseObject && object.getName().equalsIgnoreCase(databaseObject.getName())) {
                            throw new ObjectWithSameNameException("Unable to cut the object because an object with the same name already exists in target.");
                        }
                    }
                }
            }.init(parentDatabaseObject);
            bContinue = false;
        } catch (ObjectWithSameNameException e) {
            bIncName = true;
        } catch (EngineException e) {
            throw e;
        } catch (Exception e) {
            throw new EngineException("Exception in cutAndPaste", e);
        }
    }
    move(object, parentDatabaseObject);
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) EngineException(com.twinsoft.convertigo.engine.EngineException) Step(com.twinsoft.convertigo.beans.core.Step) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Criteria(com.twinsoft.convertigo.beans.core.Criteria) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Project(com.twinsoft.convertigo.beans.core.Project) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) Sheet(com.twinsoft.convertigo.beans.core.Sheet)

Aggregations

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