Search in sources :

Example 36 with IWorkspaceRunnable

use of org.eclipse.core.resources.IWorkspaceRunnable in project tdi-studio-se by Talend.

the class OpenExistVersionProcessWizard method performFinish.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
     */
@Override
public boolean performFinish() {
    if (mainPage.isCreateNewVersionJob()) {
        try {
            ProxyRepositoryFactory.getInstance().updateLockStatus();
        } catch (PersistenceException e1) {
            ExceptionHandler.process(e1);
        }
        ERepositoryStatus repositoryStatus = ProxyRepositoryFactory.getInstance().getStatus(processObject);
        if ((repositoryStatus.equals(ERepositoryStatus.READ_ONLY)) || repositoryStatus == ERepositoryStatus.LOCK_BY_OTHER || repositoryStatus.equals(ERepositoryStatus.LOCK_BY_USER)) {
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openWarning(getShell(), "Warning", Messages.getString("OpenExistVersionProcessWizard.labelContent"));
                }
            });
            return false;
        } else {
            IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

                @Override
                public void run(final IProgressMonitor monitor) throws CoreException {
                    if (!alreadyEditedByUser) {
                        refreshNewJob();
                        RelationshipItemBuilder.getInstance().addOrUpdateItem(processObject.getProperty().getItem());
                        try {
                            ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
                        } catch (Exception e) {
                            ExceptionHandler.process(e);
                        }
                    }
                    try {
                        Item newCreated = null;
                        if (processObject.getProperty() != null && processObject.getProperty().getItem() != null) {
                            newCreated = processObject.getProperty().getItem();
                        }
                        if (!(newCreated instanceof BusinessProcessItem)) {
                            ProxyRepositoryFactory.getInstance().lock(processObject);
                        }
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    } catch (LoginException e) {
                        ExceptionHandler.process(e);
                    }
                    boolean locked = processObject.getRepositoryStatus().equals(ERepositoryStatus.LOCK_BY_USER);
                    openAnotherVersion((RepositoryNode) processObject.getRepositoryNode(), !locked);
                    try {
                        ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                    }
                }
            };
            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);
            }
        }
    } else {
        StructuredSelection selection = (StructuredSelection) mainPage.getSelection();
        RepositoryNode node = (RepositoryNode) selection.getFirstElement();
        boolean lastVersion = node.getObject().getVersion().equals(processObject.getVersion());
        // processObject.getProperty().setVersion(originalVersion);
        if (lastVersion) {
            lockObject(processObject);
        }
        ERepositoryStatus status = node.getObject().getRepositoryStatus();
        boolean isLocked = false;
        if (status == ERepositoryStatus.LOCK_BY_USER) {
            isLocked = true;
        }
        // Only latest version can be editted
        openAnotherVersion(node, !lastVersion || !isLocked);
    }
    return true;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.talend.commons.exception.SystemException) BusinessException(org.talend.commons.exception.BusinessException) PersistenceException(org.talend.commons.exception.PersistenceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) Item(org.talend.core.model.properties.Item) JobScriptItem(org.talend.core.model.properties.JobScriptItem) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException)

Example 37 with IWorkspaceRunnable

use of org.eclipse.core.resources.IWorkspaceRunnable 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 38 with IWorkspaceRunnable

use of org.eclipse.core.resources.IWorkspaceRunnable 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 39 with IWorkspaceRunnable

use of org.eclipse.core.resources.IWorkspaceRunnable 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 40 with IWorkspaceRunnable

use of org.eclipse.core.resources.IWorkspaceRunnable 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

IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)53 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)53 CoreException (org.eclipse.core.runtime.CoreException)43 IWorkspace (org.eclipse.core.resources.IWorkspace)29 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 IStatus (org.eclipse.core.runtime.IStatus)18 PersistenceException (org.talend.commons.exception.PersistenceException)16 Status (org.eclipse.core.runtime.Status)14 IProject (org.eclipse.core.resources.IProject)13 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)11 IResource (org.eclipse.core.resources.IResource)10 IPath (org.eclipse.core.runtime.IPath)9 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)7 HashMap (java.util.HashMap)6 IFile (org.eclipse.core.resources.IFile)6 IProjectDescription (org.eclipse.core.resources.IProjectDescription)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)6 HashSet (java.util.HashSet)5