Example usage for com.vaadin.ui VerticalLayout setExpandRatio

List of usage examples for com.vaadin.ui VerticalLayout setExpandRatio

Introduction

In this page you can find the example usage for com.vaadin.ui VerticalLayout setExpandRatio.

Prototype

public void setExpandRatio(Component component, float ratio) 

Source Link

Document

This method is used to control how excess space in layout is distributed among components.

Usage

From source file:org.vaadin.webinars.springandvaadin.bootexample.ContactRepository.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();//  ww  w.  j a va  2s.c  o  m
    layout.setMargin(true);
    layout.setSpacing(true);
    setContent(layout);

    Label title = new Label("Contacts");
    title.addStyleName(Reindeer.LABEL_H1);
    layout.addComponent(title);

    contactsContainer = new BeanItemContainer<>(Contact.class);

    contactsTable = new Table();
    contactsTable.setSizeFull();
    contactsTable.setContainerDataSource(contactsContainer);
    contactsTable.setVisibleColumns("firstName", "lastName", "email");

    layout.addComponent(contactsTable);
    layout.setExpandRatio(contactsTable, 1f);

    HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.setSpacing(true);
    layout.addComponent(toolbar);

    refresh = new Button("Refresh", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            refresh();
        }
    });
    toolbar.addComponent(refresh);

    add = new Button("Add...", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            addWindow(new NewContactWindow());
        }
    });
    toolbar.addComponent(add);

    refresh();
}

