move classpath panel to community
[fedora-idea.git] / platform / lang-impl / src / com / intellij / util / ui / classpath / GlobalLibraryReferenceElement.java
blobc02c59754706b2e37d70e80cbd8274395ba43129
1 package com.intellij.util.ui.classpath;
3 import org.jetbrains.annotations.NotNull;
4 import org.jetbrains.annotations.NonNls;
5 import org.jdom.Element;
6 import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
7 import com.intellij.openapi.roots.libraries.LibraryTable;
8 import com.intellij.openapi.roots.libraries.Library;
9 import com.intellij.openapi.roots.OrderRootType;
10 import com.intellij.openapi.vfs.VirtualFile;
12 import java.util.List;
13 import java.util.Collections;
14 import java.util.ArrayList;
15 import java.io.IOException;
17 /**
18 * @author nik
20 public class GlobalLibraryReferenceElement implements SimpleClasspathElement {
21 @NonNls public static final String NAME_ATTRIBUTE = "name";
22 @NonNls public static final String LEVEL_ATTRIBUTE = "level";
23 private final String myLibraryName;
25 public GlobalLibraryReferenceElement(@NotNull String libraryName) {
26 myLibraryName = libraryName;
29 public GlobalLibraryReferenceElement(@NotNull Element element) {
30 myLibraryName = element.getAttributeValue(NAME_ATTRIBUTE);
33 public String getPresentableName() {
34 return myLibraryName;
37 public void writeExternal(Element element) {
38 element.setAttribute(NAME_ATTRIBUTE, myLibraryName);
39 //todo[nik,greg] remote later. this is needed only for forward compatibility with version before 8
40 element.setAttribute(LEVEL_ATTRIBUTE, LibraryTablesRegistrar.APPLICATION_LEVEL);
43 public Library getLibrary() {
44 final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable();
45 return libraryTable.getLibraryByName(myLibraryName);
48 public String getLibraryName() {
49 return myLibraryName;
52 public void serialize(Element element) throws IOException {
53 element.setAttribute(NAME_ATTRIBUTE, myLibraryName);
54 //todo[nik,greg] remote later. this is needed only for forward compatibility with version before 8
55 element.setAttribute(LEVEL_ATTRIBUTE, LibraryTablesRegistrar.APPLICATION_LEVEL);
58 public List<String> getClassesRootUrls() {
59 final Library library = getLibrary();
60 if (library != null) {
61 final List<String> list = new ArrayList<String>();
62 for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
63 list.add(file.getUrl());
65 return list;
67 return Collections.emptyList();