Search in sources :

Example 21 with Project

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;
}
Also used : IWizardPage(org.eclipse.jface.wizard.IWizardPage) Job(org.eclipse.core.runtime.jobs.Job) Engine(com.twinsoft.convertigo.engine.Engine) DatabaseObjectsManager(com.twinsoft.convertigo.engine.DatabaseObjectsManager) IOException(java.io.IOException) Wizard(org.eclipse.jface.wizard.Wizard) ProjectUrlParser(com.twinsoft.convertigo.engine.util.ProjectUrlParser) IImportWizard(org.eclipse.ui.IImportWizard) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) File(java.io.File) Project(com.twinsoft.convertigo.beans.core.Project) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ConvertigoPlugin(com.twinsoft.convertigo.eclipse.ConvertigoPlugin) ZipUtils(com.twinsoft.convertigo.engine.util.ZipUtils) IWorkbench(org.eclipse.ui.IWorkbench) EngineException(com.twinsoft.convertigo.engine.EngineException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ProjectUrlParser(com.twinsoft.convertigo.engine.util.ProjectUrlParser) Project(com.twinsoft.convertigo.beans.core.Project) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 22 with Project

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);
        }
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) Element(org.w3c.dom.Element) BeanInfo(java.beans.BeanInfo) Method(java.lang.reflect.Method) TransformerException(javax.xml.transform.TransformerException) Project(com.twinsoft.convertigo.beans.core.Project) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) HashSet(java.util.HashSet)

Example 23 with Project

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) {
        }
    }
}
Also used : ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) UIDynamicMenu(com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenu) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidParameterException(java.security.InvalidParameterException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProject(org.eclipse.core.resources.IProject) Project(com.twinsoft.convertigo.beans.core.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 24 with Project

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();
        }
    }
}
Also used : MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) Sequence(com.twinsoft.convertigo.beans.core.Sequence) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IProject(org.eclipse.core.resources.IProject) Project(com.twinsoft.convertigo.beans.core.Project) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 25 with Project

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());
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(com.twinsoft.convertigo.beans.core.Project) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException)

Aggregations

Project (com.twinsoft.convertigo.beans.core.Project)148 EngineException (com.twinsoft.convertigo.engine.EngineException)56 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)47 IOException (java.io.IOException)39 File (java.io.File)37 Sequence (com.twinsoft.convertigo.beans.core.Sequence)35 Connector (com.twinsoft.convertigo.beans.core.Connector)33 ArrayList (java.util.ArrayList)29 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)26 JSONException (org.codehaus.jettison.json.JSONException)26 Transaction (com.twinsoft.convertigo.beans.core.Transaction)24 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)22 SAXException (org.xml.sax.SAXException)21 CoreException (org.eclipse.core.runtime.CoreException)20 Step (com.twinsoft.convertigo.beans.core.Step)19 Element (org.w3c.dom.Element)19 Shell (org.eclipse.swt.widgets.Shell)18 JSONObject (org.codehaus.jettison.json.JSONObject)17 IProject (org.eclipse.core.resources.IProject)17 Cursor (org.eclipse.swt.graphics.Cursor)17