use of org.eclipse.core.resources.IWorkspaceRunnable in project tdi-studio-se by Talend.
the class AutoConversionTypesEditor method doStore.
@Override
protected void doStore() {
if (!enableBtn.getSelection()) {
return;
}
RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit(//$NON-NLS-1$
Messages.getString("AutoConversionTypesEditor.doStore.title")) {
@Override
public void run() throws PersistenceException {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
applyChange();
}
};
// unlockObject();
// alreadyEditedByUser = true; // to avoid 2 calls of unlock
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(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
} catch (CoreException e1) {
MessageBoxExceptionHandler.process(e1.getCause());
}
}
};
repositoryWorkUnit.setAvoidSvnUpdate(true);
repositoryWorkUnit.setAvoidUnloadResources(true);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project tdi-studio-se by Talend.
the class CustomComponentSettingPage method finish.
private void finish(IProgressMonitor... monitorWrap) {
IProgressMonitor monitor = null;
if (monitorWrap != null && monitorWrap.length == 1) {
monitor = monitorWrap[0];
}
final IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
if (PluginChecker.isSVNProviderPluginLoaded() && (!sharedAdded.isEmpty() || !backAdded.isEmpty())) {
RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit("Update custom components") {
@Override
public void run() throws PersistenceException {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor subMonitor) throws CoreException {
ISVNProviderService service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
String projectLabel = pro.getTechnicalLabel();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
String targetRoot = eclipseProject.getLocation().toString() + "/" + ERepositoryObjectType.getFolderName(ERepositoryObjectType.COMPONENTS);
File componentFolder = new File(targetRoot);
URL url = null;
try {
if (!componentFolder.exists()) {
FilesUtils.createFoldersIfNotExists(targetRoot, false);
}
Bundle b = Platform.getBundle(IComponentsFactory.COMPONENTS_LOCATION);
url = FileLocator.toFileURL(FileLocator.find(b, new Path(""), null));
String sourceRoot = url.getFile();
// delete share
for (IComponent component : backAdded.keySet()) {
String componentFullPath = targetRoot + File.separator + component.getName();
if (service.isSVNProject(pro)) {
service.svnEclipseHandlerDelete(eclipseProject, pro, componentFullPath);
if (subMonitor != null) {
subMonitor.worked(10);
}
} else {
File file = new File(componentFullPath);
if (file != null && file.exists()) {
org.talend.utils.io.FilesUtils.deleteFolder(file, true);
}
}
}
if (!backAdded.isEmpty()) {
getCustomComponentSettings().removeAll(backAdded.values());
}
FileFilter ff = new FileFilter() {
@Override
public boolean accept(File pathname) {
if (FilesUtils.isSVNFolder(pathname)) {
return false;
}
return true;
}
};
// share
for (IComponent component : sharedAdded.keySet()) {
String sourcePath = sourceRoot + component.getPathSource() + File.separator + component.getName();
File sourceFile = new File(sourcePath);
String targetPath = targetRoot + File.separatorChar + component.getName();
File targetFile = new File(targetPath);
FilesUtils.copyFolder(sourceFile, targetFile, true, ff, null, true, false);
if (subMonitor != null) {
subMonitor.worked(10);
}
}
} catch (Exception e) {
resetCustomComponentSetting();
ExceptionHandler.process(e);
}
try {
prf.saveProject(pro);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
try {
eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
} catch (CoreException e1) {
ExceptionHandler.process(e1);
}
}
};
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, new NullProgressMonitor());
} catch (CoreException e) {
throw new PersistenceException(e.getCause());
}
}
};
repositoryWorkUnit.setRefreshRepository(false);
repositoryWorkUnit.setForceTransaction(true);
prf.executeRepositoryWorkUnit(repositoryWorkUnit);
try {
repositoryWorkUnit.throwPersistenceExceptionIfAny();
} catch (PersistenceException e) {
e.printStackTrace();
}
}
if (monitor != null) {
monitor.done();
}
// refresh again after the gui closed .
try {
String projectLabel = pro.getTechnicalLabel();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (CoreException e1) {
ExceptionHandler.process(e1);
}
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project tdi-studio-se by Talend.
the class FTPWizard method performFinish.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.wizard.IWizard#performFinish()
*/
@Override
public boolean performFinish() {
final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
try {
if (creation) {
String nextId = factory.getNextId();
connectionProperty.setId(nextId);
factory.create(connectionItem, propertiesWizardPage.getDestinationPath());
} else {
RepositoryUpdateManager.updateFileConnection(connectionItem);
boolean isModified = propertiesWizardPage.isNameModifiedByUser();
if (isModified) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
if (service != null) {
service.refreshComponentView(connectionItem);
}
}
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRunnable operation = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
try {
factory.save(connectionItem);
closeLockStrategy();
} catch (PersistenceException e) {
throw new CoreException(new Status(IStatus.ERROR, "", "", e));
}
}
};
workspace.run(operation, null);
}
} catch (Exception e) {
String detailError = e.toString();
new //$NON-NLS-1$
ErrorDialogWidthDetailArea(//$NON-NLS-1$
getShell(), //$NON-NLS-1$
PID, //$NON-NLS-1$
"", detailError);
return false;
}
return true;
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project tdi-studio-se by Talend.
the class BuildJobHandler method build.
@Override
public void build(IProgressMonitor monitor) throws Exception {
final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
try {
buildDelegate(monitor);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
};
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.run(runnable, workspace.getRoot(), IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project tesb-studio-se by Talend.
the class OpenWSDLPage method finish.
public boolean finish() {
// changed by hqzhang for TDI-19527, label=displayName
final String label = item.getProperty().getDisplayName();
item.getProperty().setLabel(label);
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(final IProgressMonitor monitor) throws CoreException {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
try {
item.setConnection(ServicesFactory.eINSTANCE.createServiceConnection());
if (creation) {
item.getProperty().setId(factory.getNextId());
factory.create(item, getDestinationPath());
repositoryNode = new RepositoryNode(new RepositoryViewObject(item.getProperty()), repositoryNode.getParent(), ENodeType.REPOSITORY_ELEMENT);
}
((ServiceConnection) item.getConnection()).setWSDLPath(path);
((ServiceConnection) item.getConnection()).getServicePort().clear();
final IFile fileWsdl = WSDLUtils.getWsdlFile(item);
final InputStream is;
if (null == path) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// create new WSDL file from template
TemplateProcessor.processTemplate("DATA_SERVICE_WSDL", Collections.singletonMap("serviceName", (Object) label), baos, getClass().getResourceAsStream(TEMPLATE_SERVICE_WSDL));
is = new ByteArrayInputStream(baos.toByteArray());
} else {
//$NON-NLS-1$
String filenameTemplate = item.getProperty().getLabel() + '_' + item.getProperty().getVersion() + ".%d.wsdl";
Map<String, InputStream> wsdls = new WSDLLoader().load(path, filenameTemplate);
is = wsdls.remove(WSDLLoader.DEFAULT_FILENAME);
for (Map.Entry<String, InputStream> wsdl : wsdls.entrySet()) {
String filename = wsdl.getKey();
IFile importedWsdl = fileWsdl.getParent().getFile(new Path(filename));
if (!importedWsdl.exists()) {
importedWsdl.create(wsdl.getValue(), true, monitor);
} else {
importedWsdl.setContents(wsdl.getValue(), 0, monitor);
}
createReferenceResources(filename.substring(filename.lastIndexOf('.', filename.lastIndexOf('.') - 1) + 1));
}
}
// store WSDL in service
if (!fileWsdl.exists()) {
fileWsdl.create(is, true, monitor);
} else {
fileWsdl.setContents(is, 0, monitor);
}
// create reference to wsdl
//$NON-NLS-1$
createReferenceResources("wsdl");
// path
definition = WSDLUtils.getDefinition(fileWsdl);
populateModelFromWsdl(factory, definition, item, repositoryNode);
factory.save(item);
ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (Exception e) {
//delete the node if any exception during the creation
if (creation) {
try {
factory.save(item);
factory.deleteObjectPhysical(repositoryNode.getObject());
} catch (PersistenceException e1) {
throw getCoreException("WDSL creation failed", e1);
}
}
//throw the exception
if (e instanceof CoreException) {
throw (CoreException) e;
}
if (e instanceof InvocationTargetException) {
throw getCoreException("WDSL creation failed", e.getCause());
}
throw getCoreException("WDSL creation failed", e);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
// we use the workspace scheduling rule to lock all
ISchedulingRule schedulingRule = workspace.getRoot();
// workspace modifications during the run.
// the update of 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(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
} catch (CoreException e) {
MessageBoxExceptionHandler.process(e);
return false;
}
// open wsdl editor
OpenWSDLEditorAction action = new OpenWSDLEditorAction();
action.setServiceItem(item);
action.run();
// import schemas if required
if (checkImport.isVisible() && checkImport.getSelection() && null != definition) {
PublishMetadataRunnable publishMetadataRunnable = new PublishMetadataRunnable(definition, getShell());
try {
getContainer().run(true, true, publishMetadataRunnable);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
String message = (null != cause.getMessage()) ? cause.getMessage() : cause.getClass().getName();
setErrorMessage("Populate schema to repository: " + message);
return false;
} catch (InterruptedException e) {
return false;
}
}
return true;
}
Aggregations