001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.build;
011:
012: import java.io.PrintWriter;
013: import java.util.StringTokenizer;
014: import java.util.Vector;
015:
016: import org.eclipse.core.runtime.CoreException;
017: import org.eclipse.pde.core.IModelChangedEvent;
018: import org.eclipse.pde.core.ModelChangedEvent;
019: import org.eclipse.pde.core.build.IBuildEntry;
020: import org.eclipse.pde.internal.core.util.PropertiesUtil;
021:
022: public class BuildEntry extends BuildObject implements IBuildEntry {
023: private Vector tokens = new Vector();
024: private String name;
025:
026: public BuildEntry(String name) {
027: this .name = name;
028: }
029:
030: public void addToken(String token) throws CoreException {
031: ensureModelEditable();
032: tokens.add(token);
033: getModel().fireModelChanged(
034: new ModelChangedEvent(getModel(),
035: IModelChangedEvent.INSERT,
036: new Object[] { token }, null));
037: }
038:
039: public String getName() {
040: return name;
041: }
042:
043: public String[] getTokens() {
044: String[] result = new String[tokens.size()];
045: tokens.copyInto(result);
046: return result;
047: }
048:
049: public boolean contains(String token) {
050: return tokens.contains(token);
051: }
052:
053: void processEntry(String value) {
054: StringTokenizer stok = new StringTokenizer(value, ","); //$NON-NLS-1$
055: while (stok.hasMoreTokens()) {
056: String token = stok.nextToken();
057: token = token.trim();
058: tokens.add(token);
059: }
060: }
061:
062: public void removeToken(String token) throws CoreException {
063: ensureModelEditable();
064: tokens.remove(token);
065: getModel().fireModelChanged(
066: new ModelChangedEvent(getModel(),
067: IModelChangedEvent.REMOVE,
068: new Object[] { token }, null));
069: }
070:
071: public void renameToken(String oldName, String newName)
072: throws CoreException {
073: ensureModelEditable();
074: for (int i = 0; i < tokens.size(); i++) {
075: if (tokens.elementAt(i).toString().equals(oldName)) {
076: tokens.setElementAt(newName, i);
077: break;
078: }
079: }
080: getModel().fireModelChanged(
081: new ModelChangedEvent(getModel(),
082: IModelChangedEvent.CHANGE,
083: new Object[] { oldName }, null));
084: }
085:
086: public void setName(String name) throws CoreException {
087: ensureModelEditable();
088: String oldValue = this .name;
089: this .name = name;
090: getModel().fireModelObjectChanged(this , P_NAME, oldValue, name);
091: }
092:
093: public String toString() {
094: return name;
095: }
096:
097: public void write(String indent, PrintWriter writer) {
098: PropertiesUtil.writeKeyValuePair(indent, name, tokens
099: .elements(), writer);
100: }
101:
102: public void restoreProperty(String name, Object oldValue,
103: Object newValue) throws CoreException {
104: if (name.equals(P_NAME)) {
105: setName(newValue != null ? newValue.toString() : null);
106: }
107: }
108: }
|