Search in sources :

Example 1 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.

the class HtmlTransaction method addStatement.

public void addStatement(Statement statement) throws EngineException {
    checkSubLoaded();
    // Do not use getChildBeanName here because of ScHandlerStatement!!
    String newDatabaseObjectName = statement.getName();
    for (Statement st : vStatements) {
        if (newDatabaseObjectName.equals(st.getName())) {
            throw new ObjectWithSameNameException("Unable to add the statement \"" + newDatabaseObjectName + "\" to the html transaction class because a statement with the same name already exists.");
        }
    }
    vStatements.add(statement);
    // do not call super.add otherwise it will generate an exception
    statement.setParent(this);
    if (statement.priority != 0) {
        statement.priority = 0;
        statement.hasChanged = true;
    }
}
Also used : ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) ContextAddTextNodeStatement(com.twinsoft.convertigo.beans.statements.ContextAddTextNodeStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement)

Example 2 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.

the class TreeDropAdapter method performDrop.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
	 */
@Override
public boolean performDrop(Object data) {
    MobileBuilder mb = null;
    Engine.logStudio.info("---------------------- Drop started ----------------------");
    try {
        Object targetObject = getCurrentTarget();
        IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
        if (editorPart != null) {
            IEditorInput input = editorPart.getEditorInput();
            if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
                com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
                mb = editorInput.getApplication().getProject().getMobileBuilder();
            }
            if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
                com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
                mb = editorInput.getApplication().getProject().getMobileBuilder();
            }
        }
        // Handle tree objects reordering with Drag and Drop
        if (data instanceof String) {
            boolean insertBefore = (feedback & DND.FEEDBACK_INSERT_BEFORE) != 0;
            boolean insertAfter = (feedback & DND.FEEDBACK_INSERT_AFTER) != 0;
            if (insertBefore || insertAfter) {
                Object sourceObject = getSelectedObject();
                TreeParent targetTreeParent = ((TreeObject) targetObject).getParent();
                List<? extends TreeObject> children = targetTreeParent.getChildren();
                int destPosition = children.indexOf(targetObject);
                int srcPosition = children.indexOf(sourceObject);
                int delta = destPosition - srcPosition;
                int count = (delta < 0) ? (insertBefore ? delta : delta + 1) : (insertBefore ? delta - 1 : delta);
                if (count != 0) {
                    if (mb != null) {
                        mb.prepareBatchBuild();
                    }
                    BatchOperationHelper.start();
                    if (count < 0) {
                        new DatabaseObjectIncreasePriorityAction(Math.abs(count)).run();
                    } else {
                        new DatabaseObjectDecreasePriorityAction(Math.abs(count)).run();
                    }
                    BatchOperationHelper.stop();
                }
                return true;
            }
        }
        // Handle objects copy or move with Drag and drop
        if (targetObject instanceof TreeObject) {
            TreeObject targetTreeObject = (TreeObject) targetObject;
            if (targetTreeObject != null) {
                ProjectExplorerView explorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
                Document document = null;
                try {
                    Shell shell = Display.getDefault().getActiveShell();
                    try {
                        // Try to parse text data into an XML document
                        String source = data.toString();
                        document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(source)));
                        if (mb != null) {
                            mb.prepareBatchBuild();
                        }
                        BatchOperationHelper.start();
                        ClipboardAction.dnd.paste(source, shell, explorerView, targetTreeObject, true);
                        BatchOperationHelper.stop();
                        return true;
                    } catch (SAXException sax) {
                        BatchOperationHelper.cancel();
                        if (mb != null) {
                            mb.prepareBatchBuild();
                        }
                        BatchOperationHelper.start();
                        // Parse failed probably because data was not XML but an XPATH String
                        // in this case, create DatabaseObjects of the correct Type according to the folder where the XPATH is dropped on
                        performDrop(data, explorerView, targetTreeObject);
                        BatchOperationHelper.stop();
                        return true;
                    }
                } catch (Exception e) {
                    BatchOperationHelper.cancel();
                    if (e instanceof ObjectWithSameNameException) {
                        document = null;
                    }
                    if (e instanceof InvalidOperationException) {
                        document = null;
                    }
                    // Case of unauthorized databaseObject paste
                    if (document != null) {
                        try {
                            if (!(targetTreeObject instanceof IPropertyTreeObject)) {
                                Element rootElement = document.getDocumentElement();
                                NodeList nodeList = rootElement.getChildNodes();
                                boolean unauthorized = false;
                                int len = nodeList.getLength();
                                Node node;
                                // case of folder, retrieve owner object
                                targetTreeObject = explorerView.getFirstSelectedDatabaseObjectTreeObject(targetTreeObject);
                                if (detail == DND.DROP_COPY) {
                                    for (int i = 0; i < len; i++) {
                                        node = (Node) nodeList.item(i);
                                        if (node.getNodeType() != Node.TEXT_NODE) {
                                            // Special objects paste
                                            if (!paste(node, targetTreeObject)) {
                                                // Real unauthorized databaseObject paste
                                                unauthorized = true;
                                            }
                                        }
                                    }
                                    reloadTreeObject(explorerView, targetTreeObject);
                                } else if (detail == DND.DROP_MOVE) {
                                    for (int i = 0; i < len; i++) {
                                        node = (Node) nodeList.item(i);
                                        if (node.getNodeType() != Node.TEXT_NODE) {
                                            // Special objects move
                                            if (!move(node, targetTreeObject)) {
                                                // Real unauthorized databaseObject move
                                                unauthorized = true;
                                            }
                                        }
                                    }
                                    reloadTreeObject(explorerView, targetTreeObject);
                                } else {
                                    // Real unauthorized databaseObject
                                    unauthorized = true;
                                }
                                if (unauthorized) {
                                    throw e;
                                }
                                return true;
                            }
                        } catch (Exception ex) {
                            ConvertigoPlugin.errorMessageBox(ex.getMessage());
                            return false;
                        }
                    } else {
                        ConvertigoPlugin.errorMessageBox(e.getMessage());
                        return false;
                    }
                }
            }
        }
        return false;
    } finally {
        Engine.logStudio.info("---------------------- Drop ended   ----------------------");
        BatchOperationHelper.cancel();
    }
}
Also used : InputSource(org.xml.sax.InputSource) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) DatabaseObjectIncreasePriorityAction(com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectIncreasePriorityAction) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) Shell(org.eclipse.swt.widgets.Shell) StringReader(java.io.StringReader) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) DatabaseObjectDecreasePriorityAction(com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectDecreasePriorityAction) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) NodeList(org.w3c.dom.NodeList) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) IEditorInput(org.eclipse.ui.IEditorInput) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)

