Example usage for com.vaadin.ui Image addClickListener

List of usage examples for com.vaadin.ui Image addClickListener

Introduction

In this page you can find the example usage for com.vaadin.ui Image addClickListener.

Prototype

public Registration addClickListener(ClickListener listener) 

Source Link

Document

Add a click listener to the component.

Usage

From source file:dhbw.clippinggorilla.userinterface.windows.GroupProfileWindow.java

public Component getSources(GroupInterestProfile profile, boolean isAdmin) {
    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.setWidth("100%");
    VerticalLayout sourcesLayout = new VerticalLayout();
    sourcesLayout.setWidth("100%");
    Panel sourcesPanel = new Panel(sourcesLayout);

    List<CheckBox> checkBoxes = new ArrayList<>();
    HashMap<String, GridLayout> sourceLayouts = new HashMap<>();
    profile.getSources().entrySet().stream()
            .sorted((e1, e2) -> e1.getKey().getName().compareToIgnoreCase(e2.getKey().getName())).forEach(e -> {
                Source source = e.getKey();
                boolean enabled = e.getValue();
                GridLayout sourceLayout = new GridLayout(5, 1);
                sourceLayout.setSizeFull();

                CheckBox sourceSelected = new CheckBox();
                sourceSelected.setValue(enabled);
                sourceSelected.addStyleName(ValoTheme.CHECKBOX_LARGE);
                sourceSelected.addValueChangeListener(v -> profile.getSources().replace(source, v.getValue()));
                sourceSelected.setEnabled(isAdmin);
                checkBoxes.add(sourceSelected);

                Image sourceLogo = new Image();
                sourceLogo.addStyleName("logosmall");
                sourceLogo.setSource(new ExternalResource(source.getLogo()));
                if (isAdmin) {
                    sourceLogo.addClickListener(c -> {
                        sourceSelected.setValue(!sourceSelected.getValue());
                        profile.getSources().replace(source, sourceSelected.getValue());
                    });//from   w w  w .j  a v a  2 s  . c om
                }
                VerticalLayout layoutLogo = new VerticalLayout(sourceLogo);
                layoutLogo.setWidth("150px");
                layoutLogo.setHeight("50px");
                layoutLogo.setMargin(false);
                layoutLogo.setSpacing(false);
                layoutLogo.setComponentAlignment(sourceLogo, Alignment.MIDDLE_LEFT);

                Label labelHeadLine = new Label(
                        source.getCategory().getIcon().getHtml() + "  " + source.getName(), ContentMode.HTML);
                labelHeadLine.addStyleName(ValoTheme.LABEL_H3);

                Label labelDescription = new Label(source.getDescription(), ContentMode.HTML);
                labelDescription.setWidth("300px");
                PopupView popup = new PopupView(null, labelDescription);

                Button buttonDescription = new Button(VaadinIcons.INFO_CIRCLE_O);
                buttonDescription.addClickListener(ce -> {
                    popup.setPopupVisible(true);
                });

                sourceLayout.addComponents(sourceSelected, layoutLogo, labelHeadLine, popup, buttonDescription);
                sourceLayout.setComponentAlignment(sourceSelected, Alignment.MIDDLE_CENTER);
                sourceLayout.setComponentAlignment(layoutLogo, Alignment.MIDDLE_CENTER);
                sourceLayout.setColumnExpandRatio(2, 5);
                sourceLayout.setSpacing(true);

                sourceLayouts.put(source.getName().toLowerCase().replaceAll(" ", "").replaceAll("-", "")
                        .replaceAll("_", ""), sourceLayout);
                sourcesLayout.addComponent(sourceLayout);
            });

    sourcesPanel.setContent(sourcesLayout);
    sourcesPanel.setHeight("100%");
    sourcesPanel.setCaption(Language.get(Word.SOURCES));
    Language.setCustom(Word.SOURCES, s -> sourcesPanel.setCaption(s));
    windowLayout.addComponent(sourcesPanel);
    windowLayout.setExpandRatio(sourcesPanel, 1);
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);

    CheckBox checkBoxSelectAll = new CheckBox();
    Language.setCustom(Word.SELECT_ALL, s -> checkBoxSelectAll.setCaption(s));
    checkBoxSelectAll.setWidth("100%");
    checkBoxSelectAll.addValueChangeListener(e -> {
        profile.getSources().replaceAll((c, enabled) -> checkBoxSelectAll.getValue());
        checkBoxes.forEach(c -> c.setValue(checkBoxSelectAll.getValue()));
    });
    checkBoxSelectAll.setEnabled(isAdmin);

    TextField textFieldSearch = new TextField();
    Language.setCustom(Word.SEARCH, s -> textFieldSearch.setPlaceholder(s));
    textFieldSearch.setWidth("100%");
    textFieldSearch.setMaxLength(255);
    textFieldSearch.setPlaceholder(Language.get(Word.SEARCH));
    textFieldSearch.addValueChangeListener(searchValue -> {
        sourceLayouts.forEach((sourceName, sourceLayout) -> {
            if (!sourceName.contains(searchValue.getValue().toLowerCase().replaceAll(" ", "")
                    .replaceAll("-", "").replaceAll("_", ""))) {
                sourcesLayout.removeComponent(sourceLayout);
            } else {
                sourcesLayout.addComponent(sourceLayout);
            }
        });
    });

    Label placeholder = new Label();
    placeholder.setWidth("100%");

    GridLayout footer = new GridLayout(3, 1);
    footer.setSpacing(true);
    footer.setMargin(new MarginInfo(true, false, false, false));
    footer.addStyleName("menubar");
    footer.setWidth("100%");
    footer.addComponents(checkBoxSelectAll, textFieldSearch, placeholder);
    footer.setComponentAlignment(checkBoxSelectAll, Alignment.MIDDLE_LEFT);
    footer.setComponentAlignment(textFieldSearch, Alignment.MIDDLE_CENTER);

    windowLayout.addComponent(footer);
    windowLayout.setHeight("350px");
    return windowLayout;
}

