/*
* Copyright (C) 2001, 2002 Robert MacGrogan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* $Archive: SourceJammer$
* $FileName: ProjectTreeNode.java$
* $FileID: 3997$
*
* Last change:
* $AuthorName: Rob MacGrogan$
* $Date: 7/26/03 1:59 AM$
* $Comment: Allow user to configure certain types of files to be
* ignored by SJ (not added or shown in "sync view") by adding
* extensions to ignore section of filehist.props.$
*/
package org.sourcejammer.client.gui;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.table.DefaultTableModel;
import org.sourcejammer.project.view.*;
import org.sourcejammer.client.HistoryTypeMapper;
import org.sourcejammer.client.SourceJammerClient;
import org.sourcejammer.client.filesys.SourceVersionChecker;
import org.sourcejammer.client.gui.conf.FileNodeInfo;
import org.sourcejammer.client.gui.conf.GuiConf;
import org.sourcejammer.client.gui.conf.UserPrefs;
import org.sourcejammer.project.*;
import org.sourcejammer.util.AppConfig;
import org.sourcejammer.util.ConfigurationException;
import org.sourcejammer.util.SJDate;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
/**
* Title: $FileName: ProjectTreeNode.java$
* @version $VerNum: 4$
* @author $AuthorName: Rob MacGrogan$<br><br>
*
* $Description: $<br>
* $KeyWordsOff: $<br>
*/
public class ProjectTreeNode extends DefaultMutableTreeNode {
private boolean mbContentsSet = false;
private NodeList moFileChildren = null;
private DefaultTableModel moFileTableModel = null;
private Project moProject = null;
private NodeName ndName = null;
private NodeList displayList = null;
private boolean dirty = false;
private Hashtable projectChildren = null;
public ProjectTreeNode(NodeInfo info) {
setUserObject(info);
}
public ProjectTreeNode getProjectChild(long projectID){
if (projectChildren != null)
return (ProjectTreeNode)projectChildren.get(new Long(projectID));
else
return null;
}
public NodeInfo getInfo(){
return (NodeInfo)getUserObject();
}
public void setNodeName(NodeName nd){
ndName = nd;
}
public boolean getAllowsChildren(){
//Always a project, so always allows children
return true;
}
public boolean isLeaf(){
return false;
}
public boolean getContentsSet(){
return mbContentsSet;
}
public Project getProject(){
return moProject;
}
public long getUniqueID(){
return getInfo().getUniqueID();
}
private void simpleRebuild()
throws NodeExistsException{
simpleRebuild(FileNodeInfo.UNKNOWN);
}
private void simpleRebuild(int syncState)
throws NodeExistsException{
NodeList viewList = new NodeList();
NodeIterator itr = moFileChildren.getIterator();
while(itr.hasMoreNodes()){
FileNodeInfo newNode = new FileNodeInfo((NodeInfo)itr.getNextNode());
newNode.setLocalRemoteSyncState(syncState);
viewList.addNode(newNode);
}
displayList = viewList;
moFileTableModel = GuiUtil.getFileTableModel(displayList.getIterator());
}
public void rebuildDisplayList(boolean showLocalRemoteSync)
throws NodeExistsException, IOException{
if (! showLocalRemoteSync){
simpleRebuild();
}
else{
CommandCentral central = CommandCentral.getInstance();
GuiConf gc = central.getGuiConf();
java.io.File workingDir = gc.getDefaultWorkingDirectory(getNodeName());
if (workingDir != null && workingDir.exists() && workingDir.isDirectory()){
SourceVersionChecker checker = new SourceVersionChecker(workingDir,
central.currentURL(),
central.getArchiveName());
NodeList viewList = new NodeList();
NodeIterator itr = moFileChildren.getIterator();
while(itr.hasMoreNodes()){
FileNodeInfo newNode = new FileNodeInfo((NodeInfo)itr.getNextNode());
viewList.addNode(newNode);
if (! checker.isFileCurrent(newNode.getNodeName(), newNode.getLatestVerUniqueID())){
newNode.setLocalRemoteSyncState(FileNodeInfo.NOT_ON_LOCAL);
}
}
java.io.File[] files = workingDir.listFiles();
for(int i = 0; i < files.length; i++){
java.io.File fl = files[i];
if (fl.isFile() && ! fl.getName().equals(SourceVersionChecker.LOCAL_FILE_INFO_FILE_NAME)){
//Look for it in archive.
FileNodeInfo info = null;
try{
info = (FileNodeInfo)viewList.getNode(fl.getName());
//Got it.
if (info.getLocalRemoteSyncState() == FileNodeInfo.NOT_ON_LOCAL){
//must be out of sync.
info.setLocalRemoteSyncState(FileNodeInfo.OUT_OF_SYNC);
}
}
catch (NodeDoesNotExistException ex){
//Not in archive, so we need to add it to list.
NodeInfo ndInfo = new NodeInfo();
ndInfo.setNodeName(fl.getName());
ndInfo.setUniqueID(i * -1); //this should be unique.
SJDate modDate = new SJDate();
modDate.setTime(fl.lastModified());
ndInfo.setModifiedDate(modDate);
ndInfo.setSourceSizeInBytes(fl.length());
ndInfo.setNumVersions(0);
String sType = HistoryTypeMapper.getInstance().getDefaultHistoryTypeForFile(fl.getName());
boolean ignore = false;
if (sType.equals(HistoryTypeMapper.TEXT_LIST))
ndInfo.setFileType(AppConfig.FileTypes.TEXT);
else if (sType.equals(HistoryTypeMapper.IGNORE_LIST))
ignore = true;
else
ndInfo.setFileType(AppConfig.FileTypes.BINARY);
info = new FileNodeInfo(ndInfo);
info.setLocalRemoteSyncState(FileNodeInfo.NOT_IN_ARCHIVE);
if (! ignore)
viewList.addNode(info);
}
}
}
this.displayList = viewList;
moFileTableModel = GuiUtil.getFileTableModel(displayList.getIterator());
}
else{
if (workingDir == null){
simpleRebuild();
}
else{
simpleRebuild(FileNodeInfo.NOT_ON_LOCAL);
}
}
}//end else
//Update all children with set contents.
Enumeration enm = this.children();
while(enm.hasMoreElements()){
Object o = enm.nextElement();
if (o instanceof ProjectTreeNode){
ProjectTreeNode treeNode = (ProjectTreeNode)o;
if (treeNode.getContentsSet()){
treeNode.rebuildDisplayList(showLocalRemoteSync);
}
}
}
}
public long getFileUniqueIDFromName(String childName)
throws NodeDoesNotExistException{
NodeInfo nd = (NodeInfo)moFileChildren.getNode(childName);
return nd.getUniqueID();
}
public void setContents(Project project)
throws NodeExistsException{
moFileChildren = null;
moProject = project;
//remove any child leaves.
int iCurrCount = 0;
if (children != null){
iCurrCount = children.size();
}
for (int i = iCurrCount - 1; i >= 0; i--){
remove(i);
}
Hashtable buildProjChildren = new Hashtable();
//Loop through Project and add project children to tree and
//file children to child file list.
NodeList oNewFileChildren = new NodeList();
NodeIterator oAllChildren = project.childNodes();
oAllChildren = GuiUtil.sortNodeIterator(oAllChildren);
while(oAllChildren.hasMoreNodes()){
NodeInfo ndChild = (NodeInfo)oAllChildren.getNextNode();
if (ndChild.getNodeType() == AppConfig.NodeTypes.PROJECT){
ProjectTreeNode childProject = new ProjectTreeNode(ndChild);
NodeName childNodeName = new NodeName();
childNodeName.setName(ndChild.getNodeName());
childNodeName.setParent(ndName);
childProject.setNodeName(childNodeName);
add(childProject);
buildProjChildren.put(new Long(ndChild.getUniqueID()), childProject);
}
else if (ndChild.getNodeType() == AppConfig.NodeTypes.FILE){
oNewFileChildren.addNode(ndChild);
}
}
moFileChildren = oNewFileChildren;
projectChildren = buildProjChildren;
try{
rebuildDisplayList(UserPrefs.getInstance().getBoolean(UserPrefs.LOCAL_REMOTE_SYNC_VIEW, true));
}
catch (IOException ex){
throw new ConfigurationException("Error in building local-sync view.", ex);
}
mbContentsSet = true;
dirty = false;
}
public DefaultTableModel getFileTableModel(){
return moFileTableModel;
}
public String toString(){
NodeInfo oInfo = getInfo();
return oInfo.getNodeName();
}
public NodeIterator getFileChildren(){
NodeIterator oReturn = null;
if (moFileChildren != null){
oReturn = moFileChildren.getIterator();
}
return oReturn;
}
/*
* Returns the NodeInfo for the requested File
* Assuming that the moFileChildren would be avialable
* and initialized before calling this method
* Not sure how to handle exceptions,just throwing it
*/
public NodeInfo getNodeInfo(String fileName)throws NodeDoesNotExistException {
NodeInfo fileNode = (NodeInfo)moFileChildren.getNode(fileName);
return fileNode;
}
/**
* Returns NodeName object build by the client.
*/
public NodeName getNodeName(){
return ndName;
}
/**
* Returns the dirty.
* @return boolean
*/
public boolean isDirty() {
return dirty;
}
/**
* Sets the dirty.
* @param dirty The dirty to set
*/
public void setDirty(boolean dirty) {
this.dirty = dirty;
Enumeration enm = projectChildren.elements();
while(enm.hasMoreElements()){
ProjectTreeNode child = (ProjectTreeNode)enm.nextElement();
child.setDirty(dirty);
}
}
}
|