KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > wizard > library > 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.j2ee.persistence.wizard.library;
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
27 import org.netbeans.spi.project.libraries.LibraryImplementation;
28
29
30 /**
31  * copy of class from j2seplatform
32  */

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