From source file:edu.nps.moves.mmowgli.components.AvatarChooser.java

License:Open Source License

@SuppressWarnings("serial")
@Override//from   w ww .ja v a2  s . c o  m
public void initGui() {
    VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setSizeFull();
    mainLayout.setMargin(true); //test
    mainLayout.setSpacing(true);
    MediaLocator medLoc = Mmowgli2UI.getGlobals().getMediaLocator();
    Label sp;
    setContent(mainLayout);

    Panel p = new Panel(imgLay = new HorizontalLayout());
    imgLay.setSpacing(true);

    p.setWidth("100%");
    mainLayout.addComponent(p);

    Collection<?> lis = Avatar.getContainer().getItemIds();
    avIdArr = new Object[lis.size()];

    int idx = 0;

    for (Object id : lis) {
        avIdArr[idx++] = id;
        if (initSelectedID == null)
            initSelectedID = id; // sets first one
        Avatar a = Avatar.getTL(id);
        Image em = new Image(null, medLoc.locate(a.getMedia()));
        em.setWidth("95px");
        em.setHeight("95px");
        em.addClickListener(new ImageClicked());

        if (id.equals(initSelectedID)) {
            em.addStyleName("m-orangeborder5");
            lastSel = em;
        } else
            em.addStyleName("m-greyborder5");
        imgLay.addComponent(em);
    }

    butts = new HorizontalLayout();
    butts.setWidth("100%");
    butts.setSpacing(true);
    mainLayout.addComponent(butts);

    butts.addComponent(sp = new Label());
    sp.setWidth("1px");
    butts.setExpandRatio(sp, 1.0f);

    NativeButton cancelButt = new NativeButton();
    medLoc.decorateCancelButton(cancelButt);
    butts.addComponent(cancelButt);

    NativeButton selectButt = new NativeButton();
    medLoc.decorateSelectButton(selectButt);
    butts.addComponent(selectButt);

    butts.addComponent(sp = new Label(""));
    sp.setWidth("20px");

    mainLayout.addComponent(sp = new Label(""));
    sp.setHeight("1px");
    mainLayout.setExpandRatio(sp, 1.0f);
    ;

    cancelButt.addClickListener(new ClickListener() {
        @Override
        @MmowgliCodeEntry
        public void buttonClick(ClickEvent event) {
            cancelClick();
        }
    });
    selectButt.addClickListener(new ClickListener() {
        @Override
        @MmowgliCodeEntry
        public void buttonClick(ClickEvent event) {
            selectClick();
        }
    });
}

From source file:edu.nps.moves.mmowgli.components.AvatarPanel.java

License:Open Source License

@Override
public void initGui() {
    setCaption(caption);//from  ww w .  j  a v a  2s  .  c o m
    //setScrollable(true);

    imgLay = new HorizontalLayout();
    setContent(imgLay);
    //  imgLay.setHeight("105px");
    imgLay.setSpacing(true);

    @SuppressWarnings("unchecked")
    HbnContainer<Avatar> contr = (HbnContainer<Avatar>) HSess.getContainer(Avatar.class);
    Collection<?> lis = contr.getItemIds();
    avIdArr = new Object[lis.size()];

    int idx = 0;
    MediaLocator loc = Mmowgli2UI.getGlobals().mediaLocator();

    for (Object id : lis) {
        avIdArr[idx++] = id;

        Avatar a = Avatar.getTL(id);
        Image em = new Image(null, loc.locate(a.getMedia()));
        em.setWidth("95px");
        em.setHeight("95px");
        em.addClickListener(new ImageClicked());
        em.addStyleName("m-greyborder5"); //m-orangeborder5
        imgLay.addComponent(em);
    }

}

From source file:fi.semantum.strategia.Updates.java

License:Open Source License

