Search in sources :

Example 11 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tdi-studio-se by Talend.

the class JSONWizard method performFinish.

/**
     * This method determine if the 'Finish' button is enable This method is called when 'Finish' button is pressed in
     * the wizard. We will create an operation and run it using wizard as execution context.
     */
@Override
public boolean performFinish() {
    boolean formIsPerformed = false;
    IWizardPage finalPage = getCurrentPage();
    if (finalPage == null) {
        finalPage = propertiesWizardPage;
    }
    // deleteTemFile();
    if (connection.isInputModel()) {
        if (finalPage instanceof JSONFileWizardPage) {
            int step = ((JSONFileWizardPage) finalPage).step;
            if (step == 2) {
                formIsPerformed = finalPage.isPageComplete();
                if (formIsPerformed) {
                    List schemas = connection.getSchema();
                    Set tables = ConnectionHelper.getTables(connection);
                    if (!schemas.isEmpty() && !tables.isEmpty()) {
                        JSONXPathLoopDescriptor currentSchema = (JSONXPathLoopDescriptor) schemas.get(0);
                        MetadataTable currentTable = (MetadataTable) tables.toArray(new MetadataTable[0])[0];
                        if (!currentSchema.getAbsoluteXPathQuery().equals(oldAbstractQueryPath)) {
                            resetMetadata(currentSchema.getSchemaTargets(), true);
                        } else {
                            resetMetadata(currentSchema.getSchemaTargets(), false);
                        }
                    }
                }
            } else {
                formIsPerformed = finalPage.isPageComplete();
            }
        } else {
            formIsPerformed = finalPage.isPageComplete();
        }
    } else {
        formIsPerformed = finalPage.isPageComplete();
    }
    if (formIsPerformed) {
        final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        final IWorkspaceRunnable op = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (creation) {
                            String nextId = factory.getNextId();
                            connectionProperty.setId(nextId);
                            // changed by hqzhang for TDI-19527, label=displayName
                            connectionProperty.setLabel(connectionProperty.getDisplayName());
                            final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {

                                @Override
                                protected void run() throws LoginException, PersistenceException {
                                    factory.create(connectionItem, propertiesWizardPage.getDestinationPath());
                                }
                            };
                            workUnit.setAvoidUnloadResources(true);
                            factory.executeRepositoryWorkUnit(workUnit);
                        } else {
                            // changed by hqzhang for TDI-19527, label=displayName
                            connectionProperty.setLabel(connectionProperty.getDisplayName());
                            // update schemas
                            Map<String, SchemaTarget> schemaTargetMap = new HashMap<String, SchemaTarget>();
                            EList<JSONXPathLoopDescriptor> schema = connection.getSchema();
                            if (schema != null && schema.size() > 0) {
                                JSONXPathLoopDescriptor jsonXPathLoopDescriptor = schema.get(0);
                                if (jsonXPathLoopDescriptor != null) {
                                    EList<SchemaTarget> schemaTargets = jsonXPathLoopDescriptor.getSchemaTargets();
                                    if (schemaTargets != null && schemaTargets.size() > 0) {
                                        for (SchemaTarget schemaTarget : schemaTargets) {
                                            schemaTargetMap.put(schemaTarget.getTagName(), schemaTarget);
                                        }
                                    }
                                }
                            }
                            Map<String, MetadataColumn> columnsMap = new HashMap<String, MetadataColumn>();
                            MetadataTable[] tables = ConnectionHelper.getTables(connectionItem.getConnection()).toArray(new MetadataTable[0]);
                            for (MetadataTable table : tables) {
                                EList<MetadataColumn> columns = table.getColumns();
                                Iterator<MetadataColumn> columnsIter = columns.iterator();
                                while (columnsIter.hasNext()) {
                                    MetadataColumn column = columnsIter.next();
                                    if (connection.isInputModel()) {
                                        if (schemaTargetMap.get(column.getLabel()) == null) {
                                            columnsIter.remove();
                                        } else {
                                            columnsMap.put(column.getLabel(), column);
                                        }
                                    } else {
                                        columnsMap.put(column.getLabel(), column);
                                    }
                                }
                            }
                            boolean hasAddedColumns = false;
                            Iterator<Entry<String, SchemaTarget>> schemaTargetIter = schemaTargetMap.entrySet().iterator();
                            while (schemaTargetIter.hasNext()) {
                                Map.Entry<String, SchemaTarget> entry = schemaTargetIter.next();
                                String key = entry.getKey();
                                if (columnsMap.get(key) == null) {
                                    hasAddedColumns = true;
                                    break;
                                }
                            }
                            if (hasAddedColumns) {
                                MessageDialog.openInformation(getShell(), "Detect new columns", "There are some new fields to extract, guess your schema manually if you want to apply the update.");
                            }
                            // update
                            RepositoryUpdateManager.updateFileConnection(connectionItem);
                            refreshInFinish(propertiesWizardPage.isNameModifiedByUser());
                            final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {

                                @Override
                                protected void run() throws LoginException, PersistenceException {
                                    factory.save(connectionItem);
                                }
                            };
                            workUnit.setAvoidUnloadResources(true);
                            factory.executeRepositoryWorkUnit(workUnit);
                            closeLockStrategy();
                        }
                        final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {

                            @Override
                            protected void run() throws LoginException, PersistenceException {
                                ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
                            }
                        };
                        workUnit.setAvoidUnloadResources(true);
                        factory.executeRepositoryWorkUnit(workUnit);
                    }
                });
            }
        };
        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 {
            new ProgressMonitorDialog(null).run(true, true, iRunnableWithProgress);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
        //
        }
        return true;
    } else {
        return false;
    }
}
Also used : Set(java.util.Set) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Entry(java.util.Map.Entry) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) SchemaTarget(org.talend.repository.model.json.SchemaTarget) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) EList(org.eclipse.emf.common.util.EList) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IWizardPage(org.eclipse.jface.wizard.IWizardPage) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tdi-studio-se by Talend.

