Search in sources :

Example 6 with ISchedulingRule

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

the class Rules method validateEditRule.

/**
	 * Combines rules for each parameter to validateEdit from the corresponding
	 * rule factories.
	 */
public ISchedulingRule validateEditRule(IResource[] resources) {
    if (resources.length == 0)
        return null;
    //optimize rule for single file
    if (resources.length == 1) {
        if (resources[0].getType() == IResource.ROOT)
            return root;
        return factoryFor(resources[0]).validateEditRule(resources);
    }
    //gather rules for each resource from appropriate factory
    HashSet<ISchedulingRule> rules = new HashSet<ISchedulingRule>();
    IResource[] oneResource = new IResource[1];
    for (int i = 0; i < resources.length; i++) {
        if (resources[i].getType() == IResource.ROOT)
            return root;
        oneResource[0] = resources[i];
        ISchedulingRule rule = factoryFor(resources[i]).validateEditRule(oneResource);
        if (rule != null)
            rules.add(rule);
    }
    if (rules.isEmpty())
        return null;
    if (rules.size() == 1)
        return rules.iterator().next();
    ISchedulingRule[] ruleArray = rules.toArray(new ISchedulingRule[rules.size()]);
    return new MultiRule(ruleArray);
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 7 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project translationstudio8 by heartsome.

the class ResourceMgmtActionProvider method makeActions.

protected void makeActions() {
    IShellProvider sp = new IShellProvider() {

        public Shell getShell() {
            return shell;
        }
    };
    openProjectAction = new OpenResourceAction(sp);
    openProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_openProjectAction);
    closeProjectAction = new CloseResourceAction(sp);
    closeProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_closeProjectAction);
    //
    // closeUnrelatedProjectsAction = new CloseUnrelatedProjectsAction(sp);
    // closeUnrelatedProjectsAction.setText("关闭无关的项目");
    refreshAction = new RefreshAction(sp) {

        public void run() {
            final IStatus[] errorStatus = new IStatus[1];
            errorStatus[0] = Status.OK_STATUS;
            final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus);
            WorkspaceJob job = new //$NON-NLS-1$
            WorkspaceJob(//$NON-NLS-1$
            "refresh") {

                public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                    try {
                        op.run(monitor);
                        if (shell != null && !shell.isDisposed()) {
                            shell.getDisplay().asyncExec(new Runnable() {

                                public void run() {
                                    StructuredViewer viewer = getActionSite().getStructuredViewer();
                                    if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
                                        viewer.refresh();
                                    }
                                }
                            });
                        }
                    } catch (InvocationTargetException e) {
                        String msg = NLS.bind(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_logTitle, getClass().getName(), e.getTargetException());
                        throw new CoreException(new Status(IStatus.ERROR, NavigatorPlugin.PLUGIN_ID, IStatus.ERROR, msg, e.getTargetException()));
                    } catch (InterruptedException e) {
                        return Status.CANCEL_STATUS;
                    }
                    return errorStatus[0];
                }
            };
            ISchedulingRule rule = op.getRule();
            if (rule != null) {
                job.setRule(rule);
            }
            job.setUser(true);
            job.schedule();
        }
    };
    refreshAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_refreshAction);
    //$NON-NLS-1$
    refreshAction.setDisabledImageDescriptor(getImageDescriptor("dlcl16/refresh_nav.gif"));
    //$NON-NLS-1$
    refreshAction.setImageDescriptor(getImageDescriptor("elcl16/refresh_nav.gif"));
    refreshAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH);
    if (getContext() == null) {
        refreshAction.setEnabled(false);
    } else {
        IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
        refreshAction.selectionChanged(selection);
        refreshAction.setEnabled(!selection.isEmpty());
    }
// buildAction = new BuildAction(sp, IncrementalProjectBuilder.INCREMENTAL_BUILD);
// buildAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_BUILD_PROJECT);
}
Also used : IShellProvider(org.eclipse.jface.window.IShellProvider) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CloseResourceAction(org.eclipse.ui.actions.CloseResourceAction) IStatus(org.eclipse.core.runtime.IStatus) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) OpenResourceAction(org.eclipse.ui.actions.OpenResourceAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RefreshAction(org.eclipse.ui.actions.RefreshAction) CoreException(org.eclipse.core.runtime.CoreException) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer)

Example 8 with ISchedulingRule

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

the class SaveAsBusinessModelWizard method update.

private void update() {
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                assginVlaues(oldProperty, property);
                repositoryFactory.save(oldBusinessProcessItem);
                // assign value
                businessProcessItem = oldBusinessProcessItem;
            } 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());
    }
}
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) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 9 with ISchedulingRule

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

the class DeleteAllJobWhenStartUp method earlyStartup.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IStartup#earlyStartup()
     */
