core/com.nokia.cpp.utils.ui/src/com/nokia/cpp/internal/api/utils/ui/BrowseDialogUtils.java
author Ed Swartz <ed.swartz@nokia.com>
Fri, 11 Dec 2009 09:47:44 -0600
changeset 677 d13345e153e8
parent 676 7a49747f237a
permissions -rw-r--r--
More bug #10363 fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     1
/*
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     8
*
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    11
*
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    12
* Contributors:
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    13
*
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    14
* Description: 
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    15
*
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    16
*/
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    17
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    18
package com.nokia.cpp.internal.api.utils.ui;
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    19
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    20
import java.io.File;
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    21
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    22
import org.eclipse.core.runtime.IPath;
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    23
import org.eclipse.swt.widgets.DirectoryDialog;
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    24
import org.eclipse.swt.widgets.FileDialog;
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    25
import org.eclipse.swt.widgets.Text;
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    26
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    27
/**
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    28
 * Utilities to make it easier to use file and directory dialogs which are associated
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    29
 * with text entry fields.
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    30
 * <p>
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    31
 * First, promote UI where Browse... starts from the current textual entry rather than
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    32
 * some random place.
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    33
 * <p>
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    34
 * Second, overcome terrible SWT behavior:  even if you do set the filter path, then if it 
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    35
 * is not 100% correct, it will again revert to the home directory.  So, find the nearest
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    36
 * directory that <i>does</i> exist.
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    37
 */
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    38
public class BrowseDialogUtils {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    39
	/**
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    40
	 * When issuing a "Browse..." command next to a text entry field, initialize
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    41
	 * the dialog with the nearest existing file or directory in that text field.
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    42
	 * @param dialog
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    43
	 * @param textEntry
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    44
	 * @pathm defaultPath the path to use when the text entry is empty 
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    45
	 */
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    46
	public static void initializeFrom(FileDialog dialog, Text textEntry, IPath defaultPath) {
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    47
		if (textEntry != null) {
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    48
			String existing = textEntry.getText().trim();
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    49
			if (existing.length() > 0) {
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    50
				initializeFrom(dialog, existing);
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    51
				return;
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    52
			}
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    53
		}
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    54
		if (defaultPath != null) {
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    55
			initializeFrom(dialog, defaultPath);
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    56
		}
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    57
	}
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    58
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    59
	/**
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    60
	 * When issuing a "Browse..." command next to a text entry field, initialize
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    61
	 * the dialog with the nearest existing file or directory in that text field.
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    62
	 * @param dialog
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    63
	 * @param textEntry
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    64
	 */
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    65
	public static void initializeFrom(FileDialog dialog, Text textEntry) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    66
		if (textEntry == null)
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    67
			return;
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    68
		String existing = textEntry.getText().trim();
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    69
		initializeFrom(dialog, existing);
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    70
	}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    71
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    72
	/**
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    73
	 * When issuing a "Browse..." command with an expected file, initialize
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    74
	 * the dialog with the nearest existing file or directory.
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    75
	 * @param dialog
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    76
	 * @param path
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    77
	 */
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    78
	public static void initializeFrom(FileDialog dialog, IPath path) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    79
		if (path != null) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    80
			initializeFrom(dialog, path.toOSString());
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    81
		}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    82
	}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    83
	
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    84
	/**
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    85
	 * When issuing a "Browse..." command with an expected file, initialize
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    86
	 * the dialog with the nearest existing file or directory.
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    87
	 * @param dialog
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    88
	 * @param path
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    89
	 */
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    90
	public static void initializeFrom(FileDialog dialog, String path) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    91
		if (path != null && path.length() > 0) {
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    92
			boolean isDirectory = path.endsWith("/") || path.endsWith("\\");
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    93
			File file = new File(path);
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    94
			boolean exists = file.exists();
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    95
			if (exists) {
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    96
				isDirectory = file.isDirectory();
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    97
			}
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    98
			if (!isDirectory) {
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
    99
				dialog.setFileName(file.getName());
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   100
			}
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   101
			if (exists) {
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   102
				if (file.isAbsolute()) {
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   103
					dialog.setFilterPath(isDirectory ? file.getAbsolutePath() : file.getParent());
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   104
				}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   105
			} else {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   106
				if (!file.isAbsolute())
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   107
					return;
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   108
				File dir = file.getParentFile();
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   109
				while (dir != null && !dir.exists()) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   110
					dir = dir.getParentFile();
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   111
				}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   112
				if (dir != null) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   113
					dialog.setFilterPath(dir.getAbsolutePath());
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   114
				}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   115
			}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   116
		}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   117
	}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   118
	
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   119
	/**
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   120
	 * When issuing a "Browse..." command next to a text entry field, initialize
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   121
	 * the dialog with the nearest existing directory in that text field.
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   122
	 * @param dialog
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   123
	 * @param textEntry
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   124
	 * @param defaultPath the default path if the text entry is empty
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   125
	 */
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   126
	public static void initializeFrom(DirectoryDialog dialog, Text textEntry, IPath defaultPath) {
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   127
		if (textEntry != null) {
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   128
			String existing = textEntry.getText().trim();
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   129
			if (existing.length() > 0) {
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   130
				initializeFrom(dialog, existing);
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   131
				return;
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   132
			}
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   133
		}
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   134
		if (defaultPath != null) {
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   135
			initializeFrom(dialog, defaultPath);
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   136
		}
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   137
	}
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   138
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   139
	/**
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   140
	 * When issuing a "Browse..." command next to a text entry field, initialize
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   141
	 * the dialog with the nearest existing directory in that text field.
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   142
	 * @param dialog
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   143
	 * @param textEntry
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   144
	 */
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   145
	public static void initializeFrom(DirectoryDialog dialog, Text textEntry) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   146
		if (textEntry == null)
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   147
			return;
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   148
		String existing = textEntry.getText().trim();
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   149
		initializeFrom(dialog, existing);
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   150
	}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   151
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   152
	/**
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   153
	 * When issuing a "Browse..." command with an expected directory, initialize
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   154
	 * the dialog with the nearest existing path.
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   155
	 * @param dialog
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   156
	 * @param path
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   157
	 */
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   158
	public static void initializeFrom(DirectoryDialog dialog, IPath path) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   159
		if (path != null) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   160
			initializeFrom(dialog, path.toOSString());
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   161
		}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   162
	}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   163
	
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   164
	/**
677
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   165
	 * When issuing a "Browse..." command with an expected directory, initialize
d13345e153e8 More bug #10363 fixes
Ed Swartz <ed.swartz@nokia.com>
parents: 676
diff changeset
   166
	 * the dialog with the nearest existing path.
676
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   167
	 * @param dialog
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   168
	 * @param path
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   169
	 */
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   170
	public static void initializeFrom(DirectoryDialog dialog, String path) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   171
		if (path != null && path.length() > 0) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   172
			File file = new File(path);
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   173
			if (!file.isAbsolute())
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   174
				return;
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   175
			while (file != null && !file.exists()) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   176
				file = file.getParentFile();
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   177
			}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   178
			if (file != null) {
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   179
				dialog.setFilterPath(file.getAbsolutePath());
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   180
			}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   181
		}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   182
	}
7a49747f237a Initial fixes for bug #10363 (Browse... button behavior)
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   183
}