Example usage for com.vaadin.ui Component getId

List of usage examples for com.vaadin.ui Component getId

Introduction

In this page you can find the example usage for com.vaadin.ui Component getId.

Prototype

public String getId();

Source Link

Document

Gets currently set debug identifier.

Usage

From source file:annis.libgui.IDGenerator.java

License:Apache License

public static String assignID(Component c, String fieldName) {
    String id = null;//  ww w.ja  v  a2  s.  c o m
    if (c != null && fieldName != null && !fieldName.isEmpty()) {
        Preconditions.checkArgument(c.isAttached(),
                "Component " + c.getConnectorId() + " must be attached before it can get an automatic ID.");
        id = c.getId();
        if (id == null) {
            // try to get the parent ID
            HasComponents parent = c.getParent();
            if (parent == null || parent instanceof UI) {
                // use class name as ID
                id = fieldName;
            } else {
                String parentID = parent.getId();
                if (parentID == null) {
                    parentID = assignID(parent);
                }
                String idBase = parentID + ":" + fieldName;
                // check that no other child has the same ID
                int counter = 1;
                id = idBase;
                while (childHasID(parent, id)) {
                    id = idBase + "." + counter++;
                }
            }
            c.setId(id);
        }
    }
    return id;
}

From source file:annis.libgui.IDGenerator.java

License:Apache License

private static boolean childHasID(HasComponents parent, String id) {
    if (parent != null && id != null) {
        Iterator<Component> itChildren = parent.iterator();
        while (itChildren.hasNext()) {
            Component child = itChildren.next();
            if (id.equals(child.getId())) {
                return true;
            }//from w  ww.  j  a  v  a  2  s .  c  o  m
        }
    }
    return false;
}

From source file:com.mymita.vaadlets.VaadletsBuilder.java

License:Apache License

/**
 * Build a {@link com.vaadin.ui.Component} for the given {@link com.mymita.vaadlets.core.Component}.
 * //from w ww.  j a v  a2 s.  com
 * @param vaadletsComponent
 * @return never <code>null</code>
 */
private com.vaadin.ui.Component createVaadinComponent(
        final com.mymita.vaadlets.core.Component vaadletsComponent) {
    try {
        final String componentId = Objects.firstNonNull(vaadletsComponent.getId(),
                UUID.randomUUID().toString());
        final com.vaadin.ui.Component result = createComponent(vaadletsComponent);
        setComponentAttributes(result, vaadletsComponent);
        setPanelAttributes(result, vaadletsComponent);
        setSplitPanelAttributes(result, vaadletsComponent);
        setWindowAttributes(result, vaadletsComponent);
        setLayoutAttributes(result, vaadletsComponent);
        setInputAttributes(result, vaadletsComponent);
        setEmbeddedAttributes(result, vaadletsComponent);
        components.put(componentId, result);
        return result;
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new IllegalArgumentException(
                format("Can't create vaadin component for vaadlets component '%s'", vaadletsComponent), e);
    }
}

From source file:com.profitsoftware.vaadin.query.matcher.MatchId.java

License:Apache License

public boolean match(final Component component) {
    return id.equals(component.getId());
}

From source file:com.validation.manager.core.VaadinUtils.java

License:Apache License

/**
 * Change all {@code Locale} dependant properties of the
 * {@code com.vaadin.ui.Component}s within of the given component container
 * (typically an {@link UI} or other top level layout component). If the
 * specified {@code Locale} is the same as the current {@code Locale} of the
 * component container, this method does nothing. Otherwise it'll go thru
 * the components searching for it's component id. If it is in the resource
 * bundle, it'll set it's caption to the right translated string.
 *
 * <p>/*from www  .j  a  v  a 2 s.c o  m*/
 * To use this method, do something like:
 * <pre>
 * public class MyUI extends UI {
 *
 *     {@literal @}Override
 *     public void init(final VaadinRequest request) {
 *         // ... usual code
 *         // somewhere in the UI the user can change the "Form Locale". This code must
 *         // call myUI#setLocale(newLocale);
 *     }
 *
 *     // ...
 *
 * }
 *
 *      String key = "demo.tab.message";
 *      VerticalLayout vl = new VerticalLayout();
 *      Button b = new Button(key);
 *      vl.addComponent(b);
 *      ResourceBundle rb = ResourceBundle.getBundle(
 *              "resource.bundle",
 *              new Locale("es"));
 *      VaadinUtils.updateLocale(vl, new Locale("es"), rb);
 *
 *      It also works with components implementing Property:
 *
 *      VerticalLayout vl = new VerticalLayout();
 *      Label l = new Label(key);
 *      vl.addComponent(l);
 *      ResourceBundle rb = ResourceBundle.getBundle(
 *              "resource.bundle",
 *              new Locale("es"));
 *      VaadinUtils.updateLocale(vl, new Locale("es"), rb);
 * </pre>
 *
 * @param ui The component container for which the {@code Locale} dependent
 * component properties must be changed, never {@code null}
 * @param locale The new {@code Locale}, never {@code null}
 * @param rb The {@code ResourceBundle} for the specified {@code Locale},
 * never {@code null}
 */
