Search in sources :

Example 16 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project tdi-studio-se by Talend.

the class MultiSchemasUI method fetchCodes.

@SuppressWarnings("restriction")
private void fetchCodes() {
    try {
        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
        dialog.run(true, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Fetch...", IProgressMonitor.UNKNOWN);
                monitor.setCanceled(false);
                final CsvArray csvArray = processor.getCsvArray();
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        SchemasKeyData schemasModel = null;
                        boolean checked = (csvArray != null && csvArray.getRows().size() > 0);
                        CSVArrayAndSeparator uniqueCsvArray = null;
                        if (useMultiSaparators.getSelection()) {
                            getMultiSchemaManager().setKeyValues(keyValuesText.getText());
                        }
                        if (multiSchemasFilePreview.getSelectColumnIndex() < 0 && multiSchemaManager.getSelectedColumnIndex() != 0) {
                            uniqueCsvArray = getMultiSchemaManager().retrieveCsvArrayInUniqueModel(getProcessDescription(), checked, multiSchemaManager.getSelectedColumnIndex(), useMultiSaparators.getSelection());
                            schemasModel = getMultiSchemaManager().createSchemasTree(uniqueCsvArray, multiSchemaManager.getSelectedColumnIndex());
                        } else {
                            uniqueCsvArray = getMultiSchemaManager().retrieveCsvArrayInUniqueModel(getProcessDescription(), checked, multiSchemasFilePreview.getSelectColumnIndex(), useMultiSaparators.getSelection());
                            schemasModel = getMultiSchemaManager().createSchemasTree(uniqueCsvArray, multiSchemasFilePreview.getSelectColumnIndex());
                            getMultiSchemaManager().setSelectedColumnIndex(multiSchemasFilePreview.getSelectColumnIndex());
                            schemaTreeViewer.setInput(schemasModel);
                            getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
                            clearSchemaDetail();
                            checkDialog();
                        }
                    }
                });
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CsvArray(org.talend.core.utils.CsvArray) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) CSVArrayAndSeparator(org.talend.designer.filemultischemas.data.CSVArrayAndSeparator) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 17 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project tdi-studio-se by Talend.

the class ImportItemWizardPage method updateItemsList.

public void updateItemsList(final String path, boolean isneedUpdate) {
    if (!isneedUpdate) {
        if (path.equals(lastPath)) {
            return;
        }
    }
    lastPath = path;
    if (path == null || path.length() == 0) {
        selectedItems = new ArrayList<ItemRecord>();
        checkTreeViewer.refresh(true);
        // get the top item to check if tree is empty, if not then uncheck everything
        TreeItem topItem = checkTreeViewer.getTree().getTopItem();
        if (topItem != null) {
            checkTreeViewer.setSubtreeChecked(topItem.getData(), false);
        }
        // else not root element, tree is already empty
        checkValidItems();
        return;
    }
    final boolean dirSelected = this.itemFromDirectoryRadio.getSelection();
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) {
                // monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_SearchingMessage, 100);
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("DataTransferMessages.WizardProjectsImportPage_SearchingMessage"), 100);
                File directory = new File(path);
                monitor.worked(10);
                if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
                    sourceTarFile = getSpecifiedTarSourceFile(path);
                    if (sourceTarFile == null) {
                        return;
                    }
                    TarLeveledStructureProvider provider = new TarLeveledStructureProvider(sourceTarFile);
                    manager = ResourcesManagerFactory.getInstance().createResourcesManager(provider);
                    if (!manager.collectPath2Object(provider.getRoot())) {
                        return;
                    }
                } else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
                    sourceFile = getSpecifiedZipSourceFile(path);
                    if (sourceFile == null) {
                        return;
                    }
                    ZipLeveledStructureProvider provider = new ZipLeveledStructureProvider(sourceFile);
                    manager = ResourcesManagerFactory.getInstance().createResourcesManager(provider);
                    if (!manager.collectPath2Object(provider.getRoot())) {
                        return;
                    }
                } else if (dirSelected && directory.isDirectory()) {
                    manager = ResourcesManagerFactory.getInstance().createResourcesManager();
                    if (!manager.collectPath2Object(directory)) {
                        return;
                    }
                } else {
                    monitor.worked(60);
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        IDEWorkbenchPlugin.log(e.getMessage(), e);
    } catch (InterruptedException e) {
    // Nothing to do if the user interrupts.
    }
    populateItems();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) TreeItem(org.eclipse.swt.widgets.TreeItem) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 18 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project tdi-studio-se by Talend.

