Search in sources :

Example 11 with FileStoreEditorInput

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

the class CpuDumpEditor method init.

/*
     * @see MultiPageEditorPart#init(IEditorSite, IEditorInput)
     */
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    cpuModel = new CpuModelFactory().createCpuModel();
    cpuModel.addModelChangeListener(new ICpuModelChangeListener() {

        @Override
        public void modelChanged(CpuModelEvent event) {
            if (event.state == CpuModelState.CallersCalleesTargetChanged) {
                refresh();
                if (cpuModel.getCallersCalleesTarget() != null) {
                    showCallerCalleeTab();
                }
            }
        }
    });
    setPartName(input.getName());
    if (input instanceof IFileEditorInput) {
        String filePath = ((IFileEditorInput) input).getFile().getRawLocation().toOSString();
        loadDumpFile(filePath);
    } else if (input instanceof FileStoreEditorInput) {
        String filePath = ((FileStoreEditorInput) input).getURI().getPath();
        loadDumpFile(filePath);
    }
}
Also used : ICpuModelChangeListener(org.talend.designer.runtime.visualization.internal.core.cpu.ICpuModelChangeListener) IFileEditorInput(org.eclipse.ui.IFileEditorInput) CpuModelFactory(org.talend.designer.runtime.visualization.internal.core.cpu.CpuModelFactory) CpuModelEvent(org.talend.designer.runtime.visualization.internal.core.cpu.CpuModelEvent) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 12 with FileStoreEditorInput

use of org.eclipse.ui.ide.FileStoreEditorInput 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

FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)12 FileEditorInput (org.eclipse.ui.part.FileEditorInput)8 IFile (org.eclipse.core.resources.IFile)7 File (java.io.File)6 CoreException (org.eclipse.core.runtime.CoreException)6 IEditorInput (org.eclipse.ui.IEditorInput)4 URI (java.net.URI)3 IFileStore (org.eclipse.core.filesystem.IFileStore)3 FileDialog (org.eclipse.swt.widgets.FileDialog)3 Shell (org.eclipse.swt.widgets.Shell)3 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)2 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IFileEditorInput (org.eclipse.ui.IFileEditorInput)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1