Example 3 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.

the class TreeDropAdapter method paste.

public DatabaseObject paste(Node node, DatabaseObject parentDatabaseObject, boolean bChangeName) throws EngineException {
    Object object = ConvertigoPlugin.clipboardManagerDND.read(node);
    if (object instanceof DatabaseObject) {
        DatabaseObject databaseObject = (DatabaseObject) object;
        String dboName = databaseObject.getName();
        String name = null;
        boolean bContinue = true;
        int index = 0;
        while (bContinue) {
            if (bChangeName) {
                if (index == 0)
                    name = dboName;
                else
                    name = dboName + index;
                databaseObject.setName(name);
            }
            databaseObject.hasChanged = true;
            databaseObject.bNew = true;
            try {
                if (parentDatabaseObject != null)
                    parentDatabaseObject.add(databaseObject);
                bContinue = false;
            } catch (ObjectWithSameNameException owsne) {
                if ((parentDatabaseObject instanceof HtmlTransaction) && (databaseObject instanceof Statement))
                    throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
                if ((parentDatabaseObject instanceof Sequence) && (databaseObject instanceof Step))
                    throw new EngineException("Sequence already contains a step named \"" + name + "\".", owsne);
                // Silently ignore
                index++;
            }
        }
        NodeList childNodes = node.getChildNodes();
        int len = childNodes.getLength();
        Node childNode;
        String childNodeName;
        for (int i = 0; i < len; i++) {
            childNode = childNodes.item(i);
            if (childNode.getNodeType() != Node.ELEMENT_NODE)
                continue;
            childNodeName = childNode.getNodeName();
            if (!(childNodeName.equalsIgnoreCase("property")) && !(childNodeName.equalsIgnoreCase("handlers")) && !(childNodeName.equalsIgnoreCase("wsdltype")) && !(childNodeName.equalsIgnoreCase("docdata")) && !(childNodeName.equalsIgnoreCase("beandata")) && !(childNodeName.equalsIgnoreCase("dnd"))) {
                paste(childNode, databaseObject, bChangeName);
            }
        }
        // needed !
        databaseObject.isImporting = false;
        databaseObject.isSubLoaded = true;
        return databaseObject;
    }
    return null;
}
Also used : XpathableStatement(com.twinsoft.convertigo.beans.statements.XpathableStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) EngineException(com.twinsoft.convertigo.engine.EngineException) Sequence(com.twinsoft.convertigo.beans.core.Sequence) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) Step(com.twinsoft.convertigo.beans.core.Step) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject)

