Example usage for com.vaadin.ui ComboBox ComboBox

List of usage examples for com.vaadin.ui ComboBox ComboBox

Introduction

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

Prototype

protected ComboBox(DataCommunicator<T> dataCommunicator) 

Source Link

Document

Constructs and initializes an empty combo box.

Usage

From source file:edu.kit.dama.ui.admin.ServiceAccessTokenDialog.java

License:Apache License

private void buildMainLayout() {
    authenticatorSelection = new ComboBox("Credential Type");
    authenticatorSelection.setWidth("100%");
    authenticatorSelection.setNullSelectionAllowed(false);
    authenticatorSelection.addStyleName("myboldcaption");

    //load all authenticators
    authenticators.add(new MainLoginAuthenticator());
    authenticatorSelection.addItem(authenticators.get(0).getAuthenticatorId());

    //fill authenticator list and selection box
    AuthenticatorFactory.getInstance().getAuthenticators().forEach((auth) -> {
        authenticators.add(auth);/*from w w w .  j a va2 s  . c  o  m*/
        authenticatorSelection.addItem(auth.getAuthenticatorId());
    });

    //selection handler
    authenticatorSelection.addValueChangeListener((event) -> {
        String value = (String) authenticatorSelection.getValue();
        authenticators.forEach((auth) -> {
            if (auth.getAuthenticatorId().equals(value)) {
                updateAuthenticatorAttributeLayout(auth);
            }
        });
    });

    //generate secret handling
    generateButton.addClickListener((event) -> {
        String newSecret = RandomStringUtils.randomAlphanumeric(16);
        if (secretField != null) {
            //check this just to get sure
            secretField.setValue(newSecret);
            nosecretField.setValue(newSecret);
            UIComponentTools.showInformation("New random secret has been generated.");
        }
    });

    //show secret handling
    showSecret.addValueChangeListener((event2) -> {
        if (secretField != null) {
            //check this just to get sure
            if (showSecret.getValue()) {
                nosecretField.setValue(secretField.getValue());
                authenticatorConfigurationLayout.replaceComponent(secretField, nosecretField);
            } else {
                secretField.setValue(nosecretField.getValue());
                authenticatorConfigurationLayout.replaceComponent(nosecretField, secretField);
            }
        }
    });

    ClickListener listener = (Button.ClickEvent event) -> {
        boolean update = false;
        boolean created = false;

        if (okButton.equals(event.getSource()) && selectedId > 0) {
            //update of existing credential
            update = true;
            IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager();
            mdm.setAuthorizationContext(UIHelper.getSessionContext());
            try {
                ServiceAccessToken existingToken = mdm.find(ServiceAccessToken.class, selectedId);
                //transfer information from existing token to new one and persist
                ServiceAccessToken newToken = getToken(existingToken.getUserId());
                newToken.setId(selectedId);
                newToken.setServiceId(existingToken.getServiceId());
                mdm.save(newToken);
            } catch (UnauthorizedAccessAttemptException | SecretEncryptionException ex) {
                UIComponentTools.showWarning("Unable to store credential.");
                return;
            } finally {
                mdm.close();
            }
        } else if (okButton.equals(event.getSource()) && selectedId <= 0) {
            //creation of new token
            String typeSelection = (String) authenticatorSelection.getValue();
            IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager();
            mdm.setAuthorizationContext(UIHelper.getSessionContext());
            String userId = UIHelper.getSessionUser().getDistinguishedName();
            try {
                try {
                    List<ServiceAccessToken> token = mdm.findResultList(
                            "SELECT t FROM ServiceAccessToken t WHERE t.serviceId=?1 AND t.userId=?2",
                            new Object[] { typeSelection, userId }, ServiceAccessToken.class);
                    if (!token.isEmpty()) {
                        UIComponentTools.showWarning("There exists already a credential of type '"
                                + typeSelection + "' for your userId.");
                        return;
                    }
                } catch (UnauthorizedAccessAttemptException ex) {
                    UIComponentTools.showWarning("Unable to check for existing credential.");
                    return;
                }

                ServiceAccessToken newToken = getToken(userId);

                String uid = newToken.getUserId();
                newToken.setUserId(null);
                if (!mdm.find(newToken, newToken).isEmpty()) {
                    throw new UnauthorizedAccessAttemptException("Duplicate credential detected.");
                }

                newToken.setUserId(uid);
                mdm.save(newToken);
                created = true;
            } catch (UnauthorizedAccessAttemptException | SecretEncryptionException ex) {
                UIComponentTools
                        .showWarning("Failed to create new credential. (Message: " + ex.getMessage() + ")");
                return;
            } finally {
                mdm.close();
            }

        }
        //close window
        if (currentWin != null) {
            UI.getCurrent().removeWindow(currentWin);
            if (update) {
                UIComponentTools.showInformation("Credential successfully updated.");
            } else if (created) {
                UIComponentTools.showInformation("Credential successfully created.");
            }
        }
    };
    okButton.addClickListener(listener);
    cancelButton.addClickListener(listener);

    //fill dummy config layout
    authenticatorConfigurationLayout = new GridLayout(1, 1);
    authenticatorConfigurationLayout.addComponent(new Label("Please select an authenticator."));
    authenticatorConfigurationLayout.setSpacing(true);
    authenticatorConfigurationLayout.setWidth("400px");

    HorizontalLayout buttonLayout = new HorizontalLayout(cancelButton, okButton);
    buttonLayout.setSpacing(true);

    mainLayout = new VerticalLayout(authenticatorSelection, authenticatorConfigurationLayout, buttonLayout);
    mainLayout.setSpacing(true);
    mainLayout.setMargin(true);
    mainLayout.setExpandRatio(authenticatorConfigurationLayout, 1.0f);
    mainLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);
}