From source file:org.yozons.vaadin.ckeditor.CKEditorForVaadin7UI.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {
    getPage().setTitle("CKEditor for Vaadin 7");

    final VerticalLayout layout = new VerticalLayout();
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setMargin(true);/*w ww  .  j a v a  2s.c  o  m*/
    layout.setSpacing(true);
    setContent(layout);

    layout.addComponent(new Button("Hit server"));

    final String editor1InitialValue = "<p>CKEditor for Vaadin 7 is an entirely new JavaScriptComponent add-on.</p>";

    CKEditorConfig config1 = new CKEditorConfig();
    config1.useCompactTags();
    config1.disableElementsPath();
    config1.setResizeDir(CKEditorConfig.RESIZE_DIR.HORIZONTAL);
    config1.disableSpellChecker();
    final CKEditor editor1 = new CKEditor(config1, editor1InitialValue);
    layout.addComponent(editor1);

    editor1.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(String newValue) {
            if (!newValue.equals(editor1.getValue()))
                Notification.show("ERROR - Event value does not match editor #1's current value");
            else
                Notification.show("ValueChangeListener CKEditor v" + editor1.getVersion() + "/" + getVersion()
                        + " - #1 contents: " + newValue);
            editor1.focus();
        }
    });

    Button testButton = new Button("Reset editor #1");
    testButton.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            if (!editor1.isReadOnly()) {
                editor1.setValue(editor1InitialValue);
                Notification.show("Reset CKEditor v" + editor1.getVersion() + "/" + getVersion()
                        + " - #1 contents: " + editor1.getValue());
            }
        }

    });
    layout.addComponent(testButton);

    Button toggleReadOnlyButton1 = new Button("Toggle read-only editor #1");
    toggleReadOnlyButton1.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            editor1.setReadOnly(!editor1.isReadOnly());
        }
    });
    layout.addComponent(toggleReadOnlyButton1);

    Button toggleViewWithoutEditorButton1 = new Button("Toggle view-without-editor #1");
    toggleViewWithoutEditorButton1.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            editor1.setViewWithoutEditor(!editor1.isViewWithoutEditor());
        }
    });
    layout.addComponent(toggleViewWithoutEditorButton1);

    // Now add in a second editor....
    final String editor2InitialValue = "<p>Here is editor #2.</p><h1>Hope you find this useful in your Vaadin 7 projects.</h1>";

    CKEditorConfig config2 = new CKEditorConfig();
    config2.addCustomToolbarLine(
            "{ items : ['Source','Styles','Bold','VaadinSave','-','Undo','Redo','-','NumberedList','BulletedList'] }");
    config2.enableVaadinSavePlugin();
    config2.addToRemovePlugins("scayt");

    final CKEditor editor2 = new CKEditor(config2);
    editor2.setWidth(600, Unit.PIXELS);
    layout.addComponent(editor2);
    editor2.setValue(editor2InitialValue);

    editor2.addValueChangeListener(new ValueChangeListener() {

        public void valueChange(String newValue) {
            if (!newValue.equals(editor2.getValue()))
                Notification.show("ERROR - Event value does not match editor #2's current value");
            else
                Notification.show("ValueChangeListener CKEditor v" + editor2.getVersion() + "/" + getVersion()
                        + " - #2 contents: " + newValue);
        }
    });

    Button resetTextButton2 = new Button("Reset editor #2");
    resetTextButton2.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            if (!editor2.isReadOnly()) {
                editor2.setValue(editor2InitialValue);
                Notification.show("Reset CKEditor v" + editor1.getVersion() + "/" + getVersion()
                        + " - #2 contents: " + editor2.getValue());
            }
        }
    });
    layout.addComponent(resetTextButton2);

    Button toggleReadOnlyButton2 = new Button("Toggle read-only editor #2");
    toggleReadOnlyButton2.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            editor2.setReadOnly(!editor2.isReadOnly());
        }
    });
    layout.addComponent(toggleReadOnlyButton2);

    Button toggleViewWithoutEditorButton2 = new Button("Toggle view-without-editor #2");
    toggleViewWithoutEditorButton2.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            editor2.setViewWithoutEditor(!editor2.isViewWithoutEditor());
        }
    });
    layout.addComponent(toggleViewWithoutEditorButton2);

    // Now some extra tests for modal windows, etc.
    layout.addComponent(new Button("Open Modal Subwindow", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Window sub = new Window("Subwindow modal");
            VerticalLayout subLayout = new VerticalLayout();
            sub.setContent(subLayout);

            CKEditorConfig config = new CKEditorConfig();
            config.useCompactTags();
            config.disableElementsPath();
            config.disableSpellChecker();
            config.enableVaadinSavePlugin();
            // set BaseFloatZIndex 1000 higher than CKEditor's default of 10000; probably a result of an editor opening
            // in a window that's on top of the main two editors of this demo app
            config.setBaseFloatZIndex(11000);
            config.setHeight("150px");

            final CKEditor ckEditor = new CKEditor(config);
            ckEditor.addValueChangeListener(new ValueChangeListener() {

                public void valueChange(String newValue) {
                    Notification.show("CKEditor v" + ckEditor.getVersion() + "/" + getVersion()
                            + " - POPUP MODAL contents: " + newValue);
                }
            });
            ckEditor.focus();

            subLayout.addComponent(ckEditor);

            sub.setWidth("80%");
            sub.setModal(true);
            sub.center();

            event.getButton().getUI().addWindow(sub);
        }
    }));

    layout.addComponent(new Button("Open Non-Modal Subwindow with 100% Height", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Window sub = new Window("Subwindow non-modal 100% height");
            VerticalLayout subLayout = new VerticalLayout();
            sub.setContent(subLayout);
            sub.setWidth("80%");
            sub.setHeight("500px");

            subLayout.setSizeFull();

            CKEditorConfig config = new CKEditorConfig();
            config.useCompactTags();
            config.disableElementsPath();
            config.disableSpellChecker();
            config.enableVaadinSavePlugin();
            // set BaseFloatZIndex 1000 higher than CKEditor's default of 10000; probably a result of an editor opening
            // in a window that's on top of the main two editors of this demo app
            config.setBaseFloatZIndex(11000);
            config.setStartupFocus(true);

            final CKEditor ckEditor = new CKEditor(config);
            ckEditor.setHeight("100%");
            ckEditor.addValueChangeListener(new ValueChangeListener() {

                public void valueChange(String newValue) {
                    Notification.show("CKEditor v" + ckEditor.getVersion() + "/" + getVersion()
                            + " - POPUP NON-MODAL 100% HEIGHT contents: " + ckEditor.getValue());
                }
            });
            subLayout.addComponent(ckEditor);
            subLayout.setExpandRatio(ckEditor, 1.0f);

            final TextField textField = new TextField("TextField");
            textField.setImmediate(true);
            textField.addValueChangeListener(new Property.ValueChangeListener() {

                public void valueChange(ValueChangeEvent event) {
                    Notification.show("TextField - POPUP NON-MODAL 100% HEIGHT contents: "
                            + event.getProperty().getValue().toString());
                }
            });
            subLayout.addComponent(textField);

            sub.center();

            event.getButton().getUI().addWindow(sub);
        }
    }));
}

