use of com.twinsoft.convertigo.beans.core.Variable in project convertigo by convertigo.
the class ChangeToSingleValuedVariableAction method 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();
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
Object databaseObject = treeObject.getObject();
if (databaseObject != null) {
Variable multi = (Variable) databaseObject;
Variable simple = null;
if (databaseObject instanceof TestCaseMultiValuedVariable)
simple = new TestCaseVariable();
if (databaseObject instanceof StepMultiValuedVariable)
simple = new StepVariable();
if (databaseObject instanceof RequestableMultiValuedVariable)
simple = new RequestableVariable();
if (databaseObject instanceof RequestableHttpMultiValuedVariable)
simple = new RequestableHttpVariable();
if (databaseObject instanceof HttpStatementMultiValuedVariable)
simple = new HttpStatementVariable();
if (simple != null) {
if (multi instanceof StepMultiValuedVariable) {
((StepVariable) simple).setSourceDefinition(((StepVariable) multi).getSourceDefinition());
}
if (multi instanceof RequestableVariable) {
((RequestableVariable) simple).setXmlTypeAffectation(((RequestableVariable) multi).getXmlTypeAffectation());
}
if (multi instanceof RequestableHttpVariable) {
// HttpName
((RequestableHttpVariable) simple).setHttpName(((RequestableHttpVariable) multi).getHttpName());
// HttpMethod
((RequestableHttpVariable) simple).setHttpMethod(((RequestableHttpVariable) multi).getHttpMethod());
}
XMLVector<Object> xmlv = GenericUtils.cast(multi.getValueOrNull());
Object value = (xmlv == null) ? null : (xmlv.isEmpty() ? "" : xmlv.get(0).toString());
simple.setValueOrNull(value);
simple.setVisibility(multi.getVisibility());
// Comment
simple.setComment(multi.getComment());
// Description
simple.setDescription(multi.getDescription());
// Required
simple.setRequired(multi.isRequired());
simple.bNew = true;
simple.hasChanged = true;
// Add new variable to parent
DatabaseObject parentDbo = multi.getParent();
parentDbo.add(simple);
// Set correct order
if (parentDbo instanceof TestCase)
((TestCase) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof RequestableStep)
((RequestableStep) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof TransactionWithVariables)
((TransactionWithVariables) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof HTTPStatement)
((HTTPStatement) parentDbo).insertAtOrder(simple, multi.priority);
// Add new variable in Tree
VariableTreeObject2 varTreeObject = new VariableTreeObject2(explorerView.viewer, simple);
treeParent.addChild(varTreeObject);
// Delete simple variable
multi.delete();
// Set correct name
simple.setName(multi.getName());
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(simple));
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change simple variable to multi valuated variable!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Variable in project convertigo by convertigo.
the class TransactionTreeObject method treeObjectRemoved.
@Override
public void treeObjectRemoved(TreeObjectEvent treeObjectEvent) {
super.treeObjectRemoved(treeObjectEvent);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
if (!(treeObject.equals(this)) && (treeObject.getParents().contains(this))) {
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
// A variable has been removed
if (databaseObject instanceof Variable) {
String variableName = databaseObject.getName();
// This is an AbstractHttpTransaction
if (getObject() instanceof AbstractHttpTransaction) {
AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) getObject();
String transactionSubDir = httpTransaction.getSubDir();
List<String> pathVariableList = AbstractHttpTransaction.getPathVariableList(httpTransaction.getSubDir());
// Update transaction SubDir property
if (pathVariableList.contains(variableName)) {
transactionSubDir = transactionSubDir.replaceAll("\\{" + variableName + "\\}", "");
httpTransaction.setSubDir(transactionSubDir);
httpTransaction.hasChanged = true;
try {
ConvertigoPlugin.getDefault().getProjectExplorerView().updateTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not update in tree Transaction \"" + databaseObject.getName() + "\" !");
}
}
}
}
}
}
}
use of com.twinsoft.convertigo.beans.core.Variable in project convertigo by convertigo.
the class TransactionTreeObject method handlesBeanNameChanged.
protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
if (databaseObject instanceof ScreenClass) {
String oldName = StringUtils.normalize((String) oldValue);
String newName = StringUtils.normalize((String) newValue);
Transaction transaction = getObject();
// Modify Screenclass name in Transaction handlers
if (!(transaction instanceof HtmlTransaction)) {
// ScreenClass and Transaction must have the same connector!
if (transaction.getConnector().equals(databaseObject.getConnector())) {
String oldHandlerPrefix = "on" + StringUtils.normalize(oldName);
String newHandlerPrefix = "on" + StringUtils.normalize(newName);
if (transaction.handlers.indexOf(oldHandlerPrefix) != -1) {
StringEx sx = new StringEx(transaction.handlers);
// Updating comments
sx.replaceAll("handler for screen class \"" + oldName + "\"", "handler for screen class \"" + newName + "\"");
// Updating functions def & calls
sx.replaceAll(oldHandlerPrefix + "Entry", newHandlerPrefix + "Entry");
sx.replaceAll(oldHandlerPrefix + "Exit", newHandlerPrefix + "Exit");
String newHandlers = sx.toString();
if (!newHandlers.equals(transaction.handlers)) {
transaction.handlers = newHandlers;
hasBeenModified(true);
}
// Update the opened handlers editor if any
JScriptEditorInput jsinput = ConvertigoPlugin.getDefault().getJScriptEditorInput(transaction);
if (jsinput != null) {
jsinput.reload();
}
try {
ConvertigoPlugin.getDefault().getProjectExplorerView().reloadTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
}
}
}
}
}
if (databaseObject instanceof Variable) {
String oldVariableName = oldValue.toString();
String newVariableName = newValue.toString();
// A variable of this transaction has been renamed
if (getObject().equals(databaseObject.getParent())) {
if (getObject() instanceof AbstractHttpTransaction) {
AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) getObject();
try {
// Check for variables to be renamed in SubDir property
String transactionSubDir = httpTransaction.getSubDir();
List<String> pathVariableList = AbstractHttpTransaction.getPathVariableList(transactionSubDir);
if (pathVariableList.contains(oldVariableName)) {
transactionSubDir = transactionSubDir.replaceAll("\\{" + oldVariableName + "\\}", "{" + newVariableName + "}");
httpTransaction.setSubDir(transactionSubDir);
httpTransaction.hasChanged = true;
}
ConvertigoPlugin.getDefault().getProjectExplorerView().refreshTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
}
}
}
}
// Case of this transaction rename : update transaction's schema
if (treeObject.equals(this)) {
String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME + "/" + getConnectorTreeObject().getName();
String oldPath = path + "/" + (String) oldValue + ".xsd";
String newPath = path + "/" + (String) newValue + ".xsd";
IFile file = getProjectTreeObject().getFile(oldPath);
try {
file.getParent().refreshLocal(IResource.DEPTH_ONE, null);
if (file.exists()) {
// rename file (xsd/internal/connector/transaction.xsd)
file.move(new Path((String) newValue + ".xsd"), true, null);
// make replacements in schema files
List<Replacement> replacements = new ArrayList<Replacement>();
replacements.add(new Replacement("__" + (String) oldValue, "__" + (String) newValue));
IFile newFile = file.getParent().getFile(new Path((String) newValue + ".xsd"));
String newFilePath = newFile.getLocation().makeAbsolute().toString();
try {
ProjectUtils.makeReplacementsInFile(replacements, newFilePath);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not rename \"" + oldValue + "\" to \"" + newValue + "\" in schema file \"" + newPath + "\" !");
}
// refresh file
file.refreshLocal(IResource.DEPTH_ZERO, null);
Engine.theApp.schemaManager.clearCache(getProjectTreeObject().getName());
}
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not rename schema file from \"" + oldPath + "\" to \"" + newPath + "\" !");
}
}
}
use of com.twinsoft.convertigo.beans.core.Variable in project convertigo by convertigo.
the class VariableTreeObject2 method handlesBeanNameChanged.
protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
int update = treeObjectEvent.update;
// Updates variables references
if (update != TreeObjectEvent.UPDATE_NONE) {
boolean isLocalProject = false;
boolean isSameValue = false;
boolean shouldUpdate = false;
try {
if (getObject() instanceof Variable) {
Variable variable = (Variable) getObject();
if (databaseObject instanceof RequestableVariable) {
isLocalProject = variable.getProject().equals(databaseObject.getProject());
isSameValue = variable.getName().equals(oldValue);
shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
// Verify if parent of databaseObject is a transaction
if (databaseObject.getParent() instanceof Transaction) {
Transaction transaction = (Transaction) databaseObject.getParent();
// Case of rename for Call Transaction
if (variable.getParent() instanceof TransactionStep) {
TransactionStep transactionStep = (TransactionStep) variable.getParent();
if (transactionStep.getSourceTransaction().equals(transaction.getProject() + "." + transaction.getConnector() + "." + transaction.getName())) {
updateNameReference(isSameValue, shouldUpdate, variable, newValue);
}
}
/*
* propagation to testCases of variable renaming in a transaction
*/
if (variable.getParent() instanceof TransactionWithVariables) {
propagateVariableRename(true, true, treeObjectEvent, ((TransactionWithVariables) transaction).getTestCasesList(), transaction.getName());
}
}
// Verify if parent of databaseObject is a sequence
if (databaseObject.getParent() instanceof Sequence) {
Sequence sequence = (Sequence) databaseObject.getParent();
// Case of rename for Call Sequence
if (variable.getParent() instanceof SequenceStep) {
SequenceStep sequenceStep = (SequenceStep) variable.getParent();
if (sequenceStep.getSourceSequence().equals(sequence.getProject() + "." + sequence.getName())) {
updateNameReference(isSameValue, shouldUpdate, variable, newValue);
}
}
/*
* propagation to testCases of variable renaming in a sequence
*/
if (variable.getParent() instanceof Sequence) {
propagateVariableRename(true, true, treeObjectEvent, sequence.getTestCasesList(), sequence.getName());
}
}
}
}
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Unable to rename the variable references of '" + databaseObject.getName() + "'!");
}
}
}
use of com.twinsoft.convertigo.beans.core.Variable in project convertigo by convertigo.
the class AbstractCouchDbTransaction method getParameterStringValue.
public String getParameterStringValue(CouchParam param) throws EngineException {
String value = null;
Variable variable = getVariable(param.param());
if (variable != null) {
value = getParameterStringValue(param.param());
}
if (value == null) {
try {
value = (String) getClass().getMethod("getP_" + param.name()).invoke(this);
} catch (Exception e) {
// TODO: handle error
e.printStackTrace();
}
}
return value;
}
Aggregations