Search in sources :

Example 96 with IEditorInput

use of org.eclipse.ui.IEditorInput in project tdi-studio-se by Talend.

the class JobLaunchShortcut method launch.

/**
     * Locates a launchable entity in the given active editor, and launches an application in the specified mode.
     * 
     * @see org.eclipse.debug.ui.ILaunchShortcut#launch(org.eclipse.ui.IEditorPart, java.lang.String)
     * 
     * @param editor the active editor in the workbench
     * @param mode one of the launch modes defined by the launch manager
     * @see org.eclipse.debug.core.ILaunchManager
     */
@Override
public void launch(IEditorPart editor, String mode) {
    IEditorInput input = editor.getEditorInput();
    if (input instanceof RepositoryEditorInput) {
        RepositoryEditorInput rInput = (RepositoryEditorInput) input;
        launch(rInput.getItem(), mode);
    }
}
Also used : RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IEditorInput(org.eclipse.ui.IEditorInput)

Example 97 with IEditorInput

use of org.eclipse.ui.IEditorInput in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method createPage2.

// create jobscript editor
protected void createPage2() {
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(ICreateXtextProcessService.class)) {
        return;
    }
    String scriptValue = "";
    try {
        IProject currentProject = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
        String jobScriptVersion = "";
        if (getEditorInput() != null && getEditorInput() instanceof RepositoryEditorInput) {
            Item item = ((RepositoryEditorInput) getEditorInput()).getItem();
            if (item != null) {
                Property property = item.getProperty();
                if (property != null) {
                    jobScriptVersion = "_" + property.getVersion();
                }
            }
        }
        IFile file = currentProject.getFolder("temp").getFile(getEditorInput().getName() + jobScriptVersion + "_job" + ".jobscript");
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(scriptValue.getBytes());
        if (file.exists()) {
            file.delete(true, null);
            file.create(byteArrayInputStream, true, null);
            file.setContents(byteArrayInputStream, 0, null);
        } else {
            file.create(byteArrayInputStream, true, null);
        }
        String pointId = "org.talend.metalanguage.jobscript.JobScriptForMultipage";
        // the way to get the xtextEditor programmly
        IEditorInput editorInput = new FileEditorInput(file);
        IExtensionPoint ep = RegistryFactory.getRegistry().getExtensionPoint("org.eclipse.ui.editors");
        IExtension[] extensions = ep.getExtensions();
        IExtension ex;
        IConfigurationElement confElem = null;
        for (IExtension extension : extensions) {
            ex = extension;
            if (ex.getContributor().getName().equals("org.talend.metalanguage.jobscript.ui")) {
                for (IConfigurationElement c : ex.getConfigurationElements()) {
                    if (c.getName().equals("editor") && c.getAttribute("id").equals(pointId)) {
                        confElem = c;
                        break;
                    }
                }
            }
        }
        if (confElem != null) {
            jobletEditor = (AbstractDecoratedTextEditor) confElem.createExecutableExtension("class");
            if (jobletEditor != null) {
                int index = addPage(jobletEditor, editorInput);
                setPageText(index, "Jobscript");
            }
        }
    } catch (PartInitException e) {
        ExceptionHandler.process(e);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
}
Also used : RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IFile(org.eclipse.core.resources.IFile) ICreateXtextProcessService(org.talend.core.services.ICreateXtextProcessService) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IProject(org.eclipse.core.resources.IProject) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IExtension(org.eclipse.core.runtime.IExtension) FileEditorInput(org.eclipse.ui.part.FileEditorInput) PersistenceException(org.talend.commons.exception.PersistenceException) PartInitException(org.eclipse.ui.PartInitException) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IEditorInput(org.eclipse.ui.IEditorInput)

Example 98 with IEditorInput

use of org.eclipse.ui.IEditorInput in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method createPage1.

/**
     * Creates page 1 of the multi-page editor, which allows you to change the font used in page 2.
     */