Example 4 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.

the class StatementInfoWizardPage method dialogChanged.

private void dialogChanged(boolean increment) {
    String name = getBeanName();
    if (name.length() == 0) {
        updateStatus("Name must be specified");
        return;
    }
    if (!StringUtils.isNormalized(name)) {
        updateStatus("Name must be normalized.\nDon't start with number and don't use non ASCII caracters.");
        return;
    }
    Matcher m = Pattern.compile("\\d+$").matcher("");
    boolean sameName;
    do {
        sameName = false;
        try {
            ((StatementGeneratorWizardPage) getWizard().getPage("StatementGeneratorWizardPage")).getCreatedBean().setName(name);
        } catch (ObjectWithSameNameException e) {
            if (!increment) {
                updateStatus("Name already used by siblings");
                return;
            }
            sameName = true;
            m.reset(name);
            if (m.find()) {
                name = name.substring(0, m.start()) + (Integer.parseInt(m.group()) + 1);
            } else {
                name = name + "_1";
            }
            setBeanName(name);
        } catch (EngineException e) {
            updateStatus("Name could not be set on bean");
            return;
        } catch (NullPointerException e) {
            updateStatus("New Bean has not been instanciated");
            return;
        }
    } while (sameName);
    updateStatus(null);
}
Also used : ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Matcher(java.util.regex.Matcher) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 5 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.

the class ComponentInfoWizardPage method dialogChanged.

private void dialogChanged(boolean increment) {
    DatabaseObject dbo = ((ComponentExplorerWizardPage) getWizard().getPage("ComponentExplorerWizardPage")).getCreatedBean();
    if (dbo != null) {
        String name = getBeanName();
        if (name.length() == 0) {
            updateStatus("Name must be specified");
            return;
        }
        if (!StringUtils.isNormalized(name)) {
            updateStatus("Name must be normalized.\nDon't start with number and don't use non ASCII caracters.");
            return;
        }
        Matcher m = Pattern.compile("\\d+$").matcher("");
        boolean sameName;
        do {
            sameName = false;
            try {
                dbo.setName(name);
            } catch (ObjectWithSameNameException e) {
                if (!increment) {
                    updateStatus("Name already used by siblings");
                    return;
                }
                sameName = true;
                m.reset(name);
                if (m.find()) {
                    name = name.substring(0, m.start()) + (Integer.parseInt(m.group()) + 1);
                } else {
                    name = name + "_1";
                }
                setBeanName(name);
            } catch (EngineException e) {
                updateStatus("Name could not be set on bean");
                return;
            } catch (NullPointerException e) {
                updateStatus("New Bean has not been instanciated");
                return;
            }
        } while (sameName);
    }
    updateStatus(null);
}
Also used : ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Matcher(java.util.regex.Matcher) EngineException(com.twinsoft.convertigo.engine.EngineException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Aggregations

ObjectWithSameNameException (com.twinsoft.convertigo.engine.ObjectWithSameNameException)13 EngineException (com.twinsoft.convertigo.engine.EngineException)12 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)10 HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)6 Statement (com.twinsoft.convertigo.beans.core.Statement)5 HTTPStatement (com.twinsoft.convertigo.beans.statements.HTTPStatement)5 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)5 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)4 IOException (java.io.IOException)4 Matcher (java.util.regex.Matcher)4 Connector (com.twinsoft.convertigo.beans.core.Connector)3 Criteria (com.twinsoft.convertigo.beans.core.Criteria)3 Project (com.twinsoft.convertigo.beans.core.Project)3 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)3 Sheet (com.twinsoft.convertigo.beans.core.Sheet)3 Step (com.twinsoft.convertigo.beans.core.Step)3 Transaction (com.twinsoft.convertigo.beans.core.Transaction)3 ElseStatement (com.twinsoft.convertigo.beans.statements.ElseStatement)3 ThenStatement (com.twinsoft.convertigo.beans.statements.ThenStatement)3 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)3