Java Code Examples for org.eclipse.jdt.core.JavaCore#getClasspathContainer()

The following examples show how to use org.eclipse.jdt.core.JavaCore#getClasspathContainer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NativeLibrariesPropertyPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)));
		return null;
	}
	String containerName= container.getDescription();
	IStatus status= initializer.getAttributeStatus(containerPath, jproject, JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_not_supported, containerName));
		return null;
	}
	IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_read_only, containerName));
		fIsReadOnly= true;
		return entry;
	}
	Assert.isNotNull(entry);
	return entry;
}
 
Example 2
Source File: NewMavenBasedAppEngineProjectWizardTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
static IClasspathEntry[] getAppEngineServerRuntimeClasspathEntries(IProject project) {
  IJavaProject javaProject = JavaCore.create(project);
  IPath containerPath = new Path(
      "org.eclipse.jst.server.core.container/com.google.cloud.tools.eclipse.appengine.standard.runtimeClasspathProvider");
  try {
    for (IClasspathEntry entry : javaProject.getRawClasspath()) {
      if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
          && containerPath.isPrefixOf(entry.getPath())) {
        // resolve and return the entries
        IClasspathContainer container =
            JavaCore.getClasspathContainer(entry.getPath(), javaProject);
        return container.getClasspathEntries();
      }
    }
  } catch (JavaModelException ex) {
    fail(ex.toString());
    /* NOTREACHED */
  }
  fail("AppEngine Server Runtime classpath container not found");
  return null;
}
 
Example 3
Source File: SourceAttacherJob.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
protected IStatus run(IProgressMonitor monitor) {
  Preconditions.checkState(getRule() != null);
  try {
    IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, javaProject);
    LibraryClasspathContainer newContainer = attachSource(container);

    if (newContainer != null) {
      JavaCore.setClasspathContainer(containerPath, new IJavaProject[]{ javaProject },
          new IClasspathContainer[]{ newContainer }, monitor);
      serializer.saveContainer(javaProject, newContainer);
    }
  } catch (Exception ex) {
    // it's not needed to be logged normally
    logger.log(Level.FINE, Messages.getString("SourceAttachmentFailed"), ex);
  }
  return Status.OK_STATUS;  // even if it fails, we should not display an error to the user
}
 
Example 4
Source File: JavadocConfigurationPropertyPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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) {
		setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)));
		return null;
	}
	String containerName= container.getDescription();
	IStatus status= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
		setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_not_supported, containerName));
		return null;
	}
	IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
		setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_read_only, containerName));
		fIsReadOnly= true;
		return entry;
	}
	Assert.isNotNull(entry);
	setDescription(PreferencesMessages.JavadocConfigurationPropertyPage_IsPackageFragmentRoot_description);
	return entry;
}
 
Example 5
Source File: BuildPathSupport.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void updateContainerClasspath(IJavaProject jproject, IPath containerPath, IClasspathEntry newEntry, String[] changedAttributes, IProgressMonitor monitor) throws CoreException {
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
	if (container == null) {
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, "Container " + containerPath + " cannot be resolved", null));  //$NON-NLS-1$//$NON-NLS-2$
	}
	IClasspathEntry[] entries= container.getClasspathEntries();
	IClasspathEntry[] newEntries= new IClasspathEntry[entries.length];
	for (int i= 0; i < entries.length; i++) {
		IClasspathEntry curr= entries[i];
		if (curr.getEntryKind() == newEntry.getEntryKind() && curr.getPath().equals(newEntry.getPath())) {
			newEntries[i]= getUpdatedEntry(curr, newEntry, changedAttributes, jproject);
		} else {
			newEntries[i]= curr;
		}
	}
	requestContainerUpdate(jproject, container, newEntries);
	monitor.worked(1);
}
 