protected void createPage1() {
    IProcess2 process = getProcess();
    codeEditor = CodeEditorFactory.getInstance().getCodeEditor(getCurrentLang(), process);
    processor = ProcessorUtilities.getProcessor(process, process.getProperty(), process.getContextManager().getDefaultContext());
    if (processor instanceof IJavaBreakpointListener) {
        JDIDebugModel.addJavaBreakpointListener((IJavaBreakpointListener) processor);
    }
    processor.setProcessorStates(IProcessor.STATES_EDIT);
    if (codeEditor instanceof ISyntaxCheckableEditor) {
        processor.setSyntaxCheckableEditor((ISyntaxCheckableEditor) codeEditor);
    }
    if (useCodeView) {
        try {
            IEditorInput editorInput = createFileEditorInput();
            if (!(process.getProperty().getItem() instanceof ProcessItem)) {
                // shouldn't work for joblet
                editorInput = new JobletCodeEditInput();
            }
            int index = addPage(codeEditor, editorInput);
            // init Syntax Validation.
            //$NON-NLS-1$
            setPageText(index, "Code");
        } catch (PartInitException pie) {
            // pie.printStackTrace();
            ExceptionHandler.process(pie);
        }
    }
    if (DesignerPlugin.getDefault().getPreferenceStore().getBoolean(TalendDesignerPrefConstants.GENERATE_CODE_WHEN_OPEN_JOB)) {
        generateCode();
    }
}
Also used : ISyntaxCheckableEditor(org.talend.designer.core.ISyntaxCheckableEditor) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IProcess2(org.talend.core.model.process.IProcess2) PartInitException(org.eclipse.ui.PartInitException) IJavaBreakpointListener(org.eclipse.jdt.debug.core.IJavaBreakpointListener) IEditorInput(org.eclipse.ui.IEditorInput) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 99 with IEditorInput

use of org.eclipse.ui.IEditorInput in project tdi-studio-se by Talend.

the class ComponentChooseDialog method createContext.

private void createContext(List<Object> sourceList) {
    if (sourceList.size() == 0) {
        return;
    }
    boolean created = false;
    for (Object source : sourceList) {
        if (source instanceof RepositoryNode) {
            RepositoryNode sourceNode = (RepositoryNode) source;
            Item item = sourceNode.getObject().getProperty().getItem();
            if (item instanceof ContextItem) {
                ContextItem contextItem = (ContextItem) item;
                EList context = contextItem.getContext();
                Set<String> contextSet = new HashSet<String>();
                Iterator iterator = context.iterator();
                while (iterator.hasNext()) {
                    Object obj = iterator.next();
                    if (obj instanceof ContextTypeImpl) {
                        EList contextParameters = ((ContextTypeImpl) obj).getContextParameter();
                        Iterator contextParas = contextParameters.iterator();
                        while (contextParas.hasNext()) {
                            ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
                            String name = contextParameterType.getName();
                            contextSet.add(name);
                        }
                    }
                }
                IEditorInput editorInput = editor.getEditorInput();
                if (editorInput instanceof JobEditorInput) {
                    JobEditorInput jobInput = (JobEditorInput) editorInput;
                    IProcess2 process = jobInput.getLoadedProcess();
                    IContextManager contextManager = process.getContextManager();
                    List<IContext> listContext = contextManager.getListContext();
                    // 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);
                    Set<String> addedVars = ConnectionContextHelper.checkAndAddContextVariables(contextItem, contextSet, process.getContextManager(), false);
                    if (addedVars != null && !addedVars.isEmpty() && !ConnectionContextHelper.isAddContextVar(contextItem, contextManager, contextSet)) {
                        // show
                        Map<String, Set<String>> addedVarsMap = new HashMap<String, Set<String>>();
                        addedVarsMap.put(item.getProperty().getLabel(), contextSet);
                        if (ConnectionContextHelper.showContextdialog(process, contextItem, process.getContextManager(), addedVarsMap, contextSet)) {
                            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;
                // }
                // }
                }
            }
        }
    }
    if (created) {
        RepositoryPlugin.getDefault().getDesignerCoreService().switchToCurContextsView();
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) IContext(org.talend.core.model.process.IContext) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ContextParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) RulesItem(org.talend.core.model.properties.RulesItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) FileItem(org.talend.core.model.properties.FileItem) EList(org.eclipse.emf.common.util.EList) Iterator(java.util.Iterator) IProcess2(org.talend.core.model.process.IProcess2) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) ContextTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextTypeImpl) IContextManager(org.talend.core.model.process.IContextManager) IEditorInput(org.eclipse.ui.IEditorInput) HashSet(java.util.HashSet)

