1 11 package org.eclipse.pde.internal.core.build; 12 import java.io.PrintWriter ; 13 import java.util.StringTokenizer ; 14 import java.util.Vector ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.pde.core.IModelChangedEvent; 18 import org.eclipse.pde.core.ModelChangedEvent; 19 import org.eclipse.pde.core.build.IBuildEntry; 20 import org.eclipse.pde.internal.core.util.PropertiesUtil; 21 public class BuildEntry extends BuildObject implements IBuildEntry { 22 private Vector tokens = new Vector (); 23 private String name; 24 public BuildEntry(String name) { 25 this.name = name; 26 } 27 public void addToken(String token) throws CoreException { 28 ensureModelEditable(); 29 tokens.add(token); 30 getModel().fireModelChanged( 31 new ModelChangedEvent(getModel(), IModelChangedEvent.INSERT, 32 new Object []{token}, null)); 33 } 34 public String getName() { 35 return name; 36 } 37 public String [] getTokens() { 38 String [] result = new String [tokens.size()]; 39 tokens.copyInto(result); 40 return result; 41 } 42 public boolean contains(String token) { 43 return tokens.contains(token); 44 } 45 void processEntry(String value) { 46 StringTokenizer stok = new StringTokenizer (value, ","); while (stok.hasMoreTokens()) { 48 String token = stok.nextToken(); 49 token = token.trim(); 50 tokens.add(token); 51 } 52 } 53 public void removeToken(String token) throws CoreException { 54 ensureModelEditable(); 55 tokens.remove(token); 56 getModel().fireModelChanged( 57 new ModelChangedEvent(getModel(), IModelChangedEvent.REMOVE, 58 new Object []{token}, null)); 59 } 60 public void renameToken(String oldName, String newName) 61 throws CoreException { 62 ensureModelEditable(); 63 for (int i = 0; i < tokens.size(); i++) { 64 if (tokens.elementAt(i).toString().equals(oldName)) { 65 tokens.setElementAt(newName, i); 66 break; 67 } 68 } 69 getModel().fireModelChanged( 70 new ModelChangedEvent(getModel(), IModelChangedEvent.CHANGE, 71 new Object []{oldName}, null)); 72 } 73 public void setName(String name) throws CoreException { 74 ensureModelEditable(); 75 String oldValue = this.name; 76 this.name = name; 77 getModel().fireModelObjectChanged(this, P_NAME, oldValue, name); 78 } 79 public String toString() { 80 return name; 81 } 82 public void write(String indent, PrintWriter writer) { 83 PropertiesUtil.writeKeyValuePair(indent, name, tokens.elements(), 84 writer); 85 } 86 public void restoreProperty(String name, Object oldValue, Object newValue) 87 throws CoreException { 88 if (name.equals(P_NAME)) { 89 setName(newValue != null ? newValue.toString() : null); 90 } 91 } 92 } 93 | Popular Tags |