use of com.twinsoft.convertigo.beans.core.DatabaseObject 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 {
getProjectExplorerView().updateTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not update in tree Transaction \"" + databaseObject.getName() + "\" !");
}
}
}
}
}
}
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class TransactionTreeObject method treeObjectPropertyChanged.
@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
super.treeObjectPropertyChanged(treeObjectEvent);
String propertyName = (String) treeObjectEvent.propertyName;
propertyName = ((propertyName == null) ? "" : propertyName);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
// If a bean name has changed
if ("name".equals(propertyName)) {
handlesBeanNameChanged(treeObjectEvent);
} else if ("sqlQuery".equals(propertyName)) {
if (treeObject.equals(this)) {
try {
SqlTransaction sqlTransaction = (SqlTransaction) databaseObject;
sqlTransaction.initializeQueries(true);
String oldValue = (String) treeObjectEvent.oldValue;
detectVariables(sqlTransaction.getSqlQuery(), oldValue, sqlTransaction.getVariablesList());
getProjectExplorerView().reloadTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
}
}
} else if ("subDir".equals(propertyName)) {
if (treeObject.equals(this)) {
try {
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) databaseObject;
List<String> oldPathVariableList = AbstractHttpTransaction.getPathVariableList(oldValue.toString());
List<String> newPathVariableList = AbstractHttpTransaction.getPathVariableList(newValue.toString());
// Check for variables to be renamed
if (oldValue.toString().replaceAll("\\{([a-zA-Z0-9_]+)\\}", "{}").equals(newValue.toString().replaceAll("\\{([a-zA-Z0-9_]+)\\}", "{}"))) {
for (int i = 0; i < oldPathVariableList.size(); i++) {
String oldVariableName = oldPathVariableList.get(i);
String newVariableName = newPathVariableList.get(i);
if (!oldVariableName.equals(newVariableName)) {
RequestableHttpVariable httpVariable = (RequestableHttpVariable) httpTransaction.getVariable(oldVariableName);
if (httpVariable != null) {
try {
VariableTreeObject2 vto = (VariableTreeObject2) findTreeObjectByUserObject(httpVariable);
int update = TreeObjectEvent.UPDATE_NONE;
CustomDialog customDialog = new CustomDialog(viewer.getControl().getShell(), "Update object references", "Do you want to update " + "variable" + " references ?\n You can replace '" + oldVariableName + "' by '" + newVariableName + "' in all loaded projects \n or replace '" + oldVariableName + "' by '" + newVariableName + "' in current project only.", 670, 200, new ButtonSpec("Replace in all loaded projects", true), new ButtonSpec("Replace in current project", false), new ButtonSpec("Do not replace anywhere", false));
int response = customDialog.open();
if (response == 0) {
update = TreeObjectEvent.UPDATE_ALL;
}
if (response == 1) {
update = TreeObjectEvent.UPDATE_LOCAL;
}
if (update != 0) {
httpVariable.setName(newVariableName);
httpVariable.hasChanged = true;
TreeObjectEvent toEvent = new TreeObjectEvent(vto, "name", oldVariableName, newVariableName, update);
getProjectExplorerView().fireTreeObjectPropertyChanged(toEvent);
}
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not rename variable for Transaction \"" + databaseObject.getName() + "\" !");
}
}
}
}
} else {
// Check for variables to be added
for (String variableName : newPathVariableList) {
if (httpTransaction.getVariable(variableName) == null) {
RequestableHttpVariable httpVariable = new RequestableHttpVariable();
httpVariable.setName(variableName);
httpVariable.setHttpMethod("GET");
httpVariable.setHttpName("");
httpVariable.bNew = true;
httpVariable.hasChanged = true;
httpTransaction.addVariable(httpVariable);
httpTransaction.hasChanged = true;
}
}
// Check for variables to be deleted
for (String variableName : oldPathVariableList) {
RequestableHttpVariable httpVariable = (RequestableHttpVariable) httpTransaction.getVariable(variableName);
if (httpVariable != null) {
if (!newPathVariableList.contains(variableName)) {
try {
MessageBox messageBox = new MessageBox(viewer.getControl().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setMessage("Do you want to delete the variable \"" + variableName + "\"?");
messageBox.setText("Delete \"" + variableName + "\"?");
if (messageBox.open() == SWT.YES) {
httpVariable.delete();
httpTransaction.hasChanged = true;
}
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Error when deleting the variable \"" + variableName + "\"");
}
}
}
}
}
if (httpTransaction.hasChanged) {
getProjectExplorerView().reloadTreeObject(this);
}
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
}
}
}
}
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class MobileApplicationComponentTreeObject method treeObjectAdded.
@Override
public void treeObjectAdded(TreeObjectEvent treeObjectEvent) {
super.treeObjectAdded(treeObjectEvent);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
String propertyName = (String) treeObjectEvent.propertyName;
propertyName = ((propertyName == null) ? "" : propertyName);
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
DatabaseObject dbo = doto.getObject();
try {
// we add a page to this app
if (dbo instanceof PageComponent && getObject().equals(dbo.getParent())) {
PageComponent page = (PageComponent) dbo;
if (page.bNew) {
page.markPageAsDirty();
}
}
} catch (Exception e) {
}
}
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class MobileApplicationComponentTreeObject method treeObjectPropertyChanged.
@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
super.treeObjectPropertyChanged(treeObjectEvent);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
Set<Object> done = checkDone(treeObjectEvent);
String propertyName = (String) treeObjectEvent.propertyName;
propertyName = ((propertyName == null) ? "" : propertyName);
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
DatabaseObject dbo = doto.getObject();
try {
ApplicationComponent ac = getObject();
// for Page or Menu or Route
if (ac.equals(dbo.getParent())) {
markApplicationAsDirty(done);
} else // for any component inside a route
if (ac.equals(dbo.getParent().getParent())) {
markApplicationAsDirty(done);
} else // for any UI component inside a menu or a stack
if (dbo instanceof UIComponent) {
UIComponent uic = (UIComponent) dbo;
UIDynamicMenu menu = uic.getMenu();
if (menu != null) {
if (ac.equals(menu.getParent())) {
if (propertyName.equals("FormControlName") || uic.isFormControlAttribute()) {
if (!newValue.equals(oldValue)) {
try {
String oldSmart = ((MobileSmartSourceType) oldValue).getSmartValue();
String newSmart = ((MobileSmartSourceType) newValue).getSmartValue();
if (uic.getUIForm() != null) {
String form = uic.getUIForm().getFormGroupName();
if (menu.updateSmartSource(form + "\\?\\.controls\\['" + oldSmart + "'\\]", form + "?.controls['" + newSmart + "']")) {
this.viewer.refresh();
}
}
} catch (Exception e) {
}
}
}
markApplicationAsDirty(done);
}
}
} else // for this application
if (this.equals(doto)) {
if (propertyName.equals("isPWA")) {
if (!newValue.equals(oldValue)) {
markPwaAsDirty();
}
} else if (propertyName.equals("componentScriptContent")) {
if (!newValue.equals(oldValue)) {
markComponentTsAsDirty();
markApplicationAsDirty(done);
}
} else if (propertyName.equals("useClickForTap")) {
for (TreeObject to : this.getChildren()) {
if (to instanceof ObjectsFolderTreeObject) {
ObjectsFolderTreeObject ofto = (ObjectsFolderTreeObject) to;
if (ofto.folderType == ObjectsFolderTreeObject.FOLDER_TYPE_PAGES) {
for (TreeObject cto : ofto.getChildren()) {
if (cto instanceof MobilePageComponentTreeObject) {
((MobilePageComponentTreeObject) cto).markPageAsDirty(done);
}
}
}
}
}
markApplicationAsDirty(done);
} else if (propertyName.equals("tplProjectName")) {
// close app editor and reinitialize builder
Project project = ac.getProject();
closeAllEditors(false);
MobileBuilder.releaseBuilder(project);
MobileBuilder.initBuilder(project);
IProject iproject = ConvertigoPlugin.getDefault().getProjectPluginResource(project.getName());
iproject.refreshLocal(IResource.DEPTH_INFINITE, null);
// force app sources regeneration
for (TreeObject to : this.getChildren()) {
if (to instanceof ObjectsFolderTreeObject) {
ObjectsFolderTreeObject ofto = (ObjectsFolderTreeObject) to;
if (ofto.folderType == ObjectsFolderTreeObject.FOLDER_TYPE_PAGES) {
for (TreeObject cto : ofto.getChildren()) {
if (cto instanceof MobilePageComponentTreeObject) {
((MobilePageComponentTreeObject) cto).markPageAsDirty(done);
}
}
}
}
}
markApplicationAsDirty(done);
// delete node modules and alert user
final File nodeModules = new File(project.getDirPath(), "/_private/ionic/node_modules");
if (nodeModules.exists()) {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(ConvertigoPlugin.getMainShell());
dialog.open();
dialog.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("deleting node modules", IProgressMonitor.UNKNOWN);
String alert = "template changed!";
if (com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(nodeModules)) {
alert = "You have just changed the template.\nPackages have been deleted and will be reinstalled next time you run your application again.";
} else {
alert = "You have just changed the template: packages could not be deleted!\nDo not forget to reinstall the packages before running your application again, otherwise it may be corrupted!";
}
monitor.done();
ConvertigoPlugin.infoMessageBox(alert);
}
});
}
} else {
markApplicationAsDirty(done);
}
}
} catch (Exception e) {
}
}
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class MobileApplicationTreeObject method treeObjectPropertyChanged.
@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
super.treeObjectPropertyChanged(treeObjectEvent);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
String propertyName = (String) treeObjectEvent.propertyName;
propertyName = ((propertyName == null) ? "" : propertyName);
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
DatabaseObject dbo = doto.getObject();
try {
if (this.equals(doto)) {
if (propertyName.equals("applicationName")) {
if (!newValue.equals(oldValue)) {
ApplicationComponent app = (ApplicationComponent) ((MobileApplication) dbo).getApplicationComponent();
app.markPwaAsDirty();
}
}
}
} catch (Exception e) {
}
}
}
Aggregations