/* $Id$ * Copyright 2000-2002 SoundBite Corporation. All Rights Reserved. */ package com.perforce.jdev; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.Iterator; import javax.swing.Icon; import com.perforce.api.Client; import com.perforce.api.FileEntry; import com.perforce.jdev.res.Icons; import oracle.ide.model.Document; import oracle.ide.model.Element; import oracle.ide.model.Locatable; import oracle.ide.model.Workspace; import oracle.ide.scm.SCMFile; import oracle.ide.scm.SCMFileStatus; import oracle.ide.scm.error.SCMException; /** * Adapts a Perfoce depot to a JDeveloper Workspace. * * @author Paul Krause * @version Release 0 $Revision$ */ public class P4Workspace extends Workspace implements SCMFile, SCMFileStatus { /** The Perforce client rooted in this Workspace */ private final Client p4Client; /** Client-side Workspace file */ private final SCMFile jwsFile; /** * Constructs a Workspace object for the depot for which the Client * is configured. * * @param f Client-side workspace file * @param c a <code>Client</code> to map to this Workspace */ P4Workspace(SCMFile f, Client c) { super(); jwsFile = f; p4Client = c; } /** * Presents the workspace as a File. * * @return the workspace <code>File</code> */ public File toFile() { return jwsFile.toFile(); } /** * Disavows any parent. * * @param f a potential parent <code>SCMFile</code> * @return <code>false</code> */ public boolean hasParent(SCMFile f) { return false; } /** * A Workspace has no parent SCMFile. * * @return null */ public SCMFile getParent() { return null; } /** * Gets the <code>.jws</code> extension, including the dot. * * @return a <code>String</code> value */ public String getExtension() { return EXT; } /** * Presents the workspace as a File. * * @return a pathname <code>String</code> */ public String getPath() { return jwsFile.getPath(); } /** * Presents the workspace as a File. * * @return the name of the client mapped to this Workspace */ public String getName() { return jwsFile.getName(); } /** * Presents the workspace as a File. * * @return file name with extension */ public String getFileName() { return jwsFile.getFileName(); } /** * Presents the workspace as a File. * * @return an <code>SCMFileStatus</code> */ public SCMFileStatus getLatestStatus() { return this; } /** * Presents the workspace as a File. * * @return an <code>SCMFileStatus</code> */ public SCMFileStatus getStatus() { return this; } /** * Presents the workspace as a File. * * @return false (not a directory) */ public boolean isDirectory() { return false; } /** * Presents the workspace as a File. * * @return a <code>boolean</code> value */ public boolean exists() { return jwsFile.exists(); } public void copy(SCMFile f) throws SCMException { jwsFile.copy(f); } public void renameTo(SCMFile f) throws SCMException { jwsFile.renameTo(f); } public void delete() throws SCMException { jwsFile.delete(); } public String getString() { return "unversioned"; } /** * Presents the workspace Status. * * @return false (not versioned) */ public boolean isVersioned() { return false; } /** * Presents the workspace Status. * * @return false (not controlled) */ public boolean isControlled() { return false; } /** * Presents the workspace Status. * * @return null (no overlay) */ public Icon getOverlayIcon() { return null; } /** * Gets a workspace icon. * * @return The Icon */ public Icon getIcon() { return Icons.WORKAREA; } /** * Claims to be a workspace. * * @return true */ public boolean isWorkspace() { return true; } /** * Claims not to be a project. * * @return false */ public boolean isProject() { return false; } /** * Denies knowledge of any project sources. * * @return null */ public Iterator getProjectSources() { return null; } /** * Adds an Element to this Workspace. * * <p> Part of the Folder interface. The specified Element is * added to the end of the child list. However, if the Element is * null, this method does nothing. No notification is fired by * this method. * * @param elm Element to add. * @return true if Element was added */ public boolean add(Element elm) { return (elm != null) && add(elm, false); } /** * Adds an Element to this Workspace. * * <p> Part of the Container interface. The specified Element is * added to the end of the child list. Notification is fired if * notify is true. * * @param elm The Element to add, either a Document or a Container * @param notify Whether observers should be updated * @return true if Element was added */ public boolean add(Element elm, boolean notify) { if (elm.mayHaveChildren()) { boolean success = true; final Iterator children = elm.getChildren(); while (children.hasNext()) { success &= add((Element) children.next(), false); } return success && super.add(elm, notify); } try { final Document doc = (Document) elm; final FileEntry fe = FileEntry.openForAdd(p4Client.getEnv(), doc.getURL().getFile(), null); return super.add(new P4File(fe), notify); } catch (ClassCastException e) { final String msg = elm + " is not a Document"; P4Client.logException(this, "add", msg, e); return false; } catch (IOException e) { final String msg = "I/O error adding " + elm; P4Client.logException(this, "add", msg, e); return false; } } /** * Removes Element from the child list. However, if the Element is * null, this method does nothing. If the Element occurs more than * once in the child list, then only the first instance is removed. * No notification is fired by this method. * * @param elm child Element to remove * @return true if child was removed */ public boolean remove(Element elm) { return (elm != null) && remove(elm, false); } /** * Not implemented. * * @param elm Element to remove * @param notify Whether observers should be notified * @return true if element was removed */ public boolean remove(Element elm, boolean notify) { return false; } /** * Not implemented. * * @param notify Whether observers should be notified */ public void removeAll(boolean notify){} /** * Not implemented. */ public void removeAll() { removeAll(false); } /** * Description of the Method * * @param elm Element proposed for addition * @return true if Element is acceptable */ public boolean canAdd(Element elm) { if (!(super.canAdd(elm) && (elm instanceof Locatable))) { return false; } final URL url = ((Locatable) elm).getURL(); if (url.getProtocol().equals("file")) { return url.getFile().startsWith(p4Client.getRoot()); } return false; } /** * Description of the Method * * @param elm Description of Parameter * @return Description of the Returned Value */ public boolean canRemove(Element elm) { if (!(super.canRemove(elm) && (elm instanceof P4File))) { return false; } final P4File f = (P4File) elm; return f.isControlled() && f.isOpen(); } /** * Description of the Method * * @param elm Description of Parameter * @return Description of the Returned Value */ public boolean containsChild(Element elm) { return false; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 2114 | Paul Krause |
jdev 903 API changes - new SCMFile methods: copy, delete, renameTo - new SCMFileStatus method: getString |
||
#1 | 2076 | Paul Krause | jdev 9.0.2 baseline (upgrading to jdev 9.0.3) |