154 lines
4.9 KiB
Java
154 lines
4.9 KiB
Java
|
|
/*
|
||
|
|
* Copyright (c) 2003,2006 Declarative Engineering LLC.
|
||
|
|
* All rights reserved. This program and the accompanying materials
|
||
|
|
* are made available under the terms of the Declarative Engineering LLC
|
||
|
|
* verson 1 which accompanies this distribution, and is available at
|
||
|
|
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||
|
|
*/
|
||
|
|
package com.foundation.view.swt;
|
||
|
|
|
||
|
|
import java.io.File;
|
||
|
|
import org.eclipse.swt.SWT;
|
||
|
|
import com.common.debug.*;
|
||
|
|
import com.foundation.view.*;
|
||
|
|
|
||
|
|
public class FileDialog extends Dialog {
|
||
|
|
public static final int STYLE_OPEN = SWT.OPEN;
|
||
|
|
public static final int STYLE_SAVE = SWT.SAVE;
|
||
|
|
public static final int STYLE_MULTI = SWT.MULTI;
|
||
|
|
/**
|
||
|
|
* FileDialog constructor.
|
||
|
|
*/
|
||
|
|
private FileDialog() {
|
||
|
|
super();
|
||
|
|
}//FileDialog()//
|
||
|
|
/**
|
||
|
|
* FileDialog constructor.
|
||
|
|
* @param parent The parent view which is required for this dialog.
|
||
|
|
*/
|
||
|
|
public FileDialog(IView parent) {
|
||
|
|
super();
|
||
|
|
|
||
|
|
if(parent instanceof Container) {
|
||
|
|
org.eclipse.swt.widgets.Shell shell = ((Container) parent).getSwtControl().getShell();
|
||
|
|
|
||
|
|
shell.setFocus();
|
||
|
|
setSwtDialog(new org.eclipse.swt.widgets.FileDialog(shell));
|
||
|
|
}//if//
|
||
|
|
else {
|
||
|
|
Debug.log("Error: Cannot create a dialog without a valid SWT parent control.");
|
||
|
|
}//else//
|
||
|
|
}//FileDialog()//
|
||
|
|
/**
|
||
|
|
* FileDialog constructor.
|
||
|
|
* @param parent The parent view which is required for this dialog.
|
||
|
|
* @param style Zero or more of the STYLE_xxx identifiers defined by this class.
|
||
|
|
*/
|
||
|
|
public FileDialog(IView parent, int style) {
|
||
|
|
super();
|
||
|
|
|
||
|
|
if(parent instanceof Container) {
|
||
|
|
setSwtDialog(new org.eclipse.swt.widgets.FileDialog(((Container) parent).getSwtControl().getShell(), style));
|
||
|
|
}//if//
|
||
|
|
else {
|
||
|
|
Debug.log("Error: Cannot create a dialog without a valid SWT parent control.");
|
||
|
|
}//else//
|
||
|
|
}//FileDialog()//
|
||
|
|
/**
|
||
|
|
* Gets the SWT file dialog instance.
|
||
|
|
* @return The SWT file dialog.
|
||
|
|
*/
|
||
|
|
protected org.eclipse.swt.widgets.FileDialog getSwtFileDialog() {
|
||
|
|
return (org.eclipse.swt.widgets.FileDialog) getSwtDialog();
|
||
|
|
}//getSwtFileDialog()//
|
||
|
|
/**
|
||
|
|
* Gets the file name of the first file selected by the user.
|
||
|
|
* @return One of the selected file names.
|
||
|
|
*/
|
||
|
|
public String getFileName() {
|
||
|
|
return getSwtFileDialog().getFileName();
|
||
|
|
}//getFileName()//
|
||
|
|
/**
|
||
|
|
* Gets the path + file name of the first file selected by the user.
|
||
|
|
* @return One of the selected file names.
|
||
|
|
*/
|
||
|
|
public String getPathAndFileName() {
|
||
|
|
return getFilterPath() + File.separator + getFileName();
|
||
|
|
}//getPathAndFileName()//
|
||
|
|
/**
|
||
|
|
* Sets the initially selected file in the dialog.
|
||
|
|
* @return The initially selected file.
|
||
|
|
*/
|
||
|
|
public void setFileName(String fileName) {
|
||
|
|
getSwtFileDialog().setFileName(fileName);
|
||
|
|
}//setFileName()//
|
||
|
|
/**
|
||
|
|
* Gets all of the file names selected by the user.
|
||
|
|
* @return An array of the selected file names.
|
||
|
|
*/
|
||
|
|
public String[] getFileNames() {
|
||
|
|
return getSwtFileDialog().getFileNames();
|
||
|
|
}//getFileNames()//
|
||
|
|
/**
|
||
|
|
* Gets all of the path + file names selected by the user.
|
||
|
|
* @return An array of the selected file names.
|
||
|
|
*/
|
||
|
|
public String[] getPathAndFileNames() {
|
||
|
|
String[] fileNames = getFileNames();
|
||
|
|
|
||
|
|
for(int index = 0; index < fileNames.length; index++) {
|
||
|
|
fileNames[index] = getFilterPath() + File.separator + fileNames[index];
|
||
|
|
}//for//
|
||
|
|
|
||
|
|
return fileNames;
|
||
|
|
}//getPathAndFileNames()//
|
||
|
|
/**
|
||
|
|
* Gets the extensions used to filter what files the user sees.
|
||
|
|
* @return An array of file extensions that the user may view or save as.
|
||
|
|
*/
|
||
|
|
public String[] getFilterExtensions() {
|
||
|
|
return getSwtFileDialog().getFilterExtensions();
|
||
|
|
}//getFilterExtensions()//
|
||
|
|
/**
|
||
|
|
* Sets the extensions used to filter what files the user sees.
|
||
|
|
* @param filterExtensions An array of file extensions that the user may view or save as.
|
||
|
|
*/
|
||
|
|
public void setFilterExtensions(String[] filterExtensions) {
|
||
|
|
getSwtFileDialog().setFilterExtensions(filterExtensions);
|
||
|
|
}//setFilterExtensions()//
|
||
|
|
/**
|
||
|
|
* Gets the file names used to filter what files the user sees.
|
||
|
|
* @return An array of file names that the user may view or save as.
|
||
|
|
*/
|
||
|
|
public String[] getFilterNames() {
|
||
|
|
return getSwtFileDialog().getFilterNames();
|
||
|
|
}//getFilterNames()//
|
||
|
|
/**
|
||
|
|
* Sets the file names used to filter what files the user sees.
|
||
|
|
* @param filterNames An array of file names that the user may view or save as.
|
||
|
|
*/
|
||
|
|
public void setFilterNames(String[] filterNames) {
|
||
|
|
getSwtFileDialog().setFilterNames(filterNames);
|
||
|
|
}//setFilterNames()//
|
||
|
|
/**
|
||
|
|
* Gets the directory path the user will see.
|
||
|
|
* @return The directory seen by the user.
|
||
|
|
*/
|
||
|
|
public String getFilterPath() {
|
||
|
|
return getSwtFileDialog().getFilterPath();
|
||
|
|
}//getFilterPath()//
|
||
|
|
/**
|
||
|
|
* Sets the directory path the user will see.
|
||
|
|
* @param filterPath The directory seen by the user.
|
||
|
|
*/
|
||
|
|
public void setFilterPath(String filterPath) {
|
||
|
|
getSwtFileDialog().setFilterPath(filterPath);
|
||
|
|
}//setFilterPath()//
|
||
|
|
/**
|
||
|
|
* Opens the dialog making it visible to the user.
|
||
|
|
* @return The directory of the first selected file. This will be null if an error occured.
|
||
|
|
*/
|
||
|
|
public String open() {
|
||
|
|
return getSwtFileDialog().open();
|
||
|
|
}//open()//
|
||
|
|
}//FileDialog//
|