use of com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView 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.eclipse.views.projectexplorer.ProjectExplorerView in project convertigo by convertigo.
the class ChangeToElementStepAction 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();
// Attribute
if ((databaseObject != null) && (databaseObject instanceof AttributeStep)) {
AttributeStep attributeStep = (AttributeStep) databaseObject;
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// New Element step
ElementStep jelementStep = new ElementStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(attributeStep.getParent(), jelementStep)) {
// Set properties
jelementStep.setOutput(attributeStep.isOutput());
jelementStep.setEnabled(attributeStep.isEnabled());
jelementStep.setComment(attributeStep.getComment());
jelementStep.setExpression(attributeStep.getExpression());
jelementStep.setNodeText(attributeStep.getNodeText());
jelementStep.setNodeName(attributeStep.getNodeName());
jelementStep.bNew = true;
jelementStep.hasChanged = true;
// Add new Element step to parent
DatabaseObject parentDbo = attributeStep.getParent();
parentDbo.add(jelementStep);
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(jelementStep, attributeStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(jelementStep, attributeStep.priority);
// Add new Element step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, attributeStep);
treeParent.addChild(stepTreeObject);
// Delete Attribute step
long oldPriority = attributeStep.priority;
attributeStep.delete();
jelementStep.getSequence().fireStepMoved(new StepEvent(jelementStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(jelementStep));
} else {
throw new EngineException("You cannot paste to a " + attributeStep.getParent().getClass().getSimpleName() + " a database object of type " + jelementStep.getClass().getSimpleName());
}
}
}
// XML Element
if ((databaseObject != null) && (databaseObject instanceof XMLElementStep)) {
XMLElementStep elementStep = (XMLElementStep) databaseObject;
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// New Element step
ElementStep jelementStep = new ElementStep();
if (DatabaseObjectsManager.acceptDatabaseObjects(elementStep.getParent(), jelementStep)) {
// Set properties
jelementStep.setOutput(elementStep.isOutput());
jelementStep.setEnabled(elementStep.isEnabled());
jelementStep.setComment(elementStep.getComment());
// jelementStep.setSourceDefinition(elementStep.getSourceDefinition());
jelementStep.setNodeText(elementStep.getNodeText());
jelementStep.setNodeName(elementStep.getNodeName());
jelementStep.bNew = true;
jelementStep.hasChanged = true;
// Add new XMLElement step to parent
DatabaseObject parentDbo = elementStep.getParent();
parentDbo.add(jelementStep);
for (Step step : elementStep.getAllSteps()) {
try {
jelementStep.addStep(step);
} catch (Throwable t) {
}
}
// Set correct order
if (parentDbo instanceof StepWithExpressions)
((StepWithExpressions) parentDbo).insertAtOrder(jelementStep, elementStep.priority);
else if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(jelementStep, elementStep.priority);
// Add new Element step in Tree
StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, elementStep);
treeParent.addChild(stepTreeObject);
// Delete XMLAttribute step
long oldPriority = elementStep.priority;
elementStep.delete();
jelementStep.getSequence().fireStepMoved(new StepEvent(jelementStep, String.valueOf(oldPriority)));
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(jelementStep));
} else {
throw new EngineException("You cannot paste to a " + elementStep.getParent().getClass().getSimpleName() + " a database object of type " + jelementStep.getClass().getSimpleName());
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change step to Element step!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView in project convertigo by convertigo.
the class ChangeToFormParameterAction 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();
Object databaseObject = treeObject.getObject();
if ((databaseObject != null) && (databaseObject instanceof UrlMappingParameter)) {
UrlMappingParameter parameter = (UrlMappingParameter) databaseObject;
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// Create new Form parameter
FormParameter formParameter = new FormParameter();
if (DatabaseObjectsManager.acceptDatabaseObjects(parameter.getParent(), formParameter)) {
formParameter.setComment(parameter.getComment());
formParameter.setInputType(parameter.getInputType());
formParameter.setArray(parameter.isArray());
formParameter.setExposed(parameter.isExposed());
formParameter.setMultiValued(parameter.isMultiValued());
formParameter.setRequired(parameter.isRequired());
formParameter.setValueOrNull(parameter.getValueOrNull());
formParameter.setMappedVariableName(parameter.getMappedVariableName());
formParameter.bNew = true;
formParameter.hasChanged = true;
// Add new parameter to parent operation
UrlMappingOperation operation = (UrlMappingOperation) parameter.getParent();
operation.changeTo(formParameter);
// Add new parameter in Tree
UrlMappingParameterTreeObject parameterTreeObject = new UrlMappingParameterTreeObject(explorerView.viewer, formParameter);
treeParent.addChild(parameterTreeObject);
// Delete old parameter
parameter.delete();
// Rename new parameter
formParameter.setName(parameter.getName());
// Reload in tree
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(formParameter));
} else {
throw new EngineException("You cannot paste to a " + parameter.getParent().getClass().getSimpleName() + " a database object of type " + formParameter.getClass().getSimpleName());
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change parameter to Form parameter!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView in project convertigo by convertigo.
the class TreeDropAdapter method performDrop.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
*/
@Override
public boolean performDrop(Object data) {
MobileBuilder mb = null;
Engine.logStudio.info("---------------------- Drop started ----------------------");
try {
Object targetObject = getCurrentTarget();
IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
if (editorPart != null) {
IEditorInput input = editorPart.getEditorInput();
if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mb = editorInput.getApplication().getProject().getMobileBuilder();
}
if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mb = editorInput.getApplication().getProject().getMobileBuilder();
}
}
// Handle objects copy or move with Drag and drop
if (targetObject instanceof TreeObject) {
TreeObject targetTreeObject = (TreeObject) targetObject;
if (targetTreeObject != null) {
ProjectExplorerView explorerView = targetTreeObject.getProjectExplorerView();
Document document = null;
try {
Shell shell = Display.getDefault().getActiveShell();
try {
// Try to parse text data into an XML document
String source = data.toString();
document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(source)));
if (mb != null) {
mb.prepareBatchBuild();
}
BatchOperationHelper.start();
boolean insertBefore = (feedback & DND.FEEDBACK_INSERT_BEFORE) != 0;
boolean insertAfter = (feedback & DND.FEEDBACK_INSERT_AFTER) != 0;
TreeObject sourceObject = (TreeObject) getSelectedObject();
if (insertBefore || insertAfter) {
TreeParent targetTreeParent = ((TreeObject) targetObject).getParent();
if (sourceObject.getParent() != targetTreeParent) {
ProjectTreeObject prjTree = targetTreeParent.getProjectTreeObject();
String path = targetTreeParent.getPath();
ClipboardAction.dnd.paste(source, shell, explorerView, targetTreeParent, true);
targetTreeParent = (TreeParent) explorerView.findTreeObjectByPath(prjTree, path);
}
explorerView.moveChildTo(targetTreeParent, sourceObject, targetTreeObject, insertBefore);
} else {
ClipboardAction.dnd.paste(source, shell, explorerView, targetTreeObject, true);
}
BatchOperationHelper.stop();
return true;
} catch (SAXException sax) {
BatchOperationHelper.cancel();
if (mb != null) {
mb.prepareBatchBuild();
}
BatchOperationHelper.start();
// Parse failed probably because data was not XML but an XPATH String
// in this case, create DatabaseObjects of the correct Type according to the folder where the XPATH is dropped on
performDrop(data, explorerView, targetTreeObject);
BatchOperationHelper.stop();
return true;
}
} catch (Exception e) {
BatchOperationHelper.cancel();
if (e instanceof ObjectWithSameNameException) {
document = null;
}
if (e instanceof InvalidOperationException) {
document = null;
}
// Case of unauthorized databaseObject paste
if (document != null) {
try {
if (!(targetTreeObject instanceof IPropertyTreeObject)) {
Element rootElement = document.getDocumentElement();
NodeList nodeList = rootElement.getChildNodes();
boolean unauthorized = false;
int len = nodeList.getLength();
Node node;
// case of folder, retrieve owner object
targetTreeObject = explorerView.getFirstSelectedDatabaseObjectTreeObject(targetTreeObject);
if (detail == DND.DROP_COPY) {
for (int i = 0; i < len; i++) {
node = (Node) nodeList.item(i);
if (node.getNodeType() != Node.TEXT_NODE) {
// Special objects paste
if (!paste(node, targetTreeObject)) {
// Real unauthorized databaseObject paste
unauthorized = true;
}
}
}
reloadTreeObject(explorerView, targetTreeObject);
} else if (detail == DND.DROP_MOVE) {
for (int i = 0; i < len; i++) {
node = (Node) nodeList.item(i);
if (node.getNodeType() != Node.TEXT_NODE) {
// Special objects move
if (!move(node, targetTreeObject)) {
// Real unauthorized databaseObject move
unauthorized = true;
}
}
}
reloadTreeObject(explorerView, targetTreeObject);
} else {
// Real unauthorized databaseObject
unauthorized = true;
}
if (unauthorized) {
throw e;
}
return true;
}
} catch (Exception ex) {
ConvertigoPlugin.errorMessageBox(ex.getMessage());
return false;
}
} else {
ConvertigoPlugin.errorMessageBox(e.getMessage());
return false;
}
}
}
}
return false;
} finally {
Engine.logStudio.info("---------------------- Drop ended ----------------------");
BatchOperationHelper.cancel();
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView in project convertigo by convertigo.
the class JavelinConnectorComposite method add.
/**
* Adds an element to the selected property with the selected zone from the
* connector
*/
public void add() {
try {
if (connector != null) {
// gets the projectExplorerView
ProjectExplorerView pev = ConvertigoPlugin.getDefault().getProjectExplorerView();
if (pev != null) {
// gets the databaseObject of the selected element in
// project tree
DatabaseObject databaseObject = (DatabaseObject) pev.getFirstSelectedDatabaseObject();
// gets the BeanInfo
BeanInfo bi = pev.getFirstSelectedDatabaseObjectBeanInfo();
// gets the propertyDescriptor of the selected property in
// the Properties panel
PropertyDescriptor propertyDescriptor = ConvertigoPlugin.getDefault().getSelectedPropertyDescriptor(bi);
if (propertyDescriptor != null) {
// test if the selected property is addable with a
// screen selection zone (we can add an element to the
// property from the selected zone)
Class<?> editorClass = propertyDescriptor.getPropertyEditorClass();
if (editorClass != null) {
Method propertySelectionAddMethod = editorClass.getMethod("addPropertyElementFromSelectionZone", new Class[] { DatabaseObject.class, Connector.class, Method.class });
if (propertySelectionAddMethod != null) {
propertySelectionAddMethod.invoke(null, new Object[] { databaseObject, connector, propertyDescriptor.getWriteMethod() });
} else {
// the selected property is not addable with a
// screen selection zone
}
databaseObject.hasChanged = true;
pev.updateDatabaseObject(databaseObject);
StructuredSelection structuredSelection = new StructuredSelection(((DatabaseObjectTreeObject) pev.getFirstSelectedTreeObject()));
PropertySheet pv = ConvertigoPlugin.getDefault().getPropertiesView();
boolean isPinned = pv.isPinned();
if (!isPinned) {
pv.setPinned(true);
}
pv.selectionChanged((IWorkbenchPart) pev, structuredSelection);
if (!isPinned) {
pv.setPinned(false);
}
}
} else {
// no PropertyDescriptor corresponding to the selected
// property
}
} else {
// pev null
}
} else {
// connector null
}
} catch (NoSuchMethodException e) {
// the selected property is not addable with a screen selection zone
ConvertigoPlugin.logInfo("Not possible to add an element from a selection zone to the selected Property.");
} catch (Throwable e) {
String message = "Error : " + e.getMessage();
ConvertigoPlugin.logException(e, message);
}
}
Aggregations