Example 100 with IEditorInput

use of org.eclipse.ui.IEditorInput in project tdi-studio-se by Talend.

the class InfoPage method doSave.

/**
     * Saves the changed editor contents.
     * 
     * @param monitor The progress monitor
     */
protected void doSave(IProgressMonitor monitor) {
    IEditorInput input = editor.getEditorInput();
    IFile resourceFile = null;
    File file = null;
    InputStream inputStream = null;
    String comments = commentsText.getText();
    try {
        if (input instanceof IFileEditorInput) {
            resourceFile = ((IFileEditorInput) input).getFile();
            inputStream = new BufferedInputStream(resourceFile.getContents());
            file = resourceFile.getRawLocation().toFile();
        } else if (input instanceof FileStoreEditorInput) {
            file = new File(((FileStoreEditorInput) input).getURI().getPath());
            inputStream = new FileInputStream(file);
        } else {
            return;
        }
        Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream);
        Element root = document.getDocumentElement();
        //$NON-NLS-1$
        root.setAttribute("comments", comments);
        DOMSource source = new DOMSource(root);
        StreamResult result = new StreamResult(file);
        TransformerFactory.newInstance().newTransformer().transform(source, result);
        if (resourceFile != null) {
            resourceFile.refreshLocal(0, monitor);
        }
        lastComments = comments;
        editor.firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (CoreException e) {
        Activator.log(IStatus.ERROR, Messages.saveFileFailedMsg, e);
    } catch (SAXException e) {
        Activator.log(IStatus.ERROR, Messages.saveFileFailedMsg, e);
    } catch (IOException e) {
        Activator.log(IStatus.ERROR, Messages.saveFileFailedMsg, e);
    } catch (ParserConfigurationException e) {
        Activator.log(IStatus.ERROR, Messages.saveFileFailedMsg, e);
    } catch (TransformerException e) {
        Activator.log(IStatus.ERROR, Messages.saveFileFailedMsg, e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) IFile(org.eclipse.core.resources.IFile) StreamResult(javax.xml.transform.stream.StreamResult) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) CoreException(org.eclipse.core.runtime.CoreException) BufferedInputStream(java.io.BufferedInputStream) IFileEditorInput(org.eclipse.ui.IFileEditorInput) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) TransformerException(javax.xml.transform.TransformerException)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)135 IFile (org.eclipse.core.resources.IFile)38 IEditorPart (org.eclipse.ui.IEditorPart)37 PartInitException (org.eclipse.ui.PartInitException)31 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)28 CoreException (org.eclipse.core.runtime.CoreException)25 IFileEditorInput (org.eclipse.ui.IFileEditorInput)22 IDocument (org.eclipse.jface.text.IDocument)17 IEditorReference (org.eclipse.ui.IEditorReference)17 FileEditorInput (org.eclipse.ui.part.FileEditorInput)16 File (java.io.File)14 ArrayList (java.util.ArrayList)14 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)14 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)14 IResource (org.eclipse.core.resources.IResource)13 Shell (org.eclipse.swt.widgets.Shell)13 IViewPart (org.eclipse.ui.IViewPart)13 IPath (org.eclipse.core.runtime.IPath)12 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)11