Package org.gradle.gradleplugin.foundation.settings

Examples of org.gradle.gradleplugin.foundation.settings.SettingsNode


     * @param id a unique ID for these settings.
     * @param windowClass Any class. Just used for the preferences mechanism to obtain an instance. Making this an
     * argument gives you more flexibility.
     */
    public static SettingsNode restoreSettings(SettingsNode settingsNode, Window window, String id, Class windowClass) {
        SettingsNode childNode = settingsNode.getChildNode(getPrefix(windowClass, id));
        if (childNode == null) {
            return null;
        }

        int x = childNode.getValueOfChildAsInt(WINDOW_X, window.getLocation().x);
        int y = childNode.getValueOfChildAsInt(WINDOW_Y, window.getLocation().y);
        int width = childNode.getValueOfChildAsInt(WINDOW_WIDTH, window.getSize().width);
        int height = childNode.getValueOfChildAsInt(WINDOW_HEIGHT, window.getSize().height);

        window.setLocation(x, y);
        window.setSize(width, height);

        return childNode;
View Full Code Here


    /**
     * This restores the position of a frame. We not only restore the size, but we'll maximize it if its was maximized
     * when saved.
     */
    public static void restoreSettings(SettingsNode settingsNode, JFrame frame, String id, Class windowClass) {
        SettingsNode childNode = restoreSettings(settingsNode, (Window) frame, id, windowClass);
        if (childNode == null) {
            return;
        }

        int extendedState = childNode.getValueOfChildAsInt(EXTENDED_STATE, frame.getExtendedState());

        if (extendedState != JFrame.ICONIFIED) {
            frame.setExtendedState(extendedState);
        }
    }
View Full Code Here

            frame.setExtendedState(extendedState);
        }
    }

    public static void saveSettings(SettingsNode settingsNode, JSplitPane splitter, String id, Class splitterClass) {
        SettingsNode childNode = settingsNode.addChildIfNotPresent(getPrefix(splitterClass, id));

        childNode.setValueOfChildAsInt(DIVIDER_LOCATION, splitter.getDividerLocation());
    }
View Full Code Here

        childNode.setValueOfChildAsInt(DIVIDER_LOCATION, splitter.getDividerLocation());
    }

    public static void restoreSettings(SettingsNode settingsNode, JSplitPane splitter, String id, Class splitterClass) {
        SettingsNode childNode = settingsNode.getChildNode(getPrefix(splitterClass, id));
        if (childNode == null) {
            return;
        }

        int location = childNode.getValueOfChildAsInt(DIVIDER_LOCATION, splitter.getDividerLocation());
        splitter.setDividerLocation(location);
    }
View Full Code Here

     * @param saveCurrentDirectoryVsSelectedFilesParent this should be true true if you're selecting only directories,
     * false if you're selecting only files. I don't know what if you allow both.
     */
    public static void saveSettings(SettingsNode settingsNode, JFileChooser fileChooser, String id,
                                    Class fileChooserClass, boolean saveCurrentDirectoryVsSelectedFilesParent) {
        SettingsNode childNode = settingsNode.addChildIfNotPresent(getPrefix(fileChooserClass, id));

        String save;
        try {
            if (saveCurrentDirectoryVsSelectedFilesParent) {
                save = fileChooser.getCurrentDirectory().getCanonicalPath();
            } else {
                save = fileChooser.getSelectedFile().getCanonicalPath();
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
        if (save != null) {
            childNode.setValueOfChild(DIRECTORY_NAME, save);
        }
    }
View Full Code Here

        }
    }

    public static void restoreSettings(SettingsNode settingsNode, JFileChooser fileChooser, String id,
                                       Class fileChooserClass) {
        SettingsNode childNode = settingsNode.getChildNode(getPrefix(fileChooserClass, id));
        if (childNode == null) {
            return;
        }

        String lastDirectory = childNode.getValueOfChild(DIRECTORY_NAME, null);

        if (lastDirectory != null) {
            fileChooser.setCurrentDirectory(new File(lastDirectory));
        }
    }
