Search in sources :

Example 46 with NullProgressMonitor

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);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Bundle(org.osgi.framework.Bundle) IComponent(org.talend.core.model.components.IComponent) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) ISVNProviderService(org.talend.core.services.ISVNProviderService) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) FileFilter(java.io.FileFilter) File(java.io.File) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 47 with NullProgressMonitor

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());
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.talend.core.model.process.INode)

Example 48 with 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());
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) IProcess2(org.talend.core.model.process.IProcess2) IEditorPart(org.eclipse.ui.IEditorPart)

Example 49 with 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();
}
Also used : Item(org.talend.core.model.properties.Item) RoutineItem(org.talend.core.model.properties.RoutineItem) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) File(java.io.File)

Example 50 with NullProgressMonitor

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject) IRepositoryService(org.talend.repository.model.IRepositoryService) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) FolderItem(org.talend.core.model.properties.FolderItem) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1614 CoreException (org.eclipse.core.runtime.CoreException)416 Test (org.junit.Test)382 IFile (org.eclipse.core.resources.IFile)342 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)267 IProject (org.eclipse.core.resources.IProject)258 File (java.io.File)205 IPath (org.eclipse.core.runtime.IPath)182 IOException (java.io.IOException)153 Path (org.eclipse.core.runtime.Path)132 ArrayList (java.util.ArrayList)122 IStatus (org.eclipse.core.runtime.IStatus)113 IFolder (org.eclipse.core.resources.IFolder)87 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)69 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)63 InvocationTargetException (java.lang.reflect.InvocationTargetException)60 List (java.util.List)59 IProjectDescription (org.eclipse.core.resources.IProjectDescription)57 IType (org.eclipse.jdt.core.IType)57 Status (org.eclipse.core.runtime.Status)55