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();
}
}
Aggregations