]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add getter for local id #17444
authorJohn Ahlroos <john.ahlroos@jasoft.fi>
Sun, 12 Apr 2015 06:59:07 +0000 (09:59 +0300)
committerJohn Ahlroos <john@vaadin.com>
Mon, 13 Apr 2015 11:57:23 +0000 (14:57 +0300)
Change-Id: I0007bdf111bf516cb9e2f244b63fde42213f5c98

server/src/com/vaadin/ui/declarative/DesignContext.java
server/tests/src/com/vaadin/tests/design/DesignContextLocalIdTest.java

index fe3abcfb778802c4c343988b068f39d759d1cd9a..657e15896c8e349ff1c57ce479d748e5ea7a0b0a 100644 (file)
@@ -170,6 +170,7 @@ public class DesignContext implements Serializable {
      * component, the mapping from c to the string is removed. Similarly, if
      * component was mapped to some string s different from localId, the mapping
      * from s to component is removed.
+     * 
      * @param component
      *            The component whose local id is to be set.
      * @param localId
@@ -184,6 +185,18 @@ public class DesignContext implements Serializable {
                 componentToLocalId);
     }
 
+    /**
+     * Returns the local id for a component
+     * 
+     * @param component
+     *            The component whose local id to get.
+     * @return the local id of the component, or null if the component has no
+     *         local id assigned
+     */
+    public String getComponentLocalId(Component component) {
+        return componentToLocalId.get(component);
+    }
+
     /**
      * Creates a mapping between the given caption and the component. Returns
      * true if caption was already mapped to some component.
index dffeb2e412ea41e9a717b52c36426348655e9407..6cedb174099aa001a5337f0c03c7dc59408d40c8 100644 (file)
@@ -32,6 +32,7 @@ import com.vaadin.ui.CustomLayout;
 import com.vaadin.ui.GridLayout;
 import com.vaadin.ui.HorizontalLayout;
 import com.vaadin.ui.HorizontalSplitPanel;
+import com.vaadin.ui.Label;
 import com.vaadin.ui.Panel;
 import com.vaadin.ui.SingleComponentContainer;
 import com.vaadin.ui.TabSheet;
@@ -113,4 +114,13 @@ public class DesignContextLocalIdTest {
                     .getElementsByTag("v-button").first().attr("_id"));
         }
     }
+
+    @Test
+    public void testGetLocalId() {
+        DesignContext ctx = new DesignContext();
+        Label label = new Label();
+        ctx.setComponentLocalId(label, "my-local-id");
+        ctx.setRootComponent(label);
+        assertEquals("my-local-id", ctx.getComponentLocalId(label));
+    }
 }