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