home *** CD-ROM | disk | FTP | other *** search
- package allaire.cfide;
-
- import allaire.controls.CFTree;
- import allaire.controls.CFTreeItem;
- import java.net.URL;
- import java.util.Hashtable;
- import java.util.StringTokenizer;
- import netscape.application.AWTCompatibility;
- import netscape.application.Alert;
- import netscape.application.Application;
- import netscape.application.Target;
- import netscape.application.View;
- import netscape.util.Enumeration;
- import netscape.util.Vector;
-
- public class CFDirectoryTree extends CFTree implements Target {
- public boolean m_isUNIX;
- private boolean m_showFiles;
- private CFNetRouter m_cfRouter;
- private Hashtable m_hashExtensions;
- private String m_initialRoot = "";
- private String m_initialMask = "";
- private String m_mask = "*.*";
- private String m_separator = "\\";
-
- public void doubleClicked(CFTreeItem currentItem) {
- }
-
- public CFDirectoryTree(CFNetRouter cfRouter, Application application, int x, int y, int width, int height, View parentView, boolean mainTree) {
- super(x, y, width, height, parentView);
- Application currentApplication = Application.application();
- CFNavigationApplet currentApplet = (CFNavigationApplet)AWTCompatibility.awtApplet();
- currentApplet.m_treeControl = this;
- String strUNIX = currentApplication.parameterNamed("OS");
- if (strUNIX != null && strUNIX.equalsIgnoreCase("UNIX")) {
- this.m_isUNIX = true;
- this.m_mask = "*";
- this.m_separator = "/";
- this.m_initialRoot = "/";
- this.m_initialMask = "*";
- }
-
- String strVScroll = currentApplication.parameterNamed("VSCROLL");
- boolean wantVScroll = true;
- if (strVScroll != null && strVScroll.equalsIgnoreCase("no")) {
- wantVScroll = false;
- }
-
- ((CFTree)this).setVScroll(true);
- boolean wantHScroll = true;
- String strHScroll = currentApplication.parameterNamed("HSCROLL");
- if (strHScroll != null && strHScroll.equalsIgnoreCase("no")) {
- wantHScroll = false;
- }
-
- ((CFTree)this).setHScroll(wantHScroll);
- boolean wantBorder = true;
- String strBorder = currentApplication.parameterNamed("BORDER");
- if (strBorder != null && strBorder.equalsIgnoreCase("no")) {
- wantBorder = false;
- }
-
- ((CFTree)this).setBorder(wantBorder);
- this.m_cfRouter = cfRouter;
- this.init();
- }
-
- public void performCommand(String command, Object anObject) {
- if (command.equals("INITIAL_LOAD")) {
- this.initialLoad();
- ((View)this).draw();
- }
-
- }
-
- public void init() {
- Application currentApp = Application.application();
- currentApp.performCommandLater(this, "INITIAL_LOAD", this);
- }
-
- private void initialLoad() {
- String strCaption = null;
- ((View)this).rootView().setOverrideCursor(3);
- int rootIndex = ((CFTree)this).addItem("Retrieving initial directories . . .", -1, 2);
- Application currentApplication = Application.application();
- ((View)this).draw();
-
- try {
- ((View)this).disableDrawing();
- Vector vectResults = this.m_cfRouter.callRPC("BrowseDir", this.m_initialRoot, this.m_initialMask);
- this.m_showFiles = true;
- String strShowFiles = currentApplication.parameterNamed("ShowFiles");
- if (strShowFiles != null && strShowFiles.equalsIgnoreCase("no")) {
- this.m_showFiles = false;
- }
-
- if (this.m_showFiles) {
- this.m_hashExtensions = new Hashtable();
- String strExtensions = currentApplication.parameterNamed("Extensions");
- if (strExtensions != null) {
- StringTokenizer tokenizer = new StringTokenizer(strExtensions, " ,");
-
- while(tokenizer.hasMoreTokens()) {
- String nextToken = tokenizer.nextToken();
- this.m_hashExtensions.put(nextToken, nextToken);
- }
- } else {
- this.m_hashExtensions.put(".htm", ".htm");
- this.m_hashExtensions.put(".html", ".html");
- this.m_hashExtensions.put(".cfm", ".cfm");
- this.m_hashExtensions.put(".dbm", ".dbm");
- }
- }
-
- strCaption = currentApplication.parameterNamed("ServerCaption");
- if (strCaption == null) {
- URL urlOriginal = currentApplication.codeBase();
- String hostName = urlOriginal.getHost();
- strCaption = "http://" + hostName;
- }
-
- CFTreeItem rootItem = ((CFTree)this).itemAt(rootIndex);
- rootItem.m_caption = strCaption;
- if (this.m_isUNIX) {
- this.populateChildrenDisplay(vectResults, rootIndex, false);
- } else {
- for(Enumeration enumResults = vectResults.elements(); enumResults.hasMoreElements(); enumResults.nextElement()) {
- String strDriveType = (String)enumResults.nextElement();
- boolean bAddDrive = true;
- Integer nDriveType = new Integer(strDriveType);
- int nImageType = 0;
- switch (nDriveType) {
- case 2:
- nImageType = 4;
- break;
- case 3:
- nImageType = 6;
- break;
- case 4:
- nImageType = 8;
- bAddDrive = false;
- break;
- case 5:
- nImageType = 10;
- }
-
- String strDrive = (String)enumResults.nextElement();
- if (bAddDrive) {
- String strDriveLetter = strDrive;
- if (strDrive.length() > 2) {
- strDriveLetter = strDrive.substring(0, 2);
- }
-
- int nIndex = ((CFTree)this).addItem(strDrive, strDriveLetter, rootIndex, nImageType);
- CFTreeItem currentItem = ((CFTree)this).itemAt(nIndex);
- currentItem.setHasChildren();
- }
- }
- }
-
- String strDefaultPath = currentApplication.parameterNamed("DefaultPath");
- if (strDefaultPath != null) {
- if (this.m_isUNIX && strDefaultPath.startsWith("/")) {
- strDefaultPath = strDefaultPath.substring(1);
- }
-
- rootItem.setDefaultPath(strDefaultPath, this.m_separator);
- }
- } catch (CFRPCParameterException var17) {
- Alert.runAlertExternally(Alert.notificationImage(), "Logic Error", "RPC Parameter error in CFDirectoryTree", "OK", (String)null, (String)null);
- } catch (CFRPCServerException var18) {
- String errorMessage = var18.errorMessage();
- Alert.runAlertExternally(Alert.notificationImage(), "Server Error", errorMessage, "OK", (String)null, (String)null);
- }
-
- ((View)this).reenableDrawing();
- ((View)this).rootView().removeOverrideCursor();
- ((View)this).rootView().updateCursor();
- AWTCompatibility.awtApplet().showStatus("");
- }
-
- public void populateChildren(CFTreeItem currentItem) {
- try {
- int currentIndex = super.m_allItems.indexOf(currentItem);
- ((View)this).rootView().setOverrideCursor(3);
- String currentPath = currentItem.getPath(this.m_separator);
- if (this.m_isUNIX) {
- currentPath = "/" + currentPath;
- }
-
- Vector vectResults = this.m_cfRouter.callRPC("BrowseDir", currentPath, this.m_mask);
- this.populateChildrenDisplay(vectResults, currentIndex, true);
- } catch (CFRPCParameterException var6) {
- Alert.runAlertExternally(Alert.notificationImage(), "Logic Error", "RPC Parameter error in CFDirectoryTree", "OK", (String)null, (String)null);
- } catch (CFRPCServerException var7) {
- String errorMessage = var7.errorMessage();
- errorMessage = new String(errorMessage.substring(0, Math.max(0, errorMessage.length() - 2)));
- Alert.runAlertExternally(Alert.notificationImage(), "Server Access Error", errorMessage, "OK", (String)null, (String)null);
- }
-
- }
-
- public void populateChildrenDisplay(Vector vectResults, int currentIndex, boolean updateCursor) {
- Vector vectDirectories = new Vector();
- Vector vectFiles = new Vector();
- Enumeration enumResults = vectResults.elements();
-
- while(enumResults.hasMoreElements()) {
- String strItemType = (String)enumResults.nextElement();
- String strItem = (String)enumResults.nextElement();
- enumResults.nextElement();
- enumResults.nextElement();
- enumResults.nextElement();
- if (strItemType.compareTo("D:") == 0) {
- vectDirectories.addElement(strItem);
- } else if (this.m_showFiles) {
- String testItem = strItem.toLowerCase();
- int iLastIndex = testItem.lastIndexOf(".");
- if (iLastIndex >= 0 && this.m_hashExtensions.containsKey(testItem.substring(iLastIndex))) {
- vectFiles.addElement(strItem);
- }
- }
- }
-
- if (this.m_isUNIX) {
- if (!vectDirectories.isEmpty()) {
- vectDirectories.sortStrings(true, false);
- }
-
- if (!vectFiles.isEmpty()) {
- vectFiles.sortStrings(true, false);
- }
- }
-
- enumResults = vectDirectories.elements();
-
- while(enumResults.hasMoreElements()) {
- String strItem = (String)enumResults.nextElement();
- int nNewIndex = ((CFTree)this).addItem(strItem, currentIndex);
- CFTreeItem newItem = ((CFTree)this).itemAt(nNewIndex);
- newItem.setHasChildren();
- }
-
- enumResults = vectFiles.elements();
-
- while(enumResults.hasMoreElements()) {
- String strItem = (String)enumResults.nextElement();
- ((CFTree)this).addItem(strItem, currentIndex, 12);
- }
-
- if (updateCursor) {
- ((View)this).rootView().removeOverrideCursor();
- ((View)this).rootView().updateCursor();
- }
-
- }
- }
-