use of org.eclipse.swt.widgets.DirectoryDialog in project knime-core by knime.
the class WorkflowImportSelectionPage method handleDirBrowseButtonPressed.
private void handleDirBrowseButtonPressed() {
DirectoryDialog dialog = new DirectoryDialog(getShell());
// get initial root
// 1. already something entered?
String fileName = m_fromDirTextUI.getText().trim();
if (fileName.isEmpty()) {
// 2. something stored?
fileName = initialDirLocation;
}
if (fileName.isEmpty()) {
// set to workspace root
fileName = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
}
File initialDir = new File(fileName);
if (initialDir.exists()) {
if (!initialDir.isDirectory()) {
initialDir = initialDir.getParentFile();
}
dialog.setFilterPath(initialDir.getAbsolutePath());
}
final String selectedDir = dialog.open();
// null if dialog was canceled/error occurred
if (selectedDir != null) {
collectWorkflowsFromDir(selectedDir);
}
validateWorkflows();
}
use of org.eclipse.swt.widgets.DirectoryDialog in project yamcs-studio by yamcs.
the class SingleSourceHelper method handleTextInputFigureFileSelector.
public static void handleTextInputFigureFileSelector(TextInputFigure textInput) {
String startPath = textInput.getStartPath();
String currentPath = textInput.getCurrentPath();
switch(textInput.getFileReturnPart()) {
case DIRECTORY:
case FULL_PATH:
currentPath = textInput.getText();
break;
default:
if (currentPath == null) {
if (startPath == null)
currentPath = textInput.getText();
else
currentPath = startPath;
}
break;
}
switch(textInput.getFileSource()) {
case WORKSPACE:
ResourceSelectionDialog dialog = new ResourceSelectionDialog(Display.getCurrent().getActiveShell(), "Select workspace file", // $NON-NLS-2$
textInput.getFileReturnPart() == FileReturnPart.DIRECTORY ? null : new String[] { "*.*" });
if (currentPath != null)
dialog.setSelectedResource(new Path(currentPath));
if (dialog.open() == Window.OK) {
IPath path = dialog.getSelectedResource();
currentPath = path.toPortableString();
String fileString = currentPath;
switch(textInput.getFileReturnPart()) {
case NAME_ONLY:
fileString = path.removeFileExtension().lastSegment();
break;
case NAME_EXT:
fileString = path.lastSegment();
break;
case FULL_PATH:
case DIRECTORY:
default:
break;
}
textInput.setText(fileString);
textInput.setCurrentPath(currentPath);
textInput.fireManualValueChange(textInput.getText());
}
break;
case LOCAL:
IPath[] paths = null;
if (textInput.getFileReturnPart() == FileReturnPart.DIRECTORY) {
DirectoryDialog directoryDialog = new DirectoryDialog(Display.getCurrent().getActiveShell());
directoryDialog.setFilterPath(currentPath);
String directory = directoryDialog.open();
if (directory != null)
paths = new Path[] { new Path(directory) };
} else {
FileDialog fileDialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.MULTI);
if (currentPath != null)
((FileDialog) fileDialog).setFileName(currentPath);
String firstPath = fileDialog.open();
if (firstPath != null) {
paths = new Path[fileDialog.getFileNames().length];
paths[0] = new Path(firstPath);
for (int i = 1; i < paths.length; i++) {
paths[i] = paths[0].removeLastSegments(1).append(fileDialog.getFileNames()[i]);
}
}
}
if (paths != null) {
currentPath = paths[0].toOSString();
StringBuilder result = new StringBuilder();
switch(textInput.getFileReturnPart()) {
case NAME_ONLY:
for (int i = 0; i < paths.length; i++) {
if (i > 0)
result.append(SEPARATOR);
result.append(paths[i].removeFileExtension().lastSegment());
}
break;
case NAME_EXT:
for (int i = 0; i < paths.length; i++) {
if (i > 0)
result.append(SEPARATOR);
result.append(paths[i].lastSegment());
}
break;
case FULL_PATH:
case DIRECTORY:
default:
for (int i = 0; i < paths.length; i++) {
if (i > 0)
result.append(SEPARATOR);
result.append(paths[i].toOSString());
}
break;
}
textInput.setText(result.toString());
textInput.setCurrentPath(currentPath);
textInput.fireManualValueChange(textInput.getText());
}
break;
default:
break;
}
}
use of org.eclipse.swt.widgets.DirectoryDialog in project yamcs-studio by yamcs.
the class SelectWorkspaceDialog method createWorkspaceSection.
private void createWorkspaceSection(Composite parent) {
GridLayout layout = new GridLayout();
layout.numColumns = 2;
parent.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
parent.setLayoutData(gd);
workspaces = new Combo(parent, SWT.DROP_DOWN);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
workspaces.setLayoutData(gd);
// Fill w/ current workspace history, select the first one
workspaces.setItems(recentWorkspaces);
workspaces.select(0);
Button browse = new Button(parent, SWT.PUSH);
browse.setText("Browse");
browse.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setText("Select Workspace");
dialog.setMessage("Select existing workspace");
dialog.setFilterPath(getInitialBrowsePath());
String dir = dialog.open();
if (dir != null) {
workspaces.setText(dir);
}
}
});
}
Aggregations