use of com.twinsoft.convertigo.beans.steps.XMLAttributeStep in project convertigo by convertigo.
the class ChangeToAttributeStepAction 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();
// XMLAttribute
if ((databaseObject != null) && (databaseObject instanceof XMLAttributeStep)) {
XMLAttributeStep xmlAttributeStep = (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 Attribute step
AttributeStep attributeStep = new AttributeStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(xmlAttributeStep.getParent(), attributeStep)) {
// Set properties
attributeStep.setOutput(xmlAttributeStep.isOutput());
attributeStep.setEnabled(xmlAttributeStep.isEnabled());
attributeStep.setComment(xmlAttributeStep.getComment());
// attributeStep.setExpression(elementStep.getExpression());
attributeStep.setNodeText(xmlAttributeStep.getNodeText());
attributeStep.setNodeName(xmlAttributeStep.getNodeName());
attributeStep.bNew = true;
attributeStep.hasChanged = true;
// Add new Attribute step to parent
DatabaseObject parentDbo = xmlAttributeStep.getParent();
parentDbo.add(attributeStep);
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(attributeStep, xmlAttributeStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(attributeStep, xmlAttributeStep.priority);
// Add new Attribute step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, xmlAttributeStep);
treeParent.addChild(stepTreeObject);
// Delete Element step
long oldPriority = xmlAttributeStep.priority;
xmlAttributeStep.delete();
attributeStep.getSequence().fireStepMoved(new StepEvent(attributeStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(attributeStep));
} else {
throw new EngineException("You cannot paste to a " + xmlAttributeStep.getParent().getClass().getSimpleName() + " a database object of type " + attributeStep.getClass().getSimpleName());
}
}
}
// Element
if ((databaseObject != null) && (databaseObject instanceof ElementStep)) {
ElementStep elementStep = (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 Attribute step
AttributeStep attributeStep = new AttributeStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(elementStep.getParent(), attributeStep)) {
// Set properties
attributeStep.setOutput(elementStep.isOutput());
attributeStep.setEnabled(elementStep.isEnabled());
attributeStep.setComment(elementStep.getComment());
attributeStep.setExpression(elementStep.getExpression());
attributeStep.setNodeText(elementStep.getNodeText());
attributeStep.setNodeName(elementStep.getNodeName());
attributeStep.bNew = true;
attributeStep.hasChanged = true;
// Add new Attribute step to parent
DatabaseObject parentDbo = elementStep.getParent();
parentDbo.add(attributeStep);
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(attributeStep, elementStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(attributeStep, elementStep.priority);
// Add new Attribute step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, elementStep);
treeParent.addChild(stepTreeObject);
// Delete Element step
long oldPriority = elementStep.priority;
elementStep.delete();
attributeStep.getSequence().fireStepMoved(new StepEvent(attributeStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(attributeStep));
} else {
throw new EngineException("You cannot paste to a " + elementStep.getParent().getClass().getSimpleName() + " a database object of type " + attributeStep.getClass().getSimpleName());
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change to Attribute step!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations