Search in sources :

Example 6 with IRepositoryService

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

the class AbstractMultiPageTalendEditor method init.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.part.MultiPageEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
     */
@Override
public void init(final IEditorSite site, IEditorInput editorInput) throws PartInitException {
    setSite(site);
    setInput(editorInput);
    if (!(editorInput instanceof JobEditorInput)) {
        return;
    }
    site.setSelectionProvider(new MultiPageTalendSelectionProvider(this));
    getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
    // Lock the process :
    IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
    final IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    processEditorInput = (JobEditorInput) editorInput;
    final IProcess2 currentProcess = processEditorInput.getLoadedProcess();
    if (!currentProcess.isReadOnly()) {
        try {
            Property property = processEditorInput.getItem().getProperty();
            propertyInformation = new ArrayList(property.getInformations());
            property.eAdapters().add(dirtyListener);
            repFactory.lock(currentProcess);
            boolean locked = repFactory.getStatus(currentProcess) == ERepositoryStatus.LOCK_BY_USER;
            if (!locked) {
                setReadOnly(true);
            }
            revisionChanged = true;
        } catch (PersistenceException e) {
            // e.printStackTrace();
            ExceptionHandler.process(e);
        } catch (BusinessException e) {
            // Nothing to do
            ExceptionHandler.process(e);
        }
    } else {
        setReadOnly(true);
        Bundle bundle = FrameworkUtil.getBundle(AbstractMultiPageTalendEditor.class);
        final Display display = getSite().getShell().getDisplay();
        this.lockService = bundle.getBundleContext().registerService(EventHandler.class.getName(), new EventHandler() {

            @Override
            public void handleEvent(Event event) {
                String lockTopic = Constant.REPOSITORY_ITEM_EVENT_PREFIX + Constant.ITEM_LOCK_EVENT_SUFFIX;
                if (lockTopic.equals(event.getTopic())) {
                    Object o = event.getProperty(Constant.ITEM_EVENT_PROPERTY_KEY);
                    if (o != null && o instanceof Item) {
                        Item item = (Item) o;
                        String itemId = item.getProperty().getId();
                        if (itemId.equals(currentProcess.getId())) {
                            if (currentProcess.isReadOnly()) {
                                boolean readOnly = currentProcess.checkReadOnly();
                                boolean orginalReadOnlyStatus = designerEditor.isReadOnly();
                                setReadOnly(readOnly);
                                if (!readOnly) {
                                    display.asyncExec(new Runnable() {

                                        @Override
                                        public void run() {
                                            setFocus();
                                        }
                                    });
                                    if (orginalReadOnlyStatus == true) {
                                        // refresh to the given item version, nomally it is the latest
                                        // version,
                                        // means the editor/process will be refreshed to the latest version
                                        refreshProcess(item, false);
                                    }
                                    Property property = processEditorInput.getItem().getProperty();
                                    propertyInformation = new ArrayList(property.getInformations());
                                    property.eAdapters().add(dirtyListener);
                                }
                            }
                        }
                    }
                }
            }
        }, new Hashtable<String, String>(Collections.singletonMap(EventConstants.EVENT_TOPIC, //$NON-NLS-1$
        Constant.REPOSITORY_ITEM_EVENT_PREFIX + "*")));
        revisionChanged = true;
    }
    // setTitleImage(ImageProvider.getImage(getEditorTitleImage()));
    updateTitleImage(processEditorInput.getItem().getProperty());
    getSite().getWorkbenchWindow().getPartService().addPartListener(partListener);
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) EventHandler(org.osgi.service.event.EventHandler) IRepositoryService(org.talend.repository.model.IRepositoryService) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) BusinessException(org.talend.commons.exception.BusinessException) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) Event(org.osgi.service.event.Event) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PlatformObject(org.eclipse.core.runtime.PlatformObject) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) Display(org.eclipse.swt.widgets.Display)

Example 7 with IRepositoryService

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

the class EditPropertiesAction method processRename.

