use of org.eclipse.core.runtime.NullProgressMonitor 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.runtime.NullProgressMonitor in project tdi-studio-se by Talend.
the class SaveJobBeforeRunAction method saveJob.
/**
* DOC bqian Comment method "saveJob".
*
* @param nodes
* @param editor
*/
private void saveJob(List<? extends INode> nodes, MultiPageTalendEditor editor) {
for (Iterator<? extends INode> iter = nodes.iterator(); iter.hasNext(); ) {
INode node = iter.next();
//$NON-NLS-1$
boolean saveBeforeRun = Boolean.parseBoolean(ElementParameterParser.getValue(node, "__SAVE_BEFORE_RUN__"));
//$NON-NLS-1$
String process = ElementParameterParser.getValue(node, "__PROCESS_TYPE_PROCESS__");
String editorName = editor.getProcess().getName();
if (saveBeforeRun && process.indexOf(editorName) > -1) {
editor.doSave(new NullProgressMonitor());
}
}
}
use of org.eclipse.core.runtime.NullProgressMonitor in project tdi-studio-se by Talend.
the class SaveJobBeforeRunAction method run.
@Override
public void run() {
List<? extends INode> nodes = activeProcess.getGraphicalNodes();
if (nodes.isEmpty()) {
return;
}
IEditorPart part = null;
if (activeProcess instanceof IProcess2) {
// save the editor directly.
part = ((IProcess2) activeProcess).getEditor();
} else {
// try to save current active editor
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
}
if (part != null && part.isDirty()) {
if (part != null && part instanceof AbstractMultiPageTalendEditor) {
AbstractMultiPageTalendEditor editor = (AbstractMultiPageTalendEditor) part;
editor.doSave(new NullProgressMonitor());
}
}
}
use of org.eclipse.core.runtime.NullProgressMonitor in project tdi-studio-se by Talend.
the class ExportItemUtil method createLocalResources.
public Set<File> createLocalResources(File destinationDirectory, Item item) throws Exception {
List<Item> items = new ArrayList<Item>();
items.add(item);
Map<File, IPath> exportItems = exportItems2(items, destinationDirectory, false, new NullProgressMonitor());
return exportItems.keySet();
}
use of org.eclipse.core.runtime.NullProgressMonitor in project tdi-studio-se by Talend.
the class RemoveBinFolderMigrationTask method execute.
@Override
public ExecutionResult execute(Project project) {
XmiResourceManager xmiResourceManager = new XmiResourceManager();
IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
for (ERepositoryObjectType type : getTypes()) {
IFolder folder = null;
if (type != null && type.hasFolder()) {
try {
IProject fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
if (!fsProject.getFolder(ERepositoryObjectType.getFolderName(type)).exists()) {
continue;
}
folder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
for (IResource current : ResourceUtils.getMembers(folder)) {
if ((current instanceof IFolder) && ((IFolder) current).getName().equals("bin")) {
for (IResource fileCurrent : ResourceUtils.getMembers((IFolder) current)) {
if (fileCurrent instanceof IFile) {
if (xmiResourceManager.isPropertyFile((IFile) fileCurrent)) {
Property property = null;
try {
property = xmiResourceManager.loadProperty(fileCurrent);
} catch (RuntimeException e) {
// property will be null
ExceptionHandler.process(e);
}
if (property != null) {
// restore folder if doesn't exist anymore.
Item propertyItem = property.getItem();
propertyItem.getState().setDeleted(true);
EmfHelper.saveResource(propertyItem.eResource());
String oldPath = propertyItem.getState().getPath();
IPath path = new Path(oldPath);
factory.createParentFoldersRecursively(project, type, path, true);
FolderItem folderItem = factory.getFolderItem(project, type, path);
propertyItem.setParent(folderItem);
String name = fileCurrent.getName().replace(".properties", "");
// take all the files starting by the same name
IFolder typeRootFolder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
for (IResource filesToMove : ResourceUtils.getMembers((IFolder) current)) {
if (filesToMove.getName().startsWith(name)) {
IPath originalPath = filesToMove.getFullPath();
IPath finalPath = typeRootFolder.getFullPath().append(path).append(originalPath.lastSegment());
if (fsProject.getWorkspace().getRoot().getFile(finalPath).exists()) {
// if the file exists in both bin and target directory, delete
// the one from bin.
filesToMove.delete(true, new NullProgressMonitor());
} else {
ResourceUtils.moveResource(filesToMove, finalPath);
}
}
}
}
}
}
}
IResource[] binFolder = ResourceUtils.getMembers((IFolder) current);
if (binFolder.length == 0 || (binFolder.length == 1 && FilesUtils.isSVNFolder(binFolder[0]))) {
try {
((IFolder) current).delete(true, null);
} catch (CoreException e) {
// not catched, not important if can delete or not
}
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
} catch (CoreException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
// }
return ExecutionResult.SUCCESS_NO_ALERT;
}
Aggregations