Search in sources :

Example 1 with ArchiveExportOptionDialog

use of com.twinsoft.convertigo.eclipse.dialogs.ArchiveExportOptionDialog in project convertigo by convertigo.

the class ProjectDeployAction 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) {
            ProjectTreeObject projectTreeObject = (ProjectTreeObject) explorerView.getFirstSelectedTreeObject();
            Project project = projectTreeObject.getObject();
            if (projectTreeObject.hasChanged() && !projectTreeObject.save(true)) {
                return;
            }
            ArchiveExportOptionDialog dlg = new ArchiveExportOptionDialog(shell, project, true);
            if (dlg.open() != Window.OK) {
                return;
            }
            if (!dlg.getVersion().equals(project.getVersion())) {
                project.setVersion(dlg.getVersion());
                project.hasChanged = true;
                projectTreeObject.save(false);
            }
            explorerView.refreshTreeObject(projectTreeObject);
            ProjectDeployDialog projectDeployDialog = new ProjectDeployDialog(shell, project, dlg.getArchiveExportOptions());
            projectDeployDialog.open();
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to deploy the project!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ArchiveExportOptionDialog(com.twinsoft.convertigo.eclipse.dialogs.ArchiveExportOptionDialog) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) Cursor(org.eclipse.swt.graphics.Cursor) ProjectDeployDialog(com.twinsoft.convertigo.eclipse.dialogs.ProjectDeployDialog) Display(org.eclipse.swt.widgets.Display)

Example 2 with ArchiveExportOptionDialog

use of com.twinsoft.convertigo.eclipse.dialogs.ArchiveExportOptionDialog in project convertigo by convertigo.

the class ProjectExportAction method run.

@Override
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) {
            ProjectTreeObject projectTreeObject = (ProjectTreeObject) explorerView.getFirstSelectedTreeObject();
            Project project = (Project) projectTreeObject.getObject();
            String projectName = project.getName();
            if (projectTreeObject.hasChanged() && !projectTreeObject.save(true)) {
                return;
            }
            ArchiveExportOptionDialog dlg = new ArchiveExportOptionDialog(shell, project, false);
            if (dlg.open() != Window.OK) {
                return;
            }
            if (!dlg.getVersion().equals(project.getVersion())) {
                project.setVersion(dlg.getVersion());
                project.hasChanged = true;
                projectTreeObject.save(false);
            }
            explorerView.refreshTreeObject(projectTreeObject);
            String projectArchive = projectName + ".car";
            FileDialog fileDialog = new FileDialog(shell, SWT.PRIMARY_MODAL | SWT.SAVE);
            fileDialog.setText("Export a project");
            fileDialog.setFilterExtensions(new String[] { "*.car", "*.zip" });
            fileDialog.setFilterNames(new String[] { "Convertigo archives", "Convertigo archives as zip" });
            fileDialog.setFilterPath(Engine.PROJECTS_PATH);
            fileDialog.setFileName(projectArchive);
            String filePath = fileDialog.open();
            if (filePath != null) {
                File file = new File(filePath);
                if (file.exists()) {
                    if (ConvertigoPlugin.questionMessageBox(shell, "File already exists. Do you want to overwrite?") == SWT.YES) {
                        if (!file.delete()) {
                            ConvertigoPlugin.warningMessageBox("Error when deleting the file " + file.getName() + "! Please verify access rights!");
                            return;
                        }
                    } else {
                        return;
                    }
                }
                if (Pattern.matches(".+(\\.zip|\\.car)", file.getName())) {
                    CarUtils.makeArchive(file, project, dlg.getArchiveExportOptions());
                } else {
                    Toolkit.getDefaultToolkit().beep();
                    ConvertigoPlugin.logWarning("Wrong file extension!");
                }
            }
            projectTreeObject.getIProject().refreshLocal(IResource.DEPTH_ONE, null);
            explorerView.setFocus();
            explorerView.setSelectedTreeObject(projectTreeObject);
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to export the project!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ArchiveExportOptionDialog(com.twinsoft.convertigo.eclipse.dialogs.ArchiveExportOptionDialog) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) Cursor(org.eclipse.swt.graphics.Cursor) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Aggregations

Project (com.twinsoft.convertigo.beans.core.Project)2 ArchiveExportOptionDialog (com.twinsoft.convertigo.eclipse.dialogs.ArchiveExportOptionDialog)2 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)2 ProjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject)2 Cursor (org.eclipse.swt.graphics.Cursor)2 Display (org.eclipse.swt.widgets.Display)2 Shell (org.eclipse.swt.widgets.Shell)2 ProjectDeployDialog (com.twinsoft.convertigo.eclipse.dialogs.ProjectDeployDialog)1 File (java.io.File)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1