From source file:edu.kit.dama.ui.admin.utils.PathSelector.java

License:Apache License

/**
 *
 *///from   w  w w.j a v  a2 s .co m
private void buildRootBox() {
    String id = "rootBox";
    LOGGER.debug("Building " + DEBUG_ID_PREFIX + id + " ...");

    rootBox = new ComboBox("ROOT");
    rootBox.setId(DEBUG_ID_PREFIX + id);
    rootBox.setWidth("100%");
    rootBox.setImmediate(true);
    rootBox.addStyleName(CSSTokenContainer.BOLD_CAPTION);
    rootBox.setNullSelectionAllowed(false);

    rootBox.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            String root = (String) event.getProperty().getValue();
            if (root == null || root.trim().isEmpty()) {
                String warning = "Invalid root selection!";
                LOGGER.warn(warning);
                UIComponentTools.showWarning("WARNING", warning, 5);
                return;
            }
            FilesystemContainer container = new FilesystemContainer(new File(root), false);
            getTreeTable().setContainerDataSource(container);
            getTreeTable().setItemIconPropertyId("Icon");
            getTreeTable().setVisibleColumns(new Object[] { "Name", "Size", "Last Modified" });
            getPathField().setValue(root);
        }
    });

    reloadRootBox();
    rootBox.select(rootBox.getItemIds().toArray()[0]);
}

From source file:edu.kit.dama.ui.admin.workflow.DataWorkflowBasePropertiesLayout.java

License:Apache License

public ComboBox getContactBox() {
    if (contactBox == null) {
        String id = "contactBox";
        LOGGER.debug("Building " + DEBUG_ID_PREFIX + id + " ...");
        contactBox = new ComboBox("CONTACT");
        contactBox.setDescription("The user who serves as contact for this task, e.g. the developer.");
        contactBox.setId(DEBUG_ID_PREFIX + id);
        contactBox.setWidth("100%");
        contactBox.setImmediate(true);//from www .j  a v a2 s . co m
        contactBox.setNullSelectionAllowed(true);
        contactBox.setNullSelectionItemId("None");
        contactBox.addStyleName(CSSTokenContainer.BOLD_CAPTION);
    }
    return contactBox;
}

From source file:edu.kit.dama.ui.admin.workflow.ExecutionEnvironmentBasePropertiesLayout.java

License:Apache License

/**
 * Returns the access point base path field holding the base path of the
 * configured access point within the execution environment.
 *
 * @return The access point base path field.
 *//*from w  w  w .j av  a2 s . c o m*/
public final ComboBox getAccessPointBox() {
    if (accessPointBox == null) {
        String id = "accessPointBox";
        LOGGER.debug("Building " + DEBUG_ID_PREFIX + id + " ...");

        accessPointBox = new ComboBox("ACCESS POINT");
        accessPointBox.setId(DEBUG_ID_PREFIX + id);
        accessPointBox.setWidth("100%");
        accessPointBox.setNullSelectionAllowed(false);
        accessPointBox.setRequired(true);
        accessPointBox.addStyleName(CSSTokenContainer.BOLD_CAPTION);
    }
    return accessPointBox;
}

From source file:edu.kit.dama.ui.admin.workflow.property.AddEnvironmentPropertyComponent.java

License:Apache License

/**
 * Build the main layout including the type selection combobox, the buttons
 * and the placeholder for the property configuration component.
 *///from ww w  . j a v  a2s .c  o m
private void buildMainLayout() {
    propertyEditorLayout = new VerticalLayout();
    propertyEditorLayout.setSizeFull();
    propertyEditorLayout.setMargin(false);
    propertyEditorLayout.setSpacing(true);
    propertyEditorLayout.setWidth("400px");

    propertyTypeSelectionBox = new ComboBox("PROPERTY TYPE");
    propertyTypeSelectionBox.setWidth("100%");
    propertyTypeSelectionBox.setImmediate(true);
    propertyTypeSelectionBox.setNullSelectionAllowed(false);
    propertyTypeSelectionBox.addStyleName(CSSTokenContainer.BOLD_CAPTION);

    for (ENVIRONMENT_PROPERTY_TYPE type : ENVIRONMENT_PROPERTY_TYPE.values()) {
        propertyTypeSelectionBox.addItem(type.toString());
        propertyTypeSelectionBox.setItemCaption(type, type.getName());
    }

    propertyTypeSelectionBox.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            updatePropertySelection(
                    ENVIRONMENT_PROPERTY_TYPE.valueOf((String) propertyTypeSelectionBox.getValue()));
        }
    });

    final Button createButton = new Button("Create");
    final Button cancelButton = new Button("Cancel");

    Button.ClickListener listener = new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (createButton.equals(event.getButton())) {
                createProperty();
            }
            UI.getCurrent().removeWindow(propertyWindow);
            propertyWindow = null;
        }
    };

    createButton.addClickListener(listener);
    cancelButton.addClickListener(listener);

    HorizontalLayout buttonLayout = new HorizontalLayout(cancelButton, createButton);
    mainLayout = new VerticalLayout(propertyTypeSelectionBox, propertyEditorLayout, buttonLayout);
    mainLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);
    mainLayout.setExpandRatio(propertyTypeSelectionBox, .1f);
    mainLayout.setExpandRatio(propertyEditorLayout, .9f);
    mainLayout.setExpandRatio(buttonLayout, .1f);

    propertyTypeSelectionBox.setValue(ENVIRONMENT_PROPERTY_TYPE.STRING_VALUE_PROPERTY.toString());
}

From source file:edu.kit.dama.ui.admin.workflow.property.LinuxSoftwareMapPropertyConfigurationPanel.java

License:Apache License

/**
 * Get the copying policy field./*from   ww w  .j a  v a2  s  .c o m*/
 */
private ComboBox getCopyingPolicyField() {
    if (copyingPolicyField == null) {
        copyingPolicyField = new ComboBox("COPYING POLICY");
        copyingPolicyField.setWidth("100%");
        copyingPolicyField.setImmediate(true);
        copyingPolicyField.setNullSelectionAllowed(true);
        copyingPolicyField.setInputPrompt("Add Another...");
        copyingPolicyField.setTextInputAllowed(true);
        copyingPolicyField.setNewItemsAllowed(true);
        copyingPolicyField.addStyleName(CSSTokenContainer.BOLD_CAPTION);
        //add standard licenses for linux software map (see http://www.ibiblio.org/pub/linux/LICENSES/theory.html)
        copyingPolicyField.addItem("PD");
        copyingPolicyField.addItem("Shareware");
        copyingPolicyField.addItem("BSD");
        copyingPolicyField.addItem("MIT");
        copyingPolicyField.addItem("Artistic License");
        copyingPolicyField.addItem("FRS Copyrighted");
        copyingPolicyField.addItem("GPL");
        copyingPolicyField.addItem("GPL 2.0");
        copyingPolicyField.addItem("GPL+LGPL");
        copyingPolicyField.addItem("W3C");
        copyingPolicyField.addItem("restricted");
    }
    return copyingPolicyField;
}

From source file:edu.nps.moves.mmowgli.modules.administration.NewMovePhaseDialog.java

License:Open Source License

