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