重命名Action

File selected_file = (File) selection.getFirstElement();
		String oldFileName = selected_file.getName();
		// need write a class InputValidator implements IInputValidator
		InputDialog inputDlg = new InputDialog(window.getShell(), "Rename",
				"Please input new name", oldFileName, null);

		if (inputDlg.open() == InputDialog.OK) {
			String newName = inputDlg.getValue();
			File newNameFile = new File(selected_file.getParent()
					+ File.separator + newName);
			// need check name duplicated and rename failed
			if (selected_file.renameTo(newNameFile)) {
				window.refresh();
			} else {
				window.setStatus(ACTION_RENAME_INFO_FAILED);
			}
		}

 

你可能感兴趣的:(action)