package bluej.groupwork;

import java.io.File;
import java.io.IOException;
import java.util.*;

import javafx.stage.Window;

import threadchecker.OnThread;
import threadchecker.Tag;
import bluej.utility.DialogManager;
import bluej.utility.FileUtility;


| Utilities for teamwork functionality. | public class TeamUtils {
| Handle a server response in an appropriate fashion, i.e. if the response | indicates an error, then display an error dialog. | | Call on the AWT event handling thread. | @OnThread(Tag.FXPlatform) public static void handleServerResponseFX(TeamworkCommandResult result, final Window window) { if (result != null) { if (result.wasAuthFailure()) { DialogManager.showErrorFX(window, "team-authentication-problem"); } else if (result.isError() && ! result.wasAborted()) { DialogManager.showErrorTextFX(window, result.getErrorMessage()); } } }
| From a set of File objects, remove those files which should be treated as | binary files (and put them in a new set). | public static Set extractBinaryFilesFromSet(Set<File> files) { Set<File> binFiles = new HashSet<File>(); Iterator<File> i = files.iterator(); while (i.hasNext()){ File f = i.next(); if (f.isDirectory()) { continue; } String fname = f.getName(); if (! fname.endsWith(".txt") && ! fname.endsWith(".java")) { binFiles.add(f); i.remove(); } } return binFiles; }
| Backup a set of files, returning a map from the original file name to | the backup name. The backup files are created in the system's temp | folder/directory. | public static Map backupFiles(Set<File> files) throws IOException { Map<File,File> rmap = new HashMap<File,File>(); for (Iterator<File> i = files.iterator(); i.hasNext(); ) { File tempFile = File.createTempFile("bluejvcs", null); File srcFile = i.next(); FileUtility.copyFile(srcFile, tempFile); rmap.put(srcFile, tempFile); } return rmap; }
| Copy a set of files, then delete the source files. This is used to | restore a backup created by the backupFiles() method. The source | files (i.e. the backup files) are deleted afterwards. | public static void restoreBackups(Map<File,File> rmap) throws IOException { Iterator<Map.Entry<File,File>> i = rmap.entrySet().iterator(); while (i.hasNext()){ Map.Entry<File,File> entry = i.next(); File orig = entry.getKey(); File backup = entry.getValue(); FileUtility.copyFile(backup, orig); backup.delete(); } } }
top, use, map, class TeamUtils

.   handleServerResponseFX
.   extractBinaryFilesFromSet
.   backupFiles
.   restoreBackups




93 neLoCode + 12 LoComm