public static void updateTags(final Main main) {

    final Database database = main.getDatabase();

    main.tags.removeAllComponents();// www.j  a v  a 2s.  com
    main.tags.setMargin(true);

    ArrayList<Tag> sorted = new ArrayList<Tag>(Tag.enumerate(database));
    Collections.sort(sorted, new Comparator<Tag>() {

        @Override
        public int compare(Tag arg0, Tag arg1) {
            return arg0.getId(database).compareTo(arg1.getId(database));
        }

    });

    for (final Tag t : sorted) {

        final HorizontalLayout hl = new HorizontalLayout();
        hl.setSpacing(true);
        Label l = new Label(t.getId(database));
        l.setSizeUndefined();
        l.addStyleName(ValoTheme.LABEL_HUGE);

        hl.addComponent(l);
        hl.setComponentAlignment(l, Alignment.BOTTOM_LEFT);

        final Image select = new Image("", new ThemeResource("cursor.png"));
        select.setHeight("24px");
        select.setWidth("24px");
        select.setDescription("Valitse");
        select.addClickListener(new MouseEvents.ClickListener() {

            private static final long serialVersionUID = 3734678948272593793L;

            @Override
            public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                main.setCurrentItem(t, main.getUIState().currentPosition);
                Utils.loseFocus(select);
            }

        });
        hl.addComponent(select);
        hl.setComponentAlignment(select, Alignment.BOTTOM_LEFT);

        final Image edit = new Image("", new ThemeResource("table_edit.png"));
        edit.setHeight("24px");
        edit.setWidth("24px");
        edit.setDescription("Muokkaa");
        edit.addClickListener(new MouseEvents.ClickListener() {

            private static final long serialVersionUID = -3792353723974454702L;

            @Override
            public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                Utils.editTextAndId(main, "Muokkaa aihetunnistetta", t);
                updateTags(main);
            }

        });
        hl.addComponent(edit);
        hl.setComponentAlignment(edit, Alignment.BOTTOM_LEFT);

        main.tags.addComponent(hl);
        main.tags.setComponentAlignment(hl, Alignment.MIDDLE_CENTER);

        Label l2 = new Label(t.getText(database));
        l2.addStyleName(ValoTheme.LABEL_LIGHT);
        l2.setSizeUndefined();
        main.tags.addComponent(l2);
        main.tags.setComponentAlignment(l2, Alignment.MIDDLE_CENTER);

    }

}

From source file:fi.semantum.strategia.widget.Indicator.java

License:Open Source License