the class ImportItemWizardPage method performFinish.

public boolean performFinish() {
    final List<ItemRecord> itemRecords = new ArrayList<ItemRecord>();
    final List<ItemRecord> checkedItemRecords = getCheckedElements();
    itemRecords.addAll(checkedItemRecords);
    itemRecords.addAll(getHadoopSubrecords(itemRecords));
    for (ItemRecord itemRecord : itemRecords) {
        Item item = itemRecord.getProperty().getItem();
        if (item instanceof JobletProcessItem) {
            needToRefreshPalette = true;
        }
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        if (item.getState().isLocked()) {
            try {
                factory.unlock(item);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            } catch (LoginException e) {
                ExceptionHandler.process(e);
            }
        }
        ERepositoryStatus status = factory.getStatus(item);
        if (status != null && status == ERepositoryStatus.LOCK_BY_USER) {
            try {
                factory.unlock(item);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            } catch (LoginException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    try {
        IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IPath destinationPath = null;
                String contentType = "";
                if (rNode != null && rNode.getType().equals(ENodeType.SIMPLE_FOLDER)) {
                    destinationPath = RepositoryNodeUtilities.getPath(rNode);
                    contentType = rNode.getContentType().name();
                }
                repositoryUtil.setErrors(false);
                repositoryUtil.clear();
                repositoryUtil.importItemRecords(manager, itemRecords, monitor, overwrite, destinationPath, contentType);
                if (repositoryUtil.hasErrors()) {
                    throw new InvocationTargetException(new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), //$NON-NLS-1$
                    "Import errors")));
                }
            }
        };
        new ProgressMonitorDialog(getShell()).run(true, true, iRunnableWithProgress);
    } catch (InvocationTargetException e) {
        Throwable targetException = e.getTargetException();
        if (repositoryUtil.getRoutineExtModulesMap().isEmpty()) {
            if (targetException instanceof CoreException) {
                //$NON-NLS-1$
                MessageDialog.openWarning(//$NON-NLS-1$
                getShell(), //$NON-NLS-1$
                Messages.getString("ImportItemWizardPage.ImportSelectedItems"), //$NON-NLS-1$
                Messages.getString("ImportItemWizardPage.ErrorsOccured"));
            }
        }
    } catch (InterruptedException e) {
    //
    }
    ResourcesManager curManager = this.manager;
    if (curManager instanceof ProviderManager) {
        curManager.closeResource();
    }
    selectedItems = null;
    itemRecords.clear();
    return true;
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IPath(org.eclipse.core.runtime.IPath) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) JobletDocumentationItem(org.talend.core.model.properties.JobletDocumentationItem) JobDocumentationItem(org.talend.core.model.properties.JobDocumentationItem) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) TreeItem(org.eclipse.swt.widgets.TreeItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 19 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project tdi-studio-se by Talend.

the class PaletteSettingPage method okPressed.

protected void okPressed() {
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayUtils.getDefaultShell());
    IRunnableWithProgress rwp = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
            try {
                prf.saveProject(project);
                ShowStandardAction.getInstance().doRun();
                if (needCodeGen) {
                    Job refreshTemplates = CorePlugin.getDefault().getCodeGeneratorService().refreshTemplates();
                    refreshTemplates.addJobChangeListener(new JobChangeAdapter() {

                        @Override
                        public void done(IJobChangeEvent event) {
                            CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
                        }
                    });
                }
            // ComponentUtilities.updatePalette();
            } catch (Exception ex) {
                ExceptionHandler.process(ex);
            }
        }
    };
    try {
        pmd.run(true, false, rwp);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 20 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress 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)

Aggregations

IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)177 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)167 InvocationTargetException (java.lang.reflect.InvocationTargetException)160 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)83 CoreException (org.eclipse.core.runtime.CoreException)56 ArrayList (java.util.ArrayList)42 IStatus (org.eclipse.core.runtime.IStatus)39 Status (org.eclipse.core.runtime.Status)36 IFile (org.eclipse.core.resources.IFile)27 File (java.io.File)24 IOException (java.io.IOException)24 PartInitException (org.eclipse.ui.PartInitException)24 List (java.util.List)19 IProject (org.eclipse.core.resources.IProject)19 PersistenceException (org.talend.commons.exception.PersistenceException)19 Shell (org.eclipse.swt.widgets.Shell)18 Display (org.eclipse.swt.widgets.Display)17 IResource (org.eclipse.core.resources.IResource)16 IPath (org.eclipse.core.runtime.IPath)15 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)12