Search in sources :

Example 1 with ProjectInMigrationProcessException

use of com.twinsoft.convertigo.engine.ProjectInMigrationProcessException in project convertigo by convertigo.

the class ProjectLoadingJob method run.

protected IStatus run(IProgressMonitor monitor) {
    this.monitor = monitor;
    synchronized (unloadedProjectTreeObject) {
        if (unloadedProjectTreeObject.getParent() == null) {
            Display.getDefault().asyncExec(() -> viewer.refresh());
            return Status.OK_STATUS;
        }
        try {
            int worksNumber = 2 * ConvertigoPlugin.projectManager.getNumberOfObjects(projectName);
            monitor.beginTask("Opening project " + projectName + "...", worksNumber);
            if (monitor.isCanceled()) {
                Status status = new Status(Status.CANCEL, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Project " + projectName + " not loaded because of user abort", null);
                return status;
            }
            Project project;
            try {
                monitor.subTask("Importing the project...");
                Engine.theApp.databaseObjectsManager.clearCacheIfSymbolError(projectName);
                project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
                if (project == null) {
                    unloadedProjectTreeObject.getParent().removeChild(unloadedProjectTreeObject);
                    Status status = new Status(Status.CANCEL, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Project " + projectName + " doesn't exists", null);
                    return status;
                }
                monitor.subTask("Refreshing project ressources...");
                String projectDir = Engine.projectDir(projectName);
                ConvertigoPlugin.projectManager.getProjectExplorerView().createDir(projectName);
                ConvertigoPlugin.getDefault().createProjectPluginResource(projectName, projectDir, monitor);
                Engine.theApp.databaseObjectsManager.addDatabaseObjectListener(this);
                if (project.undefinedGlobalSymbols) {
                    synchronized (Engine.theApp.databaseObjectsManager) {
                        // parallel projects opening with undefined symbols, check after the first wizard
                        project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
                        if (project.undefinedGlobalSymbols) {
                            final boolean[] created = { false };
                            new WalkHelper() {

                                boolean create = false;

                                boolean forAll = false;

                                @Override
                                protected void walk(DatabaseObject databaseObject) throws Exception {
                                    if (databaseObject.isSymbolError()) {
                                        for (Entry<String, Set<String>> entry : databaseObject.getSymbolsErrors().entrySet()) {
                                            Set<String> undefinedSymbols = Engine.theApp.databaseObjectsManager.symbolsSetCheckUndefined(entry.getValue());
                                            if (!undefinedSymbols.isEmpty()) {
                                                if (!forAll) {
                                                    boolean[] response = ConvertigoPlugin.warningGlobalSymbols(projectName, databaseObject.getName(), databaseObject.getDatabaseType(), entry.getKey(), "" + databaseObject.getCompilablePropertySourceValue(entry.getKey()), undefinedSymbols, true);
                                                    create = response[0];
                                                    forAll = response[1];
                                                    created[0] |= create;
                                                }
                                                if (create) {
                                                    Engine.theApp.databaseObjectsManager.symbolsCreateUndefined(undefinedSymbols);
                                                }
                                            }
                                        }
                                    }
                                    super.walk(databaseObject);
                                }
                            }.init(project);
                            if (created[0]) {
                                project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
                            }
                        }
                    }
                }
            } finally {
                Engine.theApp.databaseObjectsManager.removeDatabaseObjectListener(this);
            }
            if (monitor.isCanceled()) {
                Status status = new Status(Status.CANCEL, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Project " + projectName + " not loaded because of user abort", null);
                return status;
            }
            monitor.subTask("Creating connectors...");
            monitor.subTask("Updating tree view...");
            TreeParent invisibleRoot = unloadedProjectTreeObject.getParent();
            projectTreeObject = new ProjectTreeObject(viewer, project);
            defaultConnectorTreeObject = null;
            demoTraceTreeObject = null;
            invisibleRoot.removeChild(unloadedProjectTreeObject);
            invisibleRoot.addChild(projectTreeObject);
            ConvertigoPlugin.projectManager.setCurrentProject((ProjectTreeObject) projectTreeObject);
            ConvertigoPlugin.getDefault().getProjectPluginResource(projectName, monitor).refreshLocal(IResource.DEPTH_INFINITE, monitor);
            loadDatabaseObject(projectTreeObject, project);
            // Comment out the following line to disable the resources tree part
            // loadResource(projectTreeObject, "Resources", resourceProject.members());
            Status status = new Status(Status.OK, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Project " + projectName + " loaded", null);
            return status;
        } catch (Exception e) {
            Status status = null;
            unloadedProjectTreeObject.isLoadable = false;
            if (e.getCause() instanceof ProjectInMigrationProcessException)
                status = new Status(Status.WARNING, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Could not open project \"" + projectName + "\" while it was still in migration check process", e);
            else
                status = new Status(Status.ERROR, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Error while loading project " + projectName, e);
            return status;
        } finally {
            // Updating the tree viewer
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    if (projectTreeObject != null) {
                        viewer.refresh();
                        ISelection selection = new StructuredSelection(projectTreeObject);
                        viewer.setSelection(selection, true);
                        if (defaultConnectorTreeObject != null && ConvertigoPlugin.getAutoOpenDefaultConnector())
                            defaultConnectorTreeObject.launchEditor();
                        TreeObjectEvent treeObjectEvent = null;
                        if (isCopy)
                            treeObjectEvent = new TreeObjectEvent(projectTreeObject, "name", originalName, projectName, 0);
                        else
                            treeObjectEvent = new TreeObjectEvent(projectTreeObject);
                        ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectAdded(treeObjectEvent);
                        viewer.getControl().getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                if (demoTraceTreeObject != null)
                                    demoTraceTreeObject.play(false);
                                Engine.execute(() -> {
                                    Project.executeAutoStartSequences(projectName);
                                });
                            }
                        });
                    }
                }
            });
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Set(java.util.Set) ProjectInMigrationProcessException(com.twinsoft.convertigo.engine.ProjectInMigrationProcessException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) CoreException(org.eclipse.core.runtime.CoreException) ProjectInMigrationProcessException(com.twinsoft.convertigo.engine.ProjectInMigrationProcessException) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException) Project(com.twinsoft.convertigo.beans.core.Project) Entry(java.util.Map.Entry) ISelection(org.eclipse.jface.viewers.ISelection) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 Project (com.twinsoft.convertigo.beans.core.Project)1 ProjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject)1 UnloadedProjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 ProjectInMigrationProcessException (com.twinsoft.convertigo.engine.ProjectInMigrationProcessException)1 WalkHelper (com.twinsoft.convertigo.engine.helpers.WalkHelper)1 IOException (java.io.IOException)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ISelection (org.eclipse.jface.viewers.ISelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1