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();
}
}
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);
}
}
}
}
Aggregations