Example usage for org.eclipse.jdt.core ClasspathContainerInitializer getSourceAttachmentStatus

List of usage examples for org.eclipse.jdt.core ClasspathContainerInitializer getSourceAttachmentStatus

Introduction

In this page you can find the example usage for org.eclipse.jdt.core ClasspathContainerInitializer getSourceAttachmentStatus.

Prototype

public IStatus getSourceAttachmentStatus(IPath containerPath, IJavaProject project) 

Source Link

Document

Returns the source attachment attribute status according to this initializer.

Usage

From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java

License:Open Source License

private IStatus evaluateContainerChildStatus(CPListElementAttribute attrib) {
    if (fProject != null) {
        ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(fPath.segment(0));
        if (initializer != null && initializer.canUpdateClasspathContainer(fPath, fProject)) {
            if (attrib.isBuiltIn()) {
                if (CPListElement.SOURCEATTACHMENT.equals(attrib.getKey())) {
                    return initializer.getSourceAttachmentStatus(fPath, fProject);
                } else if (CPListElement.ACCESSRULES.equals(attrib.getKey())) {
                    return initializer.getAccessRulesStatus(fPath, fProject);
                }//  www  .j a va2s .  co m
            } else {
                return initializer.getAttributeStatus(fPath, fProject, attrib.getKey());
            }
        }
        return new Status(IStatus.ERROR, "at.bestsolution.javafx.ide.jdt", //$NON-NLS-1$
                ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY, "", null);
    }
    return null;
}

From source file:com.drgarbage.bytecodevisualizer.editors.NoSourceViewer.java

License:Apache License

private void createSourceAttachmentControls(Composite composite, IPackageFragmentRoot root)
        throws JavaModelException {
    IClasspathEntry entry;//from   ww w .j a  v  a  2s.  co  m
    try {
        entry = root.getRawClasspathEntry();
    } catch (JavaModelException ex) {
        if (ex.isDoesNotExist())
            entry = null;
        else
            throw ex;
    }
    IPath containerPath = null;

    if (entry == null || root.getKind() != IPackageFragmentRoot.K_BINARY) {
        String s = CoreMessages.SourceAttachmentForm_message_noSource;
        createLabel(composite, MessageFormat.format(s, new Object[] { fFile.getElementName() }));
        return;
    }

    IJavaProject jproject = root.getJavaProject();
    if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        containerPath = entry.getPath();
        ClasspathContainerInitializer initializer = JavaCore
                .getClasspathContainerInitializer(containerPath.segment(0));
        IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, jproject);
        if (initializer == null || container == null) {
            createLabel(composite, MessageFormat.format(CoreMessages.SourceAttachmentForm_cannotconfigure,
                    new Object[] { containerPath.toString() }));
            return;
        }
        String containerName = container.getDescription();
        IStatus status = initializer.getSourceAttachmentStatus(containerPath, jproject);
        if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
            createLabel(composite, MessageFormat.format(CoreMessages.SourceAttachmentForm_notsupported,
                    new Object[] { containerName }));
            return;
        }
        if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
            createLabel(composite, MessageFormat.format(CoreMessages.SourceAttachmentForm_readonly,
                    new Object[] { containerName }));
            return;
        }
        entry = JavaModelUtil.findEntryInContainer(container, root.getPath());
        Assert.isNotNull(entry);
    }

    Button button;

    String msg = null;
    String btnText = null;

    IPath path = entry.getSourceAttachmentPath();
    if (path == null || path.isEmpty()) {
        msg = MessageFormat.format(CoreMessages.SourceAttachmentForm_message_noSourceAttachment,
                new Object[] { root.getElementName() });
        btnText = CoreMessages.SourceAttachmentForm_button_attachSource;
    } else {
        msg = MessageFormat.format(CoreMessages.SourceAttachmentForm_message_noSourceInAttachment,
                new Object[] { fFile.getElementName() });
        btnText = CoreMessages.SourceAttachmentForm_button_changeAttachedSource;
    }

    createLabel(composite, msg);
    createLabel(composite, CoreMessages.SourceAttachmentForm_message_pressButtonToAttach);
    createLabel(composite, null);

    button = createButton(composite, btnText);
    button.addSelectionListener(createButtonListener(entry, containerPath, jproject));
}

From source file:org.jboss.tools.as.sourcelookup.ui.actions.AttachSourcesActionDelegate.java

