Search in sources :

Example 1 with ILastVersionChecker

use of org.talend.core.ui.ILastVersionChecker in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method doSave.

/**
     * Saves the multi-page editor's document.
     */
@Override
public void doSave(final IProgressMonitor monitor) {
    Item curItem = getProcess().getProperty().getItem();
    IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    try {
        // For TDI-23825, if not lock by user try to lock again.
        if (!getProcess().isReadOnly()) {
            repFactory.lock(curItem);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    if (getProcess().isReadOnly() || repFactory.isUserReadOnlyOnCurrentProject()) {
        MessageDialog.openWarning(getEditor(0).getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.readonly"), Messages.getString("AbstractMultiPageTalendEditor.readonlyMessage"));
        return;
    }
    ERepositoryStatus status = repFactory.getStatus(curItem);
    if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
        MessageDialog.openWarning(getEditor(0).getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveTitle"), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveMessage"));
        return;
    }
    if (!isDirty()) {
        return;
    }
    Map<String, Boolean> jobletMap = new HashMap<String, Boolean>();
    changeCollapsedState(true, jobletMap);
    updateRunJobContext();
    designerEditor.getProcess().getProperty().eAdapters().remove(dirtyListener);
    repFactory.addRepositoryWorkUnitListener(repositoryWorkListener);
    if (jobletEditor == getActiveEditor()) {
        boolean isDirty = jobletEditor.isDirty();
        refreshPropertyDirtyStatus();
        jobletEditor.doSave(monitor);
        try {
            IProcess2 oldProcess = getProcess();
            ICreateXtextProcessService n = CorePlugin.getDefault().getCreateXtextProcessService();
            ProcessType processType = n.convertDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
            IProcess2 newProcess = null;
            Item item = getProcess().getProperty().getItem();
            if (item instanceof ProcessItem) {
                ((Process) designerEditor.getProcess()).updateProcess(processType);
                if (isDirty) {
                    getProcess().setProcessModified(true);
                    getProcess().setNeedRegenerateCode(true);
                }
            } else if (item instanceof JobletProcessItem) {
                AbstractProcessProvider processProvider = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
                if (processProvider != null) {
                    newProcess = processProvider.buildNewGraphicProcess(item);
                }
                designerEditor.setProcess(newProcess);
                Boolean lastVersion = null;
                if (oldProcess instanceof ILastVersionChecker) {
                    lastVersion = ((ILastVersionChecker) oldProcess).isLastVersion(item);
                }
                if (designerEditor.getEditorInput() instanceof JobEditorInput) {
                    ((JobEditorInput) designerEditor.getEditorInput()).checkInit(lastVersion, null, true);
                }
            }
            getEditor(0).doSave(monitor);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    } else {
        refreshPropertyDirtyStatus();
        getEditor(0).doSave(monitor);
    }
    /*
         * refresh should be executed before add the listener,or it will has eProxy on the property,it will cause a
         * editor dirty problem. hywang commet bug 17357
         */
    if (processEditorInput != null) {
        propertyInformation = new ArrayList(processEditorInput.getItem().getProperty().getInformations());
        propertyIsDirty = false;
    }
    if (designerEditor != null && dirtyListener != null) {
        designerEditor.getProcess().getProperty().eAdapters().add(dirtyListener);
    }
    refreshJobSettingsView();
    changeCollapsedState(false, jobletMap);
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
        ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
        if (testContainerService != null) {
            testContainerService.updateDetect(getProcess(), false);
        }
    }
    if (isCheckout) {
        CommandStack stack = (CommandStack) getAdapter(CommandStack.class);
        stack.flush();
        isCheckout = false;
    }
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ICreateXtextProcessService(org.talend.core.services.ICreateXtextProcessService) Process(org.talend.designer.core.ui.editor.process.Process) AbstractProcessProvider(org.talend.designer.core.model.process.AbstractProcessProvider) IRepositoryService(org.talend.repository.model.IRepositoryService) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ILastVersionChecker(org.talend.core.ui.ILastVersionChecker) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) CommandStack(org.eclipse.gef.commands.CommandStack) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) ProcessorException(org.talend.designer.runprocess.ProcessorException) BusinessException(org.talend.commons.exception.BusinessException) PersistenceException(org.talend.commons.exception.PersistenceException) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IResource(org.eclipse.core.resources.IResource)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 PartInitException (org.eclipse.ui.PartInitException)1 BusinessException (org.talend.commons.exception.BusinessException)1 LoginException (org.talend.commons.exception.LoginException)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 ERepositoryStatus (org.talend.commons.runtime.model.repository.ERepositoryStatus)1 IProcess2 (org.talend.core.model.process.IProcess2)1 Item (org.talend.core.model.properties.Item)1 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)1 ProcessItem (org.talend.core.model.properties.ProcessItem)1 ICreateXtextProcessService (org.talend.core.services.ICreateXtextProcessService)1 ILastVersionChecker (org.talend.core.ui.ILastVersionChecker)1 ITestContainerProviderService (org.talend.core.ui.ITestContainerProviderService)1