From source file:pl.alburnus.testcaseapp.AddressBookMainView.java

License:Apache License

private void buildMainArea() {
    VerticalLayout verticalLayout = new VerticalLayout();
    setSecondComponent(verticalLayout);//from w w  w. j  av  a  2  s.c o  m

    personTable = new Table(null, persons);//Biding Person tabel z JPAContainer
    personTable.setSelectable(true);
    personTable.setImmediate(true);
    personTable.addListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            setModificationsEnabled(event.getProperty().getValue() != null);
        }

        private void setModificationsEnabled(boolean b) {
            deleteButton.setEnabled(b);
            editButton.setEnabled(b);
        }
    });

    personTable.setSizeFull();
    // personTable.setSelectable(true);
    /*        personTable.addListener(new ItemClickListener() {
    @Override
    public void itemClick(ItemClickEvent event) {
        if (event.isDoubleClick()) {
            personTable.select(event.getItemId());
        }
    }
            });
    */
    //OK
    personTable.setVisibleColumns(
            new Object[] { "firstName", "lastName", "department", "phoneNumber", "street", "city", "zipCode" });

    HorizontalLayout toolbar = new HorizontalLayout();
    newButton = new Button("Add");
    newButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            //Tworzony jest nowy obiekt opakowany w BeanItem, ktory umozliwa jego polaczenie z FORM
            final BeanItem<Person> newPersonItem = new BeanItem<Person>(new Person());
            PersonEditor personEditor = new PersonEditor(newPersonItem);
            personEditor.addListener(new EditorSavedListener() {
                @Override
                public void editorSaved(EditorSavedEvent event) {
                    persons.addEntity(newPersonItem.getBean());
                }
            });
            UI.getCurrent().addWindow(personEditor); //Dodanie okienka do dodania adresu
        }
    });

    deleteButton = new Button("Delete");
    deleteButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            persons.removeItem(personTable.getValue());
        }
    });
    deleteButton.setEnabled(false);

    editButton = new Button("Edit");
    editButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            UI.getCurrent().addWindow(new PersonEditor(personTable.getItem(personTable.getValue())));
        }
    });
    editButton.setEnabled(false);

    searchField = new TextField();
    searchField.setInputPrompt("Search by name");
    searchField.addTextChangeListener(new TextChangeListener() {

        @Override
        public void textChange(TextChangeEvent event) {
            textFilter = event.getText();
            updateFilters();
        }
    });

    toolbar.addComponent(newButton);
    toolbar.addComponent(deleteButton);
    toolbar.addComponent(editButton);
    toolbar.addComponent(searchField);
    toolbar.setWidth("100%");
    toolbar.setExpandRatio(searchField, 1);
    toolbar.setComponentAlignment(searchField, Alignment.TOP_RIGHT);

    verticalLayout.addComponent(toolbar);
    verticalLayout.addComponent(personTable);
    verticalLayout.setExpandRatio(personTable, 1);
    verticalLayout.setSizeFull();

}

