KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > model > build > BuildEntry


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.model.build;
12
13 import java.io.*;
14 import java.util.*;
15
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.pde.core.build.*;
18 import org.eclipse.pde.internal.core.util.*;
19 import org.eclipse.pde.internal.ui.PDEPlugin;
20 import org.eclipse.pde.internal.ui.model.*;
21
22 public class BuildEntry implements IBuildEntry, IDocumentKey {
23
24     private int fLength = -1;
25     private int fOffset = -1;
26     private IBuildModel fModel;
27     private String JavaDoc fName;
28     private ArrayList fTokens = new ArrayList();
29     
30     /* (non-Javadoc)
31      * @see org.eclipse.pde.core.build.IBuildEntry#addToken(java.lang.String)
32      */

33     public void addToken(String JavaDoc token) throws CoreException {
34         fTokens.add(token);
35         getModel().fireModelObjectChanged(this, getName(), null, token);
36     }
37     /* (non-Javadoc)
38      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#getName()
39      */

40     public String JavaDoc getName() {
41         return fName;
42     }
43     /* (non-Javadoc)
44      * @see org.eclipse.pde.core.build.IBuildEntry#getTokens()
45      */

46     public String JavaDoc[] getTokens() {
47         return (String JavaDoc[])fTokens.toArray(new String JavaDoc[fTokens.size()]);
48     }
49     /* (non-Javadoc)
50      * @see org.eclipse.pde.core.build.IBuildEntry#contains(java.lang.String)
51      */

52     public boolean contains(String JavaDoc token) {
53         return fTokens.contains(token);
54     }
55     /* (non-Javadoc)
56      * @see org.eclipse.pde.core.build.IBuildEntry#removeToken(java.lang.String)
57      */

58     public void removeToken(String JavaDoc token) throws CoreException {
59         fTokens.remove(token);
60         getModel().fireModelObjectChanged(this, getName(), token, null);
61     }
62     /* (non-Javadoc)
63      * @see org.eclipse.pde.core.build.IBuildEntry#renameToken(java.lang.String, java.lang.String)
64      */

65     public void renameToken(String JavaDoc oldToken, String JavaDoc newToken)
66             throws CoreException {
67         int index = fTokens.indexOf(oldToken);
68         if (index != -1) {
69             fTokens.set(index, newToken);
70             getModel().fireModelObjectChanged(this, getName(), oldToken, newToken);
71         }
72     }
73     /* (non-Javadoc)
74      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#setName(java.lang.String)
75      */

76     public void setName(String JavaDoc name) {
77         String JavaDoc oldName = fName;
78         if (getModel() != null){
79             try {
80                 IBuild build = getModel().getBuild();
81                 build.remove(this);
82                 fName = name;
83                 build.add(this);
84             } catch (CoreException e) {
85                 PDEPlugin.logException(e);
86             }
87             getModel().fireModelObjectChanged(this, getName(), oldName, name);
88         } else
89             fName = name;
90     }
91     /* (non-Javadoc)
92      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#getOffset()
93      */

94     public int getOffset() {
95         return fOffset;
96     }
97     /* (non-Javadoc)
98      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#setOffset(int)
99      */

100     public void setOffset(int offset) {
101         fOffset = offset;
102     }
103     
104     /* (non-Javadoc)
105      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#getLength()
106      */

107     public int getLength() {
108         return fLength;
109     }
110     
111     /* (non-Javadoc)
112      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#setLength(int)
113      */

114     public void setLength(int length) {
115         fLength = length;
116     }
117     /* (non-Javadoc)
118      * @see org.eclipse.pde.core.IWritable#write(java.lang.String, java.io.PrintWriter)
119      */

120     public void write(String JavaDoc indent, PrintWriter writer) {
121     }
122     
123     public void setModel(IBuildModel model) {
124         fModel = model;
125     }
126     
127     public IBuildModel getModel() {
128         return fModel;
129     }
130     
131     public void processEntry(String JavaDoc value) {
132         StringTokenizer stok = new StringTokenizer(value, ","); //$NON-NLS-1$
133
while (stok.hasMoreTokens()) {
134             fTokens.add(stok.nextToken().trim());
135         }
136     }
137     /* (non-Javadoc)
138      * @see org.eclipse.pde.internal.ui.model.IDocumentKey#write()
139      */

140     public String JavaDoc write() {
141         return PropertiesUtil.writeKeyValuePair(getName(), getTokens());
142     }
143 }
144
Popular Tags