KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seplatform > libraries > VolumeContentModel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.j2seplatform.libraries;
21
22 import javax.swing.AbstractListModel JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.net.MalformedURLException JavaDoc;
27
28 import org.netbeans.spi.project.libraries.LibraryImplementation;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.ErrorManager;
31
32 class VolumeContentModel extends AbstractListModel JavaDoc/*<String>*/ {
33
34     private LibraryImplementation impl;
35     private String JavaDoc volumeType;
36     private List JavaDoc/*<URL>*/ content;
37
38     public VolumeContentModel (LibraryImplementation impl, String JavaDoc volumeType) {
39         //TODO: Should listen on the impl
40
this.impl = impl;
41         this.volumeType = volumeType;
42         List JavaDoc l = this.impl.getContent (volumeType);
43         if (l != null) {
44             this.content = new ArrayList JavaDoc(l);
45         }
46         else {
47             content = new ArrayList JavaDoc();
48         }
49     }
50
51     public int getSize() {
52         return this.content.size();
53     }
54
55     public Object JavaDoc getElementAt(int index) {
56         if (index < 0 || index >= this.content.size())
57             throw new IllegalArgumentException JavaDoc();
58         return this.content.get (index);
59     }
60
61     public void addResource (URL JavaDoc resource) {
62         this.content.add (resource);
63         int index = this.content.size()-1;
64         this.impl.setContent (this.volumeType, content);
65         this.fireIntervalAdded(this,index,index);
66     }
67
68     public void removeResources (int[] indices) {
69         for (int i=indices.length-1; i>=0; i--) {
70             this.content.remove(indices[i]);
71         }
72         this.impl.setContent (this.volumeType, content);
73         this.fireIntervalRemoved(this,indices[0],indices[indices.length-1]);
74     }
75
76     public void moveUp (int[] indices) {
77         for (int i=0; i< indices.length; i++) {
78             Object JavaDoc value = this.content.remove(indices[i]);
79             this.content.add(indices[i]-1,value);
80         }
81         this.impl.setContent (this.volumeType, content);
82         this.fireContentsChanged(this,indices[0]-1,indices[indices.length-1]);
83     }
84
85     public void moveDown (int[] indices) {
86         for (int i=indices.length-1; i>=0; i--) {
87             Object JavaDoc value = this.content.remove(indices[i]);
88             this.content.add(indices[i]+1,value);
89         }
90         this.impl.setContent (this.volumeType, content);
91         this.fireContentsChanged(this,indices[0],indices[indices.length-1]+1);
92     }
93
94 }
95
Popular Tags