From source file:pl.altkom.ecommerce.vaadin.view.ProductListView.java

private void initLayout() {
    HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
    addComponent(splitPanel);/*from w  w w  . j av a 2  s .c o  m*/

    VerticalLayout leftLayout = new VerticalLayout();
    splitPanel.addComponent(leftLayout);
    splitPanel.addComponent(editorLayout);
    leftLayout.addComponent(contactList);
    HorizontalLayout bottomLeftLayout = new HorizontalLayout();
    leftLayout.addComponent(bottomLeftLayout);
    bottomLeftLayout.addComponent(searchField);
    bottomLeftLayout.addComponent(addNewContactButton);
    leftLayout.setSizeFull();
    leftLayout.setExpandRatio(contactList, 1);
    contactList.setSizeFull();
    bottomLeftLayout.setWidth("100%");
    searchField.setWidth("100%");
    bottomLeftLayout.setExpandRatio(searchField, 1);
    editorLayout.setMargin(true);
    editorLayout.setVisible(false);

}

From source file:pl.exsio.frameset.vaadin.ui.support.component.data.common.DataComponent.java

License:Open Source License

private Layout buildForm(final I item, final C container, final Window formWindow, final int mode) {
    F form = this.instantiateForm(item, container, formWindow, mode);
    this.formatForm(form);
    VerticalLayout mainLayout = new VerticalLayout();
    Layout formLayout = this.decorateForm(form, item, mode);
    formLayout.setSizeUndefined();//from  w  ww  .j a v  a  2  s . c om
    formLayout.setStyleName("frameset-dc-window-form-wrapper");
    if (formLayout instanceof MarginHandler) {
        ((MarginHandler) formLayout).setMargin(new MarginInfo(false, true, false, true));
    }
    Layout controls = this.decorateFormControls(
            this.createFormControls(item, form, container, formWindow, mode), item, form, container, formWindow,
            mode);
    mainLayout.addComponent(formLayout);
    mainLayout.addComponent(controls);
    mainLayout.setExpandRatio(formLayout, 10);
    mainLayout.setExpandRatio(controls, 1);
    mainLayout.setSizeUndefined();
    return mainLayout;

}

From source file:pt.ist.vaadinframework.ui.ApplicationWindow.java

License:Open Source License

