use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ImportWizard method performFinish.
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
public boolean performFinish() {
ProjectExplorerView explorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
ProjectUrlParser parser = fileChooserPage.getParser();
String filePath = fileChooserPage.getFilePath();
if (parser.isValid()) {
ConvertigoPlugin.infoMessageBox("Loading " + parser.getProjectName() + " in a background job.");
Job.create("Import project " + parser.getProjectName(), (mon) -> {
try {
Project project = Engine.theApp.referencedProjectManager.importProject(parser, true);
if (project != null) {
TreeObject tree = explorerView.getProjectRootObject(project.getName());
if (tree != null) {
explorerView.reloadProject(tree);
}
explorerView.refreshProjects();
}
} catch (Exception e) {
Engine.logStudio.debug("Loading from remote URL failed", e);
}
}).schedule();
}
try {
if (explorerView != null) {
if (filePath != null) {
explorerView.importProject(filePath, getTargetProjectName());
}
}
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to import project !");
}
return true;
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class Set method getServiceResult.
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
Element root = document.getDocumentElement();
String[] qnames = request.getParameterValues("qnames[]");
// Remove duplicates if someone sends the qname more than once
java.util.Set<String> uniqueQnames = new HashSet<>(Arrays.asList(qnames));
for (String objectQName : uniqueQnames) {
// Create the response : success or fail
Element response = document.createElement("response");
response.setAttribute("qname", objectQName);
try {
String value = request.getParameter("value");
String property = request.getParameter("property");
DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(objectQName);
// Check if we try to update project name
if (dbo instanceof Project && "name".equals(property)) {
Project project = (Project) dbo;
String objectNewName = getPropertyValue(dbo, property, value).toString();
Engine.theApp.databaseObjectsManager.renameProject(project, objectNewName);
}
BeanInfo bi = CachedIntrospector.getBeanInfo(dbo.getClass());
PropertyDescriptor[] propertyDescriptors = bi.getPropertyDescriptors();
boolean propertyFound = false;
for (int i = 0; !propertyFound && i < propertyDescriptors.length; ++i) {
String propertyName = propertyDescriptors[i].getName();
initialPropertyElt = dbo.toXml(document, propertyName);
// Find the property we want to change
if (propertyFound = propertyName.equals(property)) {
Method setter = propertyDescriptors[i].getWriteMethod();
Class<?> propertyTypeClass = propertyDescriptors[i].getReadMethod().getReturnType();
if (propertyTypeClass.isPrimitive()) {
propertyTypeClass = ClassUtils.primitiveToWrapper(propertyTypeClass);
}
try {
String propertyValue = getPropertyValue(dbo, propertyName, value).toString();
Object oPropertyValue = com.twinsoft.convertigo.engine.admin.services.database_objects.Set.createObject(propertyTypeClass, propertyValue);
if (dbo.isCipheredProperty(propertyName)) {
Method getter = propertyDescriptors[i].getReadMethod();
String initialPropertyValue = (String) getter.invoke(dbo, (Object[]) null);
if (oPropertyValue.equals(initialPropertyValue) || DatabaseObject.encryptPropertyValue(initialPropertyValue).equals(oPropertyValue)) {
oPropertyValue = initialPropertyValue;
} else {
dbo.hasChanged = true;
}
}
// Update property value
if (oPropertyValue != null) {
Object[] args = { oPropertyValue };
setter.invoke(dbo, args);
}
} catch (IllegalArgumentException e) {
throw e;
}
}
}
// Invalid given property parameter
if (!propertyFound) {
throw new IllegalArgumentException("Property '" + property + "' not found for object '" + dbo.getQName() + "'");
}
response.setAttribute("state", "success");
response.setAttribute("message", "Property " + property + " has been successfully updated.");
Element elt = dbo.toXml(document, property);
elt.setAttribute("name", dbo.toString());
elt.setAttribute("hasChanged", Boolean.toString(dbo.hasChanged));
response.appendChild(elt);
} catch (Exception e) {
Engine.logAdmin.error("Error during saving the properties!\n" + e.getMessage());
response.setAttribute("state", "error");
response.setAttribute("message", "Error during saving the properties!");
// To restore the original value
response.appendChild(initialPropertyElt);
} finally {
root.appendChild(response);
}
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class NgxApplicationComponentTreeObject 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 NgxPageComponentTreeObject) {
((NgxPageComponentTreeObject) 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 NgxPageComponentTreeObject) {
((NgxPageComponentTreeObject) 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.Project in project convertigo by convertigo.
the class NgxUIComponentTreeObject method refactorSmartSources.
protected void refactorSmartSources(TreeObjectEvent treeObjectEvent) {
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
String propertyName = (String) treeObjectEvent.propertyName;
propertyName = ((propertyName == null) ? "" : propertyName);
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
// Case of DatabaseObjectTreeObject
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
DatabaseObject dbo = doto.getObject();
try {
boolean sourcesUpdated = false;
// A bean name has changed
if (propertyName.equals("name")) {
boolean fromSameProject = getProjectTreeObject().equals(doto.getProjectTreeObject());
if ((treeObjectEvent.update == TreeObjectEvent.UPDATE_ALL) || ((treeObjectEvent.update == TreeObjectEvent.UPDATE_LOCAL) && fromSameProject)) {
try {
if (dbo instanceof Project) {
String oldName = (String) oldValue;
String newName = (String) newValue;
if (!newValue.equals(oldValue)) {
if (getObject().updateSmartSource("'" + oldName + "\\.", "'" + newName + ".")) {
sourcesUpdated = true;
}
if (getObject().updateSmartSource("\\/" + oldName + "\\.", "/" + newName + ".")) {
sourcesUpdated = true;
}
}
} else if (dbo instanceof Sequence) {
String oldName = (String) oldValue;
String newName = (String) newValue;
String projectName = dbo.getProject().getName();
if (!newValue.equals(oldValue)) {
if (getObject().updateSmartSource("'" + projectName + "\\." + oldName, "'" + projectName + "." + newName)) {
sourcesUpdated = true;
}
}
} else if (dbo instanceof FullSyncConnector) {
String oldName = (String) oldValue;
String newName = (String) newValue;
String projectName = dbo.getProject().getName();
if (!newValue.equals(oldValue)) {
if (getObject().updateSmartSource("\\/" + projectName + "\\." + oldName + "\\.", "/" + projectName + "." + newName + ".")) {
sourcesUpdated = true;
}
if (getObject().updateSmartSource("\\/" + oldName + "\\.", "/" + newName + ".")) {
sourcesUpdated = true;
}
}
} else if (dbo instanceof DesignDocument) {
String oldName = (String) oldValue;
String newName = (String) newValue;
if (!newValue.equals(oldValue)) {
if (getObject().updateSmartSource("ddoc='" + oldName + "'", "ddoc='" + newName + "'")) {
sourcesUpdated = true;
}
}
}
if (dbo instanceof UIComponent) {
if (!newValue.equals(oldValue)) {
try {
String oldName = (String) oldValue;
String newName = (String) newValue;
if (getObject().updateSmartSource("\\." + oldName + "\\b", "." + newName)) {
sourcesUpdated = true;
}
} catch (Exception e) {
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (dbo instanceof UIComponent) {
UIComponent uic = (UIComponent) dbo;
if (hasSameScriptComponent(getObject(), uic)) {
// A ControlName property has changed
if (propertyName.equals("ControlName") || uic.isFormControlAttribute()) {
if (!newValue.equals(oldValue)) {
try {
String oldSmart = ((MobileSmartSourceType) oldValue).getSmartValue();
String newSmart = ((MobileSmartSourceType) newValue).getSmartValue();
if (uic.getUIForm() != null) {
if (getObject().updateSmartSource("\\?\\.controls\\['" + oldSmart + "'\\]", "?.controls['" + newSmart + "']")) {
sourcesUpdated = true;
}
}
} catch (Exception e) {
}
}
} else if (propertyName.equals("identifier")) {
if (!newValue.equals(oldValue)) {
try {
String oldId = (String) oldValue;
String newId = (String) newValue;
if (uic.getUIForm() != null) {
if (getObject().updateSmartSource("\"identifier\":\"" + oldId + "\"", "\"identifier\":\"" + newId + "\"")) {
sourcesUpdated = true;
}
}
} catch (Exception e) {
}
}
}
}
}
// Need TS regeneration
if (sourcesUpdated) {
hasBeenModified(true);
viewer.refresh();
markMainAsDirty(getObject());
}
} catch (Exception e) {
e.printStackTrace();
}
} else // Case of DesignDocumentViewTreeObject
if (treeObject instanceof DesignDocumentViewTreeObject) {
DesignDocumentViewTreeObject ddvto = (DesignDocumentViewTreeObject) treeObject;
try {
boolean sourcesUpdated = false;
// View name changed
if (propertyName.equals("name")) {
boolean fromSameProject = getProjectTreeObject().equals(ddvto.getProjectTreeObject());
if ((treeObjectEvent.update == TreeObjectEvent.UPDATE_ALL) || ((treeObjectEvent.update == TreeObjectEvent.UPDATE_LOCAL) && fromSameProject)) {
try {
String oldName = (String) oldValue;
String newName = (String) newValue;
if (!newValue.equals(oldValue)) {
if (getObject().updateSmartSource("view='" + oldName + "'", "view='" + newName + "'")) {
sourcesUpdated = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
// Need TS regeneration
if (sourcesUpdated) {
hasBeenModified(true);
viewer.refresh();
markMainAsDirty(getObject());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ProjectTreeObject method rename_.
@Override
protected void rename_(String newName, boolean bDialog) throws ConvertigoException, CoreException {
Project project = getObject();
String oldName = project.getName();
// First verify if an object with the same name exists
if (Engine.theApp.databaseObjectsManager.existsProject(newName)) {
throw new ConvertigoException("The project \"" + newName + "\" already exist!");
}
// save only objects which have changed
save(bDialog);
Engine.theApp.databaseObjectsManager.renameProject(project, newName, true);
// delete old resources plugin
ConvertigoPlugin.getDefault().deleteProjectPluginResource(oldName);
// create new resources plugin
ConvertigoPlugin.getDefault().createProjectPluginResource(newName, project.getDirPath());
}
Aggregations