Search in sources :

Example 1 with NewProjectAction

use of org.eclipse.ui.actions.NewProjectAction in project egit by eclipse.

the class GitCreateProjectViaWizardWizard method importProjects.

private void importProjects(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    switch(mySelectionPage.getWizardSelection()) {
        case GitSelectWizardPage.EXISTING_PROJECTS_WIZARD:
            {
                final Set<ProjectRecord> projectsToCreate = new HashSet<>();
                final List<IWorkingSet> workingSets = new ArrayList<>();
                // get the data from the page in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectsToCreate.addAll(myProjectsImportPage.getCheckedProjects());
                        IWorkingSet[] workingSetArray = myProjectsImportPage.getSelectedWorkingSets();
                        workingSets.addAll(Arrays.asList(workingSetArray));
                        myProjectsImportPage.saveWidgetValues();
                    }
                });
                ProjectUtils.createProjects(projectsToCreate, workingSets.toArray(new IWorkingSet[workingSets.size()]), monitor);
                break;
            }
        case GitSelectWizardPage.NEW_WIZARD:
            {
                final List<IProject> previousProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        new NewProjectAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()).run();
                    }
                });
                IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                    @Override
                    public void run(IProgressMonitor actMonitor) throws CoreException {
                        IProject[] currentProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                        SubMonitor progress = SubMonitor.convert(monitor, currentProjects.length);
                        for (IProject current : currentProjects) {
                            if (!previousProjects.contains(current)) {
                                ConnectProviderOperation cpo = new ConnectProviderOperation(current, myRepository.getDirectory());
                                cpo.execute(progress.newChild(1));
                            } else {
                                progress.worked(1);
                            }
                        }
                    }
                };
                try {
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
        case GitSelectWizardPage.GENERAL_WIZARD:
            {
                final String[] projectName = new String[1];
                final boolean[] defaultLocation = new boolean[1];
                // get the data from the page in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectName[0] = myCreateGeneralProjectPage.getProjectName();
                        defaultLocation[0] = myCreateGeneralProjectPage.isDefaultLocation();
                    }
                });
                try {
                    IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor actMonitor) throws CoreException {
                            final IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName[0]);
                            if (!defaultLocation[0]) {
                                desc.setLocation(new Path(myGitDir));
                            }
                            SubMonitor progress = SubMonitor.convert(actMonitor, 4);
                            IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(desc.getName());
                            prj.create(desc, progress.newChild(1));
                            prj.open(progress.newChild(1));
                            ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_ONE, progress.newChild(1));
                            File repoDir = myRepository.getDirectory();
                            ConnectProviderOperation cpo = new ConnectProviderOperation(prj, repoDir);
                            cpo.execute(progress.newChild(1));
                        }
                    };
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashSet(java.util.HashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProjectDescription(org.eclipse.core.resources.IProjectDescription) NewProjectAction(org.eclipse.ui.actions.NewProjectAction) ArrayList(java.util.ArrayList) List(java.util.List) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) File(java.io.File) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 2 with NewProjectAction

use of org.eclipse.ui.actions.NewProjectAction in project egit by eclipse.

the class GitImportWizard method importProjects.

private void importProjects(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    switch(importWithDirectoriesPage.getWizardSelection()) {
        case GitSelectWizardPage.EXISTING_PROJECTS_WIZARD:
            {
                final Set<ProjectRecord> projectsToCreate = new HashSet<>();
                final List<IWorkingSet> workingSets = new ArrayList<>();
                // get the data from the pages in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectsToCreate.addAll(projectsImportPage.getCheckedProjects());
                        IWorkingSet[] workingSetArray = projectsImportPage.getSelectedWorkingSets();
                        workingSets.addAll(Arrays.asList(workingSetArray));
                        projectsImportPage.saveWidgetValues();
                    }
                });
                ProjectUtils.createProjects(projectsToCreate, workingSets.toArray(new IWorkingSet[workingSets.size()]), monitor);
                break;
            }
        case GitSelectWizardPage.NEW_WIZARD:
            {
                final File[] repoDir = new File[1];
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        repoDir[0] = getTargetRepository().getDirectory();
                    }
                });
                final List<IProject> previousProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        new NewProjectAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()).run();
                    }
                });
                IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                    @Override
                    public void run(IProgressMonitor actMonitor) throws CoreException {
                        IProject[] currentProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                        SubMonitor progress = SubMonitor.convert(actMonitor, currentProjects.length);
                        for (IProject current : currentProjects) if (!previousProjects.contains(current)) {
                            ConnectProviderOperation cpo = new ConnectProviderOperation(current, repoDir[0]);
                            cpo.execute(progress.newChild(1));
                        } else {
                            progress.worked(1);
                        }
                    }
                };
                try {
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
        case GitSelectWizardPage.GENERAL_WIZARD:
            {
                final String[] projectName = new String[1];
                final boolean[] defaultLocation = new boolean[1];
                final String[] path = new String[1];
                final File[] repoDir = new File[1];
                // get the data from the page in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectName[0] = createGeneralProjectPage.getProjectName();
                        defaultLocation[0] = createGeneralProjectPage.isDefaultLocation();
                        path[0] = importWithDirectoriesPage.getPath();
                        repoDir[0] = getTargetRepository().getDirectory();
                    }
                });
                try {
                    IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor actMonitor) throws CoreException {
                            final IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName[0]);
                            desc.setLocation(new Path(path[0]));
                            SubMonitor progress = SubMonitor.convert(actMonitor, 4);
                            IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(desc.getName());
                            prj.create(desc, progress.newChild(1));
                            prj.open(progress.newChild(1));
                            ConnectProviderOperation cpo = new ConnectProviderOperation(prj, repoDir[0]);
                            cpo.execute(progress.newChild(1));
                            ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_ONE, progress.newChild(1));
                        }
                    };
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashSet(java.util.HashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProjectDescription(org.eclipse.core.resources.IProjectDescription) NewProjectAction(org.eclipse.ui.actions.NewProjectAction) ArrayList(java.util.ArrayList) List(java.util.List) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 3 with NewProjectAction

use of org.eclipse.ui.actions.NewProjectAction in project whole by wholeplatform.

the class AbstractOpenWizardAction method doCreateProjectFirstOnEmptyWorkspace.

/**
 * Opens the new project dialog if the workspace is empty. This method is called on {@link #run()}.
 * @param shell the shell to use
 * @return returns <code>true</code> when a project has been created, or <code>false</code> when the
 * new project has been canceled.
 */
protected boolean doCreateProjectFirstOnEmptyWorkspace(Shell shell) {
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    if (workspaceRoot.getProjects().length == 0) {
        // String title= NewWizardMessages.AbstractOpenWizardAction_noproject_title;
        // String message= NewWizardMessages.AbstractOpenWizardAction_noproject_message;
        String title = "noproject_title";
        String message = "noproject_message";
        if (MessageDialog.openQuestion(shell, title, message)) {
            new NewProjectAction().run();
            return workspaceRoot.getProjects().length != 0;
        }
        return false;
    }
    return true;
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) NewProjectAction(org.eclipse.ui.actions.NewProjectAction)

Aggregations

NewProjectAction (org.eclipse.ui.actions.NewProjectAction)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 IProject (org.eclipse.core.resources.IProject)2 IProjectDescription (org.eclipse.core.resources.IProjectDescription)2 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Path (org.eclipse.core.runtime.Path)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)2 IWorkingSet (org.eclipse.ui.IWorkingSet)2 File (java.io.File)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1