License:Open Source License

private void attachSource(IPackageFragmentRoot fragment, IPath newSourcePath) {
    try {//w  ww .ja va  2 s.c  o m
        if (fragment == null || fragment.getKind() != IPackageFragmentRoot.K_BINARY) {
            return;
        }
        IPath containerPath = null;
        IJavaProject jproject = fragment.getJavaProject();
        IClasspathEntry entry = fragment.getRawClasspathEntry();
        if (entry == null) {
            entry = JavaCore.newLibraryEntry(fragment.getPath(), null, null);
        } else {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                containerPath = entry.getPath();
                ClasspathContainerInitializer initializer = JavaCore
                        .getClasspathContainerInitializer(containerPath.segment(0));
                IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, jproject);
                if (initializer == null || container == null) {
                    return;
                }
                IStatus status = initializer.getSourceAttachmentStatus(containerPath, jproject);
                if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
                    return;
                }
                if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
                    return;
                }
                entry = JavaModelUtil.findEntryInContainer(container, fragment.getPath());
                if (entry == null) {
                    return;
                }
            }
        }
        IClasspathEntry entry1;
        CPListElement elem = CPListElement.createFromExisting(entry, null);
        elem.setAttribute(CPListElement.SOURCEATTACHMENT, newSourcePath);
        entry1 = elem.getClasspathEntry();
        if (entry1.equals(entry)) {
            return;
        }
        IClasspathEntry newEntry = entry1;
        String[] changedAttributes = { CPListElement.SOURCEATTACHMENT };
        BuildPathSupport.modifyClasspathEntry(null, newEntry, changedAttributes, jproject, containerPath,
                newEntry.getReferencingEntry() != null, new NullProgressMonitor());
    } catch (CoreException e) {
        // ignore
    }
}

From source file:org.jboss.tools.maven.sourcelookup.ui.internal.util.SourceLookupUtil.java

License:Open Source License

public static void attachSource(final IPackageFragmentRoot fragment, final IPath newSourcePath,
        boolean displayDialog) {
    try {/*from w w  w.  j a v  a 2  s.  c  o  m*/
        if (fragment == null || fragment.getKind() != IPackageFragmentRoot.K_BINARY) {
            return;
        }
        String value = SourceLookupActivator.getDefault().getAutoAddSourceAttachment();
        if (SourceLookupActivator.AUTO_ADD_JBOSS_SOURCE_ATTACHMENT_NEVER.equals(value)) {
            return;
        }
        if (displayDialog && SourceLookupActivator.AUTO_ADD_JBOSS_SOURCE_ATTACHMENT_PROMPT.equals(value)) {
            final boolean[] attach = new boolean[1];
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    attach[0] = promptToAddSourceAttachment(fragment.getElementName(),
                            newSourcePath.toString());
                }
            });
            if (!attach[0]) {
                return;
            }
            ;
        }
        IPath containerPath = null;
        IJavaProject jproject = fragment.getJavaProject();
        IClasspathEntry entry = fragment.getRawClasspathEntry();
        if (entry == null) {
            entry = JavaCore.newLibraryEntry(fragment.getPath(), null, null);
        } else {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                containerPath = entry.getPath();
                ClasspathContainerInitializer initializer = JavaCore
                        .getClasspathContainerInitializer(containerPath.segment(0));
                IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, jproject);
                if (initializer == null || container == null) {
                    return;
                }
                IStatus status = initializer.getSourceAttachmentStatus(containerPath, jproject);
                if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
                    return;
                }
                if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
                    return;
                }
                entry = JavaModelUtil.findEntryInContainer(container, fragment.getPath());
                if (entry == null) {
                    return;
                }
            }
        }
        IClasspathEntry entry1;
        CPListElement elem = CPListElement.createFromExisting(entry, null);
        elem.setAttribute(CPListElement.SOURCEATTACHMENT, newSourcePath);
        entry1 = elem.getClasspathEntry();
        if (entry1.equals(entry)) {
            return;
        }
        IClasspathEntry newEntry = entry1;
        String[] changedAttributes = { CPListElement.SOURCEATTACHMENT };
        BuildPathSupport.modifyClasspathEntry(null, newEntry, changedAttributes, jproject, containerPath,
                newEntry.getReferencingEntry() != null, new NullProgressMonitor());
    } catch (CoreException e) {
        // ignore
    }
}