Example 6
Source File: JavaSearchScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean isInsideJRE(IJavaElement element) {
	IPackageFragmentRoot root= (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
	if (root != null) {
		try {
			IClasspathEntry entry= root.getRawClasspathEntry();
			if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
				IClasspathContainer container= JavaCore.getClasspathContainer(entry.getPath(), root.getJavaProject());
				return container != null && container.getKind() == IClasspathContainer.K_DEFAULT_SYSTEM;
			}
			return false;
		} catch (JavaModelException e) {
			JavaPlugin.log(e);
		}
	}
	return true; // include JRE in doubt
}
 
Example 7
Source File: GWTRuntimeContainerInitializerTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public void testInitialize() throws Exception {
  // Start with gwt-user.jar and gwt-dev-PLAT.jar on the classpath for this
  // test
  removeGWTRuntimeFromTestProject();

  // Add the default GWT runtime to the test project (this implicitly calls
  // the GWTRuntimeContainerInitializer.intialize(...) method.
  IJavaProject project = getTestProject();
  GWTUpdateProjectSdkCommand command = new GWTUpdateProjectSdkCommand(
      project, null, GWTPreferences.getDefaultRuntime(),
      UpdateType.DEFAULT_CONTAINER, null);
  command.execute();
  JobsUtilities.waitForIdle();

  // Verify the bound classpath container
  IClasspathContainer container = JavaCore.getClasspathContainer(
      defaultRuntimePath, project);
  assertEquals(IClasspathContainer.K_APPLICATION, container.getKind());
  assertEquals(defaultRuntimePath, container.getPath());
}
 
