Example usage for org.eclipse.jdt.internal.core JavaElementDelta sourceAttached

List of usage examples for org.eclipse.jdt.internal.core JavaElementDelta sourceAttached

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core JavaElementDelta sourceAttached.

Prototype

public void sourceAttached(IJavaElement element) 

Source Link

Document

Creates the nested deltas resulting from a change operation.

Usage

From source file:org.jboss.tools.pde.sourcelookup.core.internal.utils.ClasspathUtils.java

License:Open Source License

public static void attachSource(final IPackageFragmentRoot fragment, final IPath newSourcePath,
        IProgressMonitor monitor) {//from  w  ww  . j  ava 2  s.c o  m
    try {
        if (fragment == null || fragment.getKind() != IPackageFragmentRoot.K_BINARY) {
            return;
        }
        if (!Objects.equals(fragment.getSourceAttachmentPath(), newSourcePath)) {
            // would be so cool if it refreshed the UI automatically
            fragment.attachSource(newSourcePath, null, monitor);
            // close the root so that source attachment cache is flushed. Else UI
            // won't update
            fragment.close();
            // we have to manually fire a delta to notify the UI about the source
            // attachment.
            JavaModelManager manager = JavaModelManager.getJavaModelManager();
            JavaElementDelta attachedSourceDelta = new JavaElementDelta(fragment.getJavaModel());
            attachedSourceDelta.sourceAttached(fragment);
            manager.getDeltaProcessor().fire(attachedSourceDelta, ElementChangedEvent.POST_CHANGE);
        }
    } catch (CoreException e) {
        // ignore
    }
}