public ApplicationWindow(String theme, Property applicationTitle, Property applicationSubtitle,
        Property copyright) {//from w  w  w. j  a v a  2 s . c  o  m
    setTheme(theme);
    this.applicationTitle = applicationTitle;
    this.applicationSubtitle = applicationSubtitle;
    this.copyright = copyright;
    VerticalLayout main = new VerticalLayout();
    main.setWidth(90, UNITS_PERCENTAGE);
    main.setHeight(98, UNITS_PERCENTAGE);
    main.addStyleName("application-container");

    VerticalLayout header = new VerticalLayout();
    header.setMargin(true, true, false, true);
    header.setSpacing(true);
    main.addComponent(header);
    HorizontalLayout iconAndTitle = new HorizontalLayout();
    iconAndTitle.setSizeFull();
    iconAndTitle.setSpacing(true);
    header.addComponent(iconAndTitle);
    Embedded logo = new Embedded(null, new ThemeResource("../runo/icons/64/globe.png"));
    iconAndTitle.addComponent(logo);
    iconAndTitle.setComponentAlignment(logo, Alignment.MIDDLE_LEFT);

    VerticalLayout titles = new VerticalLayout();
    titles.setSpacing(true);
    iconAndTitle.addComponent(titles);
    iconAndTitle.setExpandRatio(titles, 0.8f);
    Label title = new Label(applicationTitle);
    title.addStyleName("application-title");
    titles.addComponent(title);
    Label subtitle = new Label(applicationSubtitle);
    subtitle.addStyleName("application-subtitle");
    titles.addComponent(subtitle);

    HorizontalLayout controls = new HorizontalLayout();
    controls.setSpacing(true);
    iconAndTitle.addComponent(controls);
    iconAndTitle.setComponentAlignment(controls, Alignment.TOP_RIGHT);
    Label user = new Label("ist148357");
    controls.addComponent(user);
    Link logout = new Link("logout", new ExternalResource("#"));
    controls.addComponent(logout);

    MenuBar menu = new MenuBar();
    menu.addStyleName("application-menu");
    header.addComponent(menu);
    MenuItem hello = menu.addItem("hello", null);
    hello.addItem("sdgjk", new Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            getWindow().showNotification("skjhfgksjdfhglksdjh");
        }
    });
    MenuItem hello1 = menu.addItem("hello", null);
    hello1.addItem("sdgjk", new Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            getWindow().showNotification("skjhfgksjdfhglksdjh");
        }
    });
    MenuItem hello2 = menu.addItem("hello", null);
    hello2.addItem("sdgjk", new Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            getWindow().showNotification("skjhfgksjdfhglksdjh");
        }
    });

    body = new VerticalLayout();
    body.setSizeFull();
    body.setMargin(true);
    body.addStyleName("application-body");
    main.addComponent(body);
    main.setExpandRatio(body, 1f);
    body.addComponent(createDefaultPageBody());

    VerticalLayout footer = new VerticalLayout();
    main.addComponent(footer);
    main.setComponentAlignment(footer, Alignment.MIDDLE_CENTER);
    Label copyrightLabel = new Label(copyright);
    copyrightLabel.setSizeUndefined();
    copyrightLabel.addStyleName("application-footer");
    footer.addComponent(copyrightLabel);
    footer.setComponentAlignment(copyrightLabel, Alignment.MIDDLE_CENTER);

    VerticalLayout outer = (VerticalLayout) getContent();
    outer.setSizeFull();
    outer.addComponent(main);
    outer.setComponentAlignment(main, Alignment.MIDDLE_CENTER);
}

From source file:ro.zg.netcell.vaadin.action.user.LoginHandler.java

License:Apache License

private ComponentContainer getLoginView(ActionContext actionContext) {

    OpenGroupsApplication app = actionContext.getApp();
    Map<String, Map<String, String>> loginTypes = (Map<String, Map<String, String>>) app.getAppConfigManager()
            .getApplicationConfigParam(ApplicationConfigParam.LOGIN_TYPES);

    System.out.println("login types: " + loginTypes);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSizeFull();// w  ww.  jav a 2s.  c  o  m

    if (loginTypes == null || loginTypes.containsKey(LOCAL_LOGIN_TYPE)) {
        Component localView = getLocalLoginView(actionContext);
        hl.addComponent(localView);
        hl.setExpandRatio(localView, 2f);
    }

    if (loginTypes != null) {
        Map<String, String> openIdProviders = loginTypes.get(OPENID_LOGIN_TYPE);

        if (openIdProviders != null) {
            CssLayout openIdLayout = new CssLayout();
            openIdLayout.setSizeFull();
            openIdLayout.addStyleName("openid-login-pane");

            VerticalLayout openIdContainer = new VerticalLayout();
            openIdContainer.setSizeFull();
            openIdContainer.setMargin(true);
            openIdLayout.addComponent(openIdContainer);

            //      Label openIdLoginMessage = new Label(OpenGroupsResources.getMessage("openid.login.message"));
            //      openIdLoginMessage.addStyleName("openid-title");
            //      openIdContainer.addComponent(openIdLoginMessage);
            //      openIdContainer.setExpandRatio(openIdLoginMessage, 0.1f);

            for (Map.Entry<String, String> e : openIdProviders.entrySet()) {

                Component providerLink = getOpenidLoginComponent(actionContext, e);
                openIdContainer.addComponent(providerLink);
                openIdContainer.setComponentAlignment(providerLink, Alignment.MIDDLE_CENTER);
                openIdContainer.setExpandRatio(providerLink, 1f);

            }

            hl.addComponent(openIdLayout);
            hl.setComponentAlignment(openIdLayout, Alignment.MIDDLE_CENTER);
            hl.setExpandRatio(openIdLayout, 1f);
        }
    }
    return hl;
}

