use of com.twinsoft.convertigo.beans.steps.XMLElementStep 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();
}
}
use of com.twinsoft.convertigo.beans.steps.XMLElementStep in project convertigo by convertigo.
the class TreeDropAdapter method paste.
private boolean paste(Node node, TreeObject targetTreeObject) throws EngineException {
if (targetTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObject parent = ((DatabaseObjectTreeObject) targetTreeObject).getObject();
DatabaseObject databaseObject = paste(node, null, true);
Element element = (Element) ((Element) node).getElementsByTagName("dnd").item(0);
// SEQUENCER
if (parent instanceof Sequence || parent instanceof StepWithExpressions) {
if (parent instanceof XMLElementStep)
return false;
if (parent instanceof IThenElseContainer)
return false;
// Add a TransactionStep
if (databaseObject instanceof Transaction) {
String projectName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name");
String connectorName = ((Element) element.getElementsByTagName("connector").item(0)).getAttribute("name");
Transaction transaction = (Transaction) databaseObject;
TransactionStep transactionStep = new TransactionStep();
transactionStep.setSourceTransaction(projectName + TransactionStep.SOURCE_SEPARATOR + connectorName + TransactionStep.SOURCE_SEPARATOR + transaction.getName());
transactionStep.bNew = true;
parent.add(transactionStep);
parent.hasChanged = true;
if (transaction instanceof TransactionWithVariables) {
for (Variable variable : ((TransactionWithVariables) transaction).getVariablesList()) {
StepVariable stepVariable = variable.isMultiValued() ? new StepMultiValuedVariable() : new StepVariable();
stepVariable.setName(variable.getName());
stepVariable.setComment(variable.getComment());
stepVariable.setDescription(variable.getDescription());
stepVariable.setRequired(variable.isRequired());
stepVariable.setValueOrNull(variable.getValueOrNull());
stepVariable.setVisibility(variable.getVisibility());
transactionStep.addVariable(stepVariable);
}
}
return true;
} else // Add a SequenceStep
if (databaseObject instanceof Sequence) {
String projectName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name");
Sequence seq = (Sequence) databaseObject;
SequenceStep sequenceStep = new SequenceStep();
sequenceStep.setSourceSequence(projectName + SequenceStep.SOURCE_SEPARATOR + seq.getName());
sequenceStep.bNew = true;
parent.add(sequenceStep);
parent.hasChanged = true;
for (Variable variable : seq.getVariablesList()) {
StepVariable stepVariable = variable.isMultiValued() ? new StepMultiValuedVariable() : new StepVariable();
stepVariable.setName(variable.getName());
stepVariable.setComment(variable.getComment());
stepVariable.setDescription(variable.getDescription());
stepVariable.setRequired(variable.isRequired());
stepVariable.setValueOrNull(variable.getValueOrNull());
stepVariable.setVisibility(variable.getVisibility());
sequenceStep.addVariable(stepVariable);
}
return true;
}
} else // URLMAPPER
if (parent instanceof UrlMappingOperation) {
// Set associated requestable, add all parameters for operation
if (databaseObject instanceof RequestableObject) {
String dboQName = "";
if (databaseObject instanceof Sequence) {
dboQName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name") + "." + databaseObject.getName();
} else if (databaseObject instanceof Transaction) {
dboQName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name") + "." + ((Element) element.getElementsByTagName("connector").item(0)).getAttribute("name") + "." + databaseObject.getName();
}
UrlMappingOperation operation = (UrlMappingOperation) parent;
operation.setTargetRequestable(dboQName);
if (operation.getComment().isEmpty()) {
operation.setComment(databaseObject.getComment());
}
operation.hasChanged = true;
try {
StringTokenizer st = new StringTokenizer(dboQName, ".");
int count = st.countTokens();
Project p = Engine.theApp.databaseObjectsManager.getProjectByName(st.nextToken());
List<RequestableVariable> variables = new ArrayList<RequestableVariable>();
if (count == 2) {
variables = p.getSequenceByName(st.nextToken()).getVariablesList();
} else if (count == 3) {
variables = ((TransactionWithVariables) p.getConnectorByName(st.nextToken()).getTransactionByName(st.nextToken())).getVariablesList();
}
for (RequestableVariable variable : variables) {
String variableName = variable.getName();
Object variableValue = variable.getValueOrNull();
UrlMappingParameter parameter = null;
try {
parameter = operation.getParameterByName(variableName);
} catch (Exception e) {
}
if (parameter == null) {
boolean acceptForm = operation.getMethod().equalsIgnoreCase(HttpMethodType.POST.name()) || operation.getMethod().equalsIgnoreCase(HttpMethodType.PUT.name());
parameter = acceptForm ? new FormParameter() : new QueryParameter();
parameter.setName(variableName);
parameter.setComment(variable.getComment());
parameter.setArray(false);
parameter.setExposed(((RequestableVariable) variable).isWsdl());
parameter.setMultiValued(variable.isMultiValued());
parameter.setRequired(variable.isRequired());
parameter.setValueOrNull(!variable.isMultiValued() ? variableValue : null);
parameter.setMappedVariableName(variableName);
parameter.bNew = true;
operation.add(parameter);
operation.hasChanged = true;
}
}
} catch (Exception e) {
}
return true;
} else // Add a parameter to mapping operation
if (databaseObject instanceof RequestableVariable) {
RequestableVariable variable = (RequestableVariable) databaseObject;
UrlMappingOperation operation = (UrlMappingOperation) parent;
UrlMappingParameter parameter = null;
String variableName = variable.getName();
Object variableValue = variable.getValueOrNull();
try {
parameter = operation.getParameterByName(variableName);
} catch (Exception e) {
}
if (parameter == null) {
boolean acceptForm = operation.getMethod().equalsIgnoreCase(HttpMethodType.POST.name()) || operation.getMethod().equalsIgnoreCase(HttpMethodType.PUT.name());
parameter = acceptForm ? new FormParameter() : new QueryParameter();
parameter.setName(variableName);
parameter.setComment(variable.getComment());
parameter.setArray(false);
parameter.setExposed(((RequestableVariable) variable).isWsdl());
parameter.setMultiValued(variable.isMultiValued());
parameter.setRequired(variable.isRequired());
parameter.setValueOrNull(!variable.isMultiValued() ? variableValue : null);
parameter.setMappedVariableName(variableName);
parameter.bNew = true;
operation.add(parameter);
operation.hasChanged = true;
}
return true;
}
} else // MOBILE COMPONENTS
if (parent instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
return pasteMobileComponent(parent, databaseObject, element);
} else // NGX COMPONENTS
if (parent instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
return pasteNgxComponent(parent, databaseObject, element);
}
}
return false;
}
Aggregations