use of com.twinsoft.convertigo.beans.core.Statement 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.core.Statement in project convertigo by convertigo.
the class TreeDropAdapter method paste.
public DatabaseObject paste(Node node, DatabaseObject parentDatabaseObject, boolean bChangeName) throws EngineException {
Object object = ConvertigoPlugin.clipboardManagerDND.read(node);
if (object instanceof DatabaseObject) {
DatabaseObject databaseObject = (DatabaseObject) object;
String dboName = databaseObject.getName();
String name = null;
boolean bContinue = true;
int index = 0;
while (bContinue) {
if (bChangeName) {
if (index == 0)
name = dboName;
else
name = dboName + index;
databaseObject.setName(name);
}
databaseObject.hasChanged = true;
databaseObject.bNew = true;
try {
if (parentDatabaseObject != null)
parentDatabaseObject.add(databaseObject);
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
if ((parentDatabaseObject instanceof HtmlTransaction) && (databaseObject instanceof Statement))
throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
if ((parentDatabaseObject instanceof Sequence) && (databaseObject instanceof Step))
throw new EngineException("Sequence already contains a step named \"" + name + "\".", owsne);
// Silently ignore
index++;
}
}
NodeList childNodes = node.getChildNodes();
int len = childNodes.getLength();
Node childNode;
String childNodeName;
for (int i = 0; i < len; i++) {
childNode = childNodes.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE)
continue;
childNodeName = childNode.getNodeName();
if (!(childNodeName.equalsIgnoreCase("property")) && !(childNodeName.equalsIgnoreCase("handlers")) && !(childNodeName.equalsIgnoreCase("wsdltype")) && !(childNodeName.equalsIgnoreCase("docdata")) && !(childNodeName.equalsIgnoreCase("beandata")) && !(childNodeName.equalsIgnoreCase("dnd"))) {
paste(childNode, databaseObject, bChangeName);
}
}
// needed !
databaseObject.isImporting = false;
databaseObject.isSubLoaded = true;
return databaseObject;
}
return null;
}
use of com.twinsoft.convertigo.beans.core.Statement in project convertigo by convertigo.
the class HtmlConnectorDesignComposite method createStatementFromSelection.
public void createStatementFromSelection() {
String className = "com.twinsoft.convertigo.beans.core.Statement";
// Retrieve selected statement xpath
String statementXpath = xpathEvaluator.getSelectionXpath();
// Retrieve parent Statement
Statement parentObject = getParentStatement();
if (parentObject == null) {
ConvertigoPlugin.errorMessageBox("Unable to create a new statement.\nThe selected handler belongs to a different HTML connector.");
return;
}
// Add statement to parent statement
NewObjectWizard newObjectWizard = new NewObjectWizard(parentObject, className, statementXpath, null);
WizardDialog wzdlg = new WizardDialog(Display.getCurrent().getActiveShell(), newObjectWizard);
wzdlg.setPageSize(850, 650);
wzdlg.open();
if (wzdlg.getReturnCode() != Window.CANCEL) {
Statement statement = (Statement) newObjectWizard.newBean;
// Reload parent statement in Tree
fireObjectChanged(new CompositeEvent(parentObject));
// Set selection on new statement (will expand tree to new statement)
if (statement != null)
fireObjectSelected(new CompositeEvent(statement));
// Set back selection on parent statement
fireObjectSelected(new CompositeEvent(parentObject));
}
}
use of com.twinsoft.convertigo.beans.core.Statement in project convertigo by convertigo.
the class EventStatementGenerator method addStatement.
protected void addStatement(AbstractEventStatement stat) {
if (stat != null) {
try {
List<Statement> stats = block.getStatements();
boolean goodName = false;
String currentName = stat.getName();
while (!goodName) {
goodName = true;
for (int i = 0; i < stats.size() && goodName; i++) {
DatabaseObject obj = (DatabaseObject) stats.get(i);
goodName = !(obj.getName().equals(currentName));
}
if (!goodName) {
String base = currentName;
int count = 1;
int i_ = currentName.lastIndexOf("_");
if (i_ != -1 && i_ + 1 < currentName.length()) {
String end = currentName.substring(i_ + 1);
try {
count = Integer.parseInt(end) + 1;
base = currentName.substring(0, i_);
} catch (NumberFormatException e) {
}
}
currentName = base + "_" + count;
}
}
if (!StringUtils.isNormalized(currentName))
throw new EngineException("Statement name is not normalized : \"" + currentName + "\"");
stat.setName(currentName);
stat.hasChanged = true;
stat.bNew = true;
block.addStatement(stat);
block.hasChanged = true;
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Error when adding an '" + stat.getClass().getName() + "' statement.");
}
}
}
use of com.twinsoft.convertigo.beans.core.Statement in project convertigo by convertigo.
the class ChangeToIfThenElseStatementAction 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();
if ((databaseObject != null) && (databaseObject instanceof IfStatement)) {
IfStatement ifStatement = (IfStatement) databaseObject;
List<Statement> list = ifStatement.getStatements();
TreePath[] selectedPaths = new TreePath[list.size()];
for (int i = 0; i < list.size(); i++) {
StatementTreeObject statementTreeObject = (StatementTreeObject) explorerView.findTreeObjectByUserObject(list.get(i));
selectedPaths[i] = new TreePath(statementTreeObject);
}
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// New IfThenElseStatement statement
IfThenElseStatement ifThenElseStatement = new IfThenElseStatement(ifStatement.getCondition());
ifThenElseStatement.bNew = true;
ifThenElseStatement.hasChanged = true;
// Add new IfThenElseStatement statement to parent
DatabaseObject parentDbo = ifStatement.getParent();
parentDbo.add(ifThenElseStatement);
// Set correct order
if (parentDbo instanceof StatementWithExpressions) {
int index = ((StatementWithExpressions) parentDbo).getOrderedStatements().get(0).indexOf(ifStatement.priority);
((StatementWithExpressions) parentDbo).getOrderedStatements().get(0).add(index, ifThenElseStatement.priority);
}
// Add Then/Else statement
ThenStatement thenStatement = new ThenStatement();
thenStatement.bNew = true;
ifThenElseStatement.addStatement(thenStatement);
ElseStatement elseStatement = new ElseStatement();
elseStatement.bNew = true;
ifThenElseStatement.addStatement(elseStatement);
// Add new IfThenElseStep statement in Tree
StatementTreeObject statementTreeObject = new StatementTreeObject(explorerView.viewer, ifThenElseStatement);
treeParent.addChild(statementTreeObject);
StatementTreeObject thenTreeObject = new StatementTreeObject(explorerView.viewer, thenStatement);
statementTreeObject.addChild(thenTreeObject);
StatementTreeObject elseTreeObject = new StatementTreeObject(explorerView.viewer, elseStatement);
statementTreeObject.addChild(elseTreeObject);
// Cut/Paste steps under Then statement
if (selectedPaths.length > 0) {
new ClipboardAction(ConvertigoPlugin.clipboardManagerDND).cut(explorerView, selectedPaths, ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP);
for (int i = 0; i < ConvertigoPlugin.clipboardManagerDND.objects.length; i++) {
ConvertigoPlugin.clipboardManagerDND.cutAndPaste(ConvertigoPlugin.clipboardManagerDND.objects[i], thenTreeObject);
}
ConvertigoPlugin.clipboardManagerDND.reset();
}
// Delete If statement
ifStatement.delete();
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifThenElseStatement));
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change statement to IfThenElse statement!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations