Search in sources :

Example 71 with ISchedulingRule

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

the class SaveAsProcessWizard method update.

private void update(final ProcessType processType) {
    RepositoryWorkUnit<Object> rwu = new RepositoryWorkUnit<Object>("Save job") {

        @Override
        protected void run() throws LoginException, PersistenceException {
            IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

                @Override
                public void run(final IProgressMonitor monitor) throws CoreException {
                    try {
                        oldProcessItem.setProcess(processType);
                        assginValues(oldProperty, property);
                        RelationshipItemBuilder.getInstance().addOrUpdateItem(oldProcessItem);
                        repositoryFactory.save(oldProcessItem);
                        // assign value
                        processItem = oldProcessItem;
                    } catch (PersistenceException pe) {
                        throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), "persistance error", //$NON-NLS-1$
                        pe));
                    }
                }
            };
            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 e) {
                MessageBoxExceptionHandler.process(e.getCause());
            }
        }
    };
    rwu.setAvoidUnloadResources(true);
    rwu.setAvoidSvnUpdate(true);
    repositoryFactory.executeRepositoryWorkUnit(rwu);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) 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) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 72 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 73 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)

Example 74 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project erlide_eclipse by erlang.

the class RunDialyzerHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    final Set<IErlModule> modules = collectModulesFromSelection(selection);
    final Set<IErlProject> projects = collectProjectsFromModules(modules);
    // build
    final WorkspaceJob buildJob = new BuildOperation("Building projects", projects);
    buildJob.setUser(true);
    buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
    buildJob.schedule();
    // run dialyzer
    final Job job = new DialyzeOperation("Running Dialyzer", modules, projects);
    final ISchedulingRule rule = createRuleForModules(modules);
    job.setRule(rule);
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ISelection(org.eclipse.jface.viewers.ISelection) IErlModule(org.erlide.engine.model.root.IErlModule) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 75 with ISchedulingRule

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

the class RemovePhysicallyFromRepositoryAction method doRun.

@Override
protected void doRun() {
    final IWorkspaceRunnable op = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            int size = getSelectedObject().size();
            if (size > 0) {
                if (!MessageDialog.openConfirm(getShell(), Messages.RemoveFromRepositoryAction_Title, Messages.bind(Messages.RemoveFromRepositoryAction_confirm, size, size > 1 ? Messages.RemoveFromRepositoryAction_instances : Messages.RemoveFromRepositoryAction_instance))) {
                    return;
                }
            }
            List<IRepositoryViewObject> viewObjs = new ArrayList<IRepositoryViewObject>();
            for (Object obj : getSelectedObject()) {
                if (obj instanceof IRepositoryViewObject) {
                    IRepositoryViewObject viewObj = (IRepositoryViewObject) obj;
                    viewObjs.add(viewObj);
                }
            }
            removeViewObjects(viewObjs);
        }
    };
    // 
    IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    try {
        PlatformUI.getWorkbench().getProgressService().run(false, false, iRunnableWithProgress);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) 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) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Aggregations

ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)116 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)41 CoreException (org.eclipse.core.runtime.CoreException)40 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)32 IWorkspace (org.eclipse.core.resources.IWorkspace)30 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22 PersistenceException (org.talend.commons.exception.PersistenceException)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 IStatus (org.eclipse.core.runtime.IStatus)17 Status (org.eclipse.core.runtime.Status)15 IResource (org.eclipse.core.resources.IResource)14 MultiRule (org.eclipse.core.runtime.jobs.MultiRule)14 ArrayList (java.util.ArrayList)13 IResourceRuleFactory (org.eclipse.core.resources.IResourceRuleFactory)12 Job (org.eclipse.core.runtime.jobs.Job)12 IFile (org.eclipse.core.resources.IFile)11 HashSet (java.util.HashSet)10 IPath (org.eclipse.core.runtime.IPath)10 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)10 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)10