Search in sources :

Example 1 with JobEditorInput

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

the class AbstractTalendEditor method setInput.

// ------------------------------------------------------------------------
// Overridden from EditorPart
@Override
protected void setInput(final IEditorInput input) {
    super.setInput(input);
    try {
        if (input instanceof JobEditorInput) {
            // process = ((JobEditorInput) input).getLoadedProcess();
            projectName = CorePlugin.getDefault().getProxyRepositoryFactory().getProject(((RepositoryEditorInput) input).getItem()).getLabel();
        }
    } catch (Exception e) {
        MessageBoxExceptionHandler.process(e);
        return;
    }
    IProcess2 process = getProcess();
    if (process != null && process.getProperty().getItem() instanceof ProcessItem) {
        currentJobResource.setJobInfo(new JobInfo((ProcessItem) process.getProperty().getItem(), process.getProperty(), process.getContextManager().getDefaultContext().getName()));
        currentJobResource.setProjectName(projectName);
        JobResourceManager.getInstance().addProtection(this);
    }
}
Also used : JobEditorInput(org.talend.core.ui.editor.JobEditorInput) ProcessItem(org.talend.core.model.properties.ProcessItem) JobInfo(org.talend.core.model.process.JobInfo) IProcess2(org.talend.core.model.process.IProcess2) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 2 with JobEditorInput

use of org.talend.core.ui.editor.JobEditorInput 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 3 with JobEditorInput

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

the class AbstractMultiPageTalendEditor method turnToJobScriptPage.

protected void turnToJobScriptPage(int newPageIndex) {
    if (jobletEditor != getEditor(newPageIndex)) {
        return;
    }
    ICreateXtextProcessService convertJobtoScriptService = CorePlugin.getDefault().getCreateXtextProcessService();
    try {
        final String scriptValue = convertJobtoScriptService.convertJobtoScript(getProcess().saveXmlFile());
        IFile file = (IFile) jobletEditor.getEditorInput().getAdapter(IResource.class);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(scriptValue.getBytes());
        if (file.exists()) {
            jobletEditor.getDocumentProvider().getDocument(jobletEditor.getEditorInput()).set(scriptValue);
            boolean isProcessReadOnly = ((JobEditorInput) getEditor(0).getEditorInput()).isReadOnly();
            IProxyRepositoryFactory rFactory = ProxyRepositoryFactory.getInstance();
            if (isProcessReadOnly || rFactory.isUserReadOnlyOnCurrentProject()) {
                IDocumentProvider provider = jobletEditor.getDocumentProvider();
                Class p = provider.getClass();
                Class[] type = new Class[1];
                type[0] = Boolean.TYPE;
                Object[] para = new Object[1];
                para[0] = Boolean.TRUE;
                Method method = p.getMethod("setReadOnly", type);
                method.invoke(provider, para);
            }
            //$NON-NLS-1$
            IAction action = jobletEditor.getAction("FoldingRestore");
            action.run();
            jobletEditor.doSave(null);
        } else {
            file.create(byteArrayInputStream, true, null);
        }
        if (propertyListener == null) {
            propertyListener = new IPropertyListener() {

                @Override
                public void propertyChanged(Object source, int propId) {
                    if (source instanceof IEditorPart && ((IEditorPart) source).isDirty()) {
                        getProcess().setProcessModified(true);
                        getProcess().setNeedRegenerateCode(true);
                    }
                }
            };
            jobletEditor.addPropertyListener(propertyListener);
        }
    } catch (PartInitException e) {
        ExceptionHandler.process(e);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } catch (SecurityException e) {
        ExceptionHandler.process(e);
    } catch (NoSuchMethodException e) {
        ExceptionHandler.process(e);
    } catch (IllegalArgumentException e) {
        ExceptionHandler.process(e);
    } catch (IllegalAccessException e) {
        ExceptionHandler.process(e);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    }
    changeContextsViewStatus(false);
}
Also used : IFile(org.eclipse.core.resources.IFile) ICreateXtextProcessService(org.talend.core.services.ICreateXtextProcessService) IPropertyListener(org.eclipse.ui.IPropertyListener) PartInitException(org.eclipse.ui.PartInitException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IAction(org.eclipse.jface.action.IAction) Method(java.lang.reflect.Method) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) InvocationTargetException(java.lang.reflect.InvocationTargetException) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PlatformObject(org.eclipse.core.runtime.PlatformObject) IResource(org.eclipse.core.resources.IResource)