public static void updateIndicators(final Main main, final Base base, boolean canWrite) {

    final Database database = main.getDatabase();

    List<IndicatorDescription> descs = new ArrayList<IndicatorDescription>();
    fillIndicatorDescriptions(main, base, "", descs);

    boolean isMap = base instanceof Strategiakartta;

    if (isMap && (!descs.isEmpty() || canWrite)) {

        HorizontalLayout indiHeader = new HorizontalLayout();
        indiHeader.setSpacing(true);//  ww  w . j a  va  2 s. c o  m

        Label header = new Label("Indikaattorit (ennuste)");
        main.propertyCells.add(Utils.excelRow(header.getValue()));
        header.setHeight("32px");
        header.addStyleName(ValoTheme.LABEL_HUGE);
        header.addStyleName(ValoTheme.LABEL_BOLD);
        indiHeader.addComponent(header);
        indiHeader.setComponentAlignment(header, Alignment.BOTTOM_CENTER);

        if (canWrite) {

            final Image editIndicators = new Image(null, new ThemeResource("chart_line_edit.png"));
            editIndicators.setHeight("24px");
            editIndicators.setWidth("24px");
            editIndicators.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 2661060702097338722L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Utils.loseFocus(editIndicators);
                    manageIndicators(main, main.getUIState().currentItem);
                }

            });

            indiHeader.addComponent(editIndicators);
            indiHeader.setComponentAlignment(editIndicators, Alignment.BOTTOM_CENTER);

        }

        main.properties.addComponent(indiHeader);
        main.properties.setComponentAlignment(indiHeader, Alignment.MIDDLE_CENTER);

        VerticalLayout indicators = new VerticalLayout();

        boolean showYears = main.getUIState().time.equals(Property.AIKAVALI_KAIKKI);

        Property time = Property.find(database, Property.AIKAVALI);

        int index = 0;
        for (final IndicatorDescription desc : descs) {

            ArrayList<String> excelRow = new ArrayList<String>();

            Indicator indicator = desc.indicator;

            final HorizontalLayout hl = new HorizontalLayout();
            hl.addStyleName((((index++) & 1) == 0) ? "evenProperty" : "oddProperty");
            hl.setSpacing(true);

            Label l = new Label(desc.caption);
            excelRow.add(l.getValue().replace("%nbsp", ""));
            l.setContentMode(ContentMode.HTML);
            l.setWidth("450px");
            l.addStyleName("propertyName");
            l.setData(desc);
            hl.addComponent(l);
            hl.setComponentAlignment(l, Alignment.MIDDLE_LEFT);

            String value = updateIndicatorValue(main, hl, base, indicator, canWrite);
            excelRow.add(value);

            Label unit = new Label(indicator.getUnit());
            unit.setWidth("100px");
            hl.addComponent(unit);
            hl.setComponentAlignment(unit, Alignment.MIDDLE_LEFT);
            excelRow.add(unit.getValue());

            Label comment = new Label(indicator.getValueShortComment());
            comment.setWidth("150px");
            hl.addComponent(comment);
            hl.setComponentAlignment(comment, Alignment.MIDDLE_LEFT);
            excelRow.add(comment.getValue());

            if (showYears) {

                HorizontalLayout hl2 = new HorizontalLayout();
                hl2.setWidth("70px");
                hl2.setHeight("100%");
                hl.addComponent(hl2);
                hl.setComponentAlignment(hl2, Alignment.MIDDLE_LEFT);

                String years = time.getPropertyValue(indicator);
                if (years == null)
                    years = Property.AIKAVALI_KAIKKI;

                final Label region = new Label(years);
                region.setWidthUndefined();

                excelRow.add(region.getValue());

                hl2.addComponent(region);
                hl2.setComponentAlignment(region, Alignment.MIDDLE_CENTER);

            }

            final Image wiki = new Image();
            wiki.setSource(new ThemeResource("table_edit.png"));
            wiki.setHeight("24px");
            wiki.setWidth("24px");
            wiki.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 2661060702097338722L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Wiki.openWiki(main, desc.indicator);
                }

            });

            hl.addComponent(wiki);
            hl.setComponentAlignment(wiki, Alignment.MIDDLE_CENTER);

            indicators.addComponent(hl);
            indicators.setComponentAlignment(hl, Alignment.MIDDLE_CENTER);

            main.propertyCells.add(excelRow);

        }

        indicators.addLayoutClickListener(new LayoutClickListener() {

            private static final long serialVersionUID = 3295743025581923380L;

            private String extractData(Component c) {
                if (c instanceof AbstractComponent) {
                    Object data = ((AbstractComponent) c).getData();
                    if (data instanceof IndicatorDescription) {
                        IndicatorDescription desc = (IndicatorDescription) data;
                        return desc.indicator.getDescription(database);
                    }
                }
                return null;
            }

            @Override
            public void layoutClick(LayoutClickEvent event) {

                String desc = extractData(event.getClickedComponent());
                if (desc == null)
                    return;

                String content = "<div style=\"width: 700px; border: 2px solid; padding: 5px\">";
                content += "<div style=\"text-align: center; white-space:normal; font-size: 36px; padding: 10px\">"
                        + desc + "</div>";
                content += "</div>";

                Notification n = new Notification(content, Notification.Type.HUMANIZED_MESSAGE);
                n.setHtmlContentAllowed(true);
                n.show(Page.getCurrent());

            }

        });

        main.properties.addComponent(indicators);
        main.properties.setComponentAlignment(indicators, Alignment.MIDDLE_CENTER);

    }

}

From source file:fi.semantum.strategia.widget.Meter.java

License:Open Source License