the class VersionManagementPage method updateItemsVersion.

@Override
protected void updateItemsVersion() {
    final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(final IProgressMonitor monitor) throws CoreException {
            RepositoryWorkUnit<Object> rwu = new RepositoryWorkUnit<Object>(project, "Update items version") {

                @Override
                protected void run() throws LoginException, PersistenceException {
                    //$NON-NLS-1$
                    monitor.beginTask("Update items version", checkedObjects.size());
                    Map<String, String> versions = new HashMap<String, String>();
                    for (int i = 0; i < checkedObjects.size(); i++) {
                        ItemVersionObject object = checkedObjects.get(i);
                        versions.put(object.getItem().getProperty().getId(), object.getOldVersion());
                    }
                    for (ItemVersionObject object : checkedObjects) {
                        IRepositoryViewObject repositoryObject = object.getRepositoryNode().getObject();
                        if (repositoryObject != null && repositoryObject.getProperty() != null) {
                            if (!object.getNewVersion().equals(repositoryObject.getVersion())) {
                                final Item item = object.getItem();
                                Property itemProperty = item.getProperty();
                                itemProperty.setVersion(object.getNewVersion());
                                monitor.subTask(itemProperty.getLabel());
                                try {
                                    // for bug 12853 ,version management doesn't work for joblet because eResource
                                    // is null
                                    IRepositoryViewObject obj = null;
                                    if (itemProperty.eResource() == null) {
                                        ItemState state = item.getState();
                                        if (state != null && state.getPath() != null) {
                                            obj = FACTORY.getLastVersion(project, itemProperty.getId(), state.getPath(), object.getRepositoryNode().getObjectType());
                                        } else {
                                            obj = FACTORY.getLastVersion(project, itemProperty.getId());
                                        }
                                    }
                                    if (obj != null) {
                                        // obj.setVersion(object.getNewVersion());
                                        FACTORY.save(project, obj.getProperty());
                                        builder.addOrUpdateItem(obj.getProperty().getItem(), true);
                                    } else {
                                        String id = itemProperty.getId();
                                        FACTORY.save(project, itemProperty);
                                        if (versionLatest.getSelection()) {
                                            builder.updateItemVersion(item, object.getOldVersion(), id, versions, true);
                                        }
                                        builder.addOrUpdateItem(item, true);
                                    }
                                } catch (PersistenceException e) {
                                    ExceptionHandler.process(e);
                                }
                            }
                        }
                        monitor.worked(1);
                    }
                    try {
                        FACTORY.saveProject(project);
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                }
            };
            rwu.setAvoidUnloadResources(true);
            rwu.executeRun();
            monitor.done();
        }
    };
    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(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
        }
    };
    // final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog(null);
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(false, false, iRunnableWithProgress);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashMap(java.util.HashMap) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ItemState(org.talend.core.model.properties.ItemState) IWorkspace(org.eclipse.core.resources.IWorkspace) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject) Property(org.talend.core.model.properties.Property)

Example 13 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tdi-studio-se by Talend.

the class MavenVersionManagementProjectSettingPage method updateItemsVersion.

