public void createFileNamePanel(Shell dialog, String fileName) { Composite fileNamePanel = new Composite(dialog, SWT.NONE); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); fileNamePanel.setLayoutData(gridData); fileNamePanel.setLayout(new GridLayout(2, false)); Label fileNameLabel = new Label(fileNamePanel, SWT.NONE); fileNameLabel.setText(Messages.getString("VfsFileChooserDialog.fileName")); // $NON-NLS-1$ gridData = new GridData(SWT.FILL, SWT.CENTER, false, false); fileNameLabel.setLayoutData(gridData); fileNameText = new Text(fileNamePanel, SWT.BORDER); if (fileName != null) { fileNameText.setText(fileName); } gridData = new GridData(SWT.FILL, SWT.CENTER, true, false); fileNameText.setLayoutData(gridData); fileNameText.addKeyListener( new KeyListener() { public void keyPressed(KeyEvent arg0) {} public void keyReleased(KeyEvent event) { if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) { okPressed(); } } }); }
public void okPressed() { if (fileDialogMode == VFS_DIALOG_SAVEAS && "".equals(fileNameText.getText())) { // $NON-NLS-1$ // do nothing, user did not enter a file name for saving MessageBox messageDialog = new MessageBox(dialog, SWT.OK); messageDialog.setText(Messages.getString("VfsFileChooserDialog.error")); // $NON-NLS-1$ messageDialog.setMessage( Messages.getString("VfsFileChooserDialog.noFilenameEntered")); // $NON-NLS-1$ messageDialog.open(); return; } if (fileDialogMode == VFS_DIALOG_SAVEAS) { try { FileObject toBeSavedFile = vfsBrowser.getSelectedFileObject().resolveFile(fileNameText.getText()); if (toBeSavedFile.exists()) { MessageBox messageDialog = new MessageBox(dialog, SWT.YES | SWT.NO); messageDialog.setText( Messages.getString("VfsFileChooserDialog.fileExists")); // $NON-NLS-1$ messageDialog.setMessage( Messages.getString("VfsFileChooserDialog.fileExistsOverwrite")); // $NON-NLS-1$ int flag = messageDialog.open(); if (flag == SWT.NO) { return; } } } catch (FileSystemException e) { e.printStackTrace(); } } if (fileDialogMode == VFS_DIALOG_SAVEAS) { enteredFileName = fileNameText.getText(); } try { if (fileDialogMode == VFS_DIALOG_OPEN_FILE && vfsBrowser.getSelectedFileObject().getType().equals(FileType.FOLDER)) { // try to open this node, it is a directory vfsBrowser.selectTreeItemByFileObject(vfsBrowser.getSelectedFileObject(), true); return; } } catch (FileSystemException e) { } okPressed = true; hideCustomPanelChildren(); dialog.dispose(); }