Example 4 with JobEditorInput

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

the class OpenExistVersionProcessAction method getCorrespondingEditor.

@Override
protected IEditorPart getCorrespondingEditor(IRepositoryNode node) {
    IEditorReference[] eidtors = getActivePage().getEditorReferences();
    for (IEditorReference eidtor : eidtors) {
        try {
            IEditorInput input = eidtor.getEditorInput();
            if (!(input instanceof JobEditorInput)) {
                continue;
            }
            JobEditorInput repositoryInput = (JobEditorInput) input;
            checkUnLoadedNodeForProcess(repositoryInput);
            if (repositoryInput.getItem().equals(node.getObject().getProperty().getItem())) {
                IPath path = repositoryInput.getFile().getLocation();
                return eidtor.getEditor(false);
            }
        } catch (PartInitException e) {
            continue;
        }
    }
    return null;
}
Also used : JobEditorInput(org.talend.core.ui.editor.JobEditorInput) IEditorReference(org.eclipse.ui.IEditorReference) IPath(org.eclipse.core.runtime.IPath) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 5 with JobEditorInput

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

the class ContextsView method handleDropContext.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.ui.context.view.AbstractContextView#handleDrop(org.talend.core.model.properties.ContextItem,
     * java.util.Set, org.eclipse.ui.IEditorInput)
     */
@Override
protected boolean handleDropContext(ContextItem contextItem, Set<String> contextSet, IEditorInput editorInput) {
    boolean created = false;
    if (editorInput instanceof JobEditorInput) {
        JobEditorInput jobInput = (JobEditorInput) editorInput;
        IProcess2 process = jobInput.getLoadedProcess();
        IContextManager contextManager = process.getContextManager();
        // context group will reflect absolutely if no context variable in contextViewer
        if (!ConnectionContextHelper.containsVariable(contextManager)) {
            // for bug 15608
            ConnectionContextHelper.addContextVarForJob(process, contextItem, contextManager);
            // ConnectionContextHelper.checkAndAddContextsVarDND(contextItem,
            // contextManager);
            created = true;
        } else {
            Set<String> addedContext = ConnectionContextHelper.checkAndAddContextVariables(contextItem, contextSet, contextManager, false);
            if (addedContext != null && addedContext.size() > 0) {
                ConnectionContextHelper.addContextVarForJob(process, contextItem, contextSet);
                created = true;
            }
        }
    }
    return created;
}
Also used : JobEditorInput(org.talend.core.ui.editor.JobEditorInput) IProcess2(org.talend.core.model.process.IProcess2) IContextManager(org.talend.core.model.process.IContextManager)

Aggregations

JobEditorInput (org.talend.core.ui.editor.JobEditorInput)15 IProcess2 (org.talend.core.model.process.IProcess2)8 ProcessItem (org.talend.core.model.properties.ProcessItem)8 Item (org.talend.core.model.properties.Item)6 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)5 PersistenceException (org.talend.commons.exception.PersistenceException)5 IRepositoryNode (org.talend.repository.model.IRepositoryNode)5 CoreException (org.eclipse.core.runtime.CoreException)4 IEditorPart (org.eclipse.ui.IEditorPart)4 PartInitException (org.eclipse.ui.PartInitException)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 IEditorInput (org.eclipse.ui.IEditorInput)3 IContextManager (org.talend.core.model.process.IContextManager)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2