Search in sources :

Example 1 with ProjectInformation

use of org.eclipse.titan.designer.wizards.GUIProjectImporter.ProjectInformation in project titan.EclipsePlug-ins by eclipse.

the class TITANProjectImportWizard method performFinish.

@Override
public boolean performFinish() {
    URI targetLocation = null;
    if (!newProjectPage.useDefaults()) {
        targetLocation = newProjectPage.getLocationURI();
    }
    final IProject newProject = GUIProjectImporter.createNewProject(newProjectPage.getProjectHandle(), mainPage.getInformation(), targetLocation);
    if (newProject == null) {
        final IWorkspaceDescription description = ResourcesPlugin.getWorkspace().getDescription();
        if (description.isAutoBuilding() != wasAutoBuilding) {
            description.setAutoBuilding(wasAutoBuilding);
            try {
                ResourcesPlugin.getWorkspace().setDescription(description);
            } catch (CoreException e) {
                ErrorReporter.logExceptionStackTrace(e);
            }
        }
        Activator.getDefault().resumeHandlingResourceChanges();
        return true;
    }
    try {
        TITANNature.addTITANBuilderToProject(newProject);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    ProjectFileHandler pfHandler;
    pfHandler = new ProjectFileHandler(newProject);
    pfHandler.saveProjectSettings();
    try {
        newProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    BasicNewProjectResourceWizard.updatePerspective(config);
    selectAndReveal(newProject);
    final ProjectInformation information = mainPage.getInformation();
    List<IncludedProject> includedProjects = information.getIncludedProjects();
    if (!includedProjects.isEmpty() && (recursivelyPage == null || recursivelyPage.getRecursiveImport())) {
        final IWorkspace workspace = ResourcesPlugin.getWorkspace();
        final List<String> processedProjectFiles = new ArrayList<String>();
        processedProjectFiles.add(information.getSourceFile());
        final List<IPath> projectFilesToBeProcessed = new ArrayList<IPath>();
        for (IncludedProject includedProject : includedProjects) {
            final IPath temp = includedProject.getAbsolutePath();
            if (temp != null) {
                projectFilesToBeProcessed.add(temp);
            }
        }
        while (!projectFilesToBeProcessed.isEmpty()) {
            IPath tempPath = projectFilesToBeProcessed.remove(projectFilesToBeProcessed.size() - 1);
            if (processedProjectFiles.contains(tempPath.toOSString())) {
                continue;
            }
            final GUIProjectImporter importer = new GUIProjectImporter();
            final ProjectInformation tempProjectInformation = importer.loadProjectFile(tempPath.toOSString(), null, // false: not headless
            false);
            final IPath tempPath2 = tempPath.removeFileExtension();
            final String includedProjectName = tempPath2.lastSegment();
            IProject tempProject = workspace.getRoot().getProject(includedProjectName);
            if (tempProject.exists()) {
                continue;
            }
            tempProject = GUIProjectImporter.createNewProject(tempProject, tempProjectInformation, targetLocation);
            if (tempProject == null) {
                continue;
            }
            try {
                TITANNature.addTITANBuilderToProject(tempProject);
            } catch (CoreException e) {
                ErrorReporter.logExceptionStackTrace(e);
            }
            pfHandler = new ProjectFileHandler(tempProject);
            pfHandler.saveProjectSettings();
            try {
                tempProject.refreshLocal(IResource.DEPTH_INFINITE, null);
            } catch (CoreException e) {
                ErrorReporter.logExceptionStackTrace(e);
            }
            includedProjects = tempProjectInformation.getIncludedProjects();
            for (IncludedProject includedProject : includedProjects) {
                final IPath temp = includedProject.getAbsolutePath();
                if (temp != null) {
                    projectFilesToBeProcessed.add(temp);
                }
            }
        }
    }
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            final PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(null, newProject, GeneralConstants.PROJECT_PROPERTY_PAGE, null, null);
            if (dialog != null) {
                dialog.open();
            }
            final IWorkspaceDescription description = ResourcesPlugin.getWorkspace().getDescription();
            if (description.isAutoBuilding() != wasAutoBuilding) {
                description.setAutoBuilding(wasAutoBuilding);
                try {
                    ResourcesPlugin.getWorkspace().setDescription(description);
                } catch (CoreException e) {
                    ErrorReporter.logExceptionStackTrace(e);
                }
            }
            Activator.getDefault().resumeHandlingResourceChanges();
        }
    });
    return true;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) ProjectInformation(org.eclipse.titan.designer.wizards.GUIProjectImporter.ProjectInformation) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) IncludedProject(org.eclipse.titan.designer.wizards.GUIProjectImporter.IncludedProject) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) CoreException(org.eclipse.core.runtime.CoreException) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) IWorkspace(org.eclipse.core.resources.IWorkspace)

Aggregations

URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceDescription (org.eclipse.core.resources.IWorkspaceDescription)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 PreferenceDialog (org.eclipse.jface.preference.PreferenceDialog)1 ProjectFileHandler (org.eclipse.titan.designer.properties.data.ProjectFileHandler)1 IncludedProject (org.eclipse.titan.designer.wizards.GUIProjectImporter.IncludedProject)1 ProjectInformation (org.eclipse.titan.designer.wizards.GUIProjectImporter.ProjectInformation)1