1 19 20 package org.netbeans.modules.java.j2seplatform.libraries; 21 22 import javax.swing.AbstractListModel ; 23 import java.util.List ; 24 import java.util.ArrayList ; 25 import java.net.URL ; 26 import java.net.MalformedURLException ; 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 { 33 34 private LibraryImplementation impl; 35 private String volumeType; 36 private List content; 37 38 public VolumeContentModel (LibraryImplementation impl, String volumeType) { 39 this.impl = impl; 41 this.volumeType = volumeType; 42 List l = this.impl.getContent (volumeType); 43 if (l != null) { 44 this.content = new ArrayList (l); 45 } 46 else { 47 content = new ArrayList (); 48 } 49 } 50 51 public int getSize() { 52 return this.content.size(); 53 } 54 55 public Object getElementAt(int index) { 56 if (index < 0 || index >= this.content.size()) 57 throw new IllegalArgumentException (); 58 return this.content.get (index); 59 } 60 61 public void addResource (URL 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 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 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 |