use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject in project convertigo by convertigo.
the class ClipboardAction method paste.
public void paste(String source, Shell shell, ProjectExplorerView explorerView, TreeObject selectedTreeObject, boolean isDND) throws ConvertigoException, IOException, ParserConfigurationException, SAXException, CoreException {
if ((explorerView != null) && (selectedTreeObject != null)) {
TreeObject targetTreeObject = null;
Object targetObject = null;
if (selectedTreeObject instanceof FolderTreeObject) {
if (selectedTreeObject.getParent() instanceof IDesignTreeObject) {
selectedTreeObject = selectedTreeObject.getParent();
}
}
if (selectedTreeObject instanceof IPropertyTreeObject) {
targetTreeObject = selectedTreeObject;
targetObject = selectedTreeObject;
} else if (selectedTreeObject instanceof IDesignTreeObject) {
targetTreeObject = selectedTreeObject;
targetObject = selectedTreeObject;
if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_DOCUMENT) {
targetTreeObject = ((IDesignTreeObject) selectedTreeObject).getTreeObjectOwner();
targetObject = (DatabaseObject) targetTreeObject.getObject();
}
} else {
// case of folder, retrieve owner object
targetTreeObject = explorerView.getFirstSelectedDatabaseObjectTreeObject(selectedTreeObject);
targetObject = (DatabaseObject) targetTreeObject.getObject();
// i.e. without having to select the parent database object.
if (clipboardManager.objectsType == ProjectExplorerView.getTreeObjectType(new TreePath(targetTreeObject))) {
// it must be different from the currently selected object.
if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_SCREEN_CLASS) {
CustomDialog customDialog = new CustomDialog(shell, "Paste a Screenclass", "Do you want to paste the Screenclass as a sibling or as an inherited ScreenClass?", 500, 150, new ButtonSpec("As a sibling", true), new ButtonSpec("As an iherited", false), new ButtonSpec(IDialogConstants.CANCEL_LABEL, false));
int response = customDialog.open();
if (response == 0)
targetObject = ((DatabaseObject) targetObject).getParent();
else if (response == 2)
return;
} else if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STATEMENT_WITH_EXPRESSIONS) {
if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_FUNCTION) {
targetObject = ((DatabaseObject) targetObject).getParent();
} else {
CustomDialog customDialog = new CustomDialog(shell, "Paste a statement", "Do you want to paste the statement as a sibling or a child statement?", 500, 150, new ButtonSpec("As a sibling", true), new ButtonSpec("As a child", false), new ButtonSpec(IDialogConstants.CANCEL_LABEL, false));
int response = customDialog.open();
if (response == 0) {
targetObject = ((DatabaseObject) targetObject).getParent();
} else if (response == 2) {
return;
}
}
} else if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_MOBILE_UICOMPONENT) {
if (!clipboardManager.isCut) {
CustomDialog customDialog = new CustomDialog(shell, "Paste a Component", "Do you want to paste the Component as a sibling or as a child component?", 500, 150, new ButtonSpec("As a sibling", true), new ButtonSpec("As a child", false), new ButtonSpec(IDialogConstants.CANCEL_LABEL, false));
int response = customDialog.open();
if (response == 0) {
targetObject = ((DatabaseObject) targetObject).getParent();
} else if (response == 2) {
return;
}
}
} else if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP_WITH_EXPRESSIONS || clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP) {
targetObject = pasteStep(shell, source, (DatabaseObject) targetObject);
if (targetObject == null)
return;
} else if (isDND && clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_SEQUENCE) {
// Do not change target to parent
} else {
targetObject = ((DatabaseObject) targetObject).getParent();
}
targetTreeObject = explorerView.findTreeObjectByUserObject(((DatabaseObject) targetObject));
} else {
if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP_WITH_EXPRESSIONS || clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP) {
targetObject = pasteStep(shell, source, (DatabaseObject) targetObject);
if (targetObject == null)
return;
}
}
}
if (clipboardManager.isCut) {
TreeParent targetTreeParent = null;
String targetPath = targetTreeObject.getPath();
if (targetTreeObject instanceof DatabaseObjectTreeObject) {
targetTreeParent = ((DatabaseObjectTreeObject) targetTreeObject).getOwnerDatabaseObjectTreeObject();
} else if (targetTreeObject instanceof IPropertyTreeObject) {
targetTreeParent = ((IPropertyTreeObject) targetTreeObject).getTreeObjectOwner();
} else if (targetTreeObject instanceof IDesignTreeObject) {
targetTreeParent = ((IDesignTreeObject) targetTreeObject).getTreeObjectOwner();
}
for (int i = 0; i < clipboardManager.objects.length; i++) {
// Cut & paste
clipboardManager.cutAndPaste(clipboardManager.objects[i], targetTreeObject);
// Updating the tree
// Report 4.5: fix #401
// explorerView.reloadTreeObject(clipboardManager.parentTreeNodeOfCutObjects[i]);
TreeObject parentTreeNodeOfCutObjects = clipboardManager.parentTreeNodeOfCutObjects[i];
parentTreeNodeOfCutObjects.getProjectTreeObject().hasBeenModified(true);
if (!(parentTreeNodeOfCutObjects instanceof IDesignTreeObject)) {
explorerView.reloadTreeObject(parentTreeNodeOfCutObjects);
}
}
if (targetTreeObject != null) {
if (targetTreeObject.getParent() == null)
targetTreeObject = explorerView.findTreeObjectByPath(targetTreeParent, targetPath);
if (targetTreeObject != null)
// Report 4.5: fix #401
targetTreeObject.getProjectTreeObject().hasBeenModified(true);
}
clipboardManager.reset();
} else if (source != null) {
// Paste
clipboardManager.paste(source, targetObject, true);
// Case of project copy
if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_PROJECT) {
Object[] pastedObjects = clipboardManager.pastedObjects;
for (int i = 0; i < pastedObjects.length; i++) {
Object object = pastedObjects[i];
if ((object != null) && (object instanceof Project)) {
Project project = (Project) object;
String oldName = project.getName();
try {
Project importedProject = importProjectTempArchive(oldName, explorerView);
if (importedProject != null) {
String newName = importedProject.getName();
explorerView.importProjectTreeObject(newName, true, oldName);
} else
throw new EngineException("Unable to import project temporary archive");
} catch (Exception e) {
throw new EngineException("Unable to paste project", e);
}
}
}
}
}
// Updating the tree
if (targetTreeObject != null) {
TreeObject treeObjectToReload = targetTreeObject;
TreeObject treeObjectToSelect = targetTreeObject;
if (targetTreeObject instanceof IPropertyTreeObject) {
treeObjectToSelect = ((IPropertyTreeObject) targetTreeObject).getTreeObjectOwner();
treeObjectToReload = treeObjectToSelect;
if (treeObjectToReload instanceof DatabaseObjectTreeObject) {
treeObjectToReload = treeObjectToReload.getParent();
if (treeObjectToReload instanceof FolderTreeObject)
treeObjectToReload = treeObjectToReload.getParent();
}
}
if (targetTreeObject instanceof IDesignTreeObject) {
treeObjectToSelect = ((IDesignTreeObject) targetTreeObject).getTreeObjectOwner();
treeObjectToReload = treeObjectToSelect;
if (treeObjectToReload instanceof DatabaseObjectTreeObject) {
treeObjectToReload = treeObjectToReload.getParent();
if (treeObjectToReload instanceof FolderTreeObject)
treeObjectToReload = treeObjectToReload.getParent();
}
}
if (treeObjectToReload != null) {
// explorerView.reloadTreeObject(targetTreeObject);
// explorerView.setSelectedTreeObject(targetTreeObject);
explorerView.objectChanged(new CompositeEvent(treeObjectToReload.getObject(), treeObjectToSelect.getPath()));
}
}
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject in project convertigo by convertigo.
the class CreatePropertyTableRowAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
PropertyTableTreeObject propertyTableTreeObject = (PropertyTableTreeObject) explorerView.getFirstSelectedTreeObject();
TreeParent owner = propertyTableTreeObject.getTreeObjectOwner();
IPropertyTreeObject pto = propertyTableTreeObject.addNewRow();
if (owner instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) owner;
if (databaseObjectTreeObject.hasChanged()) {
TreeParent treeParent = databaseObjectTreeObject.getParent();
if (treeParent instanceof FolderTreeObject)
treeParent = treeParent.getParent();
// explorerView.reloadTreeObject(treeParent);
explorerView.objectChanged(new CompositeEvent(treeParent.getObject(), pto.getPath()));
}
} else
explorerView.refreshTreeObject(owner, true);
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to create a new row!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject in project convertigo by convertigo.
the class TreeDropAdapter method performDrop.
private void performDrop(Object data, final ProjectExplorerView explorerView, TreeObject targetTreeObject) throws EngineException, IOException {
boolean needReload = false;
final DatabaseObject dbo;
if (data instanceof String) {
String source = data.toString();
if (targetTreeObject instanceof ObjectsFolderTreeObject) {
ObjectsFolderTreeObject folderTreeObject = (ObjectsFolderTreeObject) targetTreeObject;
dbo = (DatabaseObject) folderTreeObject.getParent().getObject();
switch(folderTreeObject.folderType) {
case ObjectsFolderTreeObject.FOLDER_TYPE_CRITERIAS:
if (dbo instanceof HtmlScreenClass) {
// Creates a XPath criteria for this screen class
if (!dbo.equals(((HtmlConnector) dbo.getConnector()).getDefaultScreenClass())) {
((HtmlScreenClass) dbo).addCriteria(createXPath(source));
needReload = true;
}
}
break;
case ObjectsFolderTreeObject.FOLDER_TYPE_INHERITED_SCREEN_CLASSES:
if (dbo instanceof HtmlScreenClass) {
// Creates an inherited screen class with an XPath criteria for this screen class
HtmlScreenClass newSc = createHtmlScreenClass(dbo.priority + 1);
((HtmlScreenClass) dbo).addInheritedScreenClass(newSc);
newSc.addCriteria(createXPath(source));
needReload = true;
}
break;
case ObjectsFolderTreeObject.FOLDER_TYPE_EXTRACTION_RULES:
if (dbo instanceof HtmlScreenClass) {
NewObjectWizard newObjectWizard = new NewObjectWizard(dbo, "com.twinsoft.convertigo.beans.core.ExtractionRule", source, null);
WizardDialog wzdlg = new WizardDialog(Display.getDefault().getActiveShell(), newObjectWizard);
wzdlg.setPageSize(850, 650);
wzdlg.open();
needReload = true;
}
break;
default:
break;
}
if (needReload)
reloadTreeObject(explorerView, folderTreeObject.getParent());
} else if (targetTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) targetTreeObject;
dbo = (DatabaseObject) targetTreeObject.getObject();
if (databaseObjectTreeObject instanceof ScreenClassTreeObject) {
if (dbo instanceof HtmlScreenClass) {
// Creates an inherited screen class with an XPath criteria for this screen class
HtmlScreenClass newSc = createHtmlScreenClass(dbo.priority + 1);
((HtmlScreenClass) dbo).addInheritedScreenClass(newSc);
newSc.addCriteria(createXPath(source));
needReload = true;
}
} else if (dbo instanceof IXPathable) {
// Set XPath property
if (dbo instanceof XpathableStatement)
((XpathableStatement) dbo).setPureXpath(source);
else
((IXPathable) dbo).setXpath(source);
((DatabaseObject) dbo).hasChanged = true;
needReload = true;
}
if (needReload)
reloadTreeObject(explorerView, databaseObjectTreeObject);
} else if (targetTreeObject instanceof IPropertyTreeObject) {
IPropertyTreeObject pto = null;
if (detail == DND.DROP_MOVE) {
// Set XPath property
if (targetTreeObject instanceof IXPathable) {
((IXPathable) targetTreeObject).setXpath("." + source);
needReload = true;
} else // Add new row with xpath
if (targetTreeObject instanceof PropertyTableTreeObject) {
// // See Ticket #679 : Drag and drop without Control
// PropertyTableTreeObject description = (PropertyTableTreeObject)targetTreeObject;
// pto = description.addNewRow();
// needReload = true;
// if ((pto != null) && (pto instanceof IXPathable)) {
// ((IXPathable)pto).setXpath("."+source);
// }
String label = ((PropertyTableTreeObject) targetTreeObject).getRowDefaultLabel().toLowerCase();
throw new EngineException("Please hold on the 'Ctrl' key while dragging to create a new " + label);
}
} else if (detail == DND.DROP_COPY) {
// Add new row with xpath
if (targetTreeObject instanceof PropertyTableTreeObject) {
PropertyTableTreeObject description = (PropertyTableTreeObject) targetTreeObject;
pto = description.addNewRow();
needReload = true;
if ((pto != null) && (pto instanceof IXPathable)) {
((IXPathable) pto).setXpath("." + source);
}
} else // Add new column with xpath
if (targetTreeObject instanceof PropertyTableRowTreeObject) {
PropertyTableRowTreeObject row = (PropertyTableRowTreeObject) targetTreeObject;
pto = row.addNewColumn();
needReload = true;
if ((pto != null) && (pto instanceof IXPathable)) {
((IXPathable) pto).setXpath("." + source);
}
}
}
if (needReload) {
pto = (pto == null) ? (IPropertyTreeObject) targetTreeObject : pto;
targetTreeObject = ((IPropertyTreeObject) targetTreeObject).getTreeObjectOwner();
if (targetTreeObject instanceof DatabaseObjectTreeObject) {
// reloadTreeObject(explorerView, targetTreeObject);
TreeParent treeParent = targetTreeObject.getParent();
if (treeParent instanceof FolderTreeObject)
treeParent = treeParent.getParent();
explorerView.objectChanged(new CompositeEvent(treeParent.getObject(), pto.getPath()));
}
}
}
} else if (data instanceof StepSource) {
if (targetTreeObject instanceof DatabaseObjectTreeObject) {
final DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) targetTreeObject;
dbo = (DatabaseObject) targetTreeObject.getObject();
final Set<PropertyDescriptor> propertyDescriptors = new TreeSet<PropertyDescriptor>(new Comparator<PropertyDescriptor>() {
@Override
public int compare(PropertyDescriptor o1, PropertyDescriptor o2) {
return o1.getDisplayName().compareTo(o2.getDisplayName());
}
});
propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.smartType));
propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.sourceDefinition));
propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.sourcesDefinition));
if (!propertyDescriptors.isEmpty()) {
// Retrieve Source definition
final XMLVector<String> sourceDefinition = new XMLVector<String>(2);
sourceDefinition.add(((StepSource) data).getPriority());
sourceDefinition.add(((StepSource) data).getXpath());
SelectionListener selectionListener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
PropertyDescriptor propertyDescriptor = (e == null) ? propertyDescriptors.iterator().next() : (PropertyDescriptor) e.widget.getData();
String propertyName = propertyDescriptor.getName();
if (propertyDescriptor.getPropertyType().isAssignableFrom(SmartType.class)) {
SmartType smartType = new SmartType();
smartType.setMode(Mode.SOURCE);
smartType.setSourceDefinition(sourceDefinition);
databaseObjectTreeObject.setPropertyValue(propertyDescriptor.getName(), smartType);
} else if (propertyName.equals("sourceDefinition")) {
// Use setPropertyValue in order to set object's value and fire necessary events
databaseObjectTreeObject.setPropertyValue(propertyDescriptor.getName(), sourceDefinition);
} else if (propertyName.equals("sourcesDefinition")) {
try {
XMLVector<XMLVector<Object>> sourcesDefinition = GenericUtils.cast(propertyDescriptor.getReadMethod().invoke(dbo));
// make a copy to make a property change
sourcesDefinition = new XMLVector<XMLVector<Object>>(sourcesDefinition);
XMLVector<Object> row = new XMLVector<Object>();
row.add("");
row.add(sourceDefinition);
row.add("");
sourcesDefinition.add(row);
databaseObjectTreeObject.setPropertyValue(propertyName, sourcesDefinition);
} catch (Exception ex) {
ConvertigoPlugin.logError("failed to add to sourcesDefinition of " + dbo.getName());
}
}
// Properties view needs to be refreshed
refreshPropertiesView(explorerView, databaseObjectTreeObject);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
};
if (propertyDescriptors.size() == 1) {
selectionListener.widgetSelected(null);
} else {
Shell shell = ConvertigoPlugin.getMainShell();
Menu dropMenu = new Menu(shell, SWT.POP_UP);
shell.setMenu(dropMenu);
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
itemCheck.setText(propertyDescriptor.getDisplayName());
itemCheck.setData(propertyDescriptor);
itemCheck.addSelectionListener(selectionListener);
}
dropMenu.setVisible(true);
}
}
}
} else if (data instanceof PaletteSource) {
try {
if (targetTreeObject instanceof ObjectsFolderTreeObject) {
ObjectsFolderTreeObject folderTreeObject = (ObjectsFolderTreeObject) targetTreeObject;
targetTreeObject = folderTreeObject.getParent();
}
if (targetTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObject parent = (DatabaseObject) targetTreeObject.getObject();
String xmlData = ((PaletteSource) data).getXmlData();
Document document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(xmlData)));
Element rootElement = document.getDocumentElement();
NodeList nodeList = rootElement.getChildNodes();
int len = nodeList.getLength();
Node node;
// Special objects move from palette
if (detail == DND.DROP_MOVE) {
for (int i = 0; i < len; i++) {
node = (Node) nodeList.item(i);
if (node.getNodeType() != Node.TEXT_NODE) {
if (paste(node, parent, true) == null) {
throw new Exception();
}
}
}
reloadTreeObject(explorerView, targetTreeObject);
}
} else {
throw new Exception();
}
} catch (Exception ex) {
ConvertigoPlugin.logError("failed to add from palette");
}
} else if (data instanceof MobileSource) {
try {
String jsonString = ((MobileSource) data).getJsonString();
if (targetTreeObject instanceof MobileUIComponentTreeObject) {
Shell shell = ConvertigoPlugin.getMainShell();
Menu dropMenu = new Menu(shell, SWT.POP_UP);
shell.setMenu(dropMenu);
MobileUIComponentTreeObject mcto = GenericUtils.cast(targetTreeObject);
for (IPropertyDescriptor descriptor : mcto.getPropertyDescriptors()) {
if (descriptor instanceof MobileSmartSourcePropertyDescriptor) {
MobileSmartSourcePropertyDescriptor cspd = GenericUtils.cast(descriptor);
if (!cspd.isReadOnly()) {
String propertyName = (String) cspd.getId();
String propertyLabel = (String) cspd.getDisplayName();
MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
itemCheck.setText(propertyLabel);
itemCheck.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType cst = new com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType();
cst.setMode(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType.Mode.SOURCE);
cst.setSmartValue(jsonString);
mcto.setPropertyValue(propertyName, cst);
refreshPropertiesView(explorerView, mcto);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
}
}
dropMenu.setVisible(true);
}
if (targetTreeObject instanceof NgxUIComponentTreeObject) {
Shell shell = ConvertigoPlugin.getMainShell();
Menu dropMenu = new Menu(shell, SWT.POP_UP);
shell.setMenu(dropMenu);
NgxUIComponentTreeObject mcto = GenericUtils.cast(targetTreeObject);
for (IPropertyDescriptor descriptor : mcto.getPropertyDescriptors()) {
if (descriptor instanceof NgxSmartSourcePropertyDescriptor) {
NgxSmartSourcePropertyDescriptor cspd = GenericUtils.cast(descriptor);
if (!cspd.isReadOnly()) {
String propertyName = (String) cspd.getId();
String propertyLabel = (String) cspd.getDisplayName();
MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
itemCheck.setText(propertyLabel);
itemCheck.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType cst = new com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType();
cst.setMode(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType.Mode.SOURCE);
cst.setSmartValue(jsonString);
mcto.setPropertyValue(propertyName, cst);
refreshPropertiesView(explorerView, mcto);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
}
}
dropMenu.setVisible(true);
} else {
throw new Exception();
}
} catch (Exception ex) {
ConvertigoPlugin.logError("failed to add mobile source");
}
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject 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.eclipse.views.projectexplorer.model.IPropertyTreeObject in project convertigo by convertigo.
the class ClipboardManager method copy.
public String copy(TreePath[] treePaths) throws EngineException {
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
clipboardDocument = XMLUtils.getDefaultDocumentBuilder().newDocument();
ProcessingInstruction pi = clipboardDocument.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"ISO-8859-1\"");
clipboardDocument.appendChild(pi);
clipboardRootElement = clipboardDocument.createElement("convertigo-clipboard");
clipboardDocument.appendChild(clipboardRootElement);
TreePath[] selectedPaths = ((treePaths == null) ? projectExplorerView.getSelectionPaths() : treePaths);
treeObjectsList = new ArrayList<TreeObject>();
treeParentsList = new ArrayList<TreeObject>();
for (int i = 0; i < selectedPaths.length; i++) {
TreeObject treeObject = (TreeObject) selectedPaths[i].getLastPathComponent();
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) treeObject;
DatabaseObjectTreeObject parentDatabaseObjectTreeObject = databaseObjectTreeObject.getParentDatabaseObjectTreeObject();
treeObjectsList.add(databaseObjectTreeObject);
treeParentsList.add(parentDatabaseObjectTreeObject);
copyDatabaseObject((DatabaseObject) databaseObjectTreeObject.getObject());
} else if (treeObject instanceof IPropertyTreeObject) {
IPropertyTreeObject propertyTreeObject = (IPropertyTreeObject) treeObject;
treeObjectsList.add(treeObject);
treeParentsList.add(((IPropertyTreeObject) treeObject).getTreeObjectOwner());
copyPropertyObject(propertyTreeObject);
} else if (treeObject instanceof IDesignTreeObject) {
IDesignTreeObject designTreeObject = (IDesignTreeObject) treeObject;
treeObjectsList.add(treeObject);
treeParentsList.add(((IDesignTreeObject) treeObject).getTreeObjectOwner());
copyDesignObject(designTreeObject);
} else {
throw new EngineException("Tree item not supported :" + treeObject.getClass().getName());
}
}
objects = treeObjectsList.toArray(new Object[selectedPaths.length]);
parentTreeNodeOfCutObjects = treeParentsList.toArray(new TreeObject[selectedPaths.length]);
String strObject = XMLUtils.prettyPrintDOM(clipboardDocument);
return strObject;
}
Aggregations