From source file:rs.pupin.jpo.esta_ld.DSDRepoComponent.java

private void refreshContentFindDSDs(DataSet ds) {
    if (ds == null) {
        getWindow().showNotification("No dataset selected", Window.Notification.TYPE_ERROR_MESSAGE);
        return;/* w  w w .j  a  va2  s. co m*/
    }
    Structure struct = ds.getStructure();
    if (struct != null) {
        contentLayout.addComponent(new Label("The dataset already has a DSD!"));
        return;
    }

    dataset = ds.getUri();
    contentLayout.removeAllComponents();
    ;
    dataTree = new Tree("Dataset");
    dataTree.setWidth("500px");
    dataTree.setNullSelectionAllowed(true);
    dataTree.setImmediate(true);
    populateDataTree();
    addDataTreeListenersFind();
    contentLayout.addComponent(dataTree);
    contentLayout.setExpandRatio(dataTree, 0.0f);
    repoTree = new Tree("Matching Structures");
    repoTree.setNullSelectionAllowed(true);
    repoTree.setImmediate(true);
    populateRepoTree();
    VerticalLayout v = new VerticalLayout();
    contentLayout.addComponent(v);
    contentLayout.setExpandRatio(v, 2.0f);
    v.addComponent(repoTree);
    v.setExpandRatio(repoTree, 2.0f);
}

From source file:rs.pupin.jpo.validation.gui.constraints.IC01.java