public static void updateLocale(final HasComponents ui, final Locale locale, final ResourceBundle rb) {

    // locale may not be null, however the current UI Locale may be null!
    if (locale.equals(ui.getLocale())) {
        return;
    }
    final long time = System.currentTimeMillis();
    walkComponentTree(ui, (Component c) -> {
        String id = c.getId();
        String caption;
        if (c instanceof Property && ((Property) c).getValue() instanceof String) {
            caption = (String) ((Property) c).getValue();
        } else {
            caption = c.getCaption();
        }
        if (id != null && !id.trim().isEmpty()) {
            if (rb.containsKey(id)) {
                try {
                    c.setCaption(new String(rb.getString(id).getBytes("ISO-8859-1"), "UTF-8"));
                } catch (UnsupportedEncodingException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            }
        } else if (caption != null && !caption.trim().isEmpty()) {
            /**
             * This is a more complex scenario where the caption uses more
             * than one key for translation. Sort the keys in reverse so
             * substitutions are correct.
             */
            final SortedSet<String> ss = new TreeSet<>(Collections.reverseOrder());
            for (Enumeration<String> e = rb.getKeys(); e.hasMoreElements();) {
                try {
                    String key = e.nextElement();
                    ss.add(key);
                    caption = caption.replaceAll(key,
                            new String(rb.getString(key).getBytes("ISO-8859-1"), "UTF-8"));
                } catch (UnsupportedEncodingException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            }
            if (c instanceof Property) {
                ((Property) c).setValue(caption);
            } else {
                c.setCaption(caption);
            }
        }
    });
    LOG.log(Level.FINE, "Locale updated: {0} -> {1} in {2} ms.",
            new Object[] { ui.getLocale(), locale, System.currentTimeMillis() - time });
}

From source file:de.metas.procurement.webui.util.SwipeHelper.java

License:Open Source License

public synchronized void enable(final Component component, final SwipeHandler handler) {
    Preconditions.checkNotNull(component, "component is null");
    final String componentId = component.getId();
    Preconditions.checkNotNull(componentId, "componentId is null");

    final ComponentSwipe swipe = new ComponentSwipe(componentId, handler);

    component2swipe.put(component, swipe);
    componentId2swipe.put(componentId, swipe);

    registerJavaScriptFunctionsIfNeeded();

    final JavaScript javaScript = JavaScript.getCurrent();
    javaScript.execute("" + "if (!window.swipesMap) { window.swipesMap={}; }"
    ///*from  w  w  w.j  a v a  2  s .co  m*/
            + "window.swipesMap['" + componentId + "'] = Swiped.init({" + "query: '#" + componentId + "'"
            + ", left: 300" + ", right: 300" + ", tolerance: 200" + ", onOpen: function() { " + JS_FUNC_OnSwipe
            + "('" + componentId + "'); }" + "});"
            //
            + "\n console.log('Enabled swiping for element: " + componentId + "');");
}

From source file:de.metas.ui.web.vaadin.window.view.WindowRecordIndicators.java

License:Open Source License

private String getIndicatorCss(final Component indicatorComp) {
    final String indicatorId = indicatorComp.getId();

    final StringBuilder css = new StringBuilder();

    final String color = indicatorId2color.get(indicatorId);
    if (color != null) {
        css.append("background-color: " + color + ";");
    }//from  w w  w  .ja v  a 2s.  c  o m

    //
    if (css.length() == 0) {
        return null;
    }
    return css.toString();
}

From source file:edu.cornell.qatarmed.planrnaseq.AnnotateRNAseqSQL.java

public Component findById(HasComponents root, String id) {
    System.out.println("findById called on " + root);

    Iterator<Component> iterate = root.iterator();
    while (iterate.hasNext()) {
        Component c = iterate.next();
        if (id.equals(c.getId())) {
            return c;
        }/*from   www. jav a2  s  .com*/
        if (c instanceof HasComponents) {
            Component cc = findById((HasComponents) c, id);
            if (cc != null) {
                return cc;
            }
        }
    }

    return null;
}

From source file:edu.cornell.qatarmed.planrnaseq.BrowseAndAnnotate.java

public Component findById(HasComponents root, String id) {
    // System.out.println("findById called on " + root);

    Iterator<Component> iterate = root.iterator();
    while (iterate.hasNext()) {
        Component c = iterate.next();
        if (id.equals(c.getId())) {
            return c;
        }//from ww  w. j a  v  a 2  s.co m
        if (c instanceof HasComponents) {
            Component cc = findById((HasComponents) c, id);
            if (cc != null) {
                return cc;
            }
        }
    }

    return null;
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI.java

License:Apache License

public Component findMainProvider(String id) {
    Iterator<Component> it = tabSheet.iterator();
    Component me = null;/*from  w w w.  j a v a2 s .com*/
    while (it.hasNext()) {
        Component next = it.next();
        if (next.getId() != null && next.getId().equals(id)) {
            me = next;
            break;
        }
    }
    return me;
}