Search in sources :

Example 91 with IWorkspace

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

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

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

the class CodeGeneratorEmittersPoolFactory method loadEmfPersistentData.

private static List<JetBean> loadEmfPersistentData(List<LightJetBean> datas, List<JetBean> completeJetBeanList, IProgressMonitor monitorWrap) throws BusinessException {
    List<JetBean> toReturn = new ArrayList<JetBean>();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    //$NON-NLS-1$
    IProject project = workspace.getRoot().getProject(".JETEmitters");
    URL url = null;
    try {
        IFile file = project.getFile(Path.fromOSString("runtime"));
        url = file.getLocationURI().toURL();
        int lightBeanIndex = 0;
        LightJetBean lightBean = null;
        LightJetBean myLightJetBean = null;
        //$NON-NLS-1$
        String unitTemplateFullURI = "";
        long unitTemplateHashCode = 0;
        HashMap<String, LightJetBean> mapOnName = new HashMap<String, LightJetBean>();
        boolean forceMethodLoad = ComponentCompilations.getMarkers();
        if (forceMethodLoad) {
            // init specific map based on component name : mapOnName
            for (LightJetBean ljb : datas) {
                //$NON-NLS-1$
                mapOnName.put(ljb.getTemplateRelativeUri().substring(ljb.getTemplateRelativeUri().lastIndexOf("/")), ljb);
            }
        }
        int monitorBuffer = 0;
        for (JetBean unit : completeJetBeanList) {
            monitorBuffer++;
            if (monitorBuffer % 200 == 0) {
                monitorWrap.worked(200);
                monitorBuffer = 0;
            }
            unitTemplateFullURI = unit.getTemplateRelativeUri();
            unitTemplateHashCode = unit.getCrc();
            myLightJetBean = new LightJetBean(unitTemplateFullURI, unit.getVersion(), unitTemplateHashCode);
            if (((lightBeanIndex = datas.indexOf(myLightJetBean)) > -1) || forceMethodLoad) {
                if (!forceMethodLoad) {
                    lightBean = datas.get(lightBeanIndex);
                } else {
                    lightBean = mapOnName.get(myLightJetBean.getTemplateRelativeUri().substring(//$NON-NLS-1$
                    myLightJetBean.getTemplateRelativeUri().lastIndexOf("/")));
                }
                if (lightBean != null && lightBean.getCrc() == unit.getCrc()) {
                    unit.setClassName(lightBean.getClassName());
                    unit.setMethodName(lightBean.getMethodName());
                    toReturn.add(unit);
                }
            }
        }
        monitorWrap.worked(monitorBuffer);
    } catch (MalformedURLException e) {
        //$NON-NLS-1$
        log.error(Messages.getString("CodeGeneratorEmittersPoolFactory.JETEmitters.NoPresent"));
        throw new BusinessException(e);
    }
    return toReturn;
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) LightJetBean(org.talend.designer.codegen.config.LightJetBean) MalformedURLException(java.net.MalformedURLException) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) LightJetBean(org.talend.designer.codegen.config.LightJetBean) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) BusinessException(org.talend.commons.exception.BusinessException) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 94 with IWorkspace

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

the class TalendJetEmitter method loadMethod.

/**
     * DOC mhirt Comment method "loadMethod".
     * 
     * @param methodName
     * @return
     * @throws MalformedURLException
     * @throws ClassNotFoundException
     */
private Method loadMethod() throws ClassNotFoundException, MalformedURLException {
    if (jetbean == null) {
        return null;
    }
    if (currentClassLoader != jetbean.getClassLoader()) {
        final IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IProject project = workspace.getRoot().getProject(projectName);
        //$NON-NLS-1$
        URL url = new File(project.getLocation() + "/runtime").toURL();
        currentClassLoader = jetbean.getClassLoader();
        theClassLoader = new URLClassLoader(new URL[] { url }, jetbean.getClassLoader());
    }
    Class theClass;
    try {
        theClass = theClassLoader.loadClass(jetbean.getClassName());
    } catch (Error e) {
        throw new ClassNotFoundException(e.getMessage(), e);
    }
    // TDI-23079
    try {
        Method[] methods = theClass.getDeclaredMethods();
        for (Method method2 : methods) {
            if (method2.getName().equals(jetbean.getMethodName())) {
                return method2;
            }
        }
    } catch (Exception e) {
        return null;
    }
    return null;
}
Also used : IWorkspace(org.eclipse.core.resources.IWorkspace) URLClassLoader(java.net.URLClassLoader) Method(java.lang.reflect.Method) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) JETException(org.eclipse.emf.codegen.jet.JETException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 95 with IWorkspace

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

Aggregations

IWorkspace (org.eclipse.core.resources.IWorkspace)118 IProject (org.eclipse.core.resources.IProject)55 CoreException (org.eclipse.core.runtime.CoreException)54 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)36 IPath (org.eclipse.core.runtime.IPath)35 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)29 IStatus (org.eclipse.core.runtime.IStatus)27 IFile (org.eclipse.core.resources.IFile)24 PersistenceException (org.talend.commons.exception.PersistenceException)23 IProjectDescription (org.eclipse.core.resources.IProjectDescription)21 File (java.io.File)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)19 Path (org.eclipse.core.runtime.Path)19 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)19 IResource (org.eclipse.core.resources.IResource)18 Status (org.eclipse.core.runtime.Status)14 IOException (java.io.IOException)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 ArrayList (java.util.ArrayList)12