@Override
public void generateGUI() {
    Iterator<BindingSet> res = icQuery.getResults();

    if (icQuery.getStatus() == ICQuery.Status.ERROR) {
        Label label = new Label();
        label.setValue("ERROR \n" + icQuery.getErrorMessage());
        rootLayout.addComponent(label);//  w ww  .  ja v a 2  s .c  om
        return;
    }

    final HashMap<String, String> map = new HashMap<String, String>();

    while (res.hasNext()) {
        BindingSet set = res.next();
        map.put(set.getValue("obs").stringValue(), set.getValue("dsNum").stringValue());
    }

    if (map.isEmpty()) {
        Label label = new Label();
        label.setValue("All observations have links to data sets");
        rootLayout.addComponent(label);
        return;
    }

    Label label = new Label();
    label.setValue(
            "Below is the list of observations that are not linked to exactly one data set. Click on any of them to get more information and either edit the resource in OntoWiki or choose a quick solution");
    rootLayout.addComponent(label);

    final ListSelect listObs = new ListSelect("Observations", map.keySet());
    listObs.setNullSelectionAllowed(false);
    rootLayout.addComponent(listObs);
    listObs.setImmediate(true);
    listObs.setWidth("100%");

    final Table detailsTable = new Table("Details");
    detailsTable.setHeight("250px");
    detailsTable.setWidth("100%");
    detailsTable.addContainerProperty("Property", String.class, null);
    detailsTable.addContainerProperty("Object", String.class, null);
    rootLayout.addComponent(detailsTable);

    final Label lblProblem = new Label("<b>Problem description: </b>", ContentMode.HTML);
    rootLayout.addComponent(lblProblem);

    Button editInOW = new Button("Edit in OntoWiki");
    editInOW.setEnabled(owUrl != null);
    editInOW.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            editManually((String) listObs.getValue());
        }
    });

    Form panelQuickFix = new Form();
    panelQuickFix.setCaption("Quick Fix");
    panelQuickFix.setSizeFull();
    VerticalLayout panelLayout = new VerticalLayout();
    panelLayout.setSpacing(true);
    panelLayout.setSizeFull();
    panelQuickFix.setLayout(panelLayout);
    rootLayout.addComponent(panelQuickFix);
    rootLayout.setExpandRatio(panelQuickFix, 2.0f);
    panelLayout.addComponent(new Label(
            "After the fix the selected observation will belong only to the data set selected below or you can choose to edit the selected observation manually in OntoWiki"));
    final ComboBox comboDataSets = new ComboBox(null, getDataSets());
    comboDataSets.setNullSelectionAllowed(false);
    comboDataSets.setWidth("100%");
    comboDataSets.setImmediate(true);
    panelLayout.addComponent(comboDataSets);
    final Button fix = new Button("Quick Fix");
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setSpacing(true);
    buttonsLayout.addComponent(fix);
    buttonsLayout.addComponent(editInOW);
    panelLayout.addComponent(buttonsLayout);
    panelLayout.setExpandRatio(buttonsLayout, 2.0f);

    listObs.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            TupleQueryResult res = getResourceProperties((String) event.getProperty().getValue());
            int i = 1;
            detailsTable.removeAllItems();
            try {
                while (res.hasNext()) {
                    BindingSet set = res.next();
                    detailsTable.addItem(
                            new Object[] { set.getValue("p").stringValue(), set.getValue("o").stringValue() },
                            i++);
                }
            } catch (QueryEvaluationException e) {
                e.printStackTrace();
            }
            String chosenObs = (String) event.getProperty().getValue();
            lblProblem.setValue("<b>Problem description: </b>The selected observation belongs to "
                    + map.get(chosenObs) + " data sets. It should belong to exactly one.");
        }
    });

    fix.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            String chosenDataSet = (String) comboDataSets.getValue();
            String observation = (String) listObs.getValue();

            if (chosenDataSet == null) {
                Notification.show("DataSet was not selected", Notification.Type.ERROR_MESSAGE);
                return;
            }
            if (observation == null) {
                Notification.show("Observation was not selected", Notification.Type.ERROR_MESSAGE);
                return;
            }

            String dataSetProp = "http://purl.org/linked-data/cube#dataSet";
            List<String> forRemoval = getObsDataSets(observation);
            if (forRemoval.size() > 0) {
                ArrayList<Statement> stmts = new ArrayList<Statement>();
                for (String ds : forRemoval)
                    stmts.add(getStatementFromUris(observation, dataSetProp, ds));
                removeStatements(stmts);
            }
            ArrayList<Statement> addStmts = new ArrayList<Statement>();
            addStmts.add(getStatementFromUris(observation, dataSetProp, chosenDataSet));
            uploadStatements(addStmts);
            Notification.show("Fix executed");
            icQuery.eval();
        }
    });
}

From source file:rs.pupin.jpo.validation.gui.constraints.IC02.java

