use of com.twinsoft.convertigo.beans.core.StatementWithExpressions in project convertigo by convertigo.
the class HtmlConnectorDesignComposite method getParentStatement.
public StatementWithExpressions getParentStatement() {
StatementWithExpressions parentObject = null;
// TODO Case of Learning mode
// if (htmlConnector.isLearning()) {
// // parent transaction is the learning transaction
// parentObject = (HtmlTransaction)htmlConnector.getLearningTransaction();
// }
// Set parent statement to current selected StatementWithExpressions in properties view
Object object = projectExplorerView.getFirstSelectedDatabaseObject();
if (object != null && object instanceof StatementWithExpressions) {
parentObject = (StatementWithExpressions) object;
if (!parentObject.getProject().equals(htmlConnector.getProject())) {
parentObject = null;
}
}
return parentObject;
}
use of com.twinsoft.convertigo.beans.core.StatementWithExpressions in project convertigo by convertigo.
the class HtmlXpathEvaluatorComposite method makeStatementGeneratorsMenuMaker.
public MenuMaker makeStatementGeneratorsMenuMaker(final boolean overwrite) {
return new MenuMaker() {
public void makeMenu(final TwsDomTree tree, TreeItem treeItem, MouseEvent e, Menu menu) {
if (e.button == 3 && treeItem != null) {
Object object = treeItem.getData();
final TreeItem ti = treeItem;
if (object instanceof Node) {
final Node node = (Node) object;
if (overwrite || lastEval != null) {
Element element = null;
if (node instanceof Attr) {
Attr attribut = (Attr) node;
element = attribut.getOwnerElement();
} else if (overwrite) {
MenuItem item1 = new MenuItem(menu, SWT.NONE);
item1.setText("Select attributes in order to generate statement(s) in the selected statement container.");
return;
}
if (node instanceof Element || element != null) {
if (element == null)
element = (Element) node;
if (element.getTagName().equalsIgnoreCase("A") || element.getTagName().equalsIgnoreCase("INPUT") || element.getTagName().equalsIgnoreCase("TEXTAREA") || element.getTagName().equalsIgnoreCase("SELECT") || element.getTagName().equalsIgnoreCase("FORM")) {
Object selected = htmlDesign.getProjectExplorerView().getFirstSelectedDatabaseObject();
if (selected instanceof StatementWithExpressions) {
final StatementWithExpressions block = (StatementWithExpressions) selected;
boolean clickable = false, valuable = false, checkable = false, selectable = false, radioable = false, formable = false;
if (element.getTagName().equalsIgnoreCase("A")) {
clickable = true;
} else if (element.getTagName().equalsIgnoreCase("INPUT")) {
String type = element.getAttribute("type");
// warning, must be sort
clickable = Arrays.binarySearch(new String[] { "button", "checkbox", "radio", "submit" }, type) > -1;
// warning, must be sort
valuable = Arrays.binarySearch(new String[] { "", "password", "text" }, type) > -1;
// warning, must be sort
checkable = Arrays.binarySearch(new String[] { "checkbox", "radio" }, type) > -1;
radioable = type.equals("radio");
} else if (element.getTagName().equalsIgnoreCase("TEXTAREA")) {
valuable = true;
} else if (element.getTagName().equalsIgnoreCase("SELECT")) {
selectable = true;
} else if (element.getTagName().equalsIgnoreCase("FORM")) {
formable = true;
}
final String[] etats = new String[] { clickable ? "Generate mouse statement on this " + element.getTagName() : null, valuable ? "Generate set value statement on this " + element.getTagName() : null, checkable ? "Generate set checked statement on this " + element.getTagName() : null, selectable ? "Generate set selected statement on this " + element.getTagName() : null, radioable ? "Generate set checked statement for this radio group" : null, formable ? "Generate statements from FORM" : null };
for (int i = 0; i < etats.length; i++) {
if (etats[i] != null) {
final Integer index = Integer.valueOf(i);
MenuItem item2 = new MenuItem(menu, SWT.NONE);
item2.setText(etats[i]);
item2.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
TreeItem[] sel = ti.getParent().getSelection();
String xpath = overwrite ? generateSelectionXpath(sel) : lastEval;
int id = index.intValue();
try {
switch(id) {
/*clickable*/
case 0:
((XulWebViewerImpl) htmlDesign.getWebViewer()).generateMouseStatement(block, xpath);
break;
/*valuable */
case 1:
((XulWebViewerImpl) htmlDesign.getWebViewer()).generateSetInputStatement(block, xpath);
break;
/*checkable*/
case 2:
((XulWebViewerImpl) htmlDesign.getWebViewer()).generateSetCheckableStatement(block, xpath, false);
break;
/*selectable*/
case 3:
((XulWebViewerImpl) htmlDesign.getWebViewer()).generateSetSelectStatement(block, xpath);
break;
/*radioable*/
case 4:
((XulWebViewerImpl) htmlDesign.getWebViewer()).generateSetCheckableStatement(block, xpath, true);
break;
/*formable*/
case 5:
((XulWebViewerImpl) htmlDesign.getWebViewer()).generateFormElements(block, xpath);
break;
}
} catch (EngineException e1) {
ConvertigoPlugin.logException(e1, "Error when generate statement for this xPath : " + xpath);
ConvertigoPlugin.warningMessageBox("Error when generate statement for this xPath : " + xpath);
} catch (Exception e1) {
ConvertigoPlugin.logException(e1, "Error when generate statement for this xPath : " + xpath);
}
try {
htmlDesign.getProjectExplorerView().reloadDatabaseObject(block.getParentTransaction());
} catch (EngineException e1) {
ConvertigoPlugin.logException(e1, "Error when reload explorer view tree");
} catch (IOException e1) {
ConvertigoPlugin.logException(e1, "Error when reload explorer view tree");
}
}
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
});
}
}
} else {
MenuItem item1 = new MenuItem(menu, SWT.NONE);
item1.setText("Select a handler in project explorer to be able to generate statements automatically.");
}
} else {
MenuItem item1 = new MenuItem(menu, SWT.NONE);
item1.setText("Select a 'A', 'INPUT', 'TEXTAREA', 'SELECT' or 'FORM' element to be able to generate statements automatically.");
}
}
}
}
}
}
};
}
use of com.twinsoft.convertigo.beans.core.StatementWithExpressions 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.StatementWithExpressions 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();
}
}
use of com.twinsoft.convertigo.beans.core.StatementWithExpressions in project convertigo by convertigo.
the class ChangeToIfStatementAction 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 IfThenElseStatement)) {
IfThenElseStatement ifThenElseStatement = (IfThenElseStatement) databaseObject;
if (ifThenElseStatement.hasThenElseStatements()) {
ThenStatement thenStatement = ifThenElseStatement.getThenStatement();
List<Statement> list = thenStatement.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 If statement
IfStatement ifStatement = new IfStatement(ifThenElseStatement.getCondition());
ifStatement.bNew = true;
ifStatement.hasChanged = true;
// Add new If statement to parent
DatabaseObject parentDbo = ifThenElseStatement.getParent();
parentDbo.add(ifStatement);
// Set correct order
if (parentDbo instanceof StatementWithExpressions) {
int index = ((StatementWithExpressions) parentDbo).getOrderedStatements().get(0).indexOf(ifThenElseStatement.priority);
((StatementWithExpressions) parentDbo).getOrderedStatements().get(0).add(index, ifStatement.priority);
}
// Add new If statement in Tree
StatementTreeObject statementTreeObject = new StatementTreeObject(explorerView.viewer, ifStatement);
treeParent.addChild(statementTreeObject);
// Cut/Paste steps under If 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], statementTreeObject);
}
ConvertigoPlugin.clipboardManagerDND.reset();
}
// Delete IfThenElse statement
ifThenElseStatement.delete();
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifStatement));
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change statement to If statement!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations