List of usage examples for com.vaadin.ui TextArea getValue
@Override
public String getValue()
From source file:net.larbig.ScriptRunnerApplication.java
License:Apache License
@Override public void init() { window = new Window("Scriptrunner"); setMainWindow(window);//w w w. j ava 2s . co m VerticalLayout layout = new VerticalLayout(); final TextField tfDriver = new TextField("Driver"); tfDriver.setWidth(300, Sizeable.UNITS_PIXELS); tfDriver.setValue("com.mysql.jdbc.Driver"); final TextField tfURL = new TextField("URL"); tfURL.setWidth(300, Sizeable.UNITS_PIXELS); tfURL.setValue("jdbc:mysql://mysql.host.net:3306/datenbank"); final TextField tfUser = new TextField("User"); tfUser.setWidth(300, Sizeable.UNITS_PIXELS); final TextField tfPasswort = new TextField("Password"); tfPasswort.setWidth(300, Sizeable.UNITS_PIXELS); final TextArea taSQL = new TextArea("SQL"); taSQL.setWidth(300, Sizeable.UNITS_PIXELS); taSQL.setHeight(150, Sizeable.UNITS_PIXELS); Button button = new Button("Execute"); button.addListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { try { Class.forName((String) tfDriver.getValue()).newInstance(); Connection con = DriverManager.getConnection(tfURL.getValue().toString(), tfUser.getValue().toString(), tfPasswort.getValue().toString()); ScriptRunner runner = new ScriptRunner(con, false, true); Reader r = new StringReader(taSQL.getValue().toString()); runner.runScript(r); } catch (IOException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }); layout.addComponent(tfDriver); layout.addComponent(tfURL); layout.addComponent(tfUser); layout.addComponent(tfPasswort); layout.addComponent(taSQL); layout.addComponent(button); window.addComponent(layout); }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.admin.AdminScreenProvider.java
License:Apache License
private Component getEmailSettingTab() { VerticalLayout s2 = new VerticalLayout(); HorizontalSplitPanel split2 = new HorizontalSplitPanel(); s2.addComponent(split2);// ww w. j av a2 s .c o m Tree sTree2 = new Tree(TRANSLATOR.translate("general.email.settings")); sTree2.addValueChangeListener((Property.ValueChangeEvent event) -> { if (sTree2.getValue() instanceof VmSetting) { VmSetting vmSetting = (VmSetting) sTree2.getValue(); split2.setSecondComponent(displaySetting(vmSetting, !vmSetting.getSetting().equals("mail.enable"))); } }); split2.setFirstComponent(sTree2); VMSettingServer.getSettings().forEach(s -> { if (s.getSetting().startsWith("mail")) { sTree2.addItem(s); sTree2.setChildrenAllowed(s, false); sTree2.setItemCaption(s, TRANSLATOR.translate(s.getSetting())); } }); Button testEmail = new Button(TRANSLATOR.translate("general.email.settings.test"), listener -> { //Show a window to test email settings VMWindow w = new VMWindow(TRANSLATOR.translate("general.email.settings.test")); VerticalLayout vl = new VerticalLayout(); TextField to = new TextField(TRANSLATOR.translate("general.email.to")); TextField from = new TextField(TRANSLATOR.translate("general.email.from")); TextField subject = new TextField(TRANSLATOR.translate("general.email.subject")); TextArea mess = new TextArea(TRANSLATOR.translate("general.email.message")); mess.setSizeFull(); TextArea output = new TextArea(TRANSLATOR.translate("general.output")); output.setReadOnly(true); output.setSizeFull(); Button send = new Button(TRANSLATOR.translate("general.email.send"), l -> { try { Lookup.getDefault().lookup(IEmailManager.class).sendEmail(to.getValue(), null, from.getValue(), subject.getValue(), mess.getValue()); output.setValue(TRANSLATOR.translate("general.email.settings.test.success")); //Successful, update the enable setting. VMSettingServer enable = new VMSettingServer("mail.enable"); enable.setBoolVal(true); enable.write2DB(); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); output.setReadOnly(false); output.setValue(sw.toString()); output.setReadOnly(true); } }); vl.addComponent(to); vl.addComponent(from); vl.addComponent(subject); vl.addComponent(mess); vl.addComponent(send); vl.addComponent(output); w.setContent(vl); w.setHeight(75, Sizeable.Unit.PERCENTAGE); w.setWidth(75, Sizeable.Unit.PERCENTAGE); ValidationManagerUI.getInstance().addWindow(w); }); s2.addComponent(testEmail); return s2; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.RequirementComponent.java
License:Apache License
private void init() { FormLayout layout = new FormLayout(); setContent(layout);/* w ww . j a va2s .c o m*/ addStyleName(ValoTheme.FORMLAYOUT_LIGHT); BeanFieldGroup binder = new BeanFieldGroup(req.getClass()); binder.setItemDataSource(req); TextField id = (TextField) binder.buildAndBind(TRANSLATOR.translate("requirement.id"), "uniqueId", TextField.class); id.setNullRepresentation(""); layout.addComponent(id); TextArea desc = (TextArea) binder.buildAndBind(TRANSLATOR.translate("general.description"), "description", TextArea.class); desc.setNullRepresentation(""); desc.setSizeFull(); layout.addComponent(desc); TextArea notes = (TextArea) binder.buildAndBind(TRANSLATOR.translate("general.notes"), "notes", TextArea.class); notes.setNullRepresentation(""); notes.setSizeFull(); layout.addComponent(notes); if (req.getParentRequirementId() != null) { TextField tf = new TextField(TRANSLATOR.translate("general.parent")); tf.setValue(req.getParentRequirementId().getUniqueId()); tf.setReadOnly(true); layout.addComponent(tf); } if (req.getRequirementList() == null) { req.setRequirementList(new ArrayList<>()); } if (!req.getRequirementList().isEmpty() && !edit) { layout.addComponent(((VMUI) UI.getCurrent()).getDisplayRequirementList( TRANSLATOR.translate("related.requirements"), req.getRequirementList())); } else if (edit) { //Allow user to add children AbstractSelect as = ((VMUI) UI.getCurrent()).getRequirementSelectionComponent(); req.getRequirementList().forEach(sub -> { as.select(sub); }); as.addValueChangeListener(event -> { Set<Requirement> selected = (Set<Requirement>) event.getProperty().getValue(); req.getRequirementList().clear(); selected.forEach(r -> { req.getRequirementList().add(r); }); }); layout.addComponent(as); } Button cancel = new Button(TRANSLATOR.translate("general.cancel")); cancel.addClickListener((Button.ClickEvent event) -> { binder.discard(); if (req.getId() == null) { ((VMUI) UI.getCurrent()).displayObject(req.getRequirementSpecNode()); } else { ((VMUI) UI.getCurrent()).displayObject(req, false); } }); if (edit) { if (req.getId() == null) { //Creating a new one Button save = new Button(TRANSLATOR.translate("general.save")); save.addClickListener((Button.ClickEvent event) -> { req.setUniqueId(id.getValue().toString()); req.setNotes(notes.getValue().toString()); req.setDescription(desc.getValue().toString()); req.setRequirementSpecNode((RequirementSpecNode) ((VMUI) UI.getCurrent()).getSelectdValue()); new RequirementJpaController(DataBaseManager.getEntityManagerFactory()).create(req); setVisible(false); //Recreate the tree to show the addition ((VMUI) UI.getCurrent()).buildProjectTree(req); ((VMUI) UI.getCurrent()).displayObject(req, true); }); HorizontalLayout hl = new HorizontalLayout(); hl.addComponent(save); hl.addComponent(cancel); layout.addComponent(hl); } else { //Editing existing one Button update = new Button(TRANSLATOR.translate("general.update")); update.addClickListener((Button.ClickEvent event) -> { try { RequirementServer rs = new RequirementServer(req); rs.setDescription(((TextArea) desc).getValue()); rs.setNotes(((TextArea) notes).getValue()); rs.setUniqueId(((TextField) id).getValue()); ((VMUI) UI.getCurrent()).handleVersioning(rs, () -> { try { rs.write2DB(); //Recreate the tree to show the addition ((VMUI) UI.getCurrent()).buildProjectTree(rs.getEntity()); ((VMUI) UI.getCurrent()).displayObject(rs.getEntity(), false); } catch (NonexistentEntityException ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate("general.error.record.update"), ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate("general.error.record.update"), ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE); } }); setVisible(false); } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate("general.error.record.update"), ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE); } }); HorizontalLayout hl = new HorizontalLayout(); hl.addComponent(update); hl.addComponent(cancel); layout.addComponent(hl); } } try { //Add a history section if (req.getId() != null) { List<History> versions = new RequirementServer(req).getHistoryList(); if (!versions.isEmpty()) { layout.addComponent(((VMUI) UI.getCurrent()).createRequirementHistoryTable( TRANSLATOR.translate("general.history"), versions, true)); } } } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } binder.setBuffered(true); binder.setReadOnly(!edit); binder.bindMemberFields(this); setSizeFull(); }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.StepComponent.java
License:Apache License
private void init() { FormLayout layout = new FormLayout(); setContent(layout);/*from www . j a v a2 s . co m*/ addStyleName(ValoTheme.FORMLAYOUT_LIGHT); BeanFieldGroup binder = new BeanFieldGroup(s.getClass()); binder.setItemDataSource(s); Field<?> sequence = binder.buildAndBind(TRANSLATOR.translate("general.sequence"), "stepSequence"); layout.addComponent(sequence); TextArea text = new TextArea(TRANSLATOR.translate("general.text")); text.setConverter(new ByteToStringConverter()); binder.bind(text, "text"); layout.addComponent(text); TextArea result = new TextArea(TRANSLATOR.translate("expected.result")); result.setConverter(new ByteToStringConverter()); binder.bind(result, "expectedResult"); layout.addComponent(result); Field notes = binder.buildAndBind(TRANSLATOR.translate("general.notes"), "notes", TextArea.class); notes.setSizeFull(); layout.addComponent(notes); if (!s.getRequirementList().isEmpty() && !edit) { layout.addComponent(((ValidationManagerUI) UI.getCurrent()).getDisplayRequirementList( TRANSLATOR.translate("related.requirements"), s.getRequirementList())); } else { AbstractSelect requirements = ((ValidationManagerUI) UI.getCurrent()) .getRequirementSelectionComponent(); //Select the exisitng ones. if (s.getRequirementList() != null) { s.getRequirementList().forEach((r) -> { requirements.select(r); }); } requirements.addValueChangeListener(event -> { Set<Requirement> selected = (Set<Requirement>) event.getProperty().getValue(); s.getRequirementList().clear(); selected.forEach(r -> { s.getRequirementList().add(r); }); }); layout.addComponent(requirements); } DataEntryComponent fields = new DataEntryComponent(edit); binder.bind(fields, "dataEntryList"); layout.addComponent(fields); binder.setReadOnly(edit); Button cancel = new Button(TRANSLATOR.translate("general.cancel")); cancel.addClickListener((Button.ClickEvent event) -> { binder.discard(); if (s.getStepPK() == null) { ((ValidationManagerUI) UI.getCurrent()) .displayObject(((ValidationManagerUI) UI.getCurrent()).getTree().getValue()); } else { ((ValidationManagerUI) UI.getCurrent()).displayObject(s, false); } }); if (edit) { Button add = new Button(TRANSLATOR.translate("add.field")); add.addClickListener(listener -> { VMWindow w = new VMWindow(); FormLayout fl = new FormLayout(); ComboBox newType = new ComboBox(TRANSLATOR.translate("general.type")); newType.setNewItemsAllowed(false); newType.setTextInputAllowed(false); newType.addValidator(new NullValidator(TRANSLATOR.translate("message.required.field.missing") .replaceAll("%f", TRANSLATOR.translate("general.type")), false)); BeanItemContainer<DataEntryType> container = new BeanItemContainer<>(DataEntryType.class, new DataEntryTypeJpaController(DataBaseManager.getEntityManagerFactory()) .findDataEntryTypeEntities()); newType.setContainerDataSource(container); newType.getItemIds().forEach(id -> { DataEntryType temp = ((DataEntryType) id); newType.setItemCaption(id, TRANSLATOR.translate(temp.getTypeName())); }); fl.addComponent(newType); TextField tf = new TextField(TRANSLATOR.translate("general.name")); fl.addComponent(tf); HorizontalLayout hl = new HorizontalLayout(); Button a = new Button(TRANSLATOR.translate("general.add")); a.addClickListener(l -> { DataEntryType det = (DataEntryType) newType.getValue(); DataEntry de = null; switch (det.getId()) { case 1: de = DataEntryServer.getStringField(tf.getValue()); break; case 2: de = DataEntryServer.getNumericField(tf.getValue(), null, null); break; case 3: de = DataEntryServer.getBooleanField(tf.getValue()); break; case 4: de = DataEntryServer.getAttachmentField(tf.getValue()); break; } if (de != null) { s.getDataEntryList().add(de); ((ValidationManagerUI) UI.getCurrent()).displayObject(s); } UI.getCurrent().removeWindow(w); }); hl.addComponent(a); Button c = new Button(TRANSLATOR.translate("general.cancel")); c.addClickListener(l -> { UI.getCurrent().removeWindow(w); }); hl.addComponent(c); fl.addComponent(hl); w.setContent(fl); UI.getCurrent().addWindow(w); }); if (s.getStepPK() == null) { //Creating a new one Button save = new Button(TRANSLATOR.translate("general.save")); save.addClickListener(listener -> { try { s.setExpectedResult(((TextArea) result).getValue().getBytes(encoding)); s.setNotes(notes.getValue() == null ? "" : notes.getValue().toString()); s.setStepSequence(Integer.parseInt(sequence.getValue().toString())); s.setTestCase((TestCase) ((ValidationManagerUI) UI.getCurrent()).getTree().getValue()); s.setText(text.getValue().getBytes(encoding)); if (s.getRequirementList() == null) { s.setRequirementList(new ArrayList<>()); } new StepJpaController(DataBaseManager.getEntityManagerFactory()).create(s); setVisible(false); //Recreate the tree to show the addition ((ValidationManagerUI) UI.getCurrent()).updateProjectList(); ((ValidationManagerUI) UI.getCurrent()).updateScreen(); ((ValidationManagerUI) UI.getCurrent()).displayObject(s); ((ValidationManagerUI) UI.getCurrent()).buildProjectTree(s); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate("general.error.record.creation"), ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE); } }); HorizontalLayout hl = new HorizontalLayout(); hl.addComponent(save); hl.addComponent(add); hl.addComponent(cancel); layout.addComponent(hl); } else { //Editing existing one Button update = new Button(TRANSLATOR.translate("general.update")); update.addClickListener((Button.ClickEvent event) -> { try { s.setExpectedResult(((TextArea) result).getValue().getBytes(encoding)); s.setNotes(notes.getValue().toString()); s.setStepSequence(Integer.parseInt(sequence.getValue().toString())); s.setText(text.getValue().getBytes(encoding)); if (s.getRequirementList() == null) { s.setRequirementList(new ArrayList<>()); } ((ValidationManagerUI) UI.getCurrent()).handleVersioning(s, () -> { try { new StepJpaController(DataBaseManager.getEntityManagerFactory()).edit(s); } catch (NonexistentEntityException ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate("general.error.record.update"), ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate("general.error.record.update"), ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE); } }); ((ValidationManagerUI) UI.getCurrent()).displayObject(s); } catch (UnsupportedEncodingException | NumberFormatException ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate("general.error.record.creation"), ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE); } }); HorizontalLayout hl = new HorizontalLayout(); hl.addComponent(update); hl.addComponent(add); hl.addComponent(cancel); layout.addComponent(hl); } } binder.setReadOnly(!edit); binder.bindMemberFields(this); layout.setSizeFull(); setSizeFull(); }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI.java
License:Apache License
private void showVersioningPrompt(Versionable ao, Runnable r) { VerticalLayout layout = new VerticalLayout(); TextArea message = new TextArea(); message.setValue(TRANSLATOR.translate("missing.reason.message")); message.setReadOnly(true);//from w w w .j a v a2s .c om message.setSizeFull(); TextArea desc = new TextArea(TRANSLATOR.translate("general.reason")); desc.setSizeFull(); layout.addComponent(message); layout.addComponent(desc); //Prompt user with reason for change MessageBox prompt = MessageBox.createQuestion(); prompt.withCaption(TRANSLATOR.translate("missing.reason.title")).withMessage(layout).withYesButton(() -> { ao.setReason(desc.getValue()); if (r != null) { r.run(); } }, ButtonOption.focus(), ButtonOption.icon(VaadinIcons.CHECK), ButtonOption.disable()) .withNoButton(ButtonOption.icon(VaadinIcons.CLOSE)); prompt.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); desc.addTextChangeListener((TextChangeEvent event1) -> { //Enable if there is a description change. prompt.getButton(ButtonType.YES).setEnabled(!event1.getText().trim().isEmpty()); }); prompt.getWindow().setWidth(50, Unit.PERCENTAGE); prompt.getWindow().setHeight(50, Unit.PERCENTAGE); prompt.open(); }
From source file:org.activiti.explorer.ui.task.DescriptionComponent.java
License:Apache License
protected void initLayoutClickListener() { addListener(new LayoutClickListener() { public void layoutClick(LayoutClickEvent event) { if (event.getClickedComponent() != null && event.getClickedComponent().equals(descriptionLabel)) { // textarea final TextArea descriptionTextArea = new TextArea(); descriptionTextArea.setWidth(100, UNITS_PERCENTAGE); descriptionTextArea.setValue(task.getDescription()); editLayout.addComponent(descriptionTextArea); // ok button Button okButton = new Button(i18nManager.getMessage(Messages.BUTTON_OK)); editLayout.addComponent(okButton); editLayout.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT); // replace replaceComponent(descriptionLabel, editLayout); // When OK is clicked -> update task data + ui okButton.addListener(new ClickListener() { public void buttonClick(ClickEvent event) { // Update data task.setDescription(descriptionTextArea.getValue().toString()); taskService.saveTask(task); // Update UI descriptionLabel.setValue(task.getDescription()); replaceComponent(editLayout, descriptionLabel); }//from w ww .j a v a 2 s . c o m }); } } }); }
From source file:org.activiti.explorer.ui.task.TaskDetailPanel.java
License:Apache License
protected void initDescription(HorizontalLayout layout) { final CssLayout descriptionLayout = new CssLayout(); descriptionLayout.setWidth(100, UNITS_PERCENTAGE); layout.addComponent(descriptionLayout); layout.setExpandRatio(descriptionLayout, 1.0f); layout.setComponentAlignment(descriptionLayout, Alignment.MIDDLE_LEFT); String descriptionText = null; if (task.getDescription() != null && !"".equals(task.getDescription())) { descriptionText = task.getDescription(); } else {//w w w.ja v a 2 s.c o m descriptionText = i18nManager.getMessage(Messages.TASK_NO_DESCRIPTION); } final Label descriptionLabel = new Label(descriptionText); descriptionLabel.addStyleName(ExplorerLayout.STYLE_CLICKABLE); descriptionLayout.addComponent(descriptionLabel); descriptionLayout.addListener(new LayoutClickListener() { public void layoutClick(LayoutClickEvent event) { if (event.getClickedComponent() != null && event.getClickedComponent().equals(descriptionLabel)) { // layout for textarea + ok button final VerticalLayout editLayout = new VerticalLayout(); editLayout.setSpacing(true); // textarea final TextArea descriptionTextArea = new TextArea(); descriptionTextArea.setNullRepresentation(""); descriptionTextArea.setWidth(100, UNITS_PERCENTAGE); descriptionTextArea.setValue(task.getDescription()); editLayout.addComponent(descriptionTextArea); // ok button Button okButton = new Button(i18nManager.getMessage(Messages.BUTTON_OK)); editLayout.addComponent(okButton); editLayout.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT); // replace descriptionLayout.replaceComponent(descriptionLabel, editLayout); // When OK is clicked -> update task data + ui okButton.addListener(new ClickListener() { public void buttonClick(ClickEvent event) { // Update data task.setDescription(descriptionTextArea.getValue().toString()); taskService.saveTask(task); // Update UI descriptionLabel.setValue(task.getDescription()); descriptionLayout.replaceComponent(editLayout, descriptionLabel); } }); } } }); }
From source file:org.bubblecloud.ilves.comment.CommentAddComponent.java
License:Open Source License
/** * The default constructor which instantiates Vaadin * component hierarchy.//from w ww . j a v a 2s. c o m */ public CommentAddComponent() { final User user = DefaultSiteUI.getSecurityProvider().getUserFromSession(); final String contextPath = VaadinService.getCurrentRequest().getContextPath(); final Site site = Site.getCurrent(); final Company company = site.getSiteContext().getObject(Company.class); final EntityManager entityManager = site.getSiteContext().getObject(EntityManager.class); final Panel panel = new Panel(site.localize("panel-add-comment")); setCompositionRoot(panel); final VerticalLayout mainLayout = new VerticalLayout(); panel.setContent(mainLayout); mainLayout.setMargin(true); mainLayout.setSpacing(true); final TextArea commentMessageField = new TextArea(site.localize("field-comment-message")); mainLayout.addComponent(commentMessageField); commentMessageField.setWidth(100, Unit.PERCENTAGE); commentMessageField.setRows(3); commentMessageField.setMaxLength(255); final Button addCommentButton = new Button(site.localize("button-add-comment")); mainLayout.addComponent(addCommentButton); if (user == null) { commentMessageField.setEnabled(false); commentMessageField.setInputPrompt(site.localize("message-please-login-to-comment")); addCommentButton.setEnabled(false); } addCommentButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { final String commentMessage = commentMessageField.getValue(); if (StringUtils.isEmpty(commentMessage)) { return; } final Comment comment = new Comment(company, user, contextPath, commentMessage); entityManager.getTransaction().begin(); try { entityManager.persist(comment); entityManager.getTransaction().commit(); commentMessageField.setValue(""); if (commentListComponent != null) { commentListComponent.refresh(); } } finally { if (entityManager.getTransaction().isActive()) { entityManager.getTransaction().rollback(); } } } }); }
From source file:org.diretto.web.richwebclient.view.windows.UploadSettingsWindow.java
/** * Constructs an {@link UploadSettingsWindow}. * //from www. ja v a 2 s. c o m * @param mainWindow The corresponding {@code MainWindow} * @param uploadSection The corresponding {@code UploadSection} * @param fileInfo The {@code FileInfo} object * @param mediaType The {@code MediaType} of the file * @param uploadSettings The corresponding {@code UploadSettings} * @param otherFiles The names of the other upload files */ public UploadSettingsWindow(final MainWindow mainWindow, final UploadSection uploadSection, FileInfo fileInfo, MediaType mediaType, UploadSettings uploadSettings, List<String> otherFiles) { super("Upload Settings"); this.mainWindow = mainWindow; setModal(true); setStyleName(Reindeer.WINDOW_BLACK); setWidth("940px"); setHeight((((int) mainWindow.getHeight()) - 160) + "px"); setResizable(false); setClosable(false); setDraggable(false); setPositionX((int) (mainWindow.getWidth() / 2.0f) - 470); setPositionY(126); wrapperLayout = new HorizontalLayout(); wrapperLayout.setSizeFull(); wrapperLayout.setMargin(true, true, true, true); addComponent(wrapperLayout); mainLayout = new VerticalLayout(); mainLayout.setSizeFull(); mainLayout.setSpacing(true); HorizontalLayout titleLayout = new HorizontalLayout(); titleLayout.setWidth("100%"); mainLayout.addComponent(titleLayout); HorizontalLayout leftTitleLayout = new HorizontalLayout(); titleLayout.addComponent(leftTitleLayout); titleLayout.setComponentAlignment(leftTitleLayout, Alignment.MIDDLE_LEFT); Label fileNameLabel = StyleUtils.getLabelH2(fileInfo.getName()); leftTitleLayout.addComponent(fileNameLabel); leftTitleLayout.setComponentAlignment(fileNameLabel, Alignment.MIDDLE_LEFT); Label bullLabel = StyleUtils.getLabelHTML( " • "); leftTitleLayout.addComponent(bullLabel); leftTitleLayout.setComponentAlignment(bullLabel, Alignment.MIDDLE_LEFT); Label titleLabel = StyleUtils.getLabelHTML("<b>Title</b> "); leftTitleLayout.addComponent(titleLabel); leftTitleLayout.setComponentAlignment(titleLabel, Alignment.MIDDLE_LEFT); final TextField titleField = new TextField(); titleField.setMaxLength(50); titleField.setWidth("100%"); titleField.setImmediate(true); if (uploadSettings != null && uploadSettings.getTitle() != null) { titleField.setValue(uploadSettings.getTitle()); } titleField.focus(); titleField.setCursorPosition(((String) titleField.getValue()).length()); titleLayout.addComponent(titleField); titleLayout.setComponentAlignment(titleField, Alignment.MIDDLE_RIGHT); titleLayout.setExpandRatio(leftTitleLayout, 0); titleLayout.setExpandRatio(titleField, 1); mainLayout.addComponent(StyleUtils.getHorizontalLine()); GridLayout topGridLayout = new GridLayout(2, 3); topGridLayout.setColumnExpandRatio(0, 1.0f); topGridLayout.setColumnExpandRatio(1, 0.0f); topGridLayout.setWidth("100%"); topGridLayout.setSpacing(true); mainLayout.addComponent(topGridLayout); Label descriptionLabel = StyleUtils.getLabelBold("Description"); topGridLayout.addComponent(descriptionLabel, 0, 0); final TextArea descriptionArea = new TextArea(); descriptionArea.setSizeFull(); descriptionArea.setImmediate(true); if (uploadSettings != null && uploadSettings.getDescription() != null) { descriptionArea.setValue(uploadSettings.getDescription()); } topGridLayout.addComponent(descriptionArea, 0, 1); VerticalLayout tagsWrapperLayout = new VerticalLayout(); tagsWrapperLayout.setHeight("30px"); tagsWrapperLayout.setSpacing(false); topGridLayout.addComponent(tagsWrapperLayout, 0, 2); HorizontalLayout tagsLayout = new HorizontalLayout(); tagsLayout.setWidth("100%"); tagsLayout.setSpacing(true); Label tagsLabel = StyleUtils.getLabelBoldHTML("Tags "); tagsLabel.setSizeUndefined(); tagsLayout.addComponent(tagsLabel); tagsLayout.setComponentAlignment(tagsLabel, Alignment.MIDDLE_LEFT); addTagField = new TextField(); addTagField.setImmediate(true); addTagField.setInputPrompt("Enter new Tag"); addTagField.addShortcutListener(new ShortcutListener(null, KeyCode.ENTER, new int[0]) { private static final long serialVersionUID = -4767515198819351723L; @Override public void handleAction(Object sender, Object target) { if (target == addTagField) { addTag(); } } }); tagsLayout.addComponent(addTagField); tagsLayout.setComponentAlignment(addTagField, Alignment.MIDDLE_LEFT); tabSheet = new TabSheet(); tabSheet.setStyleName(Reindeer.TABSHEET_SMALL); tabSheet.addStyleName("view"); tabSheet.addListener(new ComponentDetachListener() { private static final long serialVersionUID = -657657505471281795L; @Override public void componentDetachedFromContainer(ComponentDetachEvent event) { tags.remove(tabSheet.getTab(event.getDetachedComponent()).getCaption()); } }); Button addTagButton = new Button("Add", new Button.ClickListener() { private static final long serialVersionUID = 5914473126402594623L; @Override public void buttonClick(ClickEvent event) { addTag(); } }); addTagButton.setStyleName(Reindeer.BUTTON_DEFAULT); tagsLayout.addComponent(addTagButton); tagsLayout.setComponentAlignment(addTagButton, Alignment.MIDDLE_LEFT); Label spaceLabel = StyleUtils.getLabelHTML(""); spaceLabel.setSizeUndefined(); tagsLayout.addComponent(spaceLabel); tagsLayout.setComponentAlignment(spaceLabel, Alignment.MIDDLE_LEFT); tagsLayout.addComponent(tabSheet); tagsLayout.setComponentAlignment(tabSheet, Alignment.MIDDLE_LEFT); tagsLayout.setExpandRatio(tabSheet, 1.0f); tagsWrapperLayout.addComponent(tagsLayout); tagsWrapperLayout.setComponentAlignment(tagsLayout, Alignment.TOP_LEFT); if (uploadSettings != null && uploadSettings.getTags() != null && uploadSettings.getTags().size() > 0) { for (String tag : uploadSettings.getTags()) { addTagField.setValue(tag); addTag(); } } Label presettingLabel = StyleUtils.getLabelBold("Presetting"); topGridLayout.addComponent(presettingLabel, 1, 0); final TwinColSelect twinColSelect; if (otherFiles != null && otherFiles.size() > 0) { twinColSelect = new TwinColSelect(null, otherFiles); } else { twinColSelect = new TwinColSelect(); } twinColSelect.setWidth("400px"); twinColSelect.setRows(10); topGridLayout.addComponent(twinColSelect, 1, 1); topGridLayout.setComponentAlignment(twinColSelect, Alignment.TOP_RIGHT); Label otherFilesLabel = StyleUtils .getLabelSmallHTML("Select the files which should get the settings of this file as presetting."); otherFilesLabel.setSizeUndefined(); topGridLayout.addComponent(otherFilesLabel, 1, 2); topGridLayout.setComponentAlignment(otherFilesLabel, Alignment.MIDDLE_CENTER); mainLayout.addComponent(StyleUtils.getHorizontalLine()); final UploadGoogleMap googleMap; if (uploadSettings != null && uploadSettings.getTopographicPoint() != null) { googleMap = new UploadGoogleMap(mediaType, 12, uploadSettings.getTopographicPoint().getLatitude(), uploadSettings.getTopographicPoint().getLongitude(), MapType.HYBRID); } else { googleMap = new UploadGoogleMap(mediaType, 12, 48.42255269321401d, 9.956477880477905d, MapType.HYBRID); } googleMap.setWidth("100%"); googleMap.setHeight("300px"); mainLayout.addComponent(googleMap); mainLayout.addComponent(StyleUtils.getHorizontalLine()); GridLayout bottomGridLayout = new GridLayout(3, 3); bottomGridLayout.setSizeFull(); bottomGridLayout.setSpacing(true); mainLayout.addComponent(bottomGridLayout); Label licenseLabel = StyleUtils.getLabelBold("License"); bottomGridLayout.addComponent(licenseLabel, 0, 0); final TextArea licenseArea = new TextArea(); licenseArea.setWidth("320px"); licenseArea.setHeight("175px"); licenseArea.setImmediate(true); if (uploadSettings != null && uploadSettings.getLicense() != null) { licenseArea.setValue(uploadSettings.getLicense()); } bottomGridLayout.addComponent(licenseArea, 0, 1); final Label startTimeLabel = StyleUtils.getLabelBold("Earliest possible Start Date"); startTimeLabel.setSizeUndefined(); bottomGridLayout.setComponentAlignment(startTimeLabel, Alignment.TOP_CENTER); bottomGridLayout.addComponent(startTimeLabel, 1, 0); final InlineDateField startTimeField = new InlineDateField(); startTimeField.setImmediate(true); startTimeField.setResolution(InlineDateField.RESOLUTION_SEC); boolean currentTimeAdjusted = false; if (uploadSettings != null && uploadSettings.getTimeRange() != null && uploadSettings.getTimeRange().getStartDateTime() != null) { startTimeField.setValue(uploadSettings.getTimeRange().getStartDateTime().toDate()); } else { currentTimeAdjusted = true; startTimeField.setValue(new Date()); } bottomGridLayout.setComponentAlignment(startTimeField, Alignment.TOP_CENTER); bottomGridLayout.addComponent(startTimeField, 1, 1); final CheckBox exactTimeCheckBox = new CheckBox("This is the exact point in time."); exactTimeCheckBox.setImmediate(true); bottomGridLayout.setComponentAlignment(exactTimeCheckBox, Alignment.TOP_CENTER); bottomGridLayout.addComponent(exactTimeCheckBox, 1, 2); final Label endTimeLabel = StyleUtils.getLabelBold("Latest possible Start Date"); endTimeLabel.setSizeUndefined(); bottomGridLayout.setComponentAlignment(endTimeLabel, Alignment.TOP_CENTER); bottomGridLayout.addComponent(endTimeLabel, 2, 0); final InlineDateField endTimeField = new InlineDateField(); endTimeField.setImmediate(true); endTimeField.setResolution(InlineDateField.RESOLUTION_SEC); if (uploadSettings != null && uploadSettings.getTimeRange() != null && uploadSettings.getTimeRange().getEndDateTime() != null) { endTimeField.setValue(uploadSettings.getTimeRange().getEndDateTime().toDate()); } else { endTimeField.setValue(startTimeField.getValue()); } bottomGridLayout.setComponentAlignment(endTimeField, Alignment.TOP_CENTER); bottomGridLayout.addComponent(endTimeField, 2, 1); if (!currentTimeAdjusted && ((Date) startTimeField.getValue()).equals((Date) endTimeField.getValue())) { exactTimeCheckBox.setValue(true); endTimeLabel.setEnabled(false); endTimeField.setEnabled(false); } exactTimeCheckBox.addListener(new ValueChangeListener() { private static final long serialVersionUID = 7193545421803538364L; @Override public void valueChange(ValueChangeEvent event) { if ((Boolean) event.getProperty().getValue()) { endTimeLabel.setEnabled(false); endTimeField.setEnabled(false); } else { endTimeLabel.setEnabled(true); endTimeField.setEnabled(true); } } }); mainLayout.addComponent(StyleUtils.getHorizontalLine()); HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true, false, false, false); buttonLayout.setSpacing(false); HorizontalLayout uploadButtonLayout = new HorizontalLayout(); uploadButtonLayout.setMargin(false, true, false, false); uploadButton = new Button("Upload File", new Button.ClickListener() { private static final long serialVersionUID = 8013811216568950479L; @Override @SuppressWarnings("unchecked") public void buttonClick(ClickEvent event) { String titleValue = titleField.getValue().toString().trim(); Date startTimeValue = (Date) startTimeField.getValue(); Date endTimeValue = (Date) endTimeField.getValue(); boolean exactTimeValue = (Boolean) exactTimeCheckBox.getValue(); if (titleValue.equals("")) { ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Title Field", StyleUtils.getLabelHTML("A title entry is required.")); mainWindow.addWindow(confirmWindow); } else if (titleValue.length() < 5 || titleValue.length() > 50) { ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Title Field", StyleUtils .getLabelHTML("The number of characters of the title has to be between 5 and 50.")); mainWindow.addWindow(confirmWindow); } else if (!exactTimeValue && startTimeValue.after(endTimeValue)) { ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Date Entries", StyleUtils.getLabelHTML("The second date has to be after the first date.")); mainWindow.addWindow(confirmWindow); } else if (startTimeValue.after(new Date()) || (!exactTimeValue && endTimeValue.after(new Date()))) { ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Date Entries", StyleUtils.getLabelHTML("The dates are not allowed to be in the future.")); mainWindow.addWindow(confirmWindow); } else { disableButtons(); String descriptionValue = descriptionArea.getValue().toString().trim(); String licenseValue = licenseArea.getValue().toString().trim(); TopographicPoint topographicPointValue = googleMap.getMarkerPosition(); Collection<String> presettingValues = (Collection<String>) twinColSelect.getValue(); if (exactTimeValue) { endTimeValue = startTimeValue; } TimeRange timeRange = new TimeRange(new DateTime(startTimeValue), new DateTime(endTimeValue)); UploadSettings uploadSettings = new UploadSettings(titleValue, descriptionValue, licenseValue, new Vector<String>(tags), topographicPointValue, timeRange); mainWindow.removeWindow(event.getButton().getWindow()); requestRepaint(); uploadSection.upload(uploadSettings, new Vector<String>(presettingValues)); } } }); uploadButton.setStyleName(Reindeer.BUTTON_DEFAULT); uploadButtonLayout.addComponent(uploadButton); buttonLayout.addComponent(uploadButtonLayout); HorizontalLayout cancelButtonLayout = new HorizontalLayout(); cancelButtonLayout.setMargin(false, true, false, false); cancelButton = new Button("Cancel", new Button.ClickListener() { private static final long serialVersionUID = -2565870159504952913L; @Override public void buttonClick(ClickEvent event) { disableButtons(); mainWindow.removeWindow(event.getButton().getWindow()); requestRepaint(); uploadSection.cancelUpload(); } }); cancelButton.setStyleName(Reindeer.BUTTON_DEFAULT); cancelButtonLayout.addComponent(cancelButton); buttonLayout.addComponent(cancelButtonLayout); cancelAllButton = new Button("Cancel All", new Button.ClickListener() { private static final long serialVersionUID = -8578124709201789182L; @Override public void buttonClick(ClickEvent event) { disableButtons(); mainWindow.removeWindow(event.getButton().getWindow()); requestRepaint(); uploadSection.cancelAllUploads(); } }); cancelAllButton.setStyleName(Reindeer.BUTTON_DEFAULT); buttonLayout.addComponent(cancelAllButton); mainLayout.addComponent(buttonLayout); mainLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_CENTER); wrapperLayout.addComponent(mainLayout); }
From source file:org.escidoc.browser.ui.listeners.OnContextAdminDescriptor.java
License:Open Source License
@SuppressWarnings("serial") public void adminDescriptorForm() { final Window subwindow = new Window("A modal subwindow"); subwindow.setModal(true);//from ww w . j av a2s . co m subwindow.setWidth("650px"); VerticalLayout layout = (VerticalLayout) subwindow.getContent(); layout.setMargin(true); layout.setSpacing(true); final TextField txtName = new TextField("Name"); txtName.setImmediate(true); txtName.setValidationVisible(true); final TextArea txtContent = new TextArea("Content"); txtContent.setColumns(30); txtContent.setRows(40); Button addAdmDescButton = new Button("Add Description"); addAdmDescButton.addListener(new ClickListener() { @Override public void buttonClick(@SuppressWarnings("unused") ClickEvent event) { if (txtName.getValue().toString() == null) { router.getMainWindow().showNotification(ViewConstants.PLEASE_ENTER_A_NAME, Notification.TYPE_ERROR_MESSAGE); } else if (!XmlUtil.isWellFormed(txtContent.getValue().toString())) { router.getMainWindow().showNotification(ViewConstants.XML_IS_NOT_WELL_FORMED, Notification.TYPE_ERROR_MESSAGE); } else { AdminDescriptor newAdmDesc = controller.addAdminDescriptor(txtName.getValue().toString(), txtContent.getValue().toString()); (subwindow.getParent()).removeWindow(subwindow); router.getMainWindow().showNotification("Addedd Successfully", Notification.TYPE_HUMANIZED_MESSAGE); } } }); subwindow.addComponent(txtName); subwindow.addComponent(txtContent); subwindow.addComponent(addAdmDescButton); Button close = new Button(ViewConstants.CLOSE, new Button.ClickListener() { @Override public void buttonClick(@SuppressWarnings("unused") ClickEvent event) { (subwindow.getParent()).removeWindow(subwindow); } }); layout.addComponent(close); layout.setComponentAlignment(close, Alignment.TOP_RIGHT); router.getMainWindow().addWindow(subwindow); }