@Override
public void generateGUI() {
    rootLayout.removeAllComponents();/*  w w w .  j av  a2  s . c  om*/
    Iterator<BindingSet> res = icQuery.getResults();

    if (icQuery.getStatus() == ICQuery.Status.ERROR) {
        Label label = new Label();
        label.setValue("ERROR \n" + icQuery.getErrorMessage());
        rootLayout.addComponent(label);
        return;
    }

    final HashMap<String, String> map = new HashMap<String, String>();
    while (res.hasNext()) {
        BindingSet set = res.next();
        map.put(set.getValue("dataSet").stringValue(), set.getValue("dsdNum").stringValue());
    }

    if (map.isEmpty()) {
        Label label = new Label();
        label.setValue("All data sets have exactly one link to the DSD");
        rootLayout.addComponent(label);
        return;
    }

    Label label = new Label();
    label.setValue(
            "Below is the list of data sets that are not linked to exactly one DSD. Click on any of them to get more information and either edit the data set in OntoWiki or choose a quick solution");
    rootLayout.addComponent(label);

    final ListSelect listDataSets = new ListSelect("Data Sets", map.keySet());
    listDataSets.setNullSelectionAllowed(false);
    rootLayout.addComponent(listDataSets);
    listDataSets.setImmediate(true);
    listDataSets.setWidth("100%");

    final Table detailsTable = new Table("Details");
    detailsTable.setHeight("250px");
    detailsTable.setWidth("100%");
    detailsTable.addContainerProperty("Property", String.class, null);
    detailsTable.addContainerProperty("Object", String.class, null);
    rootLayout.addComponent(detailsTable);

    final Label lblProblem = new Label("<b>Problem description: </b>", ContentMode.HTML);
    rootLayout.addComponent(lblProblem);

    Button editInOW = new Button("Edit in OntoWiki");
    editInOW.setEnabled(owUrl != null);
    editInOW.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            editManually((String) listDataSets.getValue());
        }
    });

    Form panelQuickFix = new Form();
    panelQuickFix.setCaption("Quick Fix");
    panelQuickFix.setSizeFull();
    VerticalLayout panelLayout = new VerticalLayout();
    panelLayout.setSpacing(true);
    panelLayout.setSizeFull();
    panelQuickFix.setLayout(panelLayout);
    rootLayout.addComponent(panelQuickFix);
    rootLayout.setExpandRatio(panelQuickFix, 2.0f);
    panelLayout.addComponent(new Label(
            "After the fix the selected data sets will link only to the DSD selected below or you can choose to edit the selected data set manually in OntoWiki"));
    final ComboBox comboDSDs = new ComboBox(null, getDataStructureDefinitions());
    comboDSDs.setNullSelectionAllowed(false);
    comboDSDs.setWidth("100%");
    comboDSDs.setImmediate(true);
    panelLayout.addComponent(comboDSDs);
    final Button fix = new Button("Quick Fix");
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setSpacing(true);
    buttonsLayout.addComponent(fix);
    buttonsLayout.addComponent(editInOW);
    panelLayout.addComponent(buttonsLayout);
    panelLayout.setExpandRatio(buttonsLayout, 2.0f);

    listDataSets.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            TupleQueryResult res = getResourceProperties((String) event.getProperty().getValue());
            int i = 1;
            detailsTable.removeAllItems();
            try {
                while (res.hasNext()) {
                    BindingSet set = res.next();
                    detailsTable.addItem(
                            new Object[] { set.getValue("p").stringValue(), set.getValue("o").stringValue() },
                            i++);
                }
            } catch (QueryEvaluationException e) {
                e.printStackTrace();
            }
            String chosenDataSet = (String) event.getProperty().getValue();
            lblProblem.setValue("<b>Problem description: </b>The selected data set belongs to "
                    + map.get(chosenDataSet) + " DSDs. It should belong to exactly one.");
        }
    });

    fix.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            String chosenDSD = (String) comboDSDs.getValue();
            String dataSet = (String) listDataSets.getValue();

            if (chosenDSD == null) {
                Notification.show("DSD was not selected", Notification.Type.ERROR_MESSAGE);
                return;
            }
            if (dataSet == null) {
                Notification.show("Data set was not selected", Notification.Type.ERROR_MESSAGE);
                return;
            }

            String structProp = "http://purl.org/linked-data/cube#structure";
            List<String> forRemoval = getDataSetDSDs(dataSet);
            if (forRemoval.size() > 0) {
                ArrayList<Statement> stmts = new ArrayList<Statement>();
                for (String dsd : forRemoval) {
                    stmts.add(getStatementFromUris(dataSet, structProp, dsd));
                }
                removeStatements(stmts);
            }
            ArrayList<Statement> addStmts = new ArrayList<Statement>();
            addStmts.add(getStatementFromUris(dataSet, structProp, chosenDSD));
            uploadStatements(addStmts);
            Notification.show("Fix executed");
            icQuery.eval();
        }
    });
}