use of org.eclipse.core.resources.IWorkspaceRunnable in project sling by apache.
the class ModifiableProperties method setPropertyValue.
@Override
public void setPropertyValue(Object id, Object value) {
final String key;
if (id instanceof Map.Entry<?, ?>) {
Map.Entry<String, String> entry = (Map.Entry<String, String>) id;
key = entry.getKey();
} else {
key = String.valueOf(id);
}
if ("jcr:primaryType".equals(key)) {
final String newPrimaryType = String.valueOf(value);
IWorkspaceRunnable r = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
node.changePrimaryType(newPrimaryType);
}
};
try {
ResourcesPlugin.getWorkspace().run(r, null);
} catch (CoreException e) {
Activator.getDefault().getPluginLogger().error("Error changing type to " + newPrimaryType + ": " + e, e);
e.printStackTrace();
MessageDialog.openError(Display.getDefault().getActiveShell(), "Error changing primary type", "Error changing primary type to " + newPrimaryType + ": " + e);
return;
}
if (id instanceof Map.Entry<?, ?>) {
Map.Entry<String, String> entry = (Map.Entry<String, String>) id;
entry.setValue(String.valueOf(value));
}
} else {
doSetPropertyValue(key, value);
}
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project sling by apache.
the class ImportWizard method performFinish.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
public boolean performFinish() {
if (!mainPage.isPageComplete()) {
return false;
}
final IServer server = mainPage.getServer();
IResource resource = mainPage.getResource();
final IProject project = resource.getProject();
final IPath projectRelativePath = resource.getProjectRelativePath();
try {
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// following this change ( see org.apache.sling.ide.core.ResourceUtil )
try {
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
try {
new ImportRepositoryContentAction(server, projectRelativePath, project, serializationManager).run(monitor);
} catch (SerializationException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import failed", e));
} catch (InvocationTargetException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import failed", e.getCause()));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
serializationManager.destroy();
}
}
}, project, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
mainPage.setErrorMessage("Import error : " + cause.getMessage() + " . Please see the error log for details.");
Activator.getDefault().getPluginLogger().error("Repository import failed", cause);
return false;
} catch (OperationCanceledException | InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
return true;
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project eclipse.platform.text by eclipse.
the class MarkerUtilities method createMarker.
/**
* Creates a marker on the given resource with the given type and attributes.
* <p>
* This method modifies the workspace (progress is not reported to the user).</p>
*
* @param resource the resource
* @param attributes the attribute map
* @param markerType the type of marker
* @throws CoreException if this method fails
* @see IResource#createMarker(java.lang.String)
*/
public static void createMarker(final IResource resource, final Map<String, Object> attributes, final String markerType) throws CoreException {
IWorkspaceRunnable r = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
IMarker marker = resource.createMarker(markerType);
marker.setAttributes(attributes);
}
};
resource.getWorkspace().run(r, null, IWorkspace.AVOID_UPDATE, null);
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project eclipse.platform.text by eclipse.
the class ResourceHelper method delete.
public static void delete(final IResource resource) throws CoreException {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
for (int i = 0; i < MAX_RETRY; i++) {
try {
resource.delete(true, null);
i = MAX_RETRY;
} catch (CoreException e) {
if (i == MAX_RETRY - 1) {
SearchTestPlugin.getDefault().getLog().log(e.getStatus());
throw e;
}
// help windows to really close file locks
System.gc();
try {
// sleep a second
Thread.sleep(1000);
} catch (InterruptedException e1) {
}
}
}
}
};
ResourcesPlugin.getWorkspace().run(runnable, null);
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project eclipse.platform.text by eclipse.
the class LockJob method runInWorkspace.
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor pm) throws CoreException {
try {
run2(pm);
} catch (Exception e) {
// caught and re-thrown as InterruptedException below.
throw new OperationCanceledException(e.getMessage());
}
// CoreException and OperationCanceledException are propagated
}
};
ResourcesPlugin.getWorkspace().run(workspaceRunnable, resource, IResource.NONE, monitor);
return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
}
Aggregations