001: /*
002: * Copyright (C) 2001, 2002 Robert MacGrogan
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: *
019: * $Archive: SourceJammer$
020: * $FileName: ProjectTreeNode.java$
021: * $FileID: 3997$
022: *
023: * Last change:
024: * $AuthorName: Rob MacGrogan$
025: * $Date: 7/26/03 1:59 AM$
026: * $Comment: Allow user to configure certain types of files to be
027: * ignored by SJ (not added or shown in "sync view") by adding
028: * extensions to ignore section of filehist.props.$
029: */
030:
031: package org.sourcejammer.client.gui;
032:
033: import javax.swing.tree.DefaultMutableTreeNode;
034: import javax.swing.tree.TreeNode;
035: import javax.swing.table.DefaultTableModel;
036: import org.sourcejammer.project.view.*;
037: import org.sourcejammer.client.HistoryTypeMapper;
038: import org.sourcejammer.client.SourceJammerClient;
039: import org.sourcejammer.client.filesys.SourceVersionChecker;
040: import org.sourcejammer.client.gui.conf.FileNodeInfo;
041: import org.sourcejammer.client.gui.conf.GuiConf;
042: import org.sourcejammer.client.gui.conf.UserPrefs;
043: import org.sourcejammer.project.*;
044: import org.sourcejammer.util.AppConfig;
045: import org.sourcejammer.util.ConfigurationException;
046: import org.sourcejammer.util.SJDate;
047:
048: import java.io.IOException;
049: import java.util.Enumeration;
050: import java.util.Hashtable;
051: import java.util.Vector;
052:
053: /**
054: * Title: $FileName: ProjectTreeNode.java$
055: * @version $VerNum: 4$
056: * @author $AuthorName: Rob MacGrogan$<br><br>
057: *
058: * $Description: $<br>
059: * $KeyWordsOff: $<br>
060: */
061: public class ProjectTreeNode extends DefaultMutableTreeNode {
062:
063: private boolean mbContentsSet = false;
064: private NodeList moFileChildren = null;
065: private DefaultTableModel moFileTableModel = null;
066: private Project moProject = null;
067: private NodeName ndName = null;
068: private NodeList displayList = null;
069: private boolean dirty = false;
070: private Hashtable projectChildren = null;
071:
072: public ProjectTreeNode(NodeInfo info) {
073: setUserObject(info);
074: }
075:
076: public ProjectTreeNode getProjectChild(long projectID) {
077: if (projectChildren != null)
078: return (ProjectTreeNode) projectChildren.get(new Long(
079: projectID));
080: else
081: return null;
082: }
083:
084: public NodeInfo getInfo() {
085: return (NodeInfo) getUserObject();
086: }
087:
088: public void setNodeName(NodeName nd) {
089: ndName = nd;
090: }
091:
092: public boolean getAllowsChildren() {
093: //Always a project, so always allows children
094: return true;
095: }
096:
097: public boolean isLeaf() {
098: return false;
099: }
100:
101: public boolean getContentsSet() {
102: return mbContentsSet;
103: }
104:
105: public Project getProject() {
106: return moProject;
107: }
108:
109: public long getUniqueID() {
110: return getInfo().getUniqueID();
111: }
112:
113: private void simpleRebuild() throws NodeExistsException {
114: simpleRebuild(FileNodeInfo.UNKNOWN);
115: }
116:
117: private void simpleRebuild(int syncState)
118: throws NodeExistsException {
119: NodeList viewList = new NodeList();
120: NodeIterator itr = moFileChildren.getIterator();
121: while (itr.hasMoreNodes()) {
122: FileNodeInfo newNode = new FileNodeInfo((NodeInfo) itr
123: .getNextNode());
124: newNode.setLocalRemoteSyncState(syncState);
125: viewList.addNode(newNode);
126: }
127: displayList = viewList;
128: moFileTableModel = GuiUtil.getFileTableModel(displayList
129: .getIterator());
130: }
131:
132: public void rebuildDisplayList(boolean showLocalRemoteSync)
133: throws NodeExistsException, IOException {
134: if (!showLocalRemoteSync) {
135: simpleRebuild();
136: } else {
137: CommandCentral central = CommandCentral.getInstance();
138: GuiConf gc = central.getGuiConf();
139: java.io.File workingDir = gc
140: .getDefaultWorkingDirectory(getNodeName());
141: if (workingDir != null && workingDir.exists()
142: && workingDir.isDirectory()) {
143: SourceVersionChecker checker = new SourceVersionChecker(
144: workingDir, central.currentURL(), central
145: .getArchiveName());
146: NodeList viewList = new NodeList();
147: NodeIterator itr = moFileChildren.getIterator();
148: while (itr.hasMoreNodes()) {
149: FileNodeInfo newNode = new FileNodeInfo(
150: (NodeInfo) itr.getNextNode());
151: viewList.addNode(newNode);
152: if (!checker.isFileCurrent(newNode.getNodeName(),
153: newNode.getLatestVerUniqueID())) {
154: newNode
155: .setLocalRemoteSyncState(FileNodeInfo.NOT_ON_LOCAL);
156: }
157: }
158:
159: java.io.File[] files = workingDir.listFiles();
160: for (int i = 0; i < files.length; i++) {
161: java.io.File fl = files[i];
162: if (fl.isFile()
163: && !fl
164: .getName()
165: .equals(
166: SourceVersionChecker.LOCAL_FILE_INFO_FILE_NAME)) {
167: //Look for it in archive.
168: FileNodeInfo info = null;
169: try {
170: info = (FileNodeInfo) viewList.getNode(fl
171: .getName());
172: //Got it.
173: if (info.getLocalRemoteSyncState() == FileNodeInfo.NOT_ON_LOCAL) {
174: //must be out of sync.
175: info
176: .setLocalRemoteSyncState(FileNodeInfo.OUT_OF_SYNC);
177: }
178: } catch (NodeDoesNotExistException ex) {
179: //Not in archive, so we need to add it to list.
180: NodeInfo ndInfo = new NodeInfo();
181: ndInfo.setNodeName(fl.getName());
182: ndInfo.setUniqueID(i * -1); //this should be unique.
183: SJDate modDate = new SJDate();
184: modDate.setTime(fl.lastModified());
185: ndInfo.setModifiedDate(modDate);
186: ndInfo.setSourceSizeInBytes(fl.length());
187: ndInfo.setNumVersions(0);
188:
189: String sType = HistoryTypeMapper
190: .getInstance()
191: .getDefaultHistoryTypeForFile(
192: fl.getName());
193: boolean ignore = false;
194: if (sType
195: .equals(HistoryTypeMapper.TEXT_LIST))
196: ndInfo
197: .setFileType(AppConfig.FileTypes.TEXT);
198: else if (sType
199: .equals(HistoryTypeMapper.IGNORE_LIST))
200: ignore = true;
201: else
202: ndInfo
203: .setFileType(AppConfig.FileTypes.BINARY);
204: info = new FileNodeInfo(ndInfo);
205: info
206: .setLocalRemoteSyncState(FileNodeInfo.NOT_IN_ARCHIVE);
207: if (!ignore)
208: viewList.addNode(info);
209: }
210: }
211: }
212: this .displayList = viewList;
213: moFileTableModel = GuiUtil
214: .getFileTableModel(displayList.getIterator());
215: } else {
216: if (workingDir == null) {
217: simpleRebuild();
218: } else {
219: simpleRebuild(FileNodeInfo.NOT_ON_LOCAL);
220: }
221: }
222: }//end else
223: //Update all children with set contents.
224: Enumeration enm = this .children();
225: while (enm.hasMoreElements()) {
226: Object o = enm.nextElement();
227: if (o instanceof ProjectTreeNode) {
228: ProjectTreeNode treeNode = (ProjectTreeNode) o;
229: if (treeNode.getContentsSet()) {
230: treeNode.rebuildDisplayList(showLocalRemoteSync);
231: }
232: }
233: }
234: }
235:
236: public long getFileUniqueIDFromName(String childName)
237: throws NodeDoesNotExistException {
238: NodeInfo nd = (NodeInfo) moFileChildren.getNode(childName);
239: return nd.getUniqueID();
240: }
241:
242: public void setContents(Project project) throws NodeExistsException {
243: moFileChildren = null;
244: moProject = project;
245: //remove any child leaves.
246: int iCurrCount = 0;
247: if (children != null) {
248: iCurrCount = children.size();
249: }
250: for (int i = iCurrCount - 1; i >= 0; i--) {
251: remove(i);
252: }
253:
254: Hashtable buildProjChildren = new Hashtable();
255: //Loop through Project and add project children to tree and
256: //file children to child file list.
257: NodeList oNewFileChildren = new NodeList();
258: NodeIterator oAllChildren = project.childNodes();
259: oAllChildren = GuiUtil.sortNodeIterator(oAllChildren);
260: while (oAllChildren.hasMoreNodes()) {
261: NodeInfo ndChild = (NodeInfo) oAllChildren.getNextNode();
262: if (ndChild.getNodeType() == AppConfig.NodeTypes.PROJECT) {
263: ProjectTreeNode childProject = new ProjectTreeNode(
264: ndChild);
265: NodeName childNodeName = new NodeName();
266: childNodeName.setName(ndChild.getNodeName());
267: childNodeName.setParent(ndName);
268: childProject.setNodeName(childNodeName);
269: add(childProject);
270: buildProjChildren.put(new Long(ndChild.getUniqueID()),
271: childProject);
272: } else if (ndChild.getNodeType() == AppConfig.NodeTypes.FILE) {
273: oNewFileChildren.addNode(ndChild);
274: }
275: }
276: moFileChildren = oNewFileChildren;
277: projectChildren = buildProjChildren;
278: try {
279: rebuildDisplayList(UserPrefs.getInstance().getBoolean(
280: UserPrefs.LOCAL_REMOTE_SYNC_VIEW, true));
281: } catch (IOException ex) {
282: throw new ConfigurationException(
283: "Error in building local-sync view.", ex);
284: }
285:
286: mbContentsSet = true;
287: dirty = false;
288: }
289:
290: public DefaultTableModel getFileTableModel() {
291: return moFileTableModel;
292: }
293:
294: public String toString() {
295: NodeInfo oInfo = getInfo();
296: return oInfo.getNodeName();
297: }
298:
299: public NodeIterator getFileChildren() {
300: NodeIterator oReturn = null;
301: if (moFileChildren != null) {
302: oReturn = moFileChildren.getIterator();
303: }
304: return oReturn;
305: }
306:
307: /*
308: * Returns the NodeInfo for the requested File
309: * Assuming that the moFileChildren would be avialable
310: * and initialized before calling this method
311: * Not sure how to handle exceptions,just throwing it
312: */
313:
314: public NodeInfo getNodeInfo(String fileName)
315: throws NodeDoesNotExistException {
316: NodeInfo fileNode = (NodeInfo) moFileChildren.getNode(fileName);
317: return fileNode;
318: }
319:
320: /**
321: * Returns NodeName object build by the client.
322: */
323: public NodeName getNodeName() {
324: return ndName;
325: }
326:
327: /**
328: * Returns the dirty.
329: * @return boolean
330: */
331: public boolean isDirty() {
332: return dirty;
333: }
334:
335: /**
336: * Sets the dirty.
337: * @param dirty The dirty to set
338: */
339: public void setDirty(boolean dirty) {
340: this .dirty = dirty;
341: Enumeration enm = projectChildren.elements();
342: while (enm.hasMoreElements()) {
343: ProjectTreeNode child = (ProjectTreeNode) enm.nextElement();
344: child.setDirty(dirty);
345: }
346: }
347:
348: }
|