protected void processRename(IRepositoryNode node, String originalName) {
    try {
        IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
        ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
        if (talendProcessJavaProject == null) {
            return;
        }
        IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
        IPackageFragmentRoot root = talendProcessJavaProject.getJavaProject().getPackageFragmentRoot(srcFolder);
        // add for bug TDI-24379 on August 23, 2013.
        IFolder srcInterFolder = srcFolder.getFolder(JavaUtils.JAVA_INTERNAL_DIRECTORY);
        if (srcInterFolder.exists()) {
            File file = new File(srcInterFolder.getLocationURI());
            for (File f : file.listFiles()) {
                if (f.isFile()) {
                    f.delete();
                }
            }
        }
        // qli modified to fix the bug 5400 and 6185.
        // update for fix [TESB-6784]
        IPackageFragment routinesPkg = getPackageFragment(root, node);
        // ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName +
        // SuffixConstants.SUFFIX_STRING_java);
        //$NON-NLS-1$
        ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName + ".java");
        if (unit == null) {
            return;
        }
        String newName = node.getObject().getProperty().getLabel();
        JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
        // processor.setNewElementName(newName + SuffixConstants.SUFFIX_STRING_java);
        //$NON-NLS-1$
        processor.setNewElementName(newName + ".java");
        RenameRefactoring ref = new RenameRefactoring(processor);
        final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
        IRunnableWithProgress r = new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            operation.run(monitor);
                        } catch (CoreException e) {
                            ExceptionHandler.process(e);
                        }
                    }
                });
            }
        };
        PlatformUI.getWorkbench().getProgressService().run(true, true, r);
        RefactoringStatus conditionStatus = operation.getConditionStatus();
        if (conditionStatus.hasError()) {
            //$NON-NLS-1$
            String errorMessage = Messages.getString("EditPropertiesAction.renameError", unit.getElementName(), newName);
            RefactoringStatusEntry[] entries = conditionStatus.getEntries();
            for (RefactoringStatusEntry entry : entries) {
                //$NON-NLS-1$
                errorMessage += "\n>>>" + entry.getMessage();
            }
            Shell shell = null;
            IRepositoryView viewPart = getViewPart();
            if (viewPart != null) {
                shell = viewPart.getViewSite().getShell();
            } else {
                shell = Display.getCurrent().getActiveShell();
            }
            //$NON-NLS-1$
            MessageDialog.openError(shell, Messages.getString("EditPropertiesAction.warning"), errorMessage);
            return;
        }
        // ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + SuffixConstants.SUFFIX_STRING_java);
        //$NON-NLS-1$
        ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + ".java");
        if (newUnit == null) {
            return;
        }
        RoutineItem item = (RoutineItem) node.getObject().getProperty().getItem();
        IFile javaFile = (IFile) newUnit.getAdapter(IResource.class);
        try {
            ByteArray byteArray = item.getContent();
            byteArray.setInnerContentFromFile(javaFile);
            IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
            IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
            repFactory.save(item);
        } catch (Exception e) {
            // e.printStackTrace();
            ExceptionHandler.process(e);
        }
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) PerformRefactoringOperation(org.eclipse.ltk.core.refactoring.PerformRefactoringOperation) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IRepositoryService(org.talend.repository.model.IRepositoryService) Shell(org.eclipse.swt.widgets.Shell) ByteArray(org.talend.core.model.properties.ByteArray) JavaRenameProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) RoutineItem(org.talend.core.model.properties.RoutineItem) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RenameCompilationUnitProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameCompilationUnitProcessor) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 8 with IRepositoryService

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

the class SetupProcessDependenciesRoutinesAction method doRun.

@Override
protected void doRun() {
    ISelection selection = getSelection();
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    if (obj == null) {
        return;
    }
    RepositoryNode node = (RepositoryNode) obj;
    boolean readonly = false;
    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    ERepositoryStatus status = repFactory.getStatus(node.getObject());
    if (!repFactory.isPotentiallyEditable(node.getObject()) || status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
        readonly = true;
    }
    Item item = node.getObject().getProperty().getItem();
    if (item instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) item;
        ProcessType process = processItem.getProcess();
        SetupProcessDependenciesRoutinesDialog dialog = new SetupProcessDependenciesRoutinesDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), process, readonly);
        if (dialog.open() == Window.OK && !readonly) {
            process.getParameters().getRoutinesParameter().clear();
            createRoutinesDependencies(process, dialog.getSystemRoutines());
            createRoutinesDependencies(process, dialog.getUserRoutines());
            try {
                CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(processItem);
                RelationshipItemBuilder.getInstance().addOrUpdateItem(processItem);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobProcessItem = (JobletProcessItem) item;
        ProcessType process = jobProcessItem.getJobletProcess();
        SetupProcessDependenciesRoutinesDialog dialog = new SetupProcessDependenciesRoutinesDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), process, readonly);
        if (dialog.open() == Window.OK && !readonly) {
            process.getParameters().getRoutinesParameter().clear();
            createRoutinesDependencies(process, dialog.getSystemRoutines());
            createRoutinesDependencies(process, dialog.getUserRoutines());
            try {
                CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(jobProcessItem);
                IJobletProviderService jobletService = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                if (jobletService != null) {
                    jobletService.loadComponentsFromProviders();
                }
                RelationshipItemBuilder.getInstance().addOrUpdateItem(jobProcessItem);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    }
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryService(org.talend.repository.model.IRepositoryService) IJobletProviderService(org.talend.core.ui.IJobletProviderService) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) SetupProcessDependenciesRoutinesDialog(org.talend.designer.core.ui.routine.SetupProcessDependenciesRoutinesDialog) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ISelection(org.eclipse.jface.viewers.ISelection) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 9 with IRepositoryService

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

