use of com.twinsoft.convertigo.beans.steps.ElementStep in project convertigo by convertigo.
the class ClipboardAction method pasteStep.
private Object pasteStep(Shell shell, String source, DatabaseObject targetObject) throws ParserConfigurationException, SAXException, IOException {
// Can only paste on Sequence or Step
if (targetObject instanceof Sequence)
return targetObject;
else if (!(targetObject instanceof Step))
return null;
// cannot paste to IThenElseContainer
if (targetObject instanceof IThenElseContainer)
return null;
else {
List<Object> objects = clipboardManager.read(source);
int size = objects.size();
for (Object ob : objects) {
// Can only paste step objects
if (!(ob instanceof Step))
return null;
// Can paste only on step which may contain children
if ((ob instanceof StepWithExpressions) && (!(targetObject instanceof StepWithExpressions)))
return null;
// cannot paste a ThenStep
if (ob instanceof ThenStep)
return null;
// cannot paste a ElseStep
if (ob instanceof ElseStep)
return null;
// cannot paste a ThenStatement
if (ob instanceof ThenStatement)
return null;
// cannot paste a ElseStatement
if (ob instanceof ElseStatement)
return null;
// Special case of XMLElementStep, ElementStep
if ((targetObject instanceof XMLElementStep) || (targetObject instanceof ElementStep)) {
// Case paste on itself -> target is changed to parent
if ((size == 1) && ((ob instanceof XMLElementStep) || (ob instanceof ElementStep))) {
if (((Step) ob).getName().equals(targetObject.getName())) {
return targetObject.getParent();
}
return null;
} else // Else, only accept paste of XMLAttributeStep
if (!(ob instanceof XMLAttributeStep || ob instanceof AttributeStep)) {
return null;
}
} else // Case of step which may contain children
if (targetObject instanceof StepWithExpressions) {
// Case paste on itself -> ask user what to do
if ((size == 1) && (ob.getClass().equals(targetObject.getClass()))) {
if (((Step) ob).getName().equals(targetObject.getName())) {
CustomDialog customDialog = new CustomDialog(shell, "Paste a step", "Do you want to paste the step as a sibling or a child step?", 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) {
return targetObject.getParent();
} else if (response == 2) {
return null;
} else
break;
}
}
// Else, paste
break;
} else // Other case
{
// Case paste on itself -> target is changed to parent
if ((size == 1) && (ob.getClass().equals(targetObject.getClass()))) {
if (((Step) ob).getName().equals(targetObject.getName())) {
return targetObject.getParent();
}
return null;
}
// Else, not permitted
return null;
}
}
}
return targetObject;
}
use of com.twinsoft.convertigo.beans.steps.ElementStep in project convertigo by convertigo.
the class ChangeToElementStepAction 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 Element step
ElementStep jelementStep = new ElementStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(attributeStep.getParent(), jelementStep)) {
// Set properties
jelementStep.setOutput(attributeStep.isOutput());
jelementStep.setEnabled(attributeStep.isEnabled());
jelementStep.setComment(attributeStep.getComment());
jelementStep.setExpression(attributeStep.getExpression());
jelementStep.setNodeText(attributeStep.getNodeText());
jelementStep.setNodeName(attributeStep.getNodeName());
jelementStep.bNew = true;
jelementStep.hasChanged = true;
// Add new Element step to parent
DatabaseObject parentDbo = attributeStep.getParent();
parentDbo.add(jelementStep);
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(jelementStep, attributeStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(jelementStep, attributeStep.priority);
// Add new Element step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, attributeStep);
treeParent.addChild(stepTreeObject);
// Delete Attribute step
long oldPriority = attributeStep.priority;
attributeStep.delete();
jelementStep.getSequence().fireStepMoved(new StepEvent(jelementStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(jelementStep));
} else {
throw new EngineException("You cannot paste to a " + attributeStep.getParent().getClass().getSimpleName() + " a database object of type " + jelementStep.getClass().getSimpleName());
}
}
}
// XML Element
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 Element step
ElementStep jelementStep = new ElementStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(elementStep.getParent(), jelementStep)) {
// Set properties
jelementStep.setOutput(elementStep.isOutput());
jelementStep.setEnabled(elementStep.isEnabled());
jelementStep.setComment(elementStep.getComment());
// jelementStep.setSourceDefinition(elementStep.getSourceDefinition());
jelementStep.setNodeText(elementStep.getNodeText());
jelementStep.setNodeName(elementStep.getNodeName());
jelementStep.bNew = true;
jelementStep.hasChanged = true;
// Add new XMLElement step to parent
DatabaseObject parentDbo = elementStep.getParent();
parentDbo.add(jelementStep);
for (Step step : elementStep.getAllSteps()) {
try {
jelementStep.addStep(step);
} catch (Throwable t) {
}
}
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(jelementStep, elementStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(jelementStep, elementStep.priority);
// Add new Element step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, elementStep);
treeParent.addChild(stepTreeObject);
// Delete XMLAttribute step
long oldPriority = elementStep.priority;
elementStep.delete();
jelementStep.getSequence().fireStepMoved(new StepEvent(jelementStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(jelementStep));
} else {
throw new EngineException("You cannot paste to a " + elementStep.getParent().getClass().getSimpleName() + " a database object of type " + jelementStep.getClass().getSimpleName());
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change step to Element step!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.steps.ElementStep 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();
}
}
use of com.twinsoft.convertigo.beans.steps.ElementStep 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