public static void updateMeters(final Main main, boolean canWrite) {

    if (main.getUIState().currentItem instanceof Strategiakartta)
        return;/* w w  w  . j a  v a  2  s.  c  o m*/

    final Database database = main.getDatabase();

    final Base base = main.getUIState().currentItem;

    List<MeterDescription> descs = makeMeterDescriptions(main, base, false);
    if (!descs.isEmpty() || canWrite) {

        HorizontalLayout meterHeader = new HorizontalLayout();
        meterHeader.setSpacing(true);

        Label header = new Label("Mittarit");
        main.propertyCells.add(Utils.excelRow(header.getValue()));
        header.setHeight("32px");
        header.addStyleName(ValoTheme.LABEL_HUGE);
        header.addStyleName(ValoTheme.LABEL_BOLD);
        meterHeader.addComponent(header);
        meterHeader.setComponentAlignment(header, Alignment.BOTTOM_CENTER);

        if (canWrite) {

            final Image editMeters = new Image(null, new ThemeResource("chart_bar_edit.png"));
            editMeters.setHeight("24px");
            editMeters.setWidth("24px");
            editMeters.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 2661060702097338722L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Utils.loseFocus(editMeters);
                    manageMeters(main, main.getUIState().currentItem);
                }

            });

            meterHeader.addComponent(editMeters);
            meterHeader.setComponentAlignment(editMeters, Alignment.BOTTOM_CENTER);

        }

        main.properties.addComponent(meterHeader);
        main.properties.setComponentAlignment(meterHeader, Alignment.MIDDLE_CENTER);

        VerticalLayout meters = new VerticalLayout();

        boolean showYears = main.getUIState().time.equals(Property.AIKAVALI_KAIKKI);

        Property time = Property.find(database, Property.AIKAVALI);

        int index = 0;
        for (final MeterDescription desc : descs) {

            ArrayList<String> excelRow = new ArrayList<String>();

            final Meter meter = desc.meter;

            final HorizontalLayout hl = new HorizontalLayout();
            hl.addStyleName((((index++) & 1) == 0) ? "evenProperty" : "oddProperty");
            hl.setSpacing(true);

            Label l = new Label(desc.caption);
            excelRow.add(l.getValue().replace("%nbsp", ""));
            l.setContentMode(ContentMode.HTML);
            l.setWidth("450px");
            l.addStyleName("propertyName");
            l.setData(desc);
            hl.addComponent(l);
            hl.setComponentAlignment(l, Alignment.MIDDLE_LEFT);

            String value = updateMeterValue(main, hl, base, meter, canWrite);
            excelRow.add(value);

            String shortComment = "";
            Indicator indicator = meter.getPossibleIndicator(database);
            if (indicator != null)
                shortComment = indicator.getValueShortComment();
            Label comment = new Label(shortComment);
            comment.setWidth("150px");
            hl.addComponent(comment);
            hl.setComponentAlignment(comment, Alignment.MIDDLE_LEFT);
            excelRow.add(comment.getValue());

            if (showYears) {

                HorizontalLayout hl2 = new HorizontalLayout();
                hl2.setWidth("70px");
                hl2.setHeight("100%");
                hl.addComponent(hl2);
                hl.setComponentAlignment(hl2, Alignment.MIDDLE_LEFT);

                String years = time.getPropertyValue(meter);
                if (years == null)
                    years = Property.AIKAVALI_KAIKKI;

                final Label region = new Label(years);
                region.setWidthUndefined();

                excelRow.add(region.getValue());

                hl2.addComponent(region);
                hl2.setComponentAlignment(region, Alignment.MIDDLE_CENTER);

            }

            AbsoluteLayout image = new AbsoluteLayout();
            image.setWidth("32px");
            image.setHeight("32px");
            image.addStyleName("meterColor" + index);

            String color = meter.getTrafficColor(database);

            Styles styles = Page.getCurrent().getStyles();
            styles.add(
                    ".fi_semantum_strategia div." + "meterColor" + index + " { background: " + color + "; }");

            hl.addComponent(image);
            hl.setComponentAlignment(image, Alignment.MIDDLE_CENTER);
            hl.setExpandRatio(image, 0.0f);

            meters.addComponent(hl);
            meters.setComponentAlignment(hl, Alignment.MIDDLE_CENTER);

            ThemeResource res = desc.meter.showInMap ? new ThemeResource("zoom.png")
                    : new ThemeResource("zoom_out.png");

            final Image show = new Image();
            show.setSource(res);
            show.setHeight("24px");
            show.setWidth("24px");
            if (canWrite) {
                show.setDescription("Klikkaamalla voit valita, nytetnk mittaria strategiakartassa");
                show.addClickListener(new MouseEvents.ClickListener() {

                    private static final long serialVersionUID = 7156984656942915939L;

                    @Override
                    public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                        desc.meter.setShowInMap(!desc.meter.showInMap);
                        Updates.update(main, true);
                    }

                });
            }

            hl.addComponent(show);
            hl.setComponentAlignment(show, Alignment.MIDDLE_CENTER);

            final Image wiki = new Image();
            wiki.setSource(new ThemeResource("table_edit.png"));
            wiki.setHeight("24px");
            wiki.setWidth("24px");
            wiki.setDescription("Klikkaamalla voit siirty tausta-asiakirjaan");
            wiki.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 7156984656942915939L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Wiki.openWiki(main, desc.meter);
                }

            });

            hl.addComponent(wiki);
            hl.setComponentAlignment(wiki, Alignment.MIDDLE_CENTER);

            if (canWrite) {
                final Button principalButton = new Button();
                if (meter.isPrincipal) {
                    principalButton.setCaption("Poista kokonaisarvio");
                } else {
                    principalButton.setCaption("Aseta kokonaisarvioksi");
                }
                principalButton.setStyleName(ValoTheme.BUTTON_TINY);
                principalButton.addClickListener(new ClickListener() {

                    private static final long serialVersionUID = 8247560202892661226L;

                    @Override
                    public void buttonClick(ClickEvent event) {
                        if (meter.isPrincipal) {
                            meter.isPrincipal = false;
                        } else {
                            for (Meter m : base.getMeters(database))
                                m.isPrincipal = false;
                            meter.isPrincipal = true;
                        }
                        Updates.update(main, true);

                    }

                });
                hl.addComponent(principalButton);
                hl.setComponentAlignment(principalButton, Alignment.MIDDLE_CENTER);
            }

            main.propertyCells.add(excelRow);

        }

        meters.addLayoutClickListener(new LayoutClickListener() {

            private static final long serialVersionUID = 3295743025581923380L;

            private String extractData(Component c) {
                if (c instanceof AbstractComponent) {
                    Object data = ((AbstractComponent) c).getData();
                    if (data instanceof MeterDescription) {
                        MeterDescription desc = (MeterDescription) data;
                        return desc.meter.getDescription(database);
                    }
                }
                return null;
            }

            @Override
            public void layoutClick(LayoutClickEvent event) {

                String desc = extractData(event.getClickedComponent());
                if (desc == null)
                    return;

                String content = "<div style=\"width: 700px; border: 2px solid; padding: 5px\">";
                content += "<div style=\"text-align: center; white-space:normal; font-size: 36px; padding: 10px\">"
                        + desc + "</div>";
                content += "</div>";

                Notification n = new Notification(content, Notification.Type.HUMANIZED_MESSAGE);
                n.setHtmlContentAllowed(true);
                n.show(Page.getCurrent());

            }

        });

        main.properties.addComponent(meters);
        main.properties.setComponentAlignment(meters, Alignment.MIDDLE_CENTER);

    }

}

