use of com.twinsoft.convertigo.beans.statements.IfXpathExistsStatement in project convertigo by convertigo.
the class ChangeToIfXpathExistsThenElseStatementAction 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) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
DatabaseObject databaseObject = treeObject.getObject();
// IfXpathExists
if ((databaseObject != null) && (databaseObject instanceof IfXpathExistsStatement)) {
IfXpathExistsStatement ifStatement = (IfXpathExistsStatement) databaseObject;
DatabaseObjectTreeObject parentTreeObject = treeObject.getOwnerDatabaseObjectTreeObject();
if (parentTreeObject != null) {
// New IfXpathExistsThenElseStatement statement
IfXpathExistsThenElseStatement ifThenElseStatement = new IfXpathExistsThenElseStatement();
ifThenElseStatement.bNew = true;
ifThenElseStatement.hasChanged = true;
// Add new IfThenElseStatement statement to parent
StatementWithExpressions parentDbo = (StatementWithExpressions) ifStatement.getParent();
parentDbo.addStatementAfter(ifThenElseStatement, ifStatement);
// Add Then/Else statement
ThenStatement thenStatement = new ThenStatement();
thenStatement.bNew = true;
ifThenElseStatement.addStatement(thenStatement);
ElseStatement elseStatement = new ElseStatement();
elseStatement.bNew = true;
ifThenElseStatement.addStatement(elseStatement);
for (Statement statement : ifStatement.getStatements()) {
thenStatement.addStatement(statement);
}
String name = ifStatement.getName();
// Set properties
ifThenElseStatement.setCondition(ifStatement.getCondition());
ifThenElseStatement.setComment(ifStatement.getComment());
ifThenElseStatement.setEnabled(ifStatement.isEnabled());
ifThenElseStatement.setVersion(ifStatement.getVersion());
// Delete If statement
ifStatement.delete();
ifThenElseStatement.setName(name);
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(parentTreeObject.findTreeObjectByUserObject(ifThenElseStatement));
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change statement to IfThenElse statement!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.statements.IfXpathExistsStatement in project convertigo by convertigo.
the class ChangeToIfXpathExistsStatementAction 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) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
DatabaseObject databaseObject = treeObject.getObject();
if ((databaseObject != null) && (databaseObject instanceof IfXpathExistsThenElseStatement)) {
IfXpathExistsThenElseStatement ifThenElseStatement = (IfXpathExistsThenElseStatement) databaseObject;
// IfXpathExistsThenElse statement
if (ifThenElseStatement.hasThenElseStatements()) {
DatabaseObjectTreeObject parentTreeObject = treeObject.getOwnerDatabaseObjectTreeObject();
if (parentTreeObject != null) {
// New IfXpathExistsStatement statement
IfXpathExistsStatement ifStatement = new IfXpathExistsStatement();
ifStatement.bNew = true;
ifStatement.hasChanged = true;
// Add new If statement to parent
StatementWithExpressions parentDbo = (StatementWithExpressions) ifThenElseStatement.getParent();
parentDbo.addStatementAfter(ifStatement, ifThenElseStatement);
for (Statement statement : ifThenElseStatement.getThenStatement().getStatements()) {
ifStatement.addStatement(statement);
}
// Set properties
ifStatement.setCondition(ifThenElseStatement.getCondition());
ifStatement.setComment(ifThenElseStatement.getComment());
ifStatement.setEnabled(ifThenElseStatement.isEnabled());
ifStatement.setVersion(ifThenElseStatement.getVersion());
String name = ifThenElseStatement.getName();
// Delete IfThenElse statement
ifThenElseStatement.delete();
ifStatement.setName(name);
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(parentTreeObject.findTreeObjectByUserObject(ifStatement));
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change statement to If statement!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations