Search in sources :

Example 26 with SettingsNode

use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.

the class BasicProjectAndTaskFilter method serializeIn.

/**
     * Call this to read in this object's settings. The reverse of serializeOut.
     *
     * @param settings where you read your settings.
     */
public void serializeIn(SettingsNode settings) {
    filteredOutProjectNames.clear();
    filteredOutTaskNames.clear();
    SettingsNode rootNode = settings.getChildNode(BASIC_PROJECT_AND_TASK_FILTER);
    if (rootNode == null) {
        return;
    }
    filterOutTasksWithNoDescription = rootNode.getValueOfChildAsBoolean(FILTER_OUT_TASKS_WITH_NO_DESCRIPTION, filterOutTasksWithNoDescription);
    SettingsNode filteredOutProjectsNode = rootNode.getChildNode(FILTERED_OUT_PROJECTS);
    if (filteredOutProjectsNode != null) {
        serializeInStringList(filteredOutProjectsNode, filteredOutProjectNames);
    }
    SettingsNode filteredOutTasksNode = rootNode.getChildNode(FILTERED_OUT_TASKS);
    if (filteredOutTasksNode != null) {
        serializeInStringList(filteredOutTasksNode, filteredOutTaskNames);
    }
}
Also used : SettingsNode(org.gradle.gradleplugin.foundation.settings.SettingsNode)

Example 27 with SettingsNode

use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.

the class MainGradlePanel method restoreLastTab.

private void restoreLastTab() {
    //if they're not setup, make the setup tab visible first.
    if (!gradlePluginLord.isSetupComplete()) {
        int tabToSelect = getGradleTabIndex(SetupTab.class);
        if (tabToSelect != -1) {
            tabbedPane.setSelectedIndex(tabToSelect);
        }
    } else {
        //otherwise, try to get the last-used tab
        int lastTabIndex = -1;
        //all this is to just restore the last selected tab
        SettingsNode rootNode = settings.getChildNode(MAIN_PANEL);
        if (rootNode != null) {
            String lastTabName = rootNode.getValueOfChild(CURRENT_TAB, "");
            lastTabIndex = getGradleTabIndex(lastTabName);
        }
        if (lastTabIndex != -1) {
            tabbedPane.setSelectedIndex(lastTabIndex);
        }
    }
}
Also used : SettingsNode(org.gradle.gradleplugin.foundation.settings.SettingsNode)

Example 28 with SettingsNode

use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.

the class DOM4JSettingsNodeTest method testAddingChildrenIfNotPresent2.

/**
     * This tests that if you call addChildIfNotPresent, it won't add a child if one is already present. We'll verify a
     * child is present, then call addChildIfNotPresent.
     */
public void testAddingChildrenIfNotPresent2() {
    rootNode.addChild(SAMPLE_NAME_1);
    assertNotNull(Dom4JUtility.getChild(rootElement, DOM4JSettingsNode.TAG_NAME, DOM4JSettingsNode.NAME_ATTRIBUTE, SAMPLE_NAME_1));
    assertNotNull(rootNode.getChildNode(SAMPLE_NAME_1));
    List list = Dom4JUtility.getChildren(rootElement, DOM4JSettingsNode.TAG_NAME, DOM4JSettingsNode.NAME_ATTRIBUTE, SAMPLE_NAME_1);
    //there should only be the one element.
    assertEquals(1, list.size());
    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));
    assertNotNull(rootNode.getChildNode(SAMPLE_NAME_1));
    //but make sure we didn't add an additional one. There should still be only one element.
    list = Dom4JUtility.getChildren(rootElement, DOM4JSettingsNode.TAG_NAME, DOM4JSettingsNode.NAME_ATTRIBUTE, SAMPLE_NAME_1);
    assertEquals(1, list.size());
}
Also used : SettingsNode(org.gradle.gradleplugin.foundation.settings.SettingsNode) DOM4JSettingsNode(org.gradle.gradleplugin.foundation.settings.DOM4JSettingsNode) List(java.util.List)

Example 29 with SettingsNode

use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.

the class DOM4JSettingsNodeTest method testSetValueOfChild.

/**
     * This tests setValueOfChild. We're going to make sure the value is set as well as that repeated calls to this
     * don't add child nodes.
     */