@SuppressWarnings("serial")
public NewMovePhaseDialog(Move move) {
    super("Make a new Phase for " + move.getName());
    this.moveBeingEdited = Move.getTL(move.getId());
    setSizeUndefined();//from w ww .j  a  v a  2s  .  c o m
    setWidth("390px");
    VerticalLayout vLay;
    setContent(vLay = new VerticalLayout());
    vLay.setSpacing(true);
    vLay.setMargin(true);
    vLay.addComponent(new Label("Choose a descriptive name for this phase.  Suggested names are shown in the "
            + "drop down list, but any text is permitted."));

    descriptionCB = new ComboBox("Phase description");
    vLay.addComponent(descriptionCB);
    fillCombo(descriptionCB);

    descriptionCB.setInputPrompt("Choose suggested description, or enter text");
    descriptionCB.setWidth("350px");

    descriptionCB.setImmediate(true);
    descriptionCB.setNullSelectionAllowed(false);
    descriptionCB.setTextInputAllowed(true);
    descriptionCB.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            // final String valueString = String.valueOf(event.getProperty().getValue());
            // Notification.show("Value changed:", valueString,
            // Type.TRAY_NOTIFICATION);
        }
    });
    vLay.addComponent(existingPhasesGLay = new GridLayout());
    existingPhasesGLay.setColumns(3);
    existingPhasesGLay.setRows(1); // to start
    existingPhasesGLay.setSpacing(true);
    existingPhasesGLay.addStyleName("m-greyborder");
    existingPhasesGLay.setCaption("Existing Phases");
    fillExistingPhases();

    HorizontalLayout buttHLay;
    vLay.addComponent(buttHLay = new HorizontalLayout());
    buttHLay.setWidth("100%");
    buttHLay.setSpacing(true);
    Label lab;
    buttHLay.addComponent(lab = new Label());
    lab.setWidth("1px");
    buttHLay.setExpandRatio(lab, 1.0f);
    buttHLay.addComponent(cancelButt = new Button("Cancel", saveCancelListener));
    buttHLay.addComponent(saveButt = new Button("Save", saveCancelListener));
}

From source file:eu.lod2.EPoolPartyExtractor.java

License:Apache License

public EPoolPartyExtractor(LOD2DemoState st) {

    // The internal state 
    state = st;//from www . ja v a  2 s.  c o  m

    // second component
    VerticalLayout panel = new VerticalLayout();

    Label description = new Label(
            "This service will identify text elements (tags) which correspond to concepts in a given controlled vocabulary using the PoolParty Extractor (PPX).\n"
                    + "At the moment we have fixed the controlled vocabulary to be the Social Semantic Web thesaurus also available at CKAN.\n"
                    + "The identified concepts will be inserted as triples in the current graph.\n");
    panel.addComponent(description);

    Form t2f = new Form();
    t2f.setDebugId(this.getClass().getSimpleName() + "_t2f");
    exportGraph = new ExportSelector3(state, true);
    exportGraph.setDebugId(this.getClass().getSimpleName() + "_exportGraph");
    t2f.getLayout().addComponent(exportGraph);

    ppProjectId = new TextField("PoolParty project Id:");
    ppProjectId.setDebugId(this.getClass().getSimpleName() + "_ppProjectId");
    ppProjectId.setDescription(
            "The unique identifier of the PoolParty project to use for the extraction (usually a UUID like d06bd0f8-03e4-45e0-8683-fed428fca242) ");
    t2f.getLayout().addComponent(ppProjectId);

    textLanguage = new ComboBox("Language of the text:");
    textLanguage.setDebugId(this.getClass().getSimpleName() + "_textLanguage");
    textLanguage
            .setDescription("This is the language of the text. Language can be en (english) or de (german).");
    textLanguage.addItem("en");
    textLanguage.addItem("de");
    t2f.getLayout().addComponent(textLanguage);

    TextArea textToAnnotateField = new TextArea("text:");
    textToAnnotateField.setDebugId(this.getClass().getSimpleName() + "_textToAnnotateField");
    textToAnnotateField.setImmediate(false);
    textToAnnotateField.addListener(this);
    textToAnnotateField.setWidth("100%");
    textToAnnotateField.setRows(10);
    t2f.getLayout().addComponent(textToAnnotateField);

    // initialize the footer area of the form
    HorizontalLayout t2ffooterlayout = new HorizontalLayout();
    t2f.setFooter(t2ffooterlayout);

    annotateButton = new Button("Extract concepts", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            annotateText(event);
        }
    });
    annotateButton.setDebugId(this.getClass().getSimpleName() + "_annotateButton");
    annotateButton
            .setDescription("Extract the relevant concepts w.r.t. the controlled vocabulary in PoolParty");
    annotateButton.setEnabled(false);

    t2f.getFooter().addComponent(annotateButton);

    panel.addComponent(t2f);

    // The composition root MUST be set
    setCompositionRoot(panel);
}