From source file:fi.semantum.strategia.widget.Tag.java

License:Open Source License

public static void updateRelatedTags(final Main main, boolean canWrite) {

    final Database database = main.getDatabase();

    final Base base = main.getUIState().currentItem;

    Collection<Tag> tags = base.getRelatedTags(database);
    if (!tags.isEmpty() || canWrite) {

        HorizontalLayout tagHeader = new HorizontalLayout();
        tagHeader.setSpacing(true);//from   w w w  .  java 2s . c  o  m

        Label header2 = new Label("Aihetunnisteet");
        header2.setHeight("32px");
        header2.addStyleName(ValoTheme.LABEL_HUGE);
        header2.addStyleName(ValoTheme.LABEL_BOLD);
        tagHeader.addComponent(header2);
        tagHeader.setComponentAlignment(header2, Alignment.BOTTOM_CENTER);

        if (canWrite) {
            final Image editTags = new Image("", new ThemeResource("tag_blue_edit.png"));
            editTags.setHeight("24px");
            editTags.setWidth("24px");
            editTags.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = -6140867347404571880L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Utils.loseFocus(editTags);
                    Utils.editTags(main, "Muokkaa aihetunnisteita", main.getUIState().currentItem);
                }

            });
            tagHeader.addComponent(editTags);
            tagHeader.setComponentAlignment(editTags, Alignment.BOTTOM_CENTER);
        }

        main.properties.addComponent(tagHeader);
        main.properties.setComponentAlignment(tagHeader, Alignment.MIDDLE_CENTER);

        HorizontalLayout divider = new HorizontalLayout();
        main.properties.addComponent(divider);
        main.properties.setComponentAlignment(divider, Alignment.MIDDLE_CENTER);

        VerticalLayout left = new VerticalLayout();
        left.setSpacing(true);
        left.setWidth("400px");
        left.setMargin(true);
        divider.addComponent(left);
        VerticalLayout right = new VerticalLayout();
        right.setSpacing(true);
        right.setWidth("400px");
        right.setMargin(true);
        divider.addComponent(right);

        Set<Tag> monitoredTags = getMonitoredTags(database, base);

        int i = 0;
        for (final Tag tag : tags) {

            final boolean monitor = base.hasMonitorTag(database, tag);
            String tagId = tag.getId(database);

            HorizontalLayout hl = new HorizontalLayout();
            hl.setSpacing(true);
            hl.setHeight("37px");

            Button tagButton = Utils.tagButton(database, "list", tagId, i++);
            left.addComponent(tagButton);
            left.setComponentAlignment(tagButton, Alignment.MIDDLE_RIGHT);

            if (canWrite) {
                Button b = new Button();
                b.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                b.setIcon(FontAwesome.TIMES_CIRCLE);
                b.addClickListener(new ClickListener() {

                    private static final long serialVersionUID = -4473258383318654850L;

                    @Override
                    public void buttonClick(ClickEvent event) {
                        base.removeRelatedTags(database, tag);
                        Utils.loseFocus(main.properties);
                        Updates.update(main, true);
                    }

                });
                hl.addComponent(b);
                hl.setComponentAlignment(b, Alignment.MIDDLE_LEFT);
            }

            if (base instanceof Strategiakartta) {

                Button tagButton2 = new Button();
                tagButton2.setCaption(monitor ? "Seurataan toteutuksessa" : "Ei seurata toteutuksessa");
                tagButton2.addStyleName(monitor ? "greenButton" : "redButton");
                tagButton2.addStyleName(ValoTheme.BUTTON_SMALL);
                tagButton2.setWidth("200px");
                if (canWrite) {
                    tagButton2.addClickListener(new ClickListener() {

                        private static final long serialVersionUID = -1769769368034323594L;

                        @Override
                        public void buttonClick(ClickEvent event) {
                            if (monitor) {
                                base.removeMonitorTags(database, tag);
                            } else {
                                base.assertMonitorTags(database, tag);
                            }
                            Utils.loseFocus(main.properties);
                            Updates.update(main, true);
                        }

                    });
                    tagButton2.setEnabled(true);
                } else {
                    tagButton2.setEnabled(false);
                }

                hl.addComponent(tagButton2);
                hl.setComponentAlignment(tagButton2, Alignment.MIDDLE_LEFT);

            } else {

                if (monitoredTags.contains(tag)) {
                    Label l = new Label(" toteuttaa seurattavaa aihetta ");
                    hl.addComponent(l);
                    hl.setComponentAlignment(l, Alignment.MIDDLE_LEFT);
                }

            }

            right.addComponent(hl);
            right.setComponentAlignment(hl, Alignment.MIDDLE_LEFT);

        }

    }

}

