Ignore:
Timestamp:
03/25/19 14:33:31 (5 years ago)
Author:
bln4
Message:

On profile creation a new parameter has been introducted. By passing a map, the user is able to nominate settings frames for which to be notified of their construction.

The above functionalty has been used to programmatically establish the frame number for a users credentials frame.

On user account creation, the users credential frame is migrated to the <username>-credentials folder and a redirect is setup. Functionality for doing this has been generisised and placed in FrameIO.

Location:
trunk/src/org/expeditee/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/Browser.java

    r1264 r1270  
    553553                if (profile == null) {
    554554                        try {
    555                                 profile = FrameIO.CreateNewProfile(userName, null);
     555                                profile = FrameIO.CreateNewProfile(userName, null, null);
    556556                        } catch (Exception e) {
    557557                                // TODO tell the user that there was a problem creating the
  • trunk/src/org/expeditee/gui/FrameIO.java

    r1257 r1270  
    4343import java.util.List;
    4444import java.util.Map;
     45import java.util.function.Consumer;
    4546import java.util.stream.Collectors;
    4647
     
    13491350        }
    13501351
    1351         public static Frame CreateNewProfile(String username, Map<String, Setting> initialSettings) throws InvalidFramesetNameException, ExistingFramesetException  {
     1352        public static Frame CreateNewProfile(String username, Map<String, Setting> initialSettings, Map<String, Consumer<Frame>> toNotifyOnSet) throws InvalidFramesetNameException, ExistingFramesetException  {
    13521353                Frame profile = CreateFrameset(username, PROFILE_PATH, true);
    1353                 FrameUtils.CreateDefaultProfile(username, profile, initialSettings);
     1354                FrameUtils.CreateDefaultProfile(username, profile, initialSettings, toNotifyOnSet);
    13541355                return profile;
    13551356        }
     
    19241925        }
    19251926       
    1926         public static Path setupPersonalResources(String username)
    1927         {
     1927        public static Path setupPersonalResources(String username) {
    19281928                Path personalResources = Paths.get(FrameIO.PARENT_FOLDER).resolve("resources-" + username);
    19291929                personalResources.toFile().mkdir();             
     
    19441944               
    19451945                return personalResources;
     1946        }
     1947       
     1948        public static void migrateFrame(Frame toMigrate, Path destinationDirectory) {
     1949                Path source = Paths.get(toMigrate.getFramePathReal());
     1950                String destination = source.relativize(destinationDirectory).toString().substring(3).replace(File.separator, "/");
     1951                try {
     1952                        copyFileTree(source, destinationDirectory);
     1953                } catch (IOException e) {
     1954                        System.err.println("FrameIO::migrateFrame: failed to migrate from to new location.  Message: " + e.getMessage());
     1955                        return;
     1956                }
     1957                try {
     1958                        FileWriter out = new FileWriter(source.toFile());
     1959                        out.write("REDIRECT:" + destination);
     1960                        out.flush();
     1961                        out.close();
     1962                } catch (IOException e) {
     1963                        System.err.println("FrameIO::migrateFrame: failed to update file [" + source + "] to redirect to  [" + destination + "] following migration.  Message: " + e.getMessage());
     1964                }
    19461965        }
    19471966       
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r1244 r1270  
    4141import java.util.List;
    4242import java.util.Map;
     43import java.util.function.Consumer;
    4344import java.util.jar.JarEntry;
    4445import java.util.jar.JarFile;
     
    15141515       
    15151516        public static void CreateDefaultProfile(String profileFor, Frame profile) {
    1516                 CreateDefaultProfile(profileFor, profile, null);
     1517                CreateDefaultProfile(profileFor, profile, null, null);
    15171518        }
    15181519
     
    15251526         */
    15261527        public static void CreateDefaultProfile(String profileFor, Frame profile,
    1527                         Map<String, Setting> specifiedSettings) {
     1528                        Map<String, Setting> specifiedSettings, Map<String, Consumer<Frame>> notifyWhenGenerated) {
    15281529                // If this is already the default profile then nothing (other than setting
    15291530                // title) needs to be done.
     
    15391540                                try {
    15401541                                        // If we do not have a default to copy, create one.
    1541                                         defaultFrame = FrameIO.CreateNewProfile(UserSettings.DEFAULT_PROFILE_NAME, null);
     1542                                        defaultFrame = FrameIO.CreateNewProfile(UserSettings.DEFAULT_PROFILE_NAME, null, null);
    15421543                                } catch (InvalidFramesetNameException invalidNameEx) {
    15431544                                        MessageBay.errorMessage("Failed to create default profile named: "
     
    16081609                                        }
    16091610                                }
     1611                                if (notifyWhenGenerated != null && notifyWhenGenerated.containsKey(category)) {
     1612                                        notifyWhenGenerated.get(category).accept(profile);
     1613                                }
    16101614                                FrameIO.SaveFrame(profile);
    16111615                        }
     
    17141718                        t.setColor(Colour.GREY);
    17151719                        Settings.generateSettingsTree(t);
     1720                        System.out.println("@Settings: Default settings generation complete.");
    17161721
    17171722                        FrameIO.SaveFrame(profile);
Note: See TracChangeset for help on using the changeset viewer.