use of org.eclipse.ui.statushandlers.StatusAdapter in project tdi-studio-se by Talend.
the class ComponentProjectManager method createNewProject.
/**
* Creates a new project resource with the selected name.
* <p>
* In normal usage, this method is invoked after the user has pressed Finish on the wizard; the enablement of the
* Finish button implies that all controls on the pages currently contain valid values.
* </p>
* <p>
* Note that this wizard caches the new project once it has been successfully created; subsequent invocations of
* this method will answer the same project resource without attempting to create it again.
* </p>
*
* @return the created project resource, or <code>null</code> if the project was not created
*/
public IProject createNewProject(String directroy, String projectName, Shell shell) {
if (projDir.equals(directroy)) {
return project;
}
final Shell currentShell = shell;
// get a project handle
final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (newProjectHandle.getRawLocation() != null) {
if (newProjectHandle.getRawLocation().equals(directroy)) {
return newProjectHandle;
} else {
try {
newProjectHandle.delete(false, true, null);
} catch (CoreException e) {
// e.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e);
}
}
}
// final IJavaProject javaProjHandle = JavaCore.create(newProjectHandle);
// get a project descriptor
URI location = null;
if (directroy == null || directroy.equals(PluginConstant.EMPTY_STRING)) {
return null;
} else {
location = new File(directroy).toURI();
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
description.setLocationURI(location);
// create the new project operation
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
CreateProjectOperation op = new CreateProjectOperation(description, //$NON-NLS-1$
Messages.getString("ComponentProjectManager.NewProject"));
try {
PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(currentShell));
} catch (ExecutionException e) {
throw new InvocationTargetException(e);
}
}
};
// run the new project creation o`peration
try {
ProgressUI.popProgressDialog(op, shell);
} catch (InterruptedException e) {
return null;
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
CoreException cause = (CoreException) t.getCause();
StatusAdapter status;
if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, IStatus.WARNING, Messages.getString("ComponentProjectManager.WarningMsg", //$NON-NLS-1$
newProjectHandle.getName()), cause));
} else {
status = new StatusAdapter(new Status(cause.getStatus().getSeverity(), ComponentDesigenerPlugin.PLUGIN_ID, cause.getStatus().getSeverity(), Messages.getString("ComponentProjectManager.CreationProblems"), //$NON-NLS-1$
cause));
}
//$NON-NLS-1$
status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
StatusManager.getManager().handle(status, StatusManager.BLOCK);
} else {
StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, 0, Messages.getString("ComponentProjectManager.InternalErrorMsg", t.getMessage()), //$NON-NLS-1$
t));
//$NON-NLS-1$
status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
}
return null;
}
project = newProjectHandle;
return project;
}
Aggregations