Package org.nodeclipse.enide.editors.jade.editors

Source Code of org.nodeclipse.enide.editors.jade.editors.NodeDocumentProvider

package org.nodeclipse.enide.editors.jade.editors;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.FileDocumentProvider;
import org.nodeclipse.enide.editors.jade.highlight.JadePartitionScanner;

public class NodeDocumentProvider extends FileDocumentProvider {

    @Override
    protected IDocument createDocument(Object element) throws CoreException {
        IDocument doc = super.createDocument(element);
        if (doc != null) {
            IDocumentPartitioner partitioner = new FastPartitioner(new JadePartitionScanner(), JadePartitionScanner.PARTITION_TYPES);
            partitioner.connect(doc);
            doc.setDocumentPartitioner(partitioner);
        }
        return doc;
    }

    /**
     * Alternative implementation of the method that does not require file to be
     * a physical file.
     */
    @Override
    public boolean isDeleted(Object element) {
        if (element instanceof IFileEditorInput) {
            IFileEditorInput input = (IFileEditorInput) element;

            IProject project = input.getFile().getProject();
            if (project != null && !project.exists()) {
                return true;
            }

            return !input.getFile().exists();
        }
        return super.isDeleted(element);
    }

}
TOP

Related Classes of org.nodeclipse.enide.editors.jade.editors.NodeDocumentProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.