use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent 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) {
boolean insertBefore = (feedback & DND.FEEDBACK_INSERT_BEFORE) != 0;
boolean insertAfter = (feedback & DND.FEEDBACK_INSERT_AFTER) != 0;
DatabaseObjectTreeObject dbotree = (DatabaseObjectTreeObject) targetTreeObject;
if (insertBefore || insertAfter) {
targetTreeObject = dbotree.getParent();
}
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);
if (dbotree != targetTreeObject) {
explorerView.moveLastTo((TreeParent) targetTreeObject, dbotree, insertBefore);
}
}
} 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.TreeParent 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 objects copy or move with Drag and drop
if (targetObject instanceof TreeObject) {
TreeObject targetTreeObject = (TreeObject) targetObject;
if (targetTreeObject != null) {
ProjectExplorerView explorerView = targetTreeObject.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();
boolean insertBefore = (feedback & DND.FEEDBACK_INSERT_BEFORE) != 0;
boolean insertAfter = (feedback & DND.FEEDBACK_INSERT_AFTER) != 0;
TreeObject sourceObject = (TreeObject) getSelectedObject();
if (insertBefore || insertAfter) {
TreeParent targetTreeParent = ((TreeObject) targetObject).getParent();
if (sourceObject.getParent() != targetTreeParent) {
ProjectTreeObject prjTree = targetTreeParent.getProjectTreeObject();
String path = targetTreeParent.getPath();
ClipboardAction.dnd.paste(source, shell, explorerView, targetTreeParent, true);
targetTreeParent = (TreeParent) explorerView.findTreeObjectByPath(prjTree, path);
}
explorerView.moveChildTo(targetTreeParent, sourceObject, targetTreeObject, insertBefore);
} else {
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.TreeParent in project convertigo by convertigo.
the class ChangeToXMLAttributeStepAction method run.
/* (non-Javadoc)
* @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#run()
*/
@Override
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) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
Object databaseObject = treeObject.getObject();
// Attribute
if ((databaseObject != null) && (databaseObject instanceof AttributeStep)) {
AttributeStep attributeStep = (AttributeStep) databaseObject;
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// New XMLAttribute step
XMLAttributeStep xmlAttributeStep = new XMLAttributeStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(attributeStep.getParent(), xmlAttributeStep)) {
// Set properties
xmlAttributeStep.setOutput(attributeStep.isOutput());
xmlAttributeStep.setEnabled(attributeStep.isEnabled());
xmlAttributeStep.setComment(attributeStep.getComment());
// xmlAttributeStep.setSourceDefinition(xmlElementStep.getSourceDefinition());
xmlAttributeStep.setNodeText(attributeStep.getNodeText());
xmlAttributeStep.setNodeName(attributeStep.getNodeName());
xmlAttributeStep.bNew = true;
xmlAttributeStep.hasChanged = true;
// Add new XMLAttribute step to parent
DatabaseObject parentDbo = attributeStep.getParent();
parentDbo.add(xmlAttributeStep);
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(xmlAttributeStep, attributeStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(xmlAttributeStep, attributeStep.priority);
// Add new XMLAttribute step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, attributeStep);
treeParent.addChild(stepTreeObject);
// Delete XMLElement step
long oldPriority = attributeStep.priority;
attributeStep.delete();
xmlAttributeStep.getSequence().fireStepMoved(new StepEvent(xmlAttributeStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(xmlAttributeStep));
} else {
throw new EngineException("You cannot paste to a " + attributeStep.getParent().getClass().getSimpleName() + " a database object of type " + xmlAttributeStep.getClass().getSimpleName());
}
}
}
// XML Element
if ((databaseObject != null) && (databaseObject instanceof XMLElementStep)) {
XMLElementStep xmlElementStep = (XMLElementStep) databaseObject;
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// New XMLAttribute step
XMLAttributeStep xmlAttributeStep = new XMLAttributeStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(xmlElementStep.getParent(), xmlAttributeStep)) {
// Set properties
xmlAttributeStep.setOutput(xmlElementStep.isOutput());
xmlAttributeStep.setEnabled(xmlElementStep.isEnabled());
xmlAttributeStep.setComment(xmlElementStep.getComment());
xmlAttributeStep.setSourceDefinition(xmlElementStep.getSourceDefinition());
xmlAttributeStep.setNodeText(xmlElementStep.getNodeText());
xmlAttributeStep.setNodeName(xmlElementStep.getNodeName());
xmlAttributeStep.bNew = true;
xmlAttributeStep.hasChanged = true;
// Add new XMLAttribute step to parent
DatabaseObject parentDbo = xmlElementStep.getParent();
parentDbo.add(xmlAttributeStep);
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(xmlAttributeStep, xmlElementStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(xmlAttributeStep, xmlElementStep.priority);
// Add new XMLAttribute step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, xmlElementStep);
treeParent.addChild(stepTreeObject);
// Delete XMLElement step
long oldPriority = xmlElementStep.priority;
xmlElementStep.delete();
xmlAttributeStep.getSequence().fireStepMoved(new StepEvent(xmlAttributeStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(xmlAttributeStep));
} else {
throw new EngineException("You cannot paste to a " + xmlElementStep.getParent().getClass().getSimpleName() + " a database object of type " + xmlAttributeStep.getClass().getSimpleName());
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change to XMLAttribute step!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent in project convertigo by convertigo.
the class ChangeToXMLConcatStepAction method run.
/* (non-Javadoc)
* @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#run()
*/
@Override
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) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
Object databaseObject = treeObject.getObject();
if ((databaseObject != null) && (databaseObject instanceof XMLElementStep)) {
XMLElementStep elementStep = (XMLElementStep) databaseObject;
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// New XMLConcatStep step
XMLConcatStep concatStep = new XMLConcatStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(elementStep.getParent(), concatStep)) {
XMLVector<XMLVector<Object>> sources = new XMLVector<XMLVector<Object>>();
XMLVector<Object> source = new XMLVector<Object>();
source.add("description");
source.add(elementStep.getSourceDefinition());
source.add(elementStep.getNodeText());
sources.add(source);
concatStep.setOutput(elementStep.isOutput());
concatStep.setEnabled(elementStep.isEnabled());
concatStep.setComment(elementStep.getComment());
// elementStep.getNodeText();
concatStep.setNodeName(elementStep.getNodeName());
concatStep.setSourcesDefinition(sources);
concatStep.bNew = true;
concatStep.hasChanged = true;
// Add new XMLConcatStep step to parent
DatabaseObject parentDbo = elementStep.getParent();
parentDbo.add(concatStep);
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(concatStep, elementStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(concatStep, elementStep.priority);
// Add new XMLConcatStep step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, concatStep);
treeParent.addChild(stepTreeObject);
// Delete XMLElementStep step
long oldPriority = elementStep.priority;
elementStep.delete();
concatStep.getSequence().fireStepMoved(new StepEvent(concatStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(concatStep));
} else {
throw new EngineException("You cannot paste to a " + elementStep.getParent().getClass().getSimpleName() + " a database object of type " + concatStep.getClass().getSimpleName());
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change XMLElement to XMLConcat step!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent in project convertigo by convertigo.
the class ChangeToXMLElementStepAction method run.
/* (non-Javadoc)
* @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#run()
*/
@SuppressWarnings("unchecked")
@Override
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) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
Object databaseObject = treeObject.getObject();
// XML Concat step
if ((databaseObject != null) && (databaseObject instanceof XMLConcatStep)) {
XMLConcatStep concatStep = (XMLConcatStep) databaseObject;
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// New XMLElementStep step
XMLElementStep elementStep = new XMLElementStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(concatStep.getParent(), elementStep)) {
if (concatStep.getSourcesDefinition().toString().equals("[[]]")) {
elementStep.setSourceDefinition(new XMLVector<String>());
} else {
// Set properties (Default value and Source)
XMLVector<XMLVector<Object>> sources = concatStep.getSourcesDefinition();
XMLVector<String> sourceDefinition = new XMLVector<String>();
String defaultValue = "";
for (XMLVector<Object> source : sources) {
if (sources.lastElement() == source) {
defaultValue += source.get(2);
} else {
defaultValue += source.get(2) + concatStep.getSeparator();
}
if (sourceDefinition.toString().equals("[]") && (!source.get(1).toString().equals("") && !source.get(1).toString().equals("[]"))) {
sourceDefinition = (XMLVector<String>) source.get(1);
}
}
elementStep.setOutput(concatStep.isOutput());
elementStep.setEnabled(concatStep.isEnabled());
elementStep.setComment(concatStep.getComment());
elementStep.setNodeName(concatStep.getNodeName());
elementStep.setNodeText(defaultValue);
elementStep.setSourceDefinition(sourceDefinition);
}
elementStep.bNew = true;
elementStep.hasChanged = true;
// Add new XMLElementStep step to parent
DatabaseObject parentDbo = concatStep.getParent();
parentDbo.add(elementStep);
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(elementStep, concatStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(elementStep, concatStep.priority);
// Add new XMLElementStep step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, elementStep);
treeParent.addChild(stepTreeObject);
// Delete XMLConcatStep step
long oldPriority = concatStep.priority;
concatStep.delete();
elementStep.getSequence().fireStepMoved(new StepEvent(elementStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(elementStep));
} else {
throw new EngineException("You cannot paste to a " + concatStep.getParent().getClass().getSimpleName() + " a database object of type " + elementStep.getClass().getSimpleName());
}
}
}
// XML Attribute
if ((databaseObject != null) && (databaseObject instanceof XMLAttributeStep)) {
XMLAttributeStep attributeStep = (XMLAttributeStep) databaseObject;
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// New XMLElement step
XMLElementStep elementStep = new XMLElementStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(attributeStep.getParent(), elementStep)) {
// Set properties
elementStep.setOutput(attributeStep.isOutput());
elementStep.setEnabled(attributeStep.isEnabled());
elementStep.setComment(attributeStep.getComment());
elementStep.setSourceDefinition(attributeStep.getSourceDefinition());
elementStep.setNodeText(attributeStep.getNodeText());
elementStep.setNodeName(attributeStep.getNodeName());
elementStep.bNew = true;
elementStep.hasChanged = true;
// Add new XMLElement step to parent
DatabaseObject parentDbo = attributeStep.getParent();
parentDbo.add(elementStep);
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(elementStep, attributeStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(elementStep, attributeStep.priority);
// Add new XMLElement step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, attributeStep);
treeParent.addChild(stepTreeObject);
// Delete XMLAttribute step
long oldPriority = attributeStep.priority;
attributeStep.delete();
elementStep.getSequence().fireStepMoved(new StepEvent(elementStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(elementStep));
} else {
throw new EngineException("You cannot paste to a " + attributeStep.getParent().getClass().getSimpleName() + " a database object of type " + elementStep.getClass().getSimpleName());
}
}
}
// JElement
if ((databaseObject != null) && (databaseObject instanceof ElementStep)) {
ElementStep jelementStep = (ElementStep) databaseObject;
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// New XMLElement step
XMLElementStep elementStep = new XMLElementStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(jelementStep.getParent(), elementStep)) {
// Set properties
elementStep.setOutput(jelementStep.isOutput());
elementStep.setEnabled(jelementStep.isEnabled());
elementStep.setComment(jelementStep.getComment());
// elementStep.setSourceDefinition(jelementStep.getSourceDefinition());
elementStep.setNodeText(jelementStep.getNodeText());
elementStep.setNodeName(jelementStep.getNodeName());
elementStep.bNew = true;
elementStep.hasChanged = true;
// Add new XMLElement step to parent
DatabaseObject parentDbo = jelementStep.getParent();
parentDbo.add(elementStep);
for (Step step : jelementStep.getAllSteps()) {
try {
elementStep.addStep(step);
} catch (Throwable t) {
}
}
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(elementStep, jelementStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(elementStep, jelementStep.priority);
// Add new XMLElement step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, jelementStep);
treeParent.addChild(stepTreeObject);
// Delete XMLAttribute step
long oldPriority = jelementStep.priority;
jelementStep.delete();
elementStep.getSequence().fireStepMoved(new StepEvent(elementStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(elementStep));
} else {
throw new EngineException("You cannot paste to a " + jelementStep.getParent().getClass().getSimpleName() + " a database object of type " + elementStep.getClass().getSimpleName());
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change step to XMLElement step!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations