List of usage examples for com.vaadin.ui Button addClickListener
public Registration addClickListener(ClickListener listener)
From source file:com.neatresults.mgnltweaks.neatu2b.ui.form.field.U2BField.java
License:Open Source License
/** * Initialize the field. <br>/*from w w w . j a va 2 s. co m*/ * Create as many configured Field as we have related values already stored. */ @Override protected void initFields(final PropertysetItem newValue) { root.removeAllComponents(); final TextField id = createTextField("Id", newValue); root.addComponent(id); final TextField title = createTextField("Title", newValue); root.addComponent(title); final TextFieldDefinition def = new TextFieldBuilder("description").label("Description").rows(3) .definition(); final TextArea description = (TextArea) createLocalField(def, newValue.getItemProperty(def.getName()), false); newValue.addItemProperty(def.getName(), description.getPropertyDataSource()); description.setNullRepresentation(""); description.setWidth("100%"); description.setNullSettingAllowed(true); root.addComponent(description); HorizontalLayout ddLine = new HorizontalLayout(); final TextField publishedAt = createTextField("Published", newValue); ddLine.addComponent(publishedAt); final TextField duration = createTextField("Duration", newValue); ddLine.addComponent(duration); ddLine.addComponent(createTextField("Definition", newValue)); Button fetchButton = new Button("Fetch metadata"); fetchButton.addStyleName("magnoliabutton"); fetchButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { String idStr = id.getValue(); // extract id from url when whole url is passed if (idStr.startsWith("http")) { idStr = StringUtils.substringBefore(StringUtils.substringAfter(idStr, "?v="), "&"); } U2BService service = null; try { RestEasyClient client = (RestEasyClient) restClientRegistry.getRestClient("youtube"); service = client.getClientService(U2BService.class); } catch (RegistrationException e) { log.error("Failed to get a client for [" + U2BService.class.getName() + "] with: " + e.getMessage(), e); } if (service != null) { String key = u2bModule.getGoogleKey(); JsonNode response = service.meta(idStr, "snippet", key); try { if (response.get("items").getElements().hasNext()) { JsonNode videoItem = response.get("items").getElements().next(); String descriptionStr = videoItem.get("snippet").get("description").getTextValue(); newValue.getItemProperty("description").setValue(descriptionStr); String titleStr = videoItem.get("snippet").get("title").getTextValue(); newValue.getItemProperty("title").setValue(titleStr); Iterator<Entry<String, JsonNode>> thumbs = videoItem.get("snippet").get("thumbnails") .getFields(); while (thumbs.hasNext()) { Entry<String, JsonNode> entry = thumbs.next(); newValue.getItemProperty(entry.getKey() + "Url") .setValue(entry.getValue().get("url").getTextValue()); newValue.getItemProperty(entry.getKey() + "Width") .setValue("" + entry.getValue().get("width").getLongValue()); newValue.getItemProperty(entry.getKey() + "Height") .setValue("" + entry.getValue().get("height").getLongValue()); } String publishedAtStr = videoItem.get("snippet").get("publishedAt").getTextValue(); newValue.getItemProperty("published").setValue(publishedAtStr); } } catch (Exception e) { log.error("Failed to parse the video metadata.", e); } response = service.meta(idStr, "contentDetails", key); try { if (response.get("items").getElements().hasNext()) { JsonNode videoItem = response.get("items").getElements().next(); String durationStr = videoItem.get("contentDetails").get("duration").getTextValue(); newValue.getItemProperty("duration").setValue(durationStr); String definition = videoItem.get("contentDetails").get("definition").getTextValue(); newValue.getItemProperty("definition").setValue(definition); } } catch (Exception e) { log.error("Failed to parse the video duration.", e); } } } }); ddLine.addComponent(fetchButton); ddLine.setWidth(100, Unit.PERCENTAGE); ddLine.setHeight(-1, Unit.PIXELS); ddLine.setComponentAlignment(fetchButton, Alignment.BOTTOM_RIGHT); root.addComponent(ddLine); PropertysetItem item = (PropertysetItem) getPropertyDataSource().getValue(); root.addComponent(createEntryComponent("default", item), root.getComponentCount() - 1); root.addComponent(createEntryComponent("standard", item), root.getComponentCount() - 1); root.addComponent(createEntryComponent("medium", item), root.getComponentCount() - 1); root.addComponent(createEntryComponent("high", item), root.getComponentCount() - 1); root.addComponent(createEntryComponent("maxres", item), root.getComponentCount() - 1); }
From source file:com.neatresults.mgnltweaks.ui.column.ColumnFormatterUtils.java
License:Open Source License
private static Button createButton(final String title, final String appName, final String subAppName, final String path, final Object itemId, final String rootPath, EventBus adminEventBus, EventBus eventBus, NeatTweaks4DevelopersModule module) { Button selectButton = new NativeButton(); selectButton.addStyleName("neatmagnoliabutton"); selectButton.setCaption(title);//from w w w. j av a 2 s .c om selectButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { String workPath = path; if (StringUtils.isNotBlank(rootPath) && !"/".equals(rootPath)) { workPath = StringUtils.removeStart(workPath, rootPath); } if ("browser".equals(subAppName)) { Location location = new BrowserLocation(appName, subAppName, workPath + ":treeview:"); adminEventBus.fireEvent(new LocationChangedEvent(location)); } else { // open app (subapp) Location location = new RerootBrowserLocation(appName, subAppName, workPath, module.isShowSubtreeOnlyInHelper()); adminEventBus.fireEvent(new LocationChangedEvent(location)); // expand selected node try { ContentChangedEvent cce = new ContentChangedEvent( JcrItemUtil.getItemId(RepositoryConstants.CONFIG, path), true); eventBus.fireEvent(cce); } catch (RepositoryException e) { log.error( "Ooops, failed to retrieve node at path {} and open it while trying to open definition with {}", path, e.getMessage(), e); } } } }); return selectButton; }
From source file:com.nfl.dm.clubsites.cms.articles.subapp.articleeditor.bodyeditor.BodyEditorViewImpl.java
License:Open Source License
private Layout createToolbarAssetsElements() { final CssLayout wrapper = new CssLayout(); wrapper.addStyleName("toolbar-elements"); final Button addPhotographButton = new Button("photograph"); addPhotographButton.addClickListener(new Button.ClickListener() { @Override//from w w w. j a v a 2 s .c o m public void buttonClick(Button.ClickEvent event) { listener.openMediaGallery(); } }); addPhotographButton.setStyleName("ax-shape-button"); ThemeResource sectionResource = new ThemeResource("img/photograph.png"); addPhotographButton.setIcon(sectionResource); wrapper.addComponent(addPhotographButton); List<String> assetElements = Arrays.asList(new String[] { "video", "poll", "related link", "iFrame" }); for (String name : assetElements) { Button addButton = new Button(name, new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { notImplemented(); } }); addButton.setStyleName("ax-shape-button"); ThemeResource tableResource = new ThemeResource("img/placeholder.png"); addButton.setIcon(tableResource); wrapper.addComponent(addButton); } return wrapper; }
From source file:com.ocs.dynamo.ui.component.QuickAddEntityField.java
License:Apache License
/** * Constructs the button that brings up the dialog that allows the user to add a new item * // w w w .j a v a2 s .com * @return */ protected Button constructAddButton() { Button addButton = new Button(getMessageService().getMessage("ocs.add")); addButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 4074804834729142520L; @Override public void buttonClick(ClickEvent event) { NewValueDialog dialog = new NewValueDialog(); dialog.build(); UI.getCurrent().addWindow(dialog); } }); return addButton; }
From source file:com.ocs.dynamo.ui.composite.dialog.EntityPopupDialog.java
License:Apache License
@Override protected void doBuildButtonBar(HorizontalLayout buttonBar) { // in read-only mode, display only an "OK" button that closes the dialog buttonBar.setVisible(formOptions.isReadOnly()); if (formOptions.isReadOnly()) { Button okButton = new Button(messageService.getMessage("ocs.ok")); okButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 1889018073135108348L; @Override/*from www. j a v a 2 s. co m*/ public void buttonClick(ClickEvent event) { close(); } }); buttonBar.addComponent(okButton); } }
From source file:com.ocs.dynamo.ui.composite.form.DetailsEditTable.java
License:Apache License
/** * Constructs the button that is used for adding new items * //from w w w.j a va 2 s .co m * @param buttonBar */ protected void constructAddButton(Layout buttonBar) { Button addButton = new Button(messageService.getMessage("ocs.add")); addButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { T t = createEntity(); container.addBean(t); parentForm.signalDetailsTableValid(DetailsEditTable.this, VaadinUtils.allFixedTableFieldsValid(table)); } }); addButton.setVisible(isTableEditEnabled() && !formOptions.isHideAddButton()); buttonBar.addComponent(addButton); }
From source file:com.ocs.dynamo.ui.composite.form.ModelBasedEditForm.java
License:Apache License
/** * Constructs the save button//w w w.java2 s . c o m */ private Button constructSaveButton() { Button saveButton = new Button(message("ocs.save")); saveButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { try { boolean isNew = entity.getId() == null; entity = service.save(entity); setEntity(service.fetchById(entity.getId())); Notification.show(message("ocs.changes.saved"), Notification.Type.TRAY_NOTIFICATION); // set to viewmode, load the view mode screen, and fill the // details if (getFormOptions().isOpenInViewMode()) { viewMode = true; build(); } afterEditDone(false, isNew, getEntity()); } catch (RuntimeException ex) { handleSaveException(ex); } } }); // enable/disable save button based on form validity saveButton.setEnabled(groups.get(isViewMode()).isValid()); for (Field<?> f : groups.get(isViewMode()).getFields()) { f.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { checkSaveButtonState(); } }); } return saveButton; }
From source file:com.ocs.dynamo.ui.composite.form.ModelBasedEditForm.java
License:Apache License
private HorizontalLayout constructButtonBar() { HorizontalLayout buttonBar = new DefaultHorizontalLayout(); // button to go back to the main screen when in view mode if (isViewMode() && getFormOptions().isShowBackButton()) { Button backButton = new Button(message("ocs.back")); backButton.addClickListener(new Button.ClickListener() { @Override//ww w .j a v a2s .com public void buttonClick(ClickEvent event) { back(); } }); buttonBar.addComponent(backButton); } // in edit mode, display a cancel button if (!isViewMode() && !getFormOptions().isHideCancelButton()) { Button cancelButton = new Button(message("ocs.cancel")); cancelButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (entity.getId() != null) { entity = service.fetchById(entity.getId()); } afterEditDone(true, entity.getId() == null, entity); } }); buttonBar.addComponent(cancelButton); } // create the save button if (!isViewMode()) { Button saveButton = constructSaveButton(); buttonBar.addComponent(saveButton); saveButtons.add(saveButton); } // create the edit button if (isViewMode() && getFormOptions().isShowEditButton() && isEditAllowed()) { Button editButton = new Button(message("ocs.edit")); editButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { setViewMode(false); } }); buttonBar.addComponent(editButton); } postProcessButtonBar(buttonBar, isViewMode()); return buttonBar; }
From source file:com.ocs.dynamo.ui.composite.form.UploadForm.java
License:Apache License
@Override protected void doBuildLayout(Layout main) { FormLayout form = new FormLayout(); form.setMargin(true);//from www. j ava 2 s.c o m if (ScreenMode.VERTICAL.equals(screenMode)) { form.setStyleName(DynamoConstants.CSS_CLASS_HALFSCREEN); } main.addComponent(form); // add custom components doBuildForm(form); // add file upload field UploadReceiver receiver = new UploadReceiver(); Upload upload = new Upload(message("ocs.uploadform.title"), receiver); upload.addSucceededListener(receiver); form.addComponent(upload); if (showCancelButton) { Button cancelButton = new Button(message("ocs.cancel")); cancelButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { cancel(); } }); main.addComponent(cancelButton); } }
From source file:com.ocs.dynamo.ui.composite.layout.BaseCollectionLayout.java
License:Apache License
/** * Constructs the add button/*from w w w . j a va 2 s . c om*/ * * @return */ protected Button constructAddButton() { Button ab = new Button(message("ocs.add")); ab.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = -5005648144833272606L; @Override public void buttonClick(ClickEvent event) { doAdd(); } }); ab.setVisible(!getFormOptions().isHideAddButton() && isEditAllowed()); return ab; }