Search in sources :

Example 1 with InvalidOperationException

use of com.twinsoft.convertigo.engine.InvalidOperationException 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 2 with InvalidOperationException

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

the class ClipboardManager method cutAndPaste.

public void cutAndPaste(Object object, TreeObject targetTreeObject) throws ConvertigoException {
    // Ignore cut paste on itself
    if (object.equals(targetTreeObject)) {
        return;
    }
    // Check for cut paste into itself
    if (object instanceof TreeObject) {
        if (targetTreeObject.isChildOf((TreeObject) object)) {
            throw new InvalidOperationException("You cannot cut and paste this object into itself");
        }
    }
    if (object instanceof DatabaseObjectTreeObject) {
        if (targetTreeObject instanceof DatabaseObjectTreeObject) {
            DatabaseObjectTreeObject sourceTreeObject = (DatabaseObjectTreeObject) object;
            DatabaseObject databaseObject = (DatabaseObject) sourceTreeObject.getObject();
            DatabaseObject targetObject = (DatabaseObject) targetTreeObject.getObject();
            String oldQName = databaseObject.getQName();
            cutAndPaste(databaseObject, targetObject);
            String newQName = databaseObject.getQName();
            ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
            if (projectExplorerView != null) {
                TreeObjectEvent treeObjectEvent = new TreeObjectEvent(sourceTreeObject, "qname", oldQName, newQName, TreeObjectEvent.UPDATE_ALL);
                projectExplorerView.fireTreeObjectPropertyChanged(treeObjectEvent);
            }
        }
    } else if (object instanceof IPropertyTreeObject) {
        if (targetTreeObject instanceof IPropertyTreeObject) {
            IPropertyTreeObject tpo = (IPropertyTreeObject) object;
            IPropertyTreeObject ttpo = (IPropertyTreeObject) targetTreeObject;
            if (tpo.getParent().equals(ttpo.getParent())) {
                return;
            }
            if (tpo.getParent().equals(ttpo)) {
                return;
            }
            tpo.remove(object);
            ttpo.add(object, false);
        }
    } else if (object instanceof IDesignTreeObject) {
        if (targetTreeObject instanceof IDesignTreeObject) {
            IDesignTreeObject tpo = (IDesignTreeObject) object;
            IDesignTreeObject ttpo = (IDesignTreeObject) targetTreeObject;
            if (tpo.getParent().equals(ttpo.getParent())) {
                return;
            }
            if (tpo.getParent().equals(ttpo)) {
                return;
            }
            if (ttpo.canPaste(object)) {
                tpo.remove(object);
                ttpo.add(object, false);
            }
        }
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) 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) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)2 IPropertyTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)2 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)2 InvalidOperationException (com.twinsoft.convertigo.engine.InvalidOperationException)2 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)1 DatabaseObjectDecreasePriorityAction (com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectDecreasePriorityAction)1 DatabaseObjectIncreasePriorityAction (com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectIncreasePriorityAction)1 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)1 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)1 FolderTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject)1 IDesignTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject)1 IOrderableTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject)1 MobileComponentTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject)1 MobileUIComponentTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject)1 NgxComponentTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject)1 NgxUIComponentTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject)1 ObjectsFolderTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject)1 PropertyTableRowTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject)1 PropertyTableTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject)1