the class ContextRepositoryReviewDialog method okPressed.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.ui.dialog.RepositoryReviewDialog#okPressed()
     */
@SuppressWarnings("unchecked")
@Override
protected void okPressed() {
    if (params == null || params.isEmpty()) {
        super.okPressed();
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    if (createNewButton.getSelection()) {
        if (nameInvalid(contextNameText)) {
            //$NON-NLS-1$
            MessageDialog.openError(getShell(), "Context", msg);
            return;
        } else {
            item = PropertiesFactory.eINSTANCE.createContextItem();
            if (item == null) {
                return;
            }
            Property createProperty = PropertiesFactory.eINSTANCE.createProperty();
            createProperty.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
            createProperty.setVersion(VersionUtils.DEFAULT_VERSION);
            //$NON-NLS-1$
            createProperty.setStatusCode("");
            try {
                String nextId = factory.getNextId();
                createProperty.setId(nextId);
                item.setProperty(createProperty);
                for (IContext context : contextManager.getListContext()) {
                    ContextType contextType = TalendFileFactory.eINSTANCE.createContextType();
                    contextType.setName(context.getName());
                    item.getContext().add(contextType);
                }
                item.setDefaultContext(contextManager.getDefaultContext().getName());
                item.getProperty().setLabel(contextNameText.getText().trim());
                IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                IProxyRepositoryFactory repositoryFactory = service.getProxyRepositoryFactory();
                try {
                    boolean nameAvaliabe = repositoryFactory.isNameAvailable(createProperty.getItem(), contextNameText.getText());
                    if (!nameAvaliabe) {
                        MessageDialog.openError(getShell(), "Context", //$NON-NLS-1$
                        Messages.getString(//$NON-NLS-1$
                        "PropertiesWizardPage.ItemExistsError"));
                        return;
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                    super.okPressed();
                }
                //$NON-NLS-1$
                factory.create(item, new Path(""));
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                super.okPressed();
            }
        }
    } else {
        IStructuredSelection selection = (IStructuredSelection) getRepositoryTreeViewer().getSelection();
        RepositoryNode context = (RepositoryNode) selection.getFirstElement();
        try {
            // get the item from file
            IRepositoryViewObject contextObj = factory.getLastVersion(context.getObject().getProperty().getId());
            item = (ContextItem) contextObj.getProperty().getItem();
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            super.okPressed();
        }
    }
    super.okPressed();
}
Also used : Path(org.eclipse.core.runtime.Path) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) IContext(org.talend.core.model.process.IContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryService(org.talend.repository.model.IRepositoryService) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 10 with IRepositoryService

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

the class StandAloneTalendJavaEditor method doSetInput.

@Override
public void doSetInput(IEditorInput input) throws CoreException {
    // Lock the process :
    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    if (input instanceof RepositoryEditorInput) {
        rEditorInput = (RepositoryEditorInput) input;
    } else {
        FileEditorInput fileInput = (FileEditorInput) input;
        rEditorInput = new RepositoryEditorInput(fileInput.getFile(), rEditorInput.getItem());
    }
    if (rEditorInput.getRepositoryNode() == null) {
        // retrieve node
        rEditorInput.setRepositoryNode(null);
    }
    try {
        // see bug 1321
        item = (FileItem) rEditorInput.getItem();
        if (!rEditorInput.isReadOnly()) {
            if (getRepositoryFactory().getStatus(item).isPotentiallyEditable()) {
                item.getProperty().eAdapters().add(dirtyListener);
                repFactory.lock(item);
            }
        } else {
            rEditorInput.getFile().setReadOnly(true);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    rEditorInput.getFile().refreshLocal(IResource.DEPTH_ONE, null);
    super.doSetInput(rEditorInput);
    setName();
    // only for sql template
    if (item instanceof SQLPatternItem) {
        Workspace ws = (Workspace) ResourcesPlugin.getWorkspace();
        ws.broadcastBuildEvent(item, IResourceChangeEvent.POST_CHANGE, 1);
    }
}
Also used : RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryService(org.talend.repository.model.IRepositoryService) Workspace(org.eclipse.core.internal.resources.Workspace) IWorkspace(org.eclipse.core.resources.IWorkspace)

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