use of org.eclipse.core.resources.IWorkspace in project tesb-studio-se by Talend.
the class PublishMetadataRunnable method run.
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
monitor.beginTask(Messages.PublishMetadataAction_Importing, 3);
final Collection<XmlFileConnectionItem> xmlObjs;
try {
xmlObjs = initFileConnection();
} catch (Exception e) {
String message = (null != e.getMessage()) ? e.getMessage() : e.getClass().getName();
throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Can't retrieve schemas from metadata: " + message, e));
}
Collection<XmlFileConnectionItem> selectTables;
if (xmlObjs.size() > 0) {
RewriteSchemaDialogRunnable runnable = new RewriteSchemaDialogRunnable(shell, xmlObjs);
Display.getDefault().syncExec(runnable);
selectTables = runnable.getSelectTables();
if (null == selectTables) {
return;
}
} else {
selectTables = Collections.emptyList();
}
monitor.worked(1);
if (monitor.isCanceled()) {
return;
}
boolean validateWsdl = Activator.getDefault().getPreferenceStore().getBoolean(EsbSoapServicePreferencePage.ENABLE_WSDL_VALIDATION);
if (validateWsdl) {
WSDLUtils.validateWsdl(wsdlDefinition.getDocumentBaseURI());
}
monitor.worked(1);
if (monitor.isCanceled()) {
return;
}
try {
process(wsdlDefinition, selectTables);
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error during schema processing", e));
}
monitor.done();
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all
// notification
// of changes before the end of the modifications.
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method refreshJobAndSave.
private void refreshJobAndSave(final IProxyRepositoryFactory repFactory) throws PersistenceException {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
try {
repFactory.save(item);
} catch (PersistenceException e) {
throw new CoreException(new Status(IStatus.ERROR, DesignerPlugin.ID, "Save Routine failed!", e));
}
}
;
};
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all
// notification
// of changes before the end of the modifications.
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().run(false, false, iRunnableWithProgress);
} catch (InvocationTargetException e) {
throw new PersistenceException(e);
} catch (InterruptedException e) {
throw new PersistenceException(e);
}
setTitleImage(getTitleImage());
}
use of org.eclipse.core.resources.IWorkspace 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;
}
use of org.eclipse.core.resources.IWorkspace in project bndtools by bndtools.
the class FileUtils method toWorkspaceResource.
public static IResource toWorkspaceResource(File file) {
IPath path = new Path(file.toString());
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IWorkspaceRoot workspaceRoot = workspace.getRoot();
IPath workspacePath = workspaceRoot.getLocation();
if (workspacePath.isPrefixOf(path)) {
final IPath relativePath = path.removeFirstSegments(workspacePath.segmentCount());
IResource resource;
if (file.isDirectory()) {
resource = workspaceRoot.getFolder(relativePath);
} else {
resource = workspaceRoot.getFile(relativePath);
}
return resource;
}
return null;
}
use of org.eclipse.core.resources.IWorkspace in project bndtools by bndtools.
the class BaselineErrorHandler method getResolutions.
@Override
public List<IMarkerResolution> getResolutions(IMarker marker) {
List<IMarkerResolution> result = new LinkedList<IMarkerResolution>();
final String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
if (suggestedVersion != null) {
result.add(new IMarkerResolution() {
@Override
public void run(IMarker marker) {
final IFile file = (IFile) marker.getResource();
final IWorkspace workspace = file.getWorkspace();
try {
workspace.run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
String input = "version " + suggestedVersion;
ByteArrayInputStream stream = new ByteArrayInputStream(input.getBytes());
file.setContents(stream, false, true, monitor);
}
}, null);
} catch (CoreException e) {
logger.logError("Error applying baseline version quickfix.", e);
}
}
@Override
public String getLabel() {
return "Change package version to " + suggestedVersion;
}
});
}
return result;
}
Aggregations