Search in sources :

Example 96 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor 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 97 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor 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 98 with IProgressMonitor

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

the class StatusManagerSettingPage method updateItemsVersion.

private void updateItemsVersion() {
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            //$NON-NLS-1$
            monitor.beginTask("", getModifiedVersionItems().size() * 100);
            Set<ERepositoryObjectType> types = new HashSet<ERepositoryObjectType>();
            for (RepositoryObject object : getModifiedVersionItems()) {
                // IRepositoryViewObject repositoryObject = object.getRepositoryNode().getObject();
                if (object != null && object.getProperty() != null) {
                    if (object.getStatusCode().equals(object.getProperty().getStatusCode())) {
                        final Item item = object.getProperty().getItem();
                        item.getProperty().setOldStatusCode(object.getStatusCode());
                        // types.add(object.getRepositoryNode().getObjectType());
                        try {
                            // }
                            if (object != null) {
                                // obj.setVersion(object.getNewVersion());
                                FACTORY.save(project, object.getProperty());
                            } else {
                            // FACTORY.save(project, item.getProperty());
                            }
                        } catch (PersistenceException e) {
                            ExceptionHandler.process(e);
                        }
                    }
                }
                monitor.worked(100);
            }
            // RepositoryManager.refresh(types);
            monitor.done();
        }
    };
    // final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog(null);
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(false, false, runnable);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RepositoryObject(org.talend.core.model.repository.RepositoryObject) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) PersistenceException(org.talend.commons.exception.PersistenceException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) HashSet(java.util.HashSet)

Example 99 with IProgressMonitor

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

the class ExtractDocumentationAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
protected void doRun() {
    RepositoryNode node = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    final Item item = node.getObject().getProperty().getItem();
    if (item == null) {
        return;
    }
    String initialFileName = null;
    String initialExtension = null;
    if (item instanceof DocumentationItem) {
        DocumentationItem documentationItem = (DocumentationItem) item;
        initialFileName = documentationItem.getName();
        if (documentationItem.getExtension() != null) {
            initialExtension = documentationItem.getExtension();
        }
    } else if (item instanceof LinkDocumentationItem) {
        // link documenation
        LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
        if (!LinkUtils.validateLink(linkDocItem.getLink())) {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.getString(//$NON-NLS-1$
            "ExtractDocumentationAction.fileErrorTitle"), //$NON-NLS-1$
            Messages.getString("ExtractDocumentationAction.fileErrorMessages"));
            return;
        }
        initialFileName = linkDocItem.getName();
        if (linkDocItem.getExtension() != null) {
            initialExtension = linkDocItem.getExtension();
        }
    }
    if (initialFileName != null) {
        FileDialog fileDlg = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
        if (initialExtension != null) {
            //$NON-NLS-1$
            initialFileName = initialFileName + LinkUtils.DOT + initialExtension;
            //$NON-NLS-1$ //$NON-NLS-2$
            fileDlg.setFilterExtensions(new String[] { "*." + initialExtension, "*.*" });
        }
        fileDlg.setFileName(initialFileName);
        String filename = fileDlg.open();
        if (filename != null) {
            final File file = new File(filename);
            ProgressDialog progressDialog = new ProgressDialog(Display.getCurrent().getActiveShell()) {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        if (item instanceof DocumentationItem) {
                            DocumentationItem documentationItem = (DocumentationItem) item;
                            documentationItem.getContent().setInnerContentToFile(file);
                        } else if (item instanceof LinkDocumentationItem) {
                            // link documenation
                            LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
                            ByteArray byteArray = LinkDocumentationHelper.getLinkItemContent(linkDocItem);
                            if (byteArray != null) {
                                byteArray.setInnerContentToFile(file);
                            }
                        }
                    } catch (IOException ioe) {
                        MessageBoxExceptionHandler.process(ioe);
                    }
                }
            };
            try {
                progressDialog.executeProcess();
            } catch (InvocationTargetException e) {
                ExceptionHandler.process(e);
            } catch (InterruptedException e) {
            // Nothing to do
            }
        }
    }
}
Also used : LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) IOException(java.io.IOException) RepositoryNode(org.talend.repository.model.RepositoryNode) BinRepositoryNode(org.talend.repository.model.BinRepositoryNode) DocumentationItem(org.talend.core.model.properties.DocumentationItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Item(org.talend.core.model.properties.Item) DocumentationItem(org.talend.core.model.properties.DocumentationItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ByteArray(org.talend.core.model.properties.ByteArray) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 100 with IProgressMonitor

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

the class MemoryRuntimeComposite method disconnectJVM.

private void disconnectJVM() {
    final Job disconnectJVM = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    "disconnect JVM") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            if (isRemoteMonitoring) {
                if (currentJvm != null && currentJvm.isConnected()) {
                    currentJvm.disconnect();
                }
            }
            return Status.OK_STATUS;
        }
    };
    disconnectJVM.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)392 InvocationTargetException (java.lang.reflect.InvocationTargetException)152 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)144 CoreException (org.eclipse.core.runtime.CoreException)104 IStatus (org.eclipse.core.runtime.IStatus)85 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)74 ArrayList (java.util.ArrayList)73 Status (org.eclipse.core.runtime.Status)65 Job (org.eclipse.core.runtime.jobs.Job)57 IOException (java.io.IOException)54 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)53 ITask (com.cubrid.common.core.task.ITask)49 IFile (org.eclipse.core.resources.IFile)46 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)43 File (java.io.File)42 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)41 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)37 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)37 PersistenceException (org.talend.commons.exception.PersistenceException)36 IProject (org.eclipse.core.resources.IProject)33