Example 8
Source File: ClasspathUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Replace an {@link IClasspathEntry#CPE_CONTAINER} entry with the given
 * container ID, with its corresponding resolved classpath entries.
 *
 * @param javaProject java project
 * @param containerId container ID to replace
 * @return true if a container was replaced
 *
 * @throws JavaModelException
 */
public static boolean replaceContainerWithClasspathEntries(
    IJavaProject javaProject, String containerId) throws JavaModelException {
  IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
  int containerIndex = ClasspathUtilities.indexOfClasspathEntryContainer(
      classpathEntries, containerId);
  if (containerIndex != -1) {
    List<IClasspathEntry> newClasspathEntries = new ArrayList<IClasspathEntry>(
        Arrays.asList(classpathEntries));
    IClasspathEntry classpathContainerEntry = newClasspathEntries.remove(containerIndex);
    IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(
        classpathContainerEntry.getPath(), javaProject);
    if (classpathContainer != null) {
      newClasspathEntries.addAll(containerIndex,
          Arrays.asList(classpathContainer.getClasspathEntries()));
      ClasspathUtilities.setRawClasspath(javaProject, newClasspathEntries);
      return true;
    }
  }
  return false;
}
 
Example 9
Source File: JavaDocLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void convertContainer(IClasspathEntry entry, IJavaProject project, Map<IPath, String> oldLocationMap) {
	try {
		IClasspathContainer container= JavaCore.getClasspathContainer(entry.getPath(), project);
		if (container == null) {
			return;
		}

		IClasspathEntry[] entries= container.getClasspathEntries();
		boolean hasChange= false;
		for (int i= 0; i < entries.length; i++) {
			IClasspathEntry curr= entries[i];
			IClasspathEntry updatedEntry= getConvertedEntry(curr, project, oldLocationMap);
			if (updatedEntry != null) {
				entries[i]= updatedEntry;
				hasChange= true;
			}
		}
		if (hasChange) {
			BuildPathSupport.requestContainerUpdate(project, container, entries);
		}
	} catch (CoreException e) {
		// ignore
	}
}
 
Example 10
Source File: ImportNativeAppEngineStandardProjectTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static void verifyImportedProject(IProject project, IStatus updateStatus)
    throws JavaModelException {
  assertTrue("Update failed: " + updateStatus.getMessage(), updateStatus.isOK());
  assertFalse(CloudToolsEclipseProjectUpdater.hasOldContainers(project));

  // ensure the master-library container has been resolved by checking its contents
  IJavaProject javaProject = JavaCore.create(project);
  IClasspathContainer masterContainer =
      JavaCore.getClasspathContainer(BuildPath.MASTER_CONTAINER_PATH, javaProject);
  assertThat(masterContainer.getClasspathEntries(), arrayWithSize(greaterThan(0)));
}
 
Example 11
Source File: ClassPathContainer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ClassPathContainer(IJavaProject parent, IClasspathEntry entry) {
	super(parent);
	fClassPathEntry= entry;
	try {
		fContainer= JavaCore.getClasspathContainer(entry.getPath(), parent);
	} catch (JavaModelException e) {
		fContainer= null;
	}
}
 
Example 12
Source File: JavaElementLabels.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the styled label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 *
 * @since 3.4
 */
public static StyledString getStyledContainerEntryLabel(IPath containerPath, IJavaProject project) {
	try {
		IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
		String description= null;
		if (container != null) {
			description= container.getDescription();
		}
		if (description == null) {
			ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
			if (initializer != null) {
				description= initializer.getDescription(containerPath, project);
			}
		}
		if (description != null) {
			StyledString str= new StyledString(description);
			if (containerPath.segmentCount() > 0 && JavaRuntime.JRE_CONTAINER.equals(containerPath.segment(0))) {
				int index= description.indexOf('[');
				if (index != -1) {
					str.setStyle(index, description.length() - index, DECORATIONS_STYLE);
				}
			}
			return Strings.markLTR(str);
		}
	} catch (JavaModelException e) {
		// ignore
	}
	return new StyledString(BasicElementLabels.getPathLabel(containerPath, false));
}
 
Example 13
Source File: JavaElementLabels.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 * @throws JavaModelException when resolving of the container failed
 */
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException {
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
	if (container != null) {
		return Strings.markLTR(container.getDescription());
	}
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	if (initializer != null) {
		return Strings.markLTR(initializer.getDescription(containerPath, project));
	}
	return BasicElementLabels.getPathLabel(containerPath, false);
}
 
Example 14
Source File: GWTRuntimeContainerTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static IClasspathContainer getClasspathContainer(GwtSdk sdk,
    IJavaProject project, SdkClasspathContainer.Type containerType)
    throws JavaModelException {
  IPath containerPath = SdkClasspathContainer.computeContainerPath(
      GWTRuntimeContainer.CONTAINER_ID, sdk, containerType);
  IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(
      containerPath, project);
  JobsUtilities.waitForIdle();
  return classpathContainer;
}
 
Example 15
Source File: JavaElementLabels.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 * @throws JavaModelException when resolving of the container failed
 */
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException {
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
	if (container != null) {
		return org.eclipse.jdt.internal.core.manipulation.util.Strings.markLTR(container.getDescription());
	}
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	if (initializer != null) {
		return org.eclipse.jdt.internal.core.manipulation.util.Strings.markLTR(initializer.getDescription(containerPath, project));
	}
	return BasicElementLabels.getPathLabel(containerPath, false);
}
 
Example 16
Source File: ImportNativeAppEngineStandardProjectTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static boolean hasAppEngineApi(IProject project) throws JavaModelException {
  IJavaProject javaProject = JavaCore.create(project);
  IClasspathContainer masterContainer =
      JavaCore.getClasspathContainer(BuildPath.MASTER_CONTAINER_PATH, javaProject);

  for (IClasspathEntry entry : masterContainer.getClasspathEntries()) {
    if (entry.getPath().lastSegment().startsWith("appengine-api-1.0-sdk")) {
      return true;
    }
  }
  return false;
}
 
Example 17
Source File: ClassFileEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void createSourceAttachmentControls(Composite composite, IPackageFragmentRoot root) throws JavaModelException {
	IClasspathEntry entry;
	try {
		entry= JavaModelUtil.getClasspathEntry(root);
	} catch (JavaModelException ex) {
		if (ex.isDoesNotExist())
			entry= null;
		else
			throw ex;
	}
	IPath containerPath= null;

	if (entry == null || root.getKind() != IPackageFragmentRoot.K_BINARY) {
		createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSource, BasicElementLabels.getFileName( fFile)));
		return;
	}

	IJavaProject jproject= root.getJavaProject();
	boolean canEditEncoding= true;
	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, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_cannotconfigure, BasicElementLabels.getPathLabel(containerPath, false)));
			return;
		}
		String containerName= container.getDescription();
		IStatus status= initializer.getSourceAttachmentStatus(containerPath, jproject);
		if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
			createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_notsupported, containerName));
			return;
		}
		if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
			createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_readonly, containerName));
			return;
		}
		IStatus attributeStatus= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING);
		canEditEncoding= !(attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED || attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY);
		entry= JavaModelUtil.findEntryInContainer(container, root.getPath());
		Assert.isNotNull(entry);
	}


	Button button;

	IPath path= entry.getSourceAttachmentPath();
	if (path == null || path.isEmpty()) {
		String rootLabel= JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT);
		createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceAttachment, rootLabel));
		createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToAttach);
		createLabel(composite, null);

		button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_attachSource);

	} else {
		createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceInAttachment, BasicElementLabels.getFileName(fFile)));
		createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToChange);
		createLabel(composite, null);

		button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_changeAttachedSource);
	}

	button.addSelectionListener(getButtonListener(entry, containerPath, jproject, canEditEncoding));
}
 
