From 72d2fabc95384e1f7fdb6fbd9a9f5757437087ed Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Sun, 12 Apr 2015 09:59:07 +0300 Subject: [PATCH] Add getter for local id #17444 Change-Id: I0007bdf111bf516cb9e2f244b63fde42213f5c98 --- .../com/vaadin/ui/declarative/DesignContext.java | 13 +++++++++++++ .../tests/design/DesignContextLocalIdTest.java | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/server/src/com/vaadin/ui/declarative/DesignContext.java b/server/src/com/vaadin/ui/declarative/DesignContext.java index fe3abcfb77..657e15896c 100644 --- a/server/src/com/vaadin/ui/declarative/DesignContext.java +++ b/server/src/com/vaadin/ui/declarative/DesignContext.java @@ -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. diff --git a/server/tests/src/com/vaadin/tests/design/DesignContextLocalIdTest.java b/server/tests/src/com/vaadin/tests/design/DesignContextLocalIdTest.java index dffeb2e412..6cedb17409 100644 --- a/server/tests/src/com/vaadin/tests/design/DesignContextLocalIdTest.java +++ b/server/tests/src/com/vaadin/tests/design/DesignContextLocalIdTest.java @@ -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)); + } } -- 2.39.5