View Full Code Here

        assertNull(rootElement.element(SAMPLE_NAME_1));

        //as such, we shouldn't have one at the DOM4JSettingsNode level either.
        assertNull(rootNode.getChildNode(SAMPLE_NAME_1));

        SettingsNode settingsNode = rootNode.addChild(SAMPLE_NAME_1);
        assertNotNull(settingsNode);

        //and now it should be present under both.
        assertNotNull(Dom4JUtility.getChild(rootElement, DOM4JSettingsNode.TAG_NAME, DOM4JSettingsNode.NAME_ATTRIBUTE,
                SAMPLE_NAME_1));
View Full Code Here

        assertNull(rootElement.element(SAMPLE_NAME_1));

        //as such, we shouldn't have one at the DOM4JSettingsNode level either.
        assertNull(rootNode.getChildNode(SAMPLE_NAME_1));

        SettingsNode settingsNode = rootNode.addChildIfNotPresent(SAMPLE_NAME_1);
        assertNotNull(settingsNode);

        //and now it should be present under both.
        assertNotNull(Dom4JUtility.getChild(rootElement, DOM4JSettingsNode.TAG_NAME, DOM4JSettingsNode.NAME_ATTRIBUTE,
                SAMPLE_NAME_1));
View Full Code Here

        List list = Dom4JUtility.getChildren(rootElement, DOM4JSettingsNode.TAG_NAME, DOM4JSettingsNode.NAME_ATTRIBUTE,
                SAMPLE_NAME_1);
        assertEquals(1, list.size())//there should only be the one element.

        SettingsNode settingsNode = rootNode.addChildIfNotPresent(SAMPLE_NAME_1);
        assertNotNull(settingsNode);

        //it should still be present under both.
        assertNotNull(Dom4JUtility.getChildren(rootElement, DOM4JSettingsNode.TAG_NAME,
                DOM4JSettingsNode.NAME_ATTRIBUTE, SAMPLE_NAME_1));
View Full Code Here

     * This tests that getChildNode works. We'll add some nodes and make sure they are found correctly. We'll also add a
     * duplicate named node. It should never be returned because getChildNode only finds the first one. Lastly, we'll
     * call getChildNode for a node that doesn't exist. It shouldn't be returned.
     */
    public void testGetChildNode() {
        SettingsNode childNode1 = rootNode.addChild(SAMPLE_NAME_1);
        SettingsNode childNode2 = rootNode.addChild(SAMPLE_NAME_2);
        SettingsNode childNode3 = rootNode.addChild(SAMPLE_NAME_3);
        SettingsNode childNode4 = rootNode.addChild(
                SAMPLE_NAME_2)//this is a duplicate and should never be found via getChildNode.

        assertNotNull(Dom4JUtility.getChild(rootElement, DOM4JSettingsNode.TAG_NAME, DOM4JSettingsNode.NAME_ATTRIBUTE,
                SAMPLE_NAME_1));
        assertNotNull(Dom4JUtility.getChild(rootElement, DOM4JSettingsNode.TAG_NAME, DOM4JSettingsNode.NAME_ATTRIBUTE,
                SAMPLE_NAME_2));
        assertNotNull(Dom4JUtility.getChild(rootElement, DOM4JSettingsNode.TAG_NAME, DOM4JSettingsNode.NAME_ATTRIBUTE,
                SAMPLE_NAME_3));
        assertNotNull(rootNode.getChildNode(SAMPLE_NAME_1));
        assertNotNull(rootNode.getChildNode(SAMPLE_NAME_2));
        assertNotNull(rootNode.getChildNode(SAMPLE_NAME_3));

        SettingsNode foundNode1 = rootNode.getChildNode(SAMPLE_NAME_1);
        assertEquals(foundNode1, childNode1);

        SettingsNode foundNode2 = rootNode.getChildNode(SAMPLE_NAME_2);
        assertEquals(foundNode2, childNode2);

        SettingsNode foundNode3 = rootNode.getChildNode(SAMPLE_NAME_3);
        assertEquals(foundNode3, childNode3);

        //look for the duplicated
        SettingsNode foundNode2B = rootNode.getChildNode(SAMPLE_NAME_2);
        assertEquals(foundNode2B, childNode2)//should still be childNode2.

        //this one shouldn't be found.
        SettingsNode foundNode4 = rootNode.getChildNode("notpresent");
        assertNull(foundNode4);
    }
View Full Code Here

TOP

Related Classes of org.gradle.gradleplugin.foundation.settings.SettingsNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.