diff options
author | slewis | 2008-03-15 20:34:14 +0000 |
---|---|---|
committer | slewis | 2008-03-15 20:34:14 +0000 |
commit | 857c8329a6811c59ccfe180699fd25a375382d56 (patch) | |
tree | 822537263668ebdb9257dce18b96b7728cd47d75 | |
parent | c6d622fde084becc5c9d4457535f18c2302b6561 (diff) | |
download | org.eclipse.ecf-857c8329a6811c59ccfe180699fd25a375382d56.tar.gz org.eclipse.ecf-857c8329a6811c59ccfe180699fd25a375382d56.tar.xz org.eclipse.ecf-857c8329a6811c59ccfe180699fd25a375382d56.zip |
Added TransferPreferencePage for storing the default download directory.v20080315-1344
5 files changed, 105 insertions, 9 deletions
diff --git a/framework/bundles/org.eclipse.ecf.filetransfer.ui/plugin.xml b/framework/bundles/org.eclipse.ecf.filetransfer.ui/plugin.xml index 07c08f49f..491c2e9c4 100644 --- a/framework/bundles/org.eclipse.ecf.filetransfer.ui/plugin.xml +++ b/framework/bundles/org.eclipse.ecf.filetransfer.ui/plugin.xml @@ -47,5 +47,17 @@ targetId="org.eclipse.ui.DefaultTextEditor"> </hyperlinkDetector> </extension> + <extension + point="org.eclipse.ui.preferencePages"> + <page + category="org.eclipse.ecf.ui.category" + class="org.eclipse.ecf.internal.filetransfer.ui.preferences.TransferPreferencePage" + id="org.eclipse.ecf.filetransfer.ui.preferences" + name="File Transfer"> + <keywordReference + id="org.eclipse.ecf.example.collab.ui.keywords"> + </keywordReference> + </page> + </extension> </plugin> diff --git a/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/Activator.java b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/Activator.java index d2bff0bbb..bc01d01de 100644 --- a/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/Activator.java +++ b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/Activator.java @@ -10,6 +10,8 @@ *****************************************************************************/ package org.eclipse.ecf.internal.filetransfer.ui; +import java.io.File; +import org.eclipse.core.runtime.Platform; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -21,9 +23,11 @@ public class Activator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "org.eclipse.ecf.filetransfer.ui"; //$NON-NLS-1$ + public static final String DOWNLOAD_PATH_PREFERENCE = "downloadpath"; //$NON-NLS-1$ + // The shared instance private static Activator plugin; - + /** * The constructor */ @@ -37,6 +41,22 @@ public class Activator extends AbstractUIPlugin { */ public void start(BundleContext context) throws Exception { super.start(context); + setPreferenceDefaults(); + } + + public String getDefaultDownloadPath() { + String defaultFilePath = System.getProperty("user.home"); //$NON-NLS-1$ + if (Platform.getOS().startsWith("win")) { //$NON-NLS-1$ + defaultFilePath = defaultFilePath + File.separator + "Desktop"; //$NON-NLS-1$ + } + return defaultFilePath; + } + + /** + * + */ + private void setPreferenceDefaults() { + getPreferenceStore().setDefault(DOWNLOAD_PATH_PREFERENCE, getDefaultDownloadPath()); } /* diff --git a/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/StartFileDownloadDialog.java b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/StartFileDownloadDialog.java index 19fba05b9..df715765b 100644 --- a/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/StartFileDownloadDialog.java +++ b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/StartFileDownloadDialog.java @@ -12,7 +12,6 @@ package org.eclipse.ecf.internal.filetransfer.ui; import java.io.File; import java.net.URL; -import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.*; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; @@ -33,10 +32,18 @@ public class StartFileDownloadDialog extends InputDialog { public StartFileDownloadDialog(Shell parentShell, String startURL) { super(parentShell, Messages.getString("StartFileDownloadDialog.FileTransfer"), Messages.getString("StartFileDownloadDialog.Source"), startURL, null); //$NON-NLS-1$ //$NON-NLS-2$ - filePath = System.getProperty("user.home"); //$NON-NLS-1$ - if (Platform.getOS().startsWith("win")) { //$NON-NLS-1$ - filePath = filePath + File.separator + "Desktop"; //$NON-NLS-1$ + filePath = Activator.getDefault().getPreferenceStore().getString(Activator.DOWNLOAD_PATH_PREFERENCE); + filePath = (filePath == null) ? "" : filePath; //$NON-NLS-1$ + } + + String getFullDownloadPath(String path, String fileName) { + if (fileName == null) + return filePath; + String result = filePath; + if (!result.endsWith(File.separator)) { + result = result + File.separator; } + return result + fileName; } public StartFileDownloadDialog(Shell parentShell) { @@ -59,7 +66,7 @@ public class StartFileDownloadDialog extends InputDialog { if (url != null) { String fileName = getFileNameFromURL(); if (!"".equals(fileName)) { //$NON-NLS-1$ - fileLocation.setText(filePath + File.separator + fileName); + fileLocation.setText(getFullDownloadPath(filePath, fileName)); useridText.setFocus(); } String user = url.getUserInfo(); @@ -96,6 +103,11 @@ public class StartFileDownloadDialog extends InputDialog { return fileName; } + String getCurrentDirectory() { + String currentDirectory = fileLocation.getText(); + return currentDirectory.substring(0, currentDirectory.lastIndexOf(File.separator)); + } + protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); Label label = new Label(composite, SWT.WRAP); @@ -123,8 +135,7 @@ public class StartFileDownloadDialog extends InputDialog { } public void focusLost(FocusEvent e) { - String fileName = getFileNameFromURL(); - fileLocation.setText(filePath + File.separator + fileName); + fileLocation.setText(getFullDownloadPath(getCurrentDirectory(), getFileNameFromURL())); fileLocation.setSelection(fileLocation.getText().length()); } }); @@ -138,7 +149,7 @@ public class StartFileDownloadDialog extends InputDialog { FileDialog fd = new FileDialog(fileBrowse.getShell(), SWT.SAVE); fd.setText(Messages.getString("StartFileDownloadDialog.OutputFile")); //$NON-NLS-1$ fd.setFileName(fileName); - fd.setFilterPath(filePath); + fd.setFilterPath(getCurrentDirectory()); String fname = fd.open(); if (fname != null) { fileLocation.setText(fname); diff --git a/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/messages.properties b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/messages.properties index f0895313b..f2c4071ba 100644 --- a/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/messages.properties +++ b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/messages.properties @@ -7,6 +7,7 @@ AbstractFileSendAction.TITLE_FILE_TRANSFER_SUCESSFUL=File transfer completed AbstractFileSendAction.MESSAGE_FILE_TRANSFER_SUCCESSFUL=Transfer of file {0} completed successfully AbstractFileSendAction.TITLE_FILE_TRANSFER_FAILED=File transfer failed AbstractFileSendAction.MESSAGE_FILE_TRANSFER_FAILED=Transfer of file {0} failed.\n\nException: +DownloadPreferencePage_SAVE_FILES_FIELD_EDITOR_TEXT=Save files to: FileTransfersView_BYTES=bytes FileTransfersView_COLUMN_DONE=Done FileTransfersView_COLUMN_DOWNLOAD=Download diff --git a/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/preferences/TransferPreferencePage.java b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/preferences/TransferPreferencePage.java new file mode 100644 index 000000000..3ce6e2a42 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.filetransfer.ui/src/org/eclipse/ecf/internal/filetransfer/ui/preferences/TransferPreferencePage.java @@ -0,0 +1,52 @@ +/**************************************************************************** + * Copyright (c) 2008 Composent, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Composent, Inc. - initial API and implementation + *****************************************************************************/ + +package org.eclipse.ecf.internal.filetransfer.ui.preferences; + +import org.eclipse.ecf.internal.filetransfer.ui.Activator; +import org.eclipse.ecf.internal.filetransfer.ui.Messages; +import org.eclipse.jface.preference.DirectoryFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * + */ +public class TransferPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + + public TransferPreferencePage() { + super(); + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors() + */ + protected void createFieldEditors() { + addField(new DirectoryFieldEditor(Activator.DOWNLOAD_PATH_PREFERENCE, Messages.getString("DownloadPreferencePage_SAVE_FILES_FIELD_EDITOR_TEXT"), getFieldEditorParent())); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#performDefaults() + */ + protected void performDefaults() { + super.performDefaults(); + getPreferenceStore().setDefault(Activator.DOWNLOAD_PATH_PREFERENCE, Activator.getDefault().getDefaultDownloadPath()); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + */ + public void init(IWorkbench workbench) { + // nothing to do + } +} |