From source file:fr.univlorraine.mondossierweb.views.ListeInscritsMobileView.java

License:Apache License

/**
 * Affichage du trombinoscope/*from www  .  j  a  v  a  2  s  .  c  o  m*/
 */
private void displayTrombinoscope(boolean completion) {
    // Rcupration de la liste des inscrits
    List<Inscrit> linscrits = MdwTouchkitUI.getCurrent().getListeInscrits();

    // On rinitialise le layout contenant le trombinoscope
    if (trombiLayout != null) {
        //On n'a pas fait 'afficher suivant'
        if (!completion) {
            trombiLayout.removeAllComponents();
        }
    } else {
        trombiLayout = new VerticalLayout();
        trombiLayout.setSizeFull();
        trombiLayout.setSpacing(true);
    }

    int compteurEtu = 0;
    //Pour chaque inscrit
    for (Inscrit inscrit : linscrits) {

        compteurEtu++;
        //Si on affiche tout sur une page ou si l'tudiant doit tre affich sur cette page
        if (pageMax == 1 || ((((pageEnCours - 1) * nbEtuParPage) < compteurEtu)
                && (compteurEtu <= ((pageEnCours) * nbEtuParPage)))) {

            boolean afficherEtudiant = true;

            //Si l'tudiant n'est pas dans la VET slectionne, on ne l'affiche pas
            if (StringUtils.hasText(vetSelectionnee)
                    && (inscrit.getId_etp() == null || !inscrit.getId_etp().contains(vetSelectionnee))) {
                afficherEtudiant = false;

            }

            // Si l'tudiant n'est pas dans le groupe slectionn, on ne l'affiche pas
            if (StringUtils.hasText(groupeSelectionne) && (inscrit.getCodes_groupes() == null
                    || !inscrit.getCodes_groupes().contains(groupeSelectionne))) {
                afficherEtudiant = false;
            }

            // Si l'tudiant doit tre affich
            if (afficherEtudiant) {

                // Panel contenant l'tudiant
                Panel etuPanel = new Panel();

                // Layout du Panel contenant l'tudiant
                HorizontalLayout photoLayout = new HorizontalLayout();
                // Ajout d'un id sur le layout
                photoLayout.setId(inscrit.getCod_ind());
                photoLayout.setSizeFull();

                // Si on a une url renseigne vers la photo de l'tudiant
                if (inscrit.getUrlphoto() != null) {

                    // Image contenant la photo de l'tudiant
                    Image fotoEtudiant = new Image(null, new ExternalResource(inscrit.getUrlphoto()));
                    fotoEtudiant.setWidth("120px");
                    fotoEtudiant.setStyleName(ValoTheme.BUTTON_LINK);
                    // Gestion du clic sur la photo
                    fotoEtudiant.addClickListener(e -> {
                        // Au clic sur la photo on redirige vers le contenu du dossier de l'tudiant dont la photo a t clique
                        rechercheController.accessToMobileDetail(inscrit.getCod_etu().toString(),
                                Utils.TYPE_ETU, false);
                    });
                    // Ajout de la photo au layout
                    photoLayout.addComponent(fotoEtudiant);

                }

                // Layout contenant le nom, prnom et le codetu
                VerticalLayout nomCodeLayout = new VerticalLayout();
                //nomCodeLayout.setSizeFull();
                nomCodeLayout.setSpacing(false);

                // Bouton contenant le nom/prnom
                Button btnNomEtudiant = new Button(inscrit.getPrenom() + " " + inscrit.getNom());
                Utils.setButtonStyle(btnNomEtudiant);

                // Ajout du bouton au layout
                nomCodeLayout.addComponent(btnNomEtudiant);
                //Gestion du clic sur le bouton
                btnNomEtudiant.addClickListener(e -> {
                    // Au clic sur le bouton on redirige vers le contenu du dossier de l'tudiant dont le nom a t cliqu
                    rechercheController.accessToMobileDetail(inscrit.getCod_etu().toString(), Utils.TYPE_ETU,
                            false);
                });
                nomCodeLayout.setComponentAlignment(btnNomEtudiant, Alignment.MIDDLE_CENTER);
                //nomCodeLayout.setExpandRatio(btnNomEtudiant, 1);

                // Label contenant le codetu
                Label codetuLabel = new Label(inscrit.getCod_etu());
                codetuLabel.setSizeFull();
                codetuLabel.setStyleName(ValoTheme.LABEL_TINY);
                codetuLabel.addStyleName("label-centre");

                // Ajout du label au layout
                nomCodeLayout.addComponent(codetuLabel);
                nomCodeLayout.setComponentAlignment(codetuLabel, Alignment.MIDDLE_CENTER);

                // Ajout du layout contenant nom, prnom et codetu au layout de la photo
                photoLayout.addComponent(nomCodeLayout);
                photoLayout.setComponentAlignment(nomCodeLayout, Alignment.MIDDLE_CENTER);
                photoLayout.setExpandRatio(nomCodeLayout, 1);

                // Ajout du layout de la photo comme contenu du panel
                etuPanel.setContent(photoLayout);
                trombiLayout.addComponent(etuPanel);
                trombiLayout.setComponentAlignment(etuPanel, Alignment.MIDDLE_CENTER);
            }
        }
    }

}

