Search in sources :

Example 1 with NgxConverter

use of com.twinsoft.convertigo.engine.util.NgxConverter in project convertigo by convertigo.

the class ConvertMobileUIApplicationToNgxAction method run.

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();
            ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
            if (projectTreeObject.getModified()) {
                ConvertigoPlugin.warningMessageBox("Please save project before converting it.");
                return;
            }
            Project project = projectTreeObject.getObject();
            InputDialog dlg = new InputDialog(shell, "Converting Mobile Application to NGX", "Your project '" + project.getName() + "' will be converted to use the new version of the Mobile Builder.\n" + "Please enter a new project name for a converted copy.\n" + "Or convert the current project.", project.getName(), new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    if (newText.isBlank()) {
                        return "cannot be blank";
                    }
                    if (!StringUtils.isNormalized(newText)) {
                        return "don't use special character";
                    }
                    if (newText.equals(project.getName())) {
                        return null;
                    }
                    if (Engine.theApp.databaseObjectsManager.existsProject(newText)) {
                        return "a project with that name already exists";
                    }
                    return null;
                }
            });
            if (dlg.open() == Window.CANCEL) {
                return;
            }
            String projectName = dlg.getValue();
            if (projectName.equals(project.getName())) {
                PlainMessageDialog msg = PlainMessageDialog.getBuilder(shell, "Confirmation").buttonLabels(Arrays.asList("Yes", "No")).image(IconAndMessageDialog.getImage(IconAndMessageDialog.DLG_IMG_MESSAGE_WARNING)).message("You are about to modify the current project.\n" + "The operation cannot be undone.\n" + "Please make a backup of your current version before continuing.\n" + "Are you sure you want to convert now?").build();
                int response = msg.open();
                if (response == 0) {
                    File projectDir = project.getDirFile();
                    explorerView.setSelectedTreeObject(projectTreeObject);
                    explorerView.unloadSelectedProjectTreeObject();
                    Job.create("Project '" + projectName + "' converting to NGX", monitor -> {
                        monitor.beginTask("Converting to NGX...", IProgressMonitor.UNKNOWN);
                        try {
                            new NgxConverter(projectDir).convertFile();
                        } catch (Exception e) {
                            Engine.logStudio.error("Error while converting to NGX", e);
                        }
                        monitor.beginTask("Open the converted project...", IProgressMonitor.UNKNOWN);
                        display.syncExec(() -> {
                            try {
                                TreeObject to = explorerView.getProjectRootObject(projectName);
                                if (to instanceof UnloadedProjectTreeObject) {
                                    explorerView.loadProject((UnloadedProjectTreeObject) to);
                                } else {
                                    ConvertigoPlugin.errorMessageBox("Cannot find the '" + projectName + "' project");
                                }
                            } catch (EngineException e) {
                                ConvertigoPlugin.errorMessageBox("Failed to get the '" + projectName + "' project: " + e.getMessage());
                            }
                        });
                    }).schedule();
                }
            } else {
                Job.create("Project '" + projectName + "' converting to NGX", monitor -> {
                    try {
                        monitor.beginTask("Exporting '" + project.getName() + "'", IProgressMonitor.UNKNOWN);
                        File car = CarUtils.makeArchive(project, ArchiveExportOption.all);
                        monitor.beginTask("Importing '" + projectName + "'", IProgressMonitor.UNKNOWN);
                        Project prj = Engine.theApp.databaseObjectsManager.deployProject(car.getAbsolutePath(), projectName, true);
                        if (prj == null) {
                            return;
                        }
                        monitor.beginTask("Converting to NGX...", IProgressMonitor.UNKNOWN);
                        new NgxConverter(prj.getDirFile()).convertFile();
                        prj = Engine.theApp.databaseObjectsManager.importProject(Engine.projectYamlFile(projectName), true);
                    } catch (Exception e) {
                        Engine.logStudio.error("Error while converting to NGX", e);
                    }
                    monitor.beginTask("Open the converted project...", IProgressMonitor.UNKNOWN);
                    display.syncExec(() -> {
                        try {
                            explorerView.importProjectTreeObject(projectName);
                        } catch (Exception e) {
                            ConvertigoPlugin.errorMessageBox("Failed to get the '" + projectName + "' project: " + e.getMessage());
                        }
                    });
                }).schedule();
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to edit mobile component class!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : PlainMessageDialog(org.eclipse.jface.dialogs.PlainMessageDialog) InputDialog(org.eclipse.jface.dialogs.InputDialog) PlainMessageDialog(org.eclipse.jface.dialogs.PlainMessageDialog) CarUtils(com.twinsoft.convertigo.engine.util.CarUtils) Arrays(java.util.Arrays) StringUtils(com.twinsoft.convertigo.engine.util.StringUtils) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) NgxConverter(com.twinsoft.convertigo.engine.util.NgxConverter) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) Job(org.eclipse.core.runtime.jobs.Job) Engine(com.twinsoft.convertigo.engine.Engine) IconAndMessageDialog(org.eclipse.jface.dialogs.IconAndMessageDialog) Display(org.eclipse.swt.widgets.Display) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ArchiveExportOption(com.twinsoft.convertigo.engine.enums.ArchiveExportOption) File(java.io.File) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Project(com.twinsoft.convertigo.beans.core.Project) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ConvertigoPlugin(com.twinsoft.convertigo.eclipse.ConvertigoPlugin) Window(org.eclipse.jface.window.Window) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) SWT(org.eclipse.swt.SWT) EngineException(com.twinsoft.convertigo.engine.EngineException) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) InputDialog(org.eclipse.jface.dialogs.InputDialog) EngineException(com.twinsoft.convertigo.engine.EngineException) NgxConverter(com.twinsoft.convertigo.engine.util.NgxConverter) Cursor(org.eclipse.swt.graphics.Cursor) EngineException(com.twinsoft.convertigo.engine.EngineException) Project(com.twinsoft.convertigo.beans.core.Project) Shell(org.eclipse.swt.widgets.Shell) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) File(java.io.File) Display(org.eclipse.swt.widgets.Display) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

Project (com.twinsoft.convertigo.beans.core.Project)1 ConvertigoPlugin (com.twinsoft.convertigo.eclipse.ConvertigoPlugin)1 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)1 ProjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject)1 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)1 UnloadedProjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject)1 Engine (com.twinsoft.convertigo.engine.Engine)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 ArchiveExportOption (com.twinsoft.convertigo.engine.enums.ArchiveExportOption)1 CarUtils (com.twinsoft.convertigo.engine.util.CarUtils)1 NgxConverter (com.twinsoft.convertigo.engine.util.NgxConverter)1 StringUtils (com.twinsoft.convertigo.engine.util.StringUtils)1 File (java.io.File)1 Arrays (java.util.Arrays)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1 IconAndMessageDialog (org.eclipse.jface.dialogs.IconAndMessageDialog)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 PlainMessageDialog (org.eclipse.jface.dialogs.PlainMessageDialog)1