Search in sources :

Example 1 with MobileObject

use of com.twinsoft.convertigo.beans.core.MobileObject 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
    try {
        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.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);
    } 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)

Example 2 with MobileObject

use of com.twinsoft.convertigo.beans.core.MobileObject in project convertigo by convertigo.

the class ClipboardManager method paste.

public void paste(String xmlData, Object parentObject, boolean bChangeName) throws EngineException, SAXException, IOException {
    Document document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(xmlData)));
    Element rootElement = document.getDocumentElement();
    NodeList nodeList = rootElement.getChildNodes();
    int len = nodeList.getLength();
    Node node;
    pastedSteps.clear();
    pastedComponents.clear();
    pastedObjects = new Object[] {};
    if (len > 0) {
        pastedObjects = new Object[len];
    }
    Object object = null;
    for (int i = 0; i < len; i++) {
        node = (Node) nodeList.item(i);
        if (node.getNodeType() != Node.TEXT_NODE) {
            if (parentObject instanceof IPropertyTreeObject) {
                object = paste(node, (IPropertyTreeObject) parentObject, bChangeName);
            } else if (parentObject instanceof IDesignTreeObject) {
                object = paste(node, (IDesignTreeObject) parentObject, bChangeName);
            } else {
                object = paste(node, (DatabaseObject) parentObject, bChangeName);
            }
            pastedObjects[i] = object;
        }
    }
    for (Entry<String, Step> entry : pastedSteps.entrySet()) {
        Step step = entry.getValue();
        step.getSequence().fireStepCopied(new StepEvent(step, entry.getKey()));
    }
    for (Object ob : pastedObjects) {
        // MOBILE COMPONENTS
        if (ob instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
            if (ob instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
                com.twinsoft.convertigo.beans.mobile.components.PageComponent page = GenericUtils.cast(ob);
                for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
                    if (page.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
                        page.markPageAsDirty();
                    }
                }
            } else if (ob instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
                com.twinsoft.convertigo.beans.mobile.components.UIComponent uic = GenericUtils.cast(ob);
                for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
                    if (uic.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
                        uic.markAsDirty();
                    }
                }
            }
        }
        // NGX COMPONENTS
        if (ob instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
            if (ob instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
                com.twinsoft.convertigo.beans.ngx.components.PageComponent page = GenericUtils.cast(ob);
                for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
                    if (page.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
                        page.markPageAsDirty();
                    }
                }
            } else if (ob instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
                com.twinsoft.convertigo.beans.ngx.components.UIComponent uic = GenericUtils.cast(ob);
                for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
                    if (uic.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
                        uic.markAsDirty();
                    }
                }
            }
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) 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) Document(org.w3c.dom.Document) Entry(java.util.Map.Entry) StringReader(java.io.StringReader) StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) NodeList(org.w3c.dom.NodeList) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 MobileObject (com.twinsoft.convertigo.beans.core.MobileObject)2 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)2 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)2 Step (com.twinsoft.convertigo.beans.core.Step)2 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)2 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)2 Connector (com.twinsoft.convertigo.beans.core.Connector)1 Criteria (com.twinsoft.convertigo.beans.core.Criteria)1 Project (com.twinsoft.convertigo.beans.core.Project)1 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)1 Sheet (com.twinsoft.convertigo.beans.core.Sheet)1 Statement (com.twinsoft.convertigo.beans.core.Statement)1 StepEvent (com.twinsoft.convertigo.beans.core.StepEvent)1 Transaction (com.twinsoft.convertigo.beans.core.Transaction)1 JavelinScreenClass (com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass)1 ElseStatement (com.twinsoft.convertigo.beans.statements.ElseStatement)1 FunctionStatement (com.twinsoft.convertigo.beans.statements.FunctionStatement)1 HTTPStatement (com.twinsoft.convertigo.beans.statements.HTTPStatement)1 ThenStatement (com.twinsoft.convertigo.beans.statements.ThenStatement)1