protected void updateItemsVersion() {
    List<ItemVersionObject> JobsOpenedInEditor = new ArrayList<ItemVersionObject>();
    List<ItemVersionObject> closedJobs = new ArrayList<ItemVersionObject>();
    boolean hasJobOpenedInEditor = false;
    StringBuilder builder = new StringBuilder();
    for (ItemVersionObject object : checkedObjects) {
        if (RepositoryManager.isOpenedItemInEditor(object.getRepositoryNode().getObject())) {
            hasJobOpenedInEditor = true;
            JobsOpenedInEditor.add(object);
            //$NON-NLS-1$
            builder.append(object.getRepositoryNode().getObject().getLabel() + ", ");
        } else {
            closedJobs.add(object);
        }
    }
    if (builder.length() > 0) {
        builder.delete(builder.length() - 2, builder.length());
    }
    if (hasJobOpenedInEditor) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), //$NON-NLS-1$
        Messages.getString("VersionManagementDialog.WarningTitle2"), //$NON-NLS-1$
        Messages.getString("VersionManagementDialog.openedInEditorMessage", builder.toString()));
        IWorkbenchWindow workBench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (workBench != null) {
            IWorkbenchPage page = workBench.getActivePage();
            IEditorReference[] editorRefs = page.getEditorReferences();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
                IDesignerCoreUIService service = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
                if (service != null) {
                    for (IEditorReference editorRef : editorRefs) {
                        IEditorPart editor = editorRef.getEditor(false);
                        if (editor instanceof IMultiPageTalendEditor) {
                            IProcess2 process = ((IMultiPageTalendEditor) editor).getProcess();
                            String version = null;
                            for (ItemVersionObject object : JobsOpenedInEditor) {
                                if (object.getItem().getProperty().getId().equals(process.getId())) {
                                    version = object.getNewVersion();
                                    break;
                                }
                            }
                            if (version != null) {
                                String jobDefaultVersion = MavenVersionUtils.getDefaultVersion(process.getProperty().getVersion());
                                if (version.equals(jobDefaultVersion)) {
                                    // if default, set null to remove key from property.
                                    version = null;
                                }
                                Command command = service.crateMavenDeploymentValueChangeCommand(process, MavenConstants.NAME_USER_VERSION, version);
                                if (process instanceof IGEFProcess) {
                                    service.executeCommand((IGEFProcess) process, command);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(final IProgressMonitor monitor) throws CoreException {
            RepositoryWorkUnit<Object> rwu = new //$NON-NLS-1$
            RepositoryWorkUnit<Object>(//$NON-NLS-1$
            project, //$NON-NLS-1$
            "Update items Maven version") {

                @Override
                protected void run() throws LoginException, PersistenceException {
                    //$NON-NLS-1$
                    monitor.beginTask("Update items Maven version", closedJobs.size());
                    for (ItemVersionObject object : closedJobs) {
                        final Item item = object.getItem();
                        Property itemProperty = item.getProperty();
                        MavenVersionUtils.setItemMavenVersion(itemProperty, object.getNewVersion());
                        monitor.subTask(itemProperty.getLabel());
                        FACTORY.save(project, itemProperty);
                        monitor.worked(1);
                    }
                    try {
                        FACTORY.saveProject(project);
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                }
            };
            rwu.setAvoidUnloadResources(true);
            rwu.executeRun();
            monitor.done();
        }
    };
    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(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
        }
    };
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(false, false, iRunnableWithProgress);
    } catch (InvocationTargetException | InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IMultiPageTalendEditor(org.talend.designer.core.IMultiPageTalendEditor) Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) IEditorReference(org.eclipse.ui.IEditorReference) Property(org.talend.core.model.properties.Property) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) IEditorPart(org.eclipse.ui.IEditorPart) InvocationTargetException(java.lang.reflect.InvocationTargetException) IGEFProcess(org.talend.core.ui.process.IGEFProcess) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) Command(org.eclipse.gef.commands.Command) IWorkspace(org.eclipse.core.resources.IWorkspace) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject)

Example 14 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule 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);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 15 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule 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)

Aggregations

ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)28 CoreException (org.eclipse.core.runtime.CoreException)19 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)19 IWorkspace (org.eclipse.core.resources.IWorkspace)18 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)18 PersistenceException (org.talend.commons.exception.PersistenceException)15 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 IStatus (org.eclipse.core.runtime.IStatus)8 Status (org.eclipse.core.runtime.Status)7 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)7 HashSet (java.util.HashSet)6 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)6 IResource (org.eclipse.core.resources.IResource)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)5 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 MultiRule (org.eclipse.core.runtime.jobs.MultiRule)4 Item (org.talend.core.model.properties.Item)4