Example 18
Source File: CPListElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public CPListElement(Object parent, IJavaProject project, int entryKind, IPath path, boolean newElement, IResource res, IPath linkTarget) {
	fProject= project;

	fEntryKind= entryKind;
	fPath= path;
	fOrginalPath= newElement ? null : path;
	fLinkTarget= linkTarget;
	fOrginalLinkTarget= linkTarget;
	fChildren= new ArrayList<Object>();
	fResource= res;
	fIsExported= false;

	fIsMissing= false;
	fCachedEntry= null;
	fParentContainer= parent;

	switch (entryKind) {
		case IClasspathEntry.CPE_SOURCE:
			createAttributeElement(OUTPUT, null, true);
			createAttributeElement(INCLUSION, new Path[0], true);
			createAttributeElement(EXCLUSION, new Path[0], true);
			createAttributeElement(NATIVE_LIB_PATH, null, false);
			createAttributeElement(IGNORE_OPTIONAL_PROBLEMS, null, false);
			break;
		case IClasspathEntry.CPE_LIBRARY:
		case IClasspathEntry.CPE_VARIABLE:
			createAttributeElement(SOURCEATTACHMENT, null, true);
			createAttributeElement(JAVADOC, null, false);
			createAttributeElement(SOURCE_ATTACHMENT_ENCODING, null, false);
			createAttributeElement(NATIVE_LIB_PATH, null, false);
			createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
			break;
		case IClasspathEntry.CPE_PROJECT:
			createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
			createAttributeElement(COMBINE_ACCESSRULES, Boolean.FALSE, true); // not rendered
			createAttributeElement(NATIVE_LIB_PATH, null, false);
			break;
		case IClasspathEntry.CPE_CONTAINER:
			createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
			try {
				IClasspathContainer container= JavaCore.getClasspathContainer(fPath, fProject);
				if (container != null) {
					IClasspathEntry[] entries= container.getClasspathEntries();
					if (entries != null) { // catch invalid container implementation
						for (int i= 0; i < entries.length; i++) {
							IClasspathEntry entry= entries[i];
							if (entry != null) {
								CPListElement curr= createFromExisting(this, entry, fProject);
								fChildren.add(curr);
							} else {
								JavaPlugin.logErrorMessage("Null entry in container '" + fPath + "'");  //$NON-NLS-1$//$NON-NLS-2$
							}
						}
					} else {
						JavaPlugin.logErrorMessage("container returns null as entries: '" + fPath + "'");  //$NON-NLS-1$//$NON-NLS-2$
					}
				}
			} catch (JavaModelException e) {
			}
			createAttributeElement(NATIVE_LIB_PATH, null, false);
			break;
		default:
	}
}
 
