/* $File: //guest/paul_krause/perforce/integrations/jdev/src/com/perforce/jdev/P4Change.java $
* Copyright 2000-2002 SoundBite Corporation. All Rights Reserved.
*/
package com.perforce.jdev;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Iterator;
import javax.swing.Icon;
import com.perforce.api.Change;
import com.perforce.jdev.res.Icons;
import oracle.ide.scm.SCMFile;
import oracle.ide.scm.SCMFileStatus;
import oracle.ide.scm.SCMOptions;
import com.perforce.api.SourceControlObject;
/**
* Models a change list.
*
* @author Paul Krause
* @version $Revision: #3 $ $Date: 2002/10/05 $
*/
public final class P4Change extends P4Node {
/** Description of the Field */
private final Change changeList;
public P4Change(SCMFile f, Change c) {
super(f, c);
changeList = c;
}
protected SourceControlObject getP4Object() {
return changeList;
}
/**
* Changes don't use overlays.
*
* @return null
*/
public Icon getOverlayIcon() {
return null;
}
/**
* Changes are controlled.
*
* @return true
*/
public boolean isControlled() {
return true;
}
/**
* Changes are not versioned.
*
* @return false
*/
public boolean isVersioned() {
return false;
}
/**
* Reports on the status of this change.
*
* @return true is change is still pending
*/
public boolean isPending()
{
return changeList.getStatus() == Change.PENDING;
}
/**
* Reports on the status of this change.
*
* @return true if change has already been submitted
*/
public boolean isSubmitted()
{
return changeList.getStatus() == Change.SUBMITTED;
}
public String getToolTipText() {
return changeList.getShortDescription();
}
public InputStream getInputStream() {
final String desc = changeList.getDescription();
return new ByteArrayInputStream(desc.getBytes());
}
public SCMFileStatus getLatestStatus() {
if (changeList.outOfSync(0)) changeList.sync();
return this;
}
/** This is no-op, but maybe it should check for permission. */
public void openForEdit (SCMOptions opts) {
}
public boolean getAllowsChildren() {
return true;
}
public int getChildCount() {
return getFileNodes().length;
}
public Iterator getChildren() {
final P4File[] f = getFileNodes();
return new Iterator() {
private int i;
public boolean hasNext() {
return i < f.length;
}
public Object next() {
return f[i++];
}
public void remove() {
throw new UnsupportedOperationException("remove");
}
};
}
synchronized P4File[] getFileNodes() {
return new P4File[0];
}
public Object getData() {
return changeList.getDescription();
}
public Icon getIcon() {
switch (changeList.getStatus()) {
case Change.PENDING:
return Icons.PENDING_CHANGE;
case Change.SUBMITTED:
return Icons.SUBMITTED_CHANGE;
default:
return null;
}
}
public String getLongLabel() {
return changeList.getShortDescription();
}
public String getName() {
return "Change " + changeList.getNumber();
}
public int getCategory() {
throw new UnsupportedOperationException();
}
}