Search in sources :

Example 31 with ISchedulingRule

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

the class GenericConnWizard method createOrUpdateConnectionItem.

private void createOrUpdateConnectionItem() throws CoreException {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    IWorkspaceRunnable operation = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                Form form = wizPage.getForm();
                if (form.isCallAfterFormFinish()) {
                    if (creation) {
                        factory.create(connectionItem, pathToSave);
                    }
                    compService.afterFormFinish(form.getName(), form.getProperties());
                }
                updateConnectionItem(factory);
            } catch (Throwable e) {
                throw new CoreException(new Status(IStatus.ERROR, IGenericConstants.REPOSITORY_PLUGIN_ID, "Error when saving the connection", e));
            }
        }
    };
    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(operation, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
    // Move it from WorkspaceRunnable to avoid the conflicting rules with other jobs.
    if (!creation) {
        GenericUpdateManager.updateGenericConnection(connectionItem, oldMetadataTable);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) Form(org.talend.daikon.properties.presentation.Form) IWorkspace(org.eclipse.core.resources.IWorkspace) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 32 with ISchedulingRule

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

the class PublishMetadataRunnable method run.

@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    final IWorkspaceRunnable op = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            monitor.beginTask(Messages.PublishMetadataAction_Importing, 3);
            final Collection<XmlFileConnectionItem> xmlObjs;
            try {
                xmlObjs = initFileConnection();
            } catch (Exception e) {
                String message = (null != e.getMessage()) ? e.getMessage() : e.getClass().getName();
                throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Can't retrieve schemas from metadata: " + message, e));
            }
            Collection<XmlFileConnectionItem> selectTables;
            if (xmlObjs.size() > 0) {
                RewriteSchemaDialogRunnable runnable = new RewriteSchemaDialogRunnable(shell, xmlObjs);
                Display.getDefault().syncExec(runnable);
                selectTables = runnable.getSelectTables();
                if (null == selectTables) {
                    return;
                }
            } else {
                selectTables = Collections.emptyList();
            }
            monitor.worked(1);
            if (monitor.isCanceled()) {
                return;
            }
            boolean validateWsdl = Activator.getDefault().getPreferenceStore().getBoolean(EsbSoapServicePreferencePage.ENABLE_WSDL_VALIDATION);
            if (validateWsdl) {
                WSDLUtils.validateWsdl(wsdlDefinition.getDocumentBaseURI());
            }
            monitor.worked(1);
            if (monitor.isCanceled()) {
                return;
            }
            try {
                process(wsdlDefinition, selectTables);
            } catch (Exception e) {
                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error during schema processing", e));
            }
            monitor.done();
        }
    };
    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);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem)

Example 33 with ISchedulingRule

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

the class StandAloneTalendJavaEditor method refreshJobAndSave.

private void refreshJobAndSave(final IProxyRepositoryFactory repFactory) throws PersistenceException {
    final IWorkspaceRunnable op = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                repFactory.save(item);
            } catch (PersistenceException e) {
                throw new CoreException(new Status(IStatus.ERROR, DesignerPlugin.ID, "Save Routine failed!", e));
            }
        }

        ;
    };
    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 {
        PlatformUI.getWorkbench().getProgressService().run(false, false, iRunnableWithProgress);
    } catch (InvocationTargetException e) {
        throw new PersistenceException(e);
    } catch (InterruptedException e) {
        throw new PersistenceException(e);
    }
    setTitleImage(getTitleImage());
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Aggregations

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