Example 19
Source File: UserLibraryPreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Constructor for ClasspathVariablesPreferencePage
 */
public UserLibraryPreferencePage() {
	setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore());
	fDummyProject= createPlaceholderProject();

	fAttributeDescriptors= JavaPlugin.getDefault().getClasspathAttributeConfigurationDescriptors();

	// title only used when page is shown programatically
	setTitle(PreferencesMessages.UserLibraryPreferencePage_title);
	setDescription(PreferencesMessages.UserLibraryPreferencePage_description);
	noDefaultAndApplyButton();

	fDialogSettings= JavaPlugin.getDefault().getDialogSettings();

	UserLibraryAdapter adapter= new UserLibraryAdapter();
	String[] buttonLabels= new String[] {
			PreferencesMessages.UserLibraryPreferencePage_libraries_new_button,
			PreferencesMessages.UserLibraryPreferencePage_libraries_edit_button,
			PreferencesMessages.UserLibraryPreferencePage_libraries_addjar_button,
			PreferencesMessages.UserLibraryPreferencePage_libraries_addexternaljar_button,
			PreferencesMessages.UserLibraryPreferencePage_libraries_remove_button,
			null,
			PreferencesMessages.UserLibraryPreferencePage_UserLibraryPreferencePage_libraries_up_button,
			PreferencesMessages.UserLibraryPreferencePage_UserLibraryPreferencePage_libraries_down_button,
			null,

			PreferencesMessages.UserLibraryPreferencePage_libraries_load_button,
			PreferencesMessages.UserLibraryPreferencePage_libraries_save_button
	};

	fLibraryList= new TreeListDialogField<CPUserLibraryElement>(adapter, buttonLabels, new CPListLabelProvider());
	fLibraryList.setLabelText(PreferencesMessages.UserLibraryPreferencePage_libraries_label);

	String[] names= JavaCore.getUserLibraryNames();
	ArrayList<CPUserLibraryElement> elements= new ArrayList<CPUserLibraryElement>();

	for (int i= 0; i < names.length; i++) {
		IPath path= new Path(JavaCore.USER_LIBRARY_CONTAINER_ID).append(names[i]);
		try {
			IClasspathContainer container= JavaCore.getClasspathContainer(path, fDummyProject);
			elements.add(new CPUserLibraryElement(names[i], container, fDummyProject));
		} catch (JavaModelException e) {
			JavaPlugin.log(e);
			// ignore
		}
	}
	fLibraryList.setElements(elements);
	fLibraryList.setViewerComparator(new CPListElementSorter());

	doSelectionChanged(fLibraryList); //update button enable state
}
 
Example 20
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Helper method that tests if an classpath entry can be found in a
 * container. <code>null</code> is returned if the entry can not be found
 * or if the container does not allows the configuration of source
 * attachments
 * @param jproject The container's parent project
 * @param containerPath The path of the container
 * @param libPath The path of the library to be found
 * @return IClasspathEntry A classpath entry from the container of
 * <code>null</code> if the container can not be modified.
 * @throws JavaModelException thrown if accessing the container failed
 */
public static IClasspathEntry getClasspathEntryToEdit(IJavaProject jproject, IPath containerPath, IPath libPath) throws JavaModelException {
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	if (container != null && initializer != null && initializer.canUpdateClasspathContainer(containerPath, jproject)) {
		return findEntryInContainer(container, libPath);
	}
	return null; // attachment not possible
}