From source file:eu.lod2.EPoolPartyLabel.java

License:Apache License

public EPoolPartyLabel(LOD2DemoState st) {

    // The internal state 
    state = st;/* ww w.  j a va2  s . co m*/

    // second component
    VerticalLayout panel = new VerticalLayout();

    Label description = new Label(
            "This service will identify text elements (tags) which correspond to concepts in a given controlled vocabulary using the PoolParty Extractor (PPX).\n"
                    + "At the moment we have fixed the controlled vocabulary to be the Social Semantic Web thesaurus also available at CKAN.\n"
                    + "The identified concepts will be inserted as triples in the current graph.\n");
    panel.addComponent(description);

    Form t2f = new Form();
    t2f.setDebugId(this.getClass().getSimpleName() + "_t2f");
    exportGraph = new ExportSelector3(state);
    exportGraph.setDebugId(this.getClass().getSimpleName() + "_exportGraph");
    t2f.getLayout().addComponent(exportGraph);

    ppProjectId = new TextField("PoolParty project Id:");
    ppProjectId.setDebugId(this.getClass().getSimpleName() + "_ppProjectId");
    ppProjectId.setDescription(
            "The unique identifier of the PoolParty project to use for the extraction (usually a UUID like d06bd0f8-03e4-45e0-8683-fed428fca242) ");
    t2f.getLayout().addComponent(ppProjectId);

    textLanguage = new ComboBox("Language of the text:");
    textLanguage.setDebugId(this.getClass().getSimpleName() + "_textLanguage");
    textLanguage
            .setDescription("This is the language of the text. Language can be en (english) or de (german).");
    textLanguage.addItem("en");
    textLanguage.addItem("de");
    t2f.getLayout().addComponent(textLanguage);

    TextArea textToAnnotateField = new TextArea("text:");
    textToAnnotateField.setDebugId(this.getClass().getSimpleName() + "_textToAnnotateField");
    textToAnnotateField.setImmediate(false);
    textToAnnotateField.addListener(this);
    textToAnnotateField.setWidth("100%");
    textToAnnotateField.setRows(10);
    t2f.getLayout().addComponent(textToAnnotateField);

    // initialize the footer area of the form
    HorizontalLayout t2ffooterlayout = new HorizontalLayout();
    t2f.setFooter(t2ffooterlayout);

    annotateButton = new Button("Extract concepts", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            annotateText(event);
        }
    });
    annotateButton.setDebugId(this.getClass().getSimpleName() + "_annotateButton");
    annotateButton
            .setDescription("Extract the relevant concepts w.r.t. the controlled vocabulary in PoolParty");
    annotateButton.setEnabled(false);

    t2f.getFooter().addComponent(annotateButton);

    panel.addComponent(t2f);

    // The composition root MUST be set
    setCompositionRoot(panel);
}

From source file:eu.lod2.ExportSelector.java

License:Apache License

public ExportSelector(LOD2DemoState st, Boolean update) {

    // The internal state 
    state = st;//  w  ww .j  a v  a 2 s.co  m
    updateCurrentGraph = update;

    VerticalLayout layout = new VerticalLayout();

    // the graph selector
    // it displays all acceptable graphs in Virtuoso 
    // XXX TODO show only those which are editable in OntoWiki
    graphSelector = new ComboBox("Select Export graph: ");
    graphSelector.setDebugId(this.getClass().getSimpleName() + "_graphSelector");
    graphSelector.setNewItemsAllowed(true);
    graphSelector.setImmediate(true);
    graphSelector.addListener(this);
    graphSelector.setNewItemHandler(this);
    graphSelector.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
    addCandidateGraphs(graphSelector);
    layout.addComponent(graphSelector);

    // The composition root MUST be set
    setCompositionRoot(layout);
}