From source file:fr.univlorraine.mondossierweb.views.ListeInscritsView.java

License:Apache License

private void displayTrombinoscope() {
    List<Inscrit> linscrits = MainUI.getCurrent().getListeInscrits();

    if (trombiLayout != null) {
        trombiLayout.removeAllComponents();
    } else {/*w ww .  j a v a  2  s  .com*/
        trombiLayout = new GridLayout();
        trombiLayout.setColumns(5);
        trombiLayout.setWidth("100%");
        trombiLayout.setHeight(null);
        trombiLayout.setSpacing(true);
    }

    for (Inscrit inscrit : linscrits) {
        if (listecodind.contains(inscrit.getCod_ind())) {
            VerticalLayout photoLayout = new VerticalLayout();
            photoLayout.setId(inscrit.getCod_ind());
            photoLayout.setHeight("100%");
            if (inscrit.getUrlphoto() != null) {
                //Button fotoEtu=new Button();
                Image fotoEtudiant = new Image(null, new ExternalResource(inscrit.getUrlphoto()));
                fotoEtudiant.setWidth("120px");
                fotoEtudiant.setStyleName(ValoTheme.BUTTON_LINK);
                fotoEtudiant.addClickListener(e -> {
                    rechercheController.accessToDetail(inscrit.getCod_etu().toString(), Utils.TYPE_ETU, null);
                });

                photoLayout.addComponent(fotoEtudiant);
                //photoLayout.addComponent(fotoEtu);
                photoLayout.setComponentAlignment(fotoEtudiant, Alignment.MIDDLE_CENTER);
                photoLayout.setExpandRatio(fotoEtudiant, 1);

            }
            VerticalLayout nomCodeLayout = new VerticalLayout();
            nomCodeLayout.setSizeFull();
            nomCodeLayout.setSpacing(false);

            Button btnNomEtudiant = new Button(inscrit.getPrenom() + " " + inscrit.getNom());
            btnNomEtudiant.setSizeFull();
            btnNomEtudiant.setStyleName(ValoTheme.BUTTON_BORDERLESS);
            btnNomEtudiant.addStyleName("link");
            btnNomEtudiant.addStyleName("v-link");
            nomCodeLayout.addComponent(btnNomEtudiant);
            btnNomEtudiant.addClickListener(e -> {
                rechercheController.accessToDetail(inscrit.getCod_etu().toString(), Utils.TYPE_ETU, null);
            });
            nomCodeLayout.setComponentAlignment(btnNomEtudiant, Alignment.MIDDLE_CENTER);
            //nomCodeLayout.setExpandRatio(btnNomEtudiant, 1);

            Label codetuLabel = new Label(inscrit.getCod_etu());
            codetuLabel.setSizeFull();
            codetuLabel.setStyleName(ValoTheme.LABEL_TINY);
            codetuLabel.addStyleName("label-centre");
            nomCodeLayout.addComponent(codetuLabel);
            nomCodeLayout.setComponentAlignment(codetuLabel, Alignment.TOP_CENTER);

            photoLayout.addComponent(nomCodeLayout);

            trombiLayout.addComponent(photoLayout);
            trombiLayout.setComponentAlignment(photoLayout, Alignment.MIDDLE_CENTER);
        }
    }

}

From source file:org.plukh.fluffymeow.ui.i18n.LocaleChooserComponent.java

License:Open Source License

@Inject
public LocaleChooserComponent() {
    log.trace("Creating LocaleChooserComponent...");
    setSizeUndefined();/*w  w  w .  j  a v  a2  s .  c  om*/

    HorizontalLayout layout = new HorizontalLayout();

    flags = new ArrayList<>();

    languages.forEach(language -> {
        Resource flagResource = new ThemeResource(language.getFlagFile());
        Image flag = new Image(null, flagResource);
        flag.addStyleName("pointer");
        flag.addClickListener(event -> onLanguageChange(language.getLocale()));
        flag.setData(language.getMessage());

        log.debug("Created flag for locale " + language.getLocale());

        flags.add(flag);
        layout.addComponent(flag);
    });

    setCompositionRoot(layout);

    log.debug("LocaleChooserComponent created");
}