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

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

Introduction

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

Prototype

int ATTRIBUTE_READ_ONLY

To view the source code for org.eclipse.jdt.core ClasspathContainerInitializer ATTRIBUTE_READ_ONLY.

Click Source Link

Document

Status code indicating that an attribute is not modifiable.

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);
                }//from  ww  w .j  a  va 2 s.  c o  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 w ww .j  av a 2  s  .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 {//from   w  w w  .j  a  v a2s.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 {//  w  ww .j av 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
    }
}

From source file:org.org.eclipse.dws.core.internal.jobs.UpdateJavadocAndSourcesJob.java

License:Open Source License

/**
 * Handle container entry.//from   w ww.  j  a v a  2s  . c  o  m
 * 
 * @param containerPath
 *            the container path
 * @param jproject
 *            the jproject
 * @param jarPath
 *            the jar path
 * 
 * @return the i classpath entry
 * 
 * @throws JavaModelException
 *             the java model exception
 */
@SuppressWarnings("restriction")
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath)
        throws JavaModelException {
    ClasspathContainerInitializer initializer = JavaCore
            .getClasspathContainerInitializer(containerPath.segment(0));
    IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, jproject);
    if (initializer == null || container == null) {
        logger.error("Container is not valid:" + containerPath);
        return null;
    }
    IStatus status = initializer.getAttributeStatus(containerPath, jproject,
            IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME);
    if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
        logger.error("Container does not support javadoc location attribute.");
        return null;
    }
    if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
        logger.error("Container's javadoc location attribute is read only.");
        return null;
    }
    IClasspathEntry entry = JavaModelUtil.findEntryInContainer(container, jarPath);
    Assert.isNotNull(entry);
    return entry;
}