protected void createControl(Composite parent, int treeStyle) { super.createControl(parent, treeStyle); // add 2px margin around filter text FormLayout layout = new FormLayout(); layout.marginHeight = 0; layout.marginWidth = 0; setLayout(layout); FormData data = new FormData(); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); data.bottom = new FormAttachment(100, 0); if (showFilterControls) { FormData filterData = new FormData(); filterData.top = new FormAttachment(0, 2); filterData.left = new FormAttachment(0, 2); filterData.right = new FormAttachment(100, -2); filterComposite.setLayoutData(filterData); data.top = new FormAttachment(filterComposite, 2); } else { data.top = new FormAttachment(0, 0); } treeComposite.setLayoutData(data); }
/** * Returns a short string representation of this constraints object. This method can use the given * <code>FormLayout</code> to display extra information how default alignments are mapped to * concrete alignments. Therefore it asks the related column and row as specified by this * constraints object. * * @param layout the layout to be presented as a string * @return a short string representation of this constraints object */ public String toShortString(FormLayout layout) { StringBuffer buffer = new StringBuffer("("); buffer.append(formatInt(gridX)); buffer.append(", "); buffer.append(formatInt(gridY)); buffer.append(", "); buffer.append(formatInt(gridWidth)); buffer.append(", "); buffer.append(formatInt(gridHeight)); buffer.append(", \""); buffer.append(hAlign.abbreviation()); if (hAlign == DEFAULT && layout != null) { buffer.append('='); ColumnSpec colSpec = gridWidth == 1 ? layout.getColumnSpec(gridX) : null; buffer.append(concreteAlignment(hAlign, colSpec).abbreviation()); } buffer.append(", "); buffer.append(vAlign.abbreviation()); if (vAlign == DEFAULT && layout != null) { buffer.append('='); RowSpec rowSpec = gridHeight == 1 ? layout.getRowSpec(gridY) : null; buffer.append(concreteAlignment(vAlign, rowSpec).abbreviation()); } buffer.append("\""); if (!(EMPTY_INSETS.equals(insets))) { buffer.append(", "); buffer.append(insets); } buffer.append(')'); return buffer.toString(); }
private void initLayout() { FormLayout loginForm = new FormLayout(); loginForm.setSizeUndefined(); loginForm.addComponent(userName = new TextField("Username")); loginForm.addComponent(passwordField = new PasswordField("Password")); loginForm.addComponent(login = new Button("Login")); login.addStyleName(ValoTheme.BUTTON_PRIMARY); login.setDisableOnClick(true); login.setClickShortcut(ShortcutAction.KeyCode.ENTER); login.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { login(); } }); VerticalLayout loginLayout = new VerticalLayout(); loginLayout.setSizeUndefined(); loginLayout.addComponent(loginFailedLabel = new Label()); loginLayout.setComponentAlignment(loginFailedLabel, Alignment.BOTTOM_CENTER); loginFailedLabel.setSizeUndefined(); loginFailedLabel.addStyleName(ValoTheme.LABEL_FAILURE); loginFailedLabel.setVisible(false); loginLayout.addComponent(loginForm); loginLayout.setComponentAlignment(loginForm, Alignment.TOP_CENTER); VerticalLayout rootLayout = new VerticalLayout(loginLayout); rootLayout.setSizeFull(); rootLayout.setComponentAlignment(loginLayout, Alignment.MIDDLE_CENTER); setCompositionRoot(rootLayout); setSizeFull(); }
/** * Tests the combination of a default size spec with an upper bound that shall ensure a maximum * size. */ public void testDefaultWithUpperBound() { TestComponent c1 = new TestComponent(10, 10, 50, 50); FormLayout layout = new FormLayout("[default,20px]", "[default,20px]"); JPanel panel = new JPanel(layout); panel.add(c1, cc.xy(1, 1)); Dimension minimumLayoutSize = layout.minimumLayoutSize(panel); Dimension preferredLayoutSize = layout.preferredLayoutSize(panel); assertEquals("Minimum layout width", 10, minimumLayoutSize.width); assertEquals("Minimum layout height", 10, minimumLayoutSize.height); assertEquals("Preferred layout width", 20, preferredLayoutSize.width); assertEquals("Preferred layout height", 20, preferredLayoutSize.height); panel.setSize(minimumLayoutSize); panel.doLayout(); int columnWidth = c1.getWidth(); int rowHeight = c1.getHeight(); assertEquals("Column width (container min)", 10, columnWidth); assertEquals("Row height (container min)", 10, rowHeight); panel.setSize(preferredLayoutSize); panel.doLayout(); columnWidth = c1.getWidth(); rowHeight = c1.getHeight(); assertEquals("Column width (container pref)", 20, columnWidth); assertEquals("Row height (container pref)", 20, rowHeight); }
/** * Sets the component's bounds using the given component and cell bounds. * * @param c the component to set bounds * @param layout the FormLayout instance that computes the bounds * @param cellBounds the cell's bounds * @param minWidthMeasure measures the minimum width * @param minHeightMeasure measures the minimum height * @param prefWidthMeasure measures the preferred width * @param prefHeightMeasure measures the preferred height */ void setBounds( Control c, FormLayout layout, Rectangle cellBounds, FormLayout.Measure minWidthMeasure, FormLayout.Measure minHeightMeasure, FormLayout.Measure prefWidthMeasure, FormLayout.Measure prefHeightMeasure) { ColumnSpec colSpec = gridWidth == 1 ? layout.getColumnSpec(gridX) : null; RowSpec rowSpec = gridHeight == 1 ? layout.getRowSpec(gridY) : null; Alignment concreteHAlign = concreteAlignment(this.hAlign, colSpec); Alignment concreteVAlign = concreteAlignment(this.vAlign, rowSpec); Insets concreteInsets = this.insets != null ? this.insets : EMPTY_INSETS; int cellX = cellBounds.x + concreteInsets.getLeft(); int cellY = cellBounds.y + concreteInsets.getTop(); int cellW = cellBounds.width - concreteInsets.getLeft() - concreteInsets.getRight(); int cellH = cellBounds.height - concreteInsets.getTop() - concreteInsets.getBottom(); int compW = componentSize(c, colSpec, cellW, minWidthMeasure, prefWidthMeasure); int compH = componentSize(c, rowSpec, cellH, minHeightMeasure, prefHeightMeasure); int x = origin(concreteHAlign, cellX, cellW, compW); int y = origin(concreteVAlign, cellY, cellH, compH); int w = extent(concreteHAlign, cellW, compW); int h = extent(concreteVAlign, cellH, compH); c.setBounds(x, y, w, h); }
/** Checks basic layout functions. */ public void testBasic() { FormLayout layout = new FormLayout("1px, 2px, 3px, 5px, 7px", "1px, 2px, 3px"); JPanel panel = new JPanel(layout); panel.doLayout(); FormLayout.LayoutInfo info = layout.getLayoutInfo(panel); assertEquals("Columns", 6, info.columnOrigins.length); assertEquals("Rows", 4, info.rowOrigins.length); assertEquals("Column 0", 0, info.columnOrigins[0]); assertEquals("Column 1", 1, info.columnOrigins[1]); assertEquals("Column 2", 3, info.columnOrigins[2]); assertEquals("Column 3", 6, info.columnOrigins[3]); assertEquals("Column 4", 11, info.columnOrigins[4]); assertEquals("Column 5", 18, info.columnOrigins[5]); }
/** * Checks and verifies that components that span multiple columns and that expand the container * are measured using the correct measure. */ public void testExtraExpansionHonorsCurrentMeasure() { TestComponent c1 = new TestComponent(10, 1, 50, 1); TestComponent c2 = new TestComponent(10, 1, 50, 1); TestComponent c3 = new TestComponent(10, 1, 50, 1); TestComponent c4 = new TestComponent(10, 1, 50, 1); FormLayout layout = new FormLayout("10px, 15px:grow, 20px", "pref, pref"); JPanel panel = new JPanel(layout); panel.add(c1, cc.xy(1, 1)); panel.add(c2, cc.xy(2, 1)); panel.add(c3, cc.xy(3, 1)); panel.add(c4, cc.xyw(1, 2, 2)); int minimumLayoutWidth = layout.minimumLayoutSize(panel).width; int preferredLayoutWidth = layout.preferredLayoutSize(panel).width; assertEquals("Minimum layout width", 45, minimumLayoutWidth); assertEquals("Preferred layout width", 70, preferredLayoutWidth); }
public void testVisibility(boolean containerHonorsVisibility) { TestComponent visible = new TestComponent(10, 10, 10, 10); TestComponent invisible = new TestComponent(10, 10, 10, 10); invisible.setVisible(false); TestComponent invisibleHonorsVisibility = new TestComponent(10, 10, 10, 10); invisibleHonorsVisibility.setVisible(false); TestComponent invisibleIgnoresVisibility = new TestComponent(10, 10, 10, 10); invisibleIgnoresVisibility.setVisible(false); FormLayout layout = new FormLayout("pref, pref, pref, pref", "pref, pref, pref, pref"); layout.setHonorsVisibility(containerHonorsVisibility); JPanel panel = new JPanel(layout); panel.add(visible, cc.xy(1, 1)); panel.add(invisible, cc.xy(2, 2)); panel.add(invisibleHonorsVisibility, cc.xy(3, 3)); panel.add(invisibleIgnoresVisibility, cc.xy(4, 4)); layout.setHonorsVisibility(invisibleHonorsVisibility, Boolean.TRUE); layout.setHonorsVisibility(invisibleIgnoresVisibility, Boolean.FALSE); panel.doLayout(); FormLayout.LayoutInfo info = layout.getLayoutInfo(panel); int size1 = 10; int size2 = containerHonorsVisibility ? 0 : 10; int size3 = 0; int size4 = 10; int origin1 = size1; int origin2 = origin1 + size2; int origin3 = origin2 + size3; int origin4 = origin3 + size4; assertEquals("Column 0", 0, info.columnOrigins[0]); assertEquals("Column 1", origin1, info.columnOrigins[1]); assertEquals("Column 2", origin2, info.columnOrigins[2]); assertEquals("Column 3", origin3, info.columnOrigins[3]); assertEquals("Column 4", origin4, info.columnOrigins[4]); assertEquals("Row 0", 0, info.rowOrigins[0]); assertEquals("Row 1", origin1, info.rowOrigins[1]); assertEquals("Row 2", origin2, info.rowOrigins[2]); assertEquals("Row 3", origin3, info.rowOrigins[3]); assertEquals("Row 4", origin4, info.rowOrigins[4]); }
/** Creates content Composite. */ Composite eswtConstructContent(int style) { Composite comp = super.eswtConstructContent(SWT.VERTICAL); FormLayout layout = new FormLayout(); layout.marginBottom = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTBOTTOMMARGIN); layout.marginTop = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTTOPMARGIN); layout.marginLeft = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTLEFTMARGIN); layout.marginRight = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTRIGHTMARGIN); layout.spacing = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTVERTICALSPACING); comp.setLayout(layout); eswtScrolledText = new ScrolledTextComposite(comp, comp.getVerticalBar()); eswtImgLabel = new LabelExtension(comp, SWT.NONE); FormData imageLD = new FormData(); imageLD.right = new FormAttachment(100); imageLD.top = new FormAttachment(0); eswtImgLabel.setLayoutData(imageLD); FormData scrolledTextLD = new FormData(); scrolledTextLD.left = new FormAttachment(0); scrolledTextLD.top = new FormAttachment(0); scrolledTextLD.right = new FormAttachment(eswtImgLabel); eswtScrolledText.setLayoutData(scrolledTextLD); eswtProgbarLD = new FormData(); eswtProgbarLD.left = new FormAttachment(0); eswtProgbarLD.right = new FormAttachment(100); eswtProgbarLD.bottom = new FormAttachment(100); eswtUpdateProgressbar(comp, false, false); return comp; }
/** * Checks and verifies that components that span multiple columns do not expand the container of * no column grows. */ public void testExtraExpansionIfSpannedColumnsGrow() { TestComponent c1 = new TestComponent(10, 1, 50, 1); TestComponent c2 = new TestComponent(10, 1, 50, 1); TestComponent c3 = new TestComponent(10, 1, 50, 1); TestComponent c4 = new TestComponent(10, 1, 50, 1); FormLayout layout = new FormLayout("10px, 15px:grow, 20px", "pref, pref"); JPanel panel = new JPanel(layout); panel.add(c1, cc.xy(1, 1)); panel.add(c2, cc.xy(2, 1)); panel.add(c3, cc.xy(3, 1)); panel.add(c4, cc.xyw(1, 2, 2)); Dimension preferredLayoutSize = layout.preferredLayoutSize(panel); panel.setSize(preferredLayoutSize); panel.doLayout(); int col1And2Width = c2.getX() + c2.getWidth(); int gridWidth = c3.getX() + c3.getWidth(); int totalWidth = preferredLayoutSize.width; assertEquals("Col1+2 width", 50, col1And2Width); assertEquals("Grid width", 70, gridWidth); assertEquals("Total width", 70, totalWidth); }
/** * Fills the form with current field component. Adds additional widgets if needed (i.e. "select * all" box) * * @param form The form to place the field in * @param layout The layout that displays the field */ public void placeYourselfInForm(Form form, FormLayout layout) { if (fieldComponent == null) { return; } if (fieldComponent instanceof Field) { form.addField(name, (Field) fieldComponent); } else if (fieldComponent instanceof FilterContainer) { for (Select select : ((FilterContainer) fieldComponent).getLevels()) { form.addField(select.getCaption(), select); } } else { layout.addComponent(fieldComponent); } if (selectAll) { final CheckBox saCheckbox = UiFactory.createCheckBox(UiIds.AR_MSG_SELECT_ALL, null); saCheckbox.addListener( new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { boolean selected = (Boolean) saCheckbox.getValue(); if (fieldComponent instanceof Select) { for (Object itemId : ((Select) fieldComponent).getItemIds()) { if (selected) { ((Select) fieldComponent).select(itemId); } else { ((Select) fieldComponent).unselect(itemId); } } } if (fieldComponent instanceof FilterContainer) { List<Select> selectList = ((FilterContainer) fieldComponent).getLevels(); Select select = selectList.get(selectList.size() - 1); for (Object itemId : select.getItemIds()) { if (selected) { select.select(itemId); } else { select.unselect(itemId); } } } } }); form.addField(name + "_all", saCheckbox); } }
private void initLayout() { layout.setMargin(true); setContent(layout); form.setCaption("Employee Details "); PropertysetItem item = new PropertysetItem(); item.addItemProperty("Name", new ObjectProperty<String>("")); item.addItemProperty("Address", new ObjectProperty<String>("")); ComboBox combobox = new ComboBox("Sex"); combobox.setInvalidAllowed(true); combobox.setNullSelectionAllowed(false); combobox.addItem("Male"); combobox.addItem("Female"); item.addItemProperty("Age", new ObjectProperty<String>("")); item.addItemProperty("Email", new ObjectProperty<String>("")); item.addItemProperty("Mobile No", new ObjectProperty<String>("")); Form form = new Form(); final Form reader = new Form(); form.setCaption("Fill Your Details"); form.setItemDataSource(item); reader.setItemDataSource(item); reader.setCaption("Your registation details"); reader.setReadOnly(true); button.addClickListener( new Button.ClickListener() { public void buttonClick(ClickEvent event) { Label message = new Label("You are Registered"); layout.addComponent(message); layout.addComponent(reader); } }); layout.addComponent(form); final RichTextArea area = new RichTextArea(); area.setValue("Add more details here"); layout.addComponent(area); layout.addComponent(button); }
private FormLayout getShellLayout() { FormLayout layout = new FormLayout(); layout.marginWidth = MARGIN_WIDTH; layout.marginHeight = MARGIN_WIDTH; return layout; }
public Composite createSashForm(final Composite composite) { if (!tv.isTabViewsEnabled()) { tableComposite = tv.createMainPanel(composite); return tableComposite; } ConfigurationManager configMan = ConfigurationManager.getInstance(); int iNumViews = 0; UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT(); UISWTViewEventListenerWrapper[] pluginViews = null; if (uiFunctions != null) { UISWTInstance pluginUI = uiFunctions.getUISWTInstance(); if (pluginUI != null) { pluginViews = pluginUI.getViewListeners(tv.getTableID()); iNumViews += pluginViews.length; } } if (iNumViews == 0) { tableComposite = tv.createMainPanel(composite); return tableComposite; } FormData formData; final Composite form = new Composite(composite, SWT.NONE); FormLayout flayout = new FormLayout(); flayout.marginHeight = 0; flayout.marginWidth = 0; form.setLayout(flayout); GridData gridData; gridData = new GridData(GridData.FILL_BOTH); form.setLayoutData(gridData); // Create them in reverse order, so we can have the table auto-grow, and // set the tabFolder's height manually final int TABHEIGHT = 20; tabFolder = new CTabFolder(form, SWT.TOP | SWT.BORDER); tabFolder.setMinimizeVisible(true); tabFolder.setTabHeight(TABHEIGHT); final int iFolderHeightAdj = tabFolder.computeSize(SWT.DEFAULT, 0).y; final Sash sash = new Sash(form, SWT.HORIZONTAL); tableComposite = tv.createMainPanel(form); Composite cFixLayout = tableComposite; while (cFixLayout != null && cFixLayout.getParent() != form) { cFixLayout = cFixLayout.getParent(); } if (cFixLayout == null) { cFixLayout = tableComposite; } GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginHeight = 0; layout.marginWidth = 0; cFixLayout.setLayout(layout); // FormData for Folder formData = new FormData(); formData.left = new FormAttachment(0, 0); formData.right = new FormAttachment(100, 0); formData.bottom = new FormAttachment(100, 0); int iSplitAt = configMan.getIntParameter(tv.getPropertiesPrefix() + ".SplitAt", 3000); // Was stored at whole if (iSplitAt < 100) { iSplitAt *= 100; } double pct = iSplitAt / 10000.0; if (pct < 0.03) { pct = 0.03; } else if (pct > 0.97) { pct = 0.97; } // height will be set on first resize call sash.setData("PCT", new Double(pct)); tabFolder.setLayoutData(formData); final FormData tabFolderData = formData; // FormData for Sash formData = new FormData(); formData.left = new FormAttachment(0, 0); formData.right = new FormAttachment(100, 0); formData.bottom = new FormAttachment(tabFolder); formData.height = 5; sash.setLayoutData(formData); // FormData for table Composite formData = new FormData(); formData.left = new FormAttachment(0, 0); formData.right = new FormAttachment(100, 0); formData.top = new FormAttachment(0, 0); formData.bottom = new FormAttachment(sash); cFixLayout.setLayoutData(formData); // Listeners to size the folder sash.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { final boolean FASTDRAG = true; if (FASTDRAG && e.detail == SWT.DRAG) { return; } if (tabFolder.getMinimized()) { tabFolder.setMinimized(false); refreshSelectedSubView(); ConfigurationManager configMan = ConfigurationManager.getInstance(); configMan.setParameter(tv.getPropertiesPrefix() + ".subViews.minimized", false); } Rectangle area = form.getClientArea(); tabFolderData.height = area.height - e.y - e.height - iFolderHeightAdj; form.layout(); Double l = new Double((double) tabFolder.getBounds().height / form.getBounds().height); sash.setData("PCT", l); if (e.detail != SWT.DRAG) { ConfigurationManager configMan = ConfigurationManager.getInstance(); configMan.setParameter( tv.getPropertiesPrefix() + ".SplitAt", (int) (l.doubleValue() * 10000)); } } }); final CTabFolder2Adapter folderListener = new CTabFolder2Adapter() { public void minimize(CTabFolderEvent event) { tabFolder.setMinimized(true); tabFolderData.height = iFolderHeightAdj; CTabItem[] items = tabFolder.getItems(); for (int i = 0; i < items.length; i++) { CTabItem tabItem = items[i]; tabItem.getControl().setVisible(false); } form.layout(); UISWTViewCore view = getActiveSubView(); if (view != null) { view.triggerEvent(UISWTViewEvent.TYPE_FOCUSLOST, null); } ConfigurationManager configMan = ConfigurationManager.getInstance(); configMan.setParameter(tv.getPropertiesPrefix() + ".subViews.minimized", true); } public void restore(CTabFolderEvent event) { tabFolder.setMinimized(false); CTabItem selection = tabFolder.getSelection(); if (selection != null) { selection.getControl().setVisible(true); } form.notifyListeners(SWT.Resize, null); UISWTViewCore view = getActiveSubView(); if (view != null) { view.triggerEvent(UISWTViewEvent.TYPE_FOCUSGAINED, null); } refreshSelectedSubView(); ConfigurationManager configMan = ConfigurationManager.getInstance(); configMan.setParameter(tv.getPropertiesPrefix() + ".subViews.minimized", false); } }; tabFolder.addCTabFolder2Listener(folderListener); tabFolder.addSelectionListener( new SelectionListener() { public void widgetSelected(SelectionEvent e) { // make sure its above try { ((CTabItem) e.item).getControl().setVisible(true); ((CTabItem) e.item).getControl().moveAbove(null); // TODO: Need to viewDeactivated old one UISWTViewCore view = getActiveSubView(); if (view != null) { view.triggerEvent(UISWTViewEvent.TYPE_FOCUSGAINED, null); } } catch (Exception t) { } } public void widgetDefaultSelected(SelectionEvent e) {} }); tabFolder.addMouseListener( new MouseAdapter() { public void mouseDown(MouseEvent e) { if (tabFolder.getMinimized()) { folderListener.restore(null); // If the user clicked down on the restore button, and we restore // before the CTabFolder does, CTabFolder will minimize us again // There's no way that I know of to determine if the mouse is // on that button! // one of these will tell tabFolder to cancel e.button = 0; tabFolder.notifyListeners(SWT.MouseExit, null); } } }); form.addListener( SWT.Resize, new Listener() { public void handleEvent(Event e) { if (tabFolder.getMinimized()) { return; } Double l = (Double) sash.getData("PCT"); if (l != null) { tabFolderData.height = (int) (form.getBounds().height * l.doubleValue()) - iFolderHeightAdj; form.layout(); } } }); // Call plugin listeners if (pluginViews != null) { for (UISWTViewEventListenerWrapper l : pluginViews) { if (l != null) { try { UISWTViewImpl view = new UISWTViewImpl(tv.getTableID(), l.getViewID(), l, null); addTabView(view); } catch (Exception e) { // skip, plugin probably specifically asked to not be added } } } } if (configMan.getBooleanParameter(tv.getPropertiesPrefix() + ".subViews.minimized", false)) { tabFolder.setMinimized(true); tabFolderData.height = iFolderHeightAdj; } else { tabFolder.setMinimized(false); } tabFolder.setSelection(0); return form; }
private Component buildProfileTab() { HorizontalLayout root = new HorizontalLayout(); root.setCaption("Profile"); root.setIcon(FontAwesome.USER); root.setWidth(100.0f, Unit.PERCENTAGE); root.setSpacing(true); root.setMargin(true); root.addStyleName("profile-form"); VerticalLayout pic = new VerticalLayout(); pic.setSizeUndefined(); pic.setSpacing(true); Image profilePic = new Image(null, new ThemeResource("img/profile-pic-300px.jpg")); profilePic.setWidth(100.0f, Unit.PIXELS); pic.addComponent(profilePic); Button upload = new Button( "Change…", event -> { Notification.show("Not implemented in this demo"); }); upload.addStyleName(ValoTheme.BUTTON_TINY); pic.addComponent(upload); root.addComponent(pic); FormLayout details = new FormLayout(); details.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); root.addComponent(details); root.setExpandRatio(details, 1); firstNameField = new TextField("First Name"); details.addComponent(firstNameField); lastNameField = new TextField("Last Name"); details.addComponent(lastNameField); titleField = new ComboBox("Title"); titleField.setInputPrompt("Please specify"); titleField.addItem("Mr."); titleField.addItem("Mrs."); titleField.addItem("Ms."); titleField.setNewItemsAllowed(true); details.addComponent(titleField); sexField = new OptionGroup("Sex"); sexField.addItem(Boolean.FALSE); sexField.setItemCaption(Boolean.FALSE, "Female"); sexField.addItem(Boolean.TRUE); sexField.setItemCaption(Boolean.TRUE, "Male"); sexField.addStyleName("horizontal"); details.addComponent(sexField); Label section = new Label("Contact Info"); section.addStyleName(ValoTheme.LABEL_H4); section.addStyleName(ValoTheme.LABEL_COLORED); details.addComponent(section); emailField = new TextField("Email"); emailField.setWidth("100%"); emailField.setRequired(true); emailField.setNullRepresentation(""); details.addComponent(emailField); locationField = new TextField("Location"); locationField.setWidth("100%"); locationField.setNullRepresentation(""); locationField.setComponentError(new UserError("This address doesn't exist")); details.addComponent(locationField); phoneField = new TextField("Phone"); phoneField.setWidth("100%"); phoneField.setNullRepresentation(""); details.addComponent(phoneField); newsletterField = new OptionalSelect<>(); newsletterField.addOption(0, "Daily"); newsletterField.addOption(1, "Weekly"); newsletterField.addOption(2, "Monthly"); details.addComponent(newsletterField); section = new Label("Additional Info"); section.addStyleName(ValoTheme.LABEL_H4); section.addStyleName(ValoTheme.LABEL_COLORED); details.addComponent(section); websiteField = new TextField("Website"); websiteField.setInputPrompt("http://"); websiteField.setWidth("100%"); websiteField.setNullRepresentation(""); details.addComponent(websiteField); bioField = new TextArea("Bio"); bioField.setWidth("100%"); bioField.setRows(4); bioField.setNullRepresentation(""); details.addComponent(bioField); return root; }
public EditVehicleWindow(final VehicleView parent, final long vehID) { super("Edycja pojazdu"); FormLayout newVehicleLayout = new FormLayout(); final FieldGroup fields = new FieldGroup(); Table vehiclesList = parent.getVehiclesList(); fields.setBuffered(true); String fieldName = ""; fieldName = VehicleView.BRAND; TextField fieldBRAND = new TextField(fieldName); fieldBRAND.setValue( (String) vehiclesList .getContainerProperty(vehiclesList.getValue(), VehicleView.BRAND) .getValue()); fieldBRAND.addValidator( new StringLengthValidator("Niepoprawna długość pola marka", 3, 64, false)); fieldBRAND.addValidator( new RegexpValidator("^[\\p{L}0-9- ]*$", "Model zawiera nie właściwe znaki")); fieldBRAND.setWidth("20em"); fieldBRAND.setRequired(true); fieldBRAND.setRequiredError("Pole Model jest wymagane"); fieldBRAND.setImmediate(true); newVehicleLayout.addComponent(fieldBRAND); fields.bind(fieldBRAND, fieldName); fieldName = VehicleView.COLOUR; TextField fieldCOLOUR = new TextField(fieldName); fieldCOLOUR.setValue( (String) vehiclesList .getContainerProperty(vehiclesList.getValue(), VehicleView.COLOUR) .getValue()); fieldCOLOUR.addValidator( new StringLengthValidator("Niepoprawna długość pola Kolor nadwozia", 3, 64, false)); fieldCOLOUR.addValidator( new RegexpValidator("^[\\p{L}]*$", "pole Kolor nadwozia zawiera niewłaściwe znaki")); fieldCOLOUR.setWidth("20em"); fieldCOLOUR.setRequired(true); fieldCOLOUR.setRequiredError("Pole Kolor nadwozia jest wymagane"); fieldCOLOUR.setImmediate(true); newVehicleLayout.addComponent(fieldCOLOUR); fields.bind(fieldCOLOUR, fieldName); fieldName = VehicleView.MAX_LOAD; TextField fieldMAX_LOAD = new TextField(fieldName); fieldMAX_LOAD.setValue( vehiclesList .getContainerProperty(vehiclesList.getValue(), VehicleView.MAX_LOAD) .getValue() .toString()); fieldMAX_LOAD.setConverter(Integer.class); fieldMAX_LOAD.setConversionError("Wprowadzona wartość nie jest liczbą"); fieldMAX_LOAD.addValidator( new IntegerRangeValidator("Niewłaściwa wartość ładowności", 0, Integer.MAX_VALUE)); fieldMAX_LOAD.setWidth("20em"); fieldMAX_LOAD.setRequired(true); fieldMAX_LOAD.setRequiredError("Pole Ładowność jest wymagane"); fieldMAX_LOAD.setImmediate(true); newVehicleLayout.addComponent(fieldMAX_LOAD); fields.bind(fieldMAX_LOAD, fieldName); fieldName = VehicleView.REGISTRATION_NR; TextField fieldREGISTRATION_NR = new TextField(fieldName); fieldREGISTRATION_NR.setValue( (String) vehiclesList .getContainerProperty(vehiclesList.getValue(), VehicleView.REGISTRATION_NR) .getValue()); fieldREGISTRATION_NR.addValidator( new StringLengthValidator("Niepoprawna długość pola Nr rejestracyjny", 4, 12, false)); fieldREGISTRATION_NR.addValidator( new RegexpValidator("^[A-Z0-9-]+$", "pole Kolor zawiera nie właściwe znaki")); fieldREGISTRATION_NR.setWidth("20em"); fieldREGISTRATION_NR.setRequired(true); fieldREGISTRATION_NR.setRequiredError("Pole Nr rejestracyjny jest wymagane"); fieldREGISTRATION_NR.setImmediate(true); newVehicleLayout.addComponent(fieldREGISTRATION_NR); fields.bind(fieldREGISTRATION_NR, fieldName); Button changeDriver = new Button("Zatwierdź"); Button cancel = new Button("Anuluj"); HorizontalLayout hl = new HorizontalLayout(); hl.addComponent(changeDriver); hl.addComponent(cancel); newVehicleLayout.addComponent(hl); cancel.addClickListener( new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); changeDriver.addClickListener( new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Vehicle veh = new Vehicle(); veh.setId(vehID); veh.setBrand((String) fields.getField(VehicleView.BRAND).getValue()); veh.setColour((String) fields.getField(VehicleView.COLOUR).getValue()); Integer truckLoad = null; try { truckLoad = Integer.parseInt(fields.getField(VehicleView.MAX_LOAD).getValue().toString()); } catch (NumberFormatException e) { Notification delayNot = new Notification("Proszę wypełnić pola poprawnie"); delayNot.setDelayMsec(1000); delayNot.show(Page.getCurrent()); return; } veh.setTruckload(truckLoad); veh.setRegistrationNumber( (String) fields.getField(VehicleView.REGISTRATION_NR).getValue()); Boolean valOk = true; Collection colFields = fields.getFields(); for (Object o : colFields) { Field fi = (Field) o; try { fi.validate(); } catch (Validator.InvalidValueException e) { Notification delayNot = new Notification("Proszę wypełnić pola poprawnie"); delayNot.setDelayMsec(1000); delayNot.show(Page.getCurrent()); valOk = false; break; } } if (valOk) { veh = ReceiveVehicle.changeVehicle(veh); if (veh == null) { Notification.show("Nie wprowadzono zmian"); close(); return; } Notification.show("Wprowadzono zmiany"); parent.refreshDataSource(); close(); } } }); addCloseListener( new Window.CloseListener() { @Override public void windowClose(Window.CloseEvent e) { parent.setEnabled(true); } }); parent.setEnabled(false); setContent(newVehicleLayout); setResizable(false); setDraggable(false); center(); }