public void testSetValueOfChild() {
    //make sure we have no children first
    List<SettingsNode> children = rootNode.getChildNodes();
    assertEquals(0, children.size());
    //set the value of a child
    rootNode.setValueOfChild(SAMPLE_NAME_1, "myValue");
    //verify it was set properly
    SettingsNode childNode1 = rootNode.getChildNode(SAMPLE_NAME_1);
    assertNotNull(childNode1);
    assertEquals("myValue", childNode1.getValue());
    //make sure there's only 1 child.
    children = rootNode.getChildNodes();
    assertEquals(1, children.size());
    //set the value again. This should set the value and NOT add an additional node
    rootNode.setValueOfChild(SAMPLE_NAME_1, "newvalue");
    childNode1 = rootNode.getChildNode(SAMPLE_NAME_1);
    assertNotNull(childNode1);
    assertEquals("newvalue", childNode1.getValue());
    //make sure there's still only 1 child.
    children = rootNode.getChildNodes();
    assertEquals(1, children.size());
}
Also used : SettingsNode(org.gradle.gradleplugin.foundation.settings.SettingsNode) DOM4JSettingsNode(org.gradle.gradleplugin.foundation.settings.DOM4JSettingsNode)

Example 30 with SettingsNode

use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.

the class DOM4JSettingsNodeTest method testRemoveFromParent.

/**
     * This tests that removeFromParent works. We'll add some sample nodes and then delete them one by one and verify
     * they're really removed. We'll also add two with the same name just to make sure that the wrong one isn't
     * deleted.
     */
public void testRemoveFromParent() {
    //make sure we have no children first
    List<SettingsNode> children = rootNode.getChildNodes();
    assertEquals(0, children.size());
    //add some sample nodes.
    SettingsNode childNode1 = rootNode.addChild(SAMPLE_NAME_1);
    SettingsNode childNode2 = rootNode.addChild(SAMPLE_NAME_2);
    SettingsNode childNode3 = rootNode.addChild(SAMPLE_NAME_3);
    //notice this has the same name as childNode2
    SettingsNode childNode4 = rootNode.addChild(SAMPLE_NAME_2);
    //make sure they're all present as expected
    children = rootNode.getChildNodes();
    TestUtility.assertListContents(children, childNode1, childNode2, childNode3, childNode4);
    //now give the two with the same names different values
    childNode2.setValue("first");
    childNode4.setValue("second");
    //delete the 'first' one with SAMPLE_NAME_2
    childNode2.removeFromParent();
    //make sure its not longer present
    children = rootNode.getChildNodes();
    TestUtility.assertListContents(children, childNode1, childNode3, childNode4);
    //make sure that we didn't delete the wrong node with SAMPLE_NAME_2. The 'second' one should still be present.
    SettingsNode foundNode = rootNode.getChildNode(SAMPLE_NAME_2);
    assertEquals("second", foundNode.getValue());
    //delete another one and make sure its no longer present
    childNode3.removeFromParent();
    children = rootNode.getChildNodes();
    TestUtility.assertListContents(children, childNode1, childNode4);
    //delete yet another one and make sure its no longer present
    childNode1.removeFromParent();
    children = rootNode.getChildNodes();
    TestUtility.assertListContents(children, childNode4);
    //delete the last one and make sure that the children are now empty.
    childNode4.removeFromParent();
    children = rootNode.getChildNodes();
    assertEquals(0, children.size());
    //just for grins, try to delete one that's already deleted. It shouldn't do anything (like crash)
    childNode3.removeFromParent();
    children = rootNode.getChildNodes();
    assertEquals(0, children.size());
    //just to be paranoid, verify they're gone using getChildNode. Each of these should return nothing.
    assertNull(rootNode.getChildNode(SAMPLE_NAME_1));
    assertNull(rootNode.getChildNode(SAMPLE_NAME_2));
    assertNull(rootNode.getChildNode(SAMPLE_NAME_3));
    //make sure the nodes are gone from a DOM4J standpoint.
    assertEquals(0, rootElement.elements().size());
}
Also used : SettingsNode(org.gradle.gradleplugin.foundation.settings.SettingsNode) DOM4JSettingsNode(org.gradle.gradleplugin.foundation.settings.DOM4JSettingsNode)

Aggregations

SettingsNode (org.gradle.gradleplugin.foundation.settings.SettingsNode)35 DOM4JSettingsNode (org.gradle.gradleplugin.foundation.settings.DOM4JSettingsNode)19 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 SettingsNodeVersion1 (org.gradle.openapi.external.ui.SettingsNodeVersion1)1