Search in sources :

Example 16 with IRepositoryService

use of org.talend.repository.model.IRepositoryService in project tdi-studio-se by Talend.

the class TalendJavaSourceViewer method getImports.

private static String getImports() {
    //$NON-NLS-1$
    String imports = "";
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRepositoryService.class)) {
        return imports;
    }
    IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
    IProxyRepositoryFactory repositoryFactory = service.getProxyRepositoryFactory();
    Project project = ProjectManager.getInstance().getProject(null);
    try {
        List<IRepositoryViewObject> routines = repositoryFactory.getAll(ERepositoryObjectType.ROUTINES);
        for (IRepositoryViewObject routine : routines) {
            if (routine.getProperty().getItem() instanceof RoutineItem && ((RoutineItem) routine.getProperty().getItem()).isBuiltIn()) {
                //$NON-NLS-1$ //$NON-NLS-2$
                imports += "import routines." + routine.getLabel() + ";\n";
            } else {
                //$NON-NLS-1$ //$NON-NLS-2$ 
                imports += "import routines." + routine.getLabel() + ";\n";
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        //$NON-NLS-1$
        return "";
    }
    //$NON-NLS-1$
    imports += "import routines.system.*;\n";
    //$NON-NLS-1$
    imports += "import java.text.ParseException;\n";
    //$NON-NLS-1$
    imports += "import java.text.SimpleDateFormat;\n";
    //$NON-NLS-1$
    imports += "import java.util.Date;\n";
    //$NON-NLS-1$
    imports += "import java.util.List;\n";
    //$NON-NLS-1$
    imports += "import java.math.BigDecimal;\n";
    imports += "\n";
    imports += "@SuppressWarnings(\"unused\")";
    imports += "\n\n";
    return imports;
}
Also used : Project(org.talend.core.model.properties.Project) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) RoutineItem(org.talend.core.model.properties.RoutineItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 17 with IRepositoryService

use of org.talend.repository.model.IRepositoryService in project tdi-studio-se by Talend.

the class StandAloneTalendJavaEditor method resetItem.

public void resetItem() throws PersistenceException {
    if (item.getProperty().eResource() == null || item.eResource() == null) {
        IRepositoryService service = CoreRuntimePlugin.getInstance().getRepositoryService();
        IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
        //
        // Property updated = factory.getUptodateProperty(getItem().getProperty());
        Property updatedProperty = null;
        try {
            factory.initialize();
            IRepositoryViewObject repositoryViewObject = factory.getLastVersion(new Project(ProjectManager.getInstance().getProject(item.getProperty().getItem())), item.getProperty().getId());
            if (repositoryViewObject != null) {
                updatedProperty = repositoryViewObject.getProperty();
                item = (FileItem) updatedProperty.getItem();
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : Project(org.talend.core.model.general.Project) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IProject(org.eclipse.core.resources.IProject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 18 with IRepositoryService

use of org.talend.repository.model.IRepositoryService 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)

Example 19 with IRepositoryService

use of org.talend.repository.model.IRepositoryService in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method dispose.

/**
     * The <code>MultiPageEditorPart</code> implementation of this <code>IWorkbenchPart</code> method disposes all
     * nested editors. Subclasses may extend.
     */
@Override
public void dispose() {
    getSite().setSelectionProvider(null);
    getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(this);
    /* after the release of eclipse3.6,this parameter can't be null */
    // setInput(null);
    ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
    getSite().getWorkbenchWindow().getPartService().removePartListener(partListener);
    if (this.lockService != null) {
        this.lockService.unregister();
    }
    super.dispose();
    if (getProcess() != null && !getProcess().isReadOnly()) {
        if (isKeepPropertyLocked()) {
            return;
        }
        // Unlock the process :
        IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
        IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
        try {
            getProcess().getProperty().eAdapters().remove(dirtyListener);
            Property property = getProcess().getProperty();
            if (property.eResource() == null || property.getItem().eResource() == null) {
                property = repFactory.getUptodateProperty(property);
            }
            // fix for bug 12524 for db repository
            // property = repFactory.reload(property);
            JobletUtil jUtil = new JobletUtil();
            jUtil.makeSureUnlockJoblet(getProcess());
            Item item = getProcess().getProperty().getItem();
            boolean keep = jUtil.keepLockJoblet(item);
            if (keep) {
                repFactory.unlock(property.getItem());
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        } catch (LoginException e) {
            ExceptionHandler.process(e);
        }
    }
    if (processEditorInput != null) {
        processEditorInput.dispose();
        processEditorInput = null;
    }
    designerEditor = null;
    codeEditor = null;
    if (processor instanceof IJavaBreakpointListener) {
        JDIDebugModel.removeJavaBreakpointListener((IJavaBreakpointListener) processor);
    }
    processor = null;
    dirtyListener = null;
    NodeTransferDragSourceListener.getInstance().setEditPart(null);
}
Also used : JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IJavaBreakpointListener(org.eclipse.jdt.debug.core.IJavaBreakpointListener) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IRepositoryService(org.talend.repository.model.IRepositoryService) JobletUtil(org.talend.designer.core.ui.editor.jobletcontainer.JobletUtil)

Example 20 with IRepositoryService

use of org.talend.repository.model.IRepositoryService in project tdi-studio-se by Talend.

the class CreateProcess method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
protected void doRun() {
    final NewProcessWizard processWizard;
    if (isToolbar()) {
        processWizard = new NewProcessWizard(null);
    } else {
        ISelection selection = getSelection();
        if (selection == null) {
            return;
        }
        Object obj = ((IStructuredSelection) selection).getFirstElement();
        IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
        IPath path = service.getRepositoryPath((IRepositoryNode) obj);
        if (RepositoryConstants.isSystemFolder(path.toString())) {
            // Not allowed to create in system folder.
            return;
        }
        processWizard = new NewProcessWizard(path);
    }
    WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), processWizard);
    if (dlg.open() == Window.OK) {
        if (processWizard.getProcess() == null) {
            return;
        }
        ProcessEditorInput fileEditorInput;
        try {
            // Set readonly to false since created job will always be editable.
            fileEditorInput = new ProcessEditorInput(processWizard.getProcess(), false, true, false);
            IRepositoryNode repositoryNode = RepositorySeekerManager.getInstance().searchRepoViewNode(fileEditorInput.getItem().getProperty().getId(), false);
            fileEditorInput.setRepositoryNode(repositoryNode);
            IWorkbenchPage page = getActivePage();
            page.openEditor(fileEditorInput, MultiPageTalendEditor.ID, true);
        // // use project setting true
        // ProjectSettingManager.defaultUseProjectSetting(fileEditorInput.getLoadedProcess());
        } catch (PartInitException e) {
            // TODO Auto-generated catch block
            ExceptionHandler.process(e);
        } catch (PersistenceException e) {
            MessageBoxExceptionHandler.process(e);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IRepositoryNode(org.talend.repository.model.IRepositoryNode) NewProcessWizard(org.talend.designer.core.ui.wizards.NewProcessWizard) ISelection(org.eclipse.jface.viewers.ISelection) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IRepositoryService(org.talend.repository.model.IRepositoryService) ProcessEditorInput(org.talend.designer.core.ui.editor.ProcessEditorInput)

Aggregations

IRepositoryService (org.talend.repository.model.IRepositoryService)27 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)21 PersistenceException (org.talend.commons.exception.PersistenceException)19 Item (org.talend.core.model.properties.Item)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 PartInitException (org.eclipse.ui.PartInitException)8 CoreException (org.eclipse.core.runtime.CoreException)7 Property (org.talend.core.model.properties.Property)7 LoginException (org.talend.commons.exception.LoginException)6 ProcessItem (org.talend.core.model.properties.ProcessItem)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IPath (org.eclipse.core.runtime.IPath)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 ERepositoryStatus (org.talend.commons.runtime.model.repository.ERepositoryStatus)5 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)5 IFile (org.eclipse.core.resources.IFile)4 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 IProject (org.eclipse.core.resources.IProject)3