2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.roots
.ui
.configuration
.libraryEditor
;
18 import com
.intellij
.openapi
.Disposable
;
19 import com
.intellij
.openapi
.roots
.OrderRootType
;
20 import com
.intellij
.openapi
.roots
.impl
.libraries
.LibraryEx
;
21 import com
.intellij
.openapi
.roots
.libraries
.Library
;
22 import com
.intellij
.openapi
.util
.Disposer
;
23 import com
.intellij
.openapi
.vfs
.VirtualFile
;
25 public class LibraryEditor
implements Disposable
{
26 private final Library myLibrary
;
27 private String myLibraryName
= null;
28 private Library
.ModifiableModel myModel
= null;
30 public LibraryEditor(Library library
) {
34 public String
getName() {
35 if (myLibraryName
!= null) {
38 return myLibrary
.getName();
41 public void dispose() {
44 public String
[] getUrls(OrderRootType rootType
) {
45 if (myModel
!= null) {
46 return myModel
.getUrls(rootType
);
48 return myLibrary
.getUrls(rootType
);
51 public VirtualFile
[] getFiles(OrderRootType rootType
) {
52 if (myModel
!= null) {
53 return myModel
.getFiles(rootType
);
55 return myLibrary
.getFiles(rootType
);
58 public void setName(String name
) {
60 getModel().setName(name
);
63 public void addRoot(String url
, OrderRootType rootType
) {
64 getModel().addRoot(url
, rootType
);
67 public void addRoot(VirtualFile file
, OrderRootType rootType
) {
68 getModel().addRoot(file
, rootType
);
71 public void addJarDirectory(String url
, boolean recursive
) {
72 getModel().addJarDirectory(url
, recursive
);
75 public void addJarDirectory(VirtualFile file
, boolean recursive
) {
76 getModel().addJarDirectory(file
, recursive
);
79 public void removeRoot(String url
, OrderRootType rootType
) {
80 while (getModel().removeRoot(url
, rootType
)) ;
83 public void commit() {
84 if (myModel
!= null) {
91 public Library
.ModifiableModel
getModel() {
92 if (myModel
== null) {
93 myModel
= myLibrary
.getModifiableModel();
94 Disposer
.register(this, myModel
);
99 public boolean hasChanges() {
100 return myModel
!= null && myModel
.isChanged();
103 public boolean isJarDirectory(String url
) {
104 if (myModel
!= null) {
105 return myModel
.isJarDirectory(url
);
107 return myLibrary
.isJarDirectory(url
);
110 public boolean allPathsValid(OrderRootType orderRootType
) {
111 if (myModel
!= null) {
112 return ((LibraryEx
.ModifiableModelEx
)myModel
).allPathsValid(orderRootType
);
114 return ((LibraryEx
)myLibrary
).allPathsValid(orderRootType
);
117 public boolean isValid(final String url
, final OrderRootType orderRootType
) {
118 if (myModel
!= null) {
119 return myModel
.isValid(url
, orderRootType
);
121 return myLibrary
.isValid(url
, orderRootType
);