@Override
public void earlyStartup() {
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        return;
    }
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject codeProject = root.getProject(TalendMavenConstants.PROJECT_NAME);
    if (!codeProject.exists() || !codeProject.isAccessible()) {
        return;
    }
    final IWorkspaceRunnable op = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
            ITalendProcessJavaProject talendJavaProject = processService.getTalendProcessJavaProject();
            if (talendJavaProject != null) {
                IJavaProject jProject = talendJavaProject.getJavaProject();
                if (!jProject.isOpen()) {
                    jProject.open(monitor);
                }
                // empty the src/main/java...
                IFolder srcFolder = talendJavaProject.getSrcFolder();
                talendJavaProject.cleanFolder(monitor, srcFolder);
                // contexts
                IFolder resourcesFolder = talendJavaProject.getResourcesFolder();
                emptyContexts(monitor, resourcesFolder, talendJavaProject);
                // empty the outputs, target
                IFolder targetFolder = talendJavaProject.getTargetFolder();
                talendJavaProject.cleanFolder(monitor, targetFolder);
                // empty the src/test/java
                IFolder testSrcFolder = talendJavaProject.getTestSrcFolder();
                talendJavaProject.cleanFolder(monitor, testSrcFolder);
                // empty the src/test/java (main for contexts)
                IFolder testResourcesFolder = talendJavaProject.getTestResourcesFolder();
                talendJavaProject.cleanFolder(monitor, testResourcesFolder);
                // empty temp
                IFolder tempFolder = talendJavaProject.getTempFolder();
                talendJavaProject.cleanFolder(monitor, tempFolder);
                // empty lib/...
                IFolder libFolder = talendJavaProject.getLibFolder();
                talendJavaProject.cleanFolder(monitor, libFolder);
                // rules
                IFolder rulesResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_RULES_DIRECTORY);
                talendJavaProject.cleanFolder(monitor, rulesResFolder);
                // sqltempalte
                IFolder sqlTemplateResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_SQLPATTERNS_DIRECTORY);
                talendJavaProject.cleanFolder(monitor, sqlTemplateResFolder);
            }
        }

        ;
    };
    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) {
        if (e.getCause() != null) {
            ExceptionHandler.process(e.getCause());
        } else {
            ExceptionHandler.process(e);
        }
    }
    executed = true;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IFolder(org.eclipse.core.resources.IFolder) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 10 with ISchedulingRule

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

the class AbstractJobSettingsPage method save.

protected void save() {
    List<String> checkedObjects = new ArrayList<String>();
    List<IRepositoryViewObject> allProcess = null;
    try {
        allProcess = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.PROCESS);
    } catch (PersistenceException e1) {
        ExceptionHandler.process(e1);
    }
    for (IRepositoryViewObject object : allProcess) {
        if (isStatUseProjectSetting(object)) {
            if (!checkedObjects.contains(object.getProperty().getId())) {
                checkedObjects.add(object.getProperty().getId());
                if (!checkedNodeObject.contains(object)) {
                    checkedNodeObject.add(object);
                }
            }
        }
    }
    List<IProcess2> allOpenedProcessList = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(getEditors());
    if (allOpenedProcessList != null) {
        for (int i = 0; i < allOpenedProcessList.size(); i++) {
            if (checkedObjects.contains(allOpenedProcessList.get(i).getProperty().getId())) {
                openedProcessList.add(allOpenedProcessList.get(i));
            }
        }
    }
    //
    final IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(getTaskMessages(), (checkedNodeObject.size()) * 100);
            final Map<String, Set<String>> contextVars = DetectContextVarsUtils.detectByPropertyType(elem, true);
            // must init this
            addContextModel = false;
            if (!contextVars.isEmpty()) {
                // boolean showDialog = false;
                Set<String> contextSet = new HashSet<String>();
                for (String key : contextVars.keySet()) {
                    contextSet = contextVars.get(key);
                    break;
                }
                Connection connection = null;
                IElementParameter ptParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
                if (ptParam != null) {
                    IElementParameter propertyElem = ptParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
                    Object proValue = propertyElem.getValue();
                    if (proValue instanceof String && ((String) proValue).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
                        IElementParameter repositoryElem = ptParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                        String value = (String) repositoryElem.getValue();
                        ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(value);
                        connection = connectionItem.getConnection();
                        if (connection != null && connection.isContextMode()) {
                            addContextModel = true;
                        // ContextItem contextItem =
                        // ContextUtils.getContextItemById(connection.getContextId());
                        // for (IProcess process : openedProcessList) {
                        // Set<String> addedContext =
                        // ConnectionContextHelper.checkAndAddContextVariables(contextItem,
                        // contextSet, process.getContextManager(), false);
                        // if (addedContext != null && !addedContext.isEmpty()) {
                        // showDialog = true;
                        // break;
                        // }
                        // }
                        }
                    }
                }
                if (addContextModel) {
                    // if the context is not existed in job, will add or not.
                    Display disp = Display.getCurrent();
                    if (disp == null) {
                        disp = Display.getDefault();
                    }
                    if (disp != null) {
                        disp.syncExec(new Runnable() {

                            @Override
                            public void run() {
                                showContextAndCheck(contextVars);
                            }
                        });
                    } else {
                        showContextAndCheck(contextVars);
                    }
                }
            }
            monitor.worked(10);
            IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {

                @Override
                public void run(IProgressMonitor monitor) throws CoreException {
                    for (IRepositoryViewObject object : checkedNodeObject) {
                        saveProcess(object, addContextModel, contextVars, monitor);
                    }
                }
            };
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                workspace.run(workspaceRunnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
            monitor.done();
        }
    };
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ArrayList(java.util.ArrayList) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IElementParameter(org.talend.core.model.process.IElementParameter) HashSet(java.util.HashSet) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Display(org.eclipse.swt.widgets.Display)

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