List of usage examples for com.vaadin.ui GridLayout setWidth
@Override public void setWidth(float width, Unit unit)
From source file:org.activiti.explorer.ui.reports.SavedReportDetailPanel.java
License:Apache License
protected void initHeader() { GridLayout details = new GridLayout(2, 2); details.setWidth(100, UNITS_PERCENTAGE); details.addStyleName(ExplorerLayout.STYLE_TITLE_BLOCK); details.setSpacing(true);//from w w w . ja va2s. c o m details.setMargin(false, false, true, false); details.setColumnExpandRatio(1, 1.0f); detailPanelLayout.addComponent(details); // Image Embedded image = new Embedded(null, Images.REPORT_50); details.addComponent(image, 0, 0, 0, 1); // Name Label nameLabel = new Label(SavedReportListItem.getReportDisplayName(historicProcessInstance)); nameLabel.addStyleName(Reindeer.LABEL_H2); details.addComponent(nameLabel, 1, 0); // Properties HorizontalLayout propertiesLayout = new HorizontalLayout(); propertiesLayout.setSpacing(true); details.addComponent(propertiesLayout); // Created Time String createLabel = i18nManager.getMessage(Messages.REPORTING_CREATE_TIME, new HumanTime(i18nManager).format(historicProcessInstance.getEndTime())); Label versionLabel = new Label(createLabel); versionLabel.addStyleName(ExplorerLayout.STYLE_PROCESS_HEADER_START_TIME); propertiesLayout.addComponent(versionLabel); }
From source file:org.activiti.explorer.ui.task.HistoricTaskDetailPanel.java
License:Apache License
protected void initHeader() { GridLayout taskDetails = new GridLayout(5, 2); taskDetails.setWidth(100, UNITS_PERCENTAGE); taskDetails.addStyleName(ExplorerLayout.STYLE_TITLE_BLOCK); taskDetails.setSpacing(true);/* w w w . j a va2 s. c o m*/ taskDetails.setMargin(false, false, true, false); // Add image Embedded image = new Embedded(null, Images.TASK_50); taskDetails.addComponent(image, 0, 0, 0, 1); // Add task name Label nameLabel = new Label(historicTask.getName()); nameLabel.addStyleName(Reindeer.LABEL_H2); taskDetails.addComponent(nameLabel, 1, 0, 4, 0); // Add due date PrettyTimeLabel dueDateLabel = new PrettyTimeLabel(i18nManager.getMessage(Messages.TASK_DUEDATE_SHORT), historicTask.getDueDate(), i18nManager.getMessage(Messages.TASK_DUEDATE_UNKNOWN), false); dueDateLabel.addStyleName(ExplorerLayout.STYLE_TASK_HEADER_DUEDATE); taskDetails.addComponent(dueDateLabel, 1, 1); // Add priority Integer lowMedHighPriority = convertPriority(historicTask.getPriority()); Label priorityLabel = new Label(); switch (lowMedHighPriority) { case 1: priorityLabel.setValue(i18nManager.getMessage(Messages.TASK_PRIORITY_LOW)); priorityLabel.addStyleName(ExplorerLayout.STYLE_TASK_HEADER_PRIORITY_LOW); break; case 2: priorityLabel.setValue(i18nManager.getMessage(Messages.TASK_PRIORITY_MEDIUM)); priorityLabel.addStyleName(ExplorerLayout.STYLE_TASK_HEADER_PRIORITY_MEDIUM); break; case 3: default: priorityLabel.setValue(i18nManager.getMessage(Messages.TASK_PRIORITY_HIGH)); priorityLabel.addStyleName(ExplorerLayout.STYLE_TASK_HEADER_PRIORITY_HIGH); } taskDetails.addComponent(priorityLabel, 2, 1); // Add create date PrettyTimeLabel createLabel = new PrettyTimeLabel(i18nManager.getMessage(Messages.TASK_CREATED_SHORT), historicTask.getStartTime(), "", true); createLabel.addStyleName(ExplorerLayout.STYLE_TASK_HEADER_CREATE_TIME); taskDetails.addComponent(createLabel, 3, 1); // Add label to fill excess space Label spacer = new Label(); spacer.setContentMode(Label.CONTENT_XHTML); spacer.setValue(" "); spacer.setSizeUndefined(); taskDetails.addComponent(spacer); taskDetails.setColumnExpandRatio(1, 1.0f); taskDetails.setColumnExpandRatio(2, 1.0f); taskDetails.setColumnExpandRatio(3, 1.0f); taskDetails.setColumnExpandRatio(4, 1.0f); centralLayout.addComponent(taskDetails); }
From source file:org.activiti.explorer.ui.task.TaskDetailPanel.java
License:Apache License
protected void initHeader() { GridLayout taskDetails = new GridLayout(2, 2); taskDetails.setWidth(100, UNITS_PERCENTAGE); taskDetails.addStyleName(ExplorerLayout.STYLE_TITLE_BLOCK); taskDetails.setSpacing(true);//from ww w . j a v a 2 s . c o m taskDetails.setMargin(false, false, true, false); taskDetails.setColumnExpandRatio(1, 1.0f); centralLayout.addComponent(taskDetails); // Add image Embedded image = new Embedded(null, Images.TASK_50); taskDetails.addComponent(image, 0, 0, 0, 1); // Add task name Label nameLabel = new Label(task.getName()); nameLabel.addStyleName(Reindeer.LABEL_H2); taskDetails.addComponent(nameLabel, 1, 0); taskDetails.setComponentAlignment(nameLabel, Alignment.MIDDLE_LEFT); // Properties HorizontalLayout propertiesLayout = new HorizontalLayout(); propertiesLayout.setSpacing(true); taskDetails.addComponent(propertiesLayout); propertiesLayout.addComponent(new DueDateComponent(task, i18nManager, taskService)); propertiesLayout.addComponent(new PriorityComponent(task, i18nManager, taskService)); initCreateTime(propertiesLayout); }
From source file:org.hip.vif.web.util.RatingsTable.java
License:Open Source License
private Component createRatingsTable(final RatingsHelper inRatings) { final GridLayout outLayout = new GridLayout(4, 6); outLayout.setWidth(400, Unit.PIXELS); outLayout.setStyleName("vif-ratings"); //$NON-NLS-1$ final IMessages lMessages = Activator.getMessages(); // first row: table header final Label lSpacer = new Label(""); //$NON-NLS-1$ lSpacer.setWidth(70, Unit.PIXELS);// w w w.j a v a 2 s . c om outLayout.addComponent(lSpacer, 0, 0); outLayout.addComponent(createLabel(lMessages.getMessage("ratings.table.column.correctness")), 1, 0); //$NON-NLS-1$ outLayout.addComponent(createLabel(lMessages.getMessage("ratings.table.column.responsiveness")), 2, 0); //$NON-NLS-1$ outLayout.addComponent(createLabel(lMessages.getMessage("ratings.table.column.etiquette")), 3, 0); //$NON-NLS-1$ // first content: good addComponent(outLayout, RatingValue.GOOD.render(), 0, 1, Alignment.MIDDLE_CENTER); //$NON-NLS-1$ addComponent(outLayout, createLabel(inRatings.getCorrectnessA()), 1, 1, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEfficiencyA()), 2, 1, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEtiquetteA()), 3, 1, Alignment.MIDDLE_CENTER); // second content: average addComponent(outLayout, RatingValue.AVERAGE.render(), 0, 2, Alignment.MIDDLE_CENTER); //$NON-NLS-1$ addComponent(outLayout, createLabel(inRatings.getCorrectnessB()), 1, 2, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEfficiencyB()), 2, 2, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEtiquetteB()), 3, 2, Alignment.MIDDLE_CENTER); // third content: bad addComponent(outLayout, RatingValue.BAD.render(), 0, 3, Alignment.MIDDLE_CENTER); //$NON-NLS-1$ addComponent(outLayout, createLabel(inRatings.getCorrectnessC()), 1, 3, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEfficiencyC()), 2, 3, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getEtiquetteC()), 3, 3, Alignment.MIDDLE_CENTER); // total addComponent(outLayout, new Label(lMessages.getMessage("ratings.table.label.total")), 0, 4, //$NON-NLS-1$ Alignment.MIDDLE_LEFT); addComponent(outLayout, createLabel(inRatings.getTotal1()), 1, 4, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getTotal2()), 2, 4, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getTotal3()), 3, 4, Alignment.MIDDLE_CENTER); // average addComponent(outLayout, new Label(lMessages.getMessage("ratings.table.label.mean")), 0, 5, //$NON-NLS-1$ Alignment.MIDDLE_LEFT); addComponent(outLayout, createLabel(inRatings.getMean1()), 1, 5, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getMean2()), 2, 5, Alignment.MIDDLE_CENTER); addComponent(outLayout, createLabel(inRatings.getMean3()), 3, 5, Alignment.MIDDLE_CENTER); return outLayout; }
From source file:org.ikasan.dashboard.ui.framework.window.AdminPasswordDialog.java
License:BSD License
/** * Helper method to initialise this object. * /*from w w w . j a v a2s . co m*/ * @param userService * @param authProvider * @param visibilityGroup * @param userDetailsHelper * @param commitHandler */ protected void init() { super.setModal(true); super.setResizable(false); super.center(); this.setWidth(300, Unit.PIXELS); this.setHeight(220, Unit.PIXELS); super.setClosable(false); GridLayout form = new GridLayout(2, 4); form.setColumnExpandRatio(0, .15f); form.setColumnExpandRatio(1, .85f); form.setWidth(100, Unit.PERCENTAGE); form.setMargin(true); form.setSpacing(true); Label newTypeLabel = new Label("Initial Administration Password"); newTypeLabel.setStyleName(ValoTheme.LABEL_HUGE); form.addComponent(newTypeLabel, 0, 0, 1, 0); Label passwordLabel = new Label("Password:"); passwordLabel.setSizeUndefined(); form.addComponent(passwordLabel, 0, 1); form.setComponentAlignment(passwordLabel, Alignment.MIDDLE_RIGHT); final PasswordField passwordField = new PasswordField(); passwordField.addValidator(new StringLengthValidator("The username must not be empty", 1, null, true)); passwordField.setValidationVisible(false); passwordField.setStyleName("ikasan"); form.addComponent(passwordField, 1, 1); Label passwordConfirmLabel = new Label("Confirm Password:"); passwordConfirmLabel.setSizeUndefined(); form.addComponent(passwordConfirmLabel, 0, 2); form.setComponentAlignment(passwordConfirmLabel, Alignment.MIDDLE_RIGHT); final PasswordField passwordConfirmField = new PasswordField(); passwordConfirmField.setStyleName("ikasan"); passwordConfirmField .addValidator(new StringLengthValidator("The password must not be empty", 1, null, true)); passwordConfirmField.setValidationVisible(false); form.addComponent(passwordConfirmField, 1, 2); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button saveButton = new Button("Save"); saveButton.addStyleName(ValoTheme.BUTTON_SMALL); saveButton.setClickShortcut(KeyCode.ENTER); saveButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { try { passwordField.validate(); passwordConfirmField.validate(); if (!passwordField.getValue().equals(passwordConfirmField.getValue())) { Notification.show("Password and confirmation must be the same!", Type.ERROR_MESSAGE); return; } } catch (InvalidValueException e) { passwordField.setValidationVisible(true); passwordConfirmField.setValidationVisible(true); return; } password = passwordField.getValue(); passwordField.setValue(""); passwordConfirmField.setValue(""); close(); } }); buttons.addComponent(saveButton); form.addComponent(buttons, 0, 3, 1, 3); form.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER); this.setContent(form); }
From source file:org.ikasan.dashboard.ui.framework.window.LoginDialog.java
License:BSD License
/** * Helper method to initialise this object. * // w w w . j a v a 2 s. c om * @param userService * @param authProvider * @param visibilityGroup * @param userDetailsHelper * @param commitHandler */ protected void init(AuthenticationService authenticationService, VisibilityGroup visibilityGroup, final NavigationPanel commitHandler) { super.setModal(true); super.setResizable(false); super.center(); this.setWidth(300, Unit.PIXELS); this.setHeight(200, Unit.PIXELS); PropertysetItem item = new PropertysetItem(); item.addItemProperty(LoginFieldGroup.USERNAME, new ObjectProperty<String>("")); item.addItemProperty(LoginFieldGroup.PASSWORD, new ObjectProperty<String>("")); GridLayout form = new GridLayout(2, 4); form.setColumnExpandRatio(0, .15f); form.setColumnExpandRatio(1, .85f); form.setWidth(100, Unit.PERCENTAGE); form.setMargin(true); form.setSpacing(true); Label newTypeLabel = new Label("Login"); newTypeLabel.setStyleName(ValoTheme.LABEL_HUGE); form.addComponent(newTypeLabel, 0, 0, 1, 0); Label usernameLabel = new Label("Username:"); usernameLabel.setSizeUndefined(); form.addComponent(usernameLabel, 0, 1); form.setComponentAlignment(usernameLabel, Alignment.MIDDLE_RIGHT); final TextField userNameField = new TextField(); userNameField.addValidator(new StringLengthValidator("The username must not be empty", 1, null, true)); userNameField.setValidationVisible(false); userNameField.setStyleName("ikasan"); form.addComponent(userNameField, 1, 1); Label passwordLabel = new Label("Password:"); passwordLabel.setSizeUndefined(); form.addComponent(passwordLabel, 0, 2); form.setComponentAlignment(passwordLabel, Alignment.MIDDLE_RIGHT); final PasswordField passwordField = new PasswordField(); passwordField.setStyleName("ikasan"); passwordField.addValidator(new StringLengthValidator("The password must not be empty", 1, null, true)); passwordField.setValidationVisible(false); form.addComponent(passwordField, 1, 2); final LoginFieldGroup binder = new LoginFieldGroup(item, visibilityGroup, authenticationService); binder.bind(userNameField, LoginFieldGroup.USERNAME); binder.bind(passwordField, LoginFieldGroup.PASSWORD); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button loginButton = new Button("Login"); loginButton.addStyleName(ValoTheme.BUTTON_SMALL); loginButton.setClickShortcut(KeyCode.ENTER); loginButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { try { userNameField.validate(); passwordField.validate(); } catch (InvalidValueException e) { userNameField.setValidationVisible(true); passwordField.setValidationVisible(true); return; } try { binder.commit(); userNameField.setValue(""); passwordField.setValue(""); close(); commitHandler.postCommit(); } catch (CommitException e) { Notification.show(e.getMessage(), Notification.Type.ERROR_MESSAGE); } } }); buttons.addComponent(loginButton); Button cancelButton = new Button("Cancel"); cancelButton.setStyleName(ValoTheme.BUTTON_SMALL); cancelButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { close(); binder.discard(); } }); buttons.addComponent(cancelButton); form.addComponent(buttons, 0, 3, 1, 3); form.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER); this.setContent(form); }
From source file:org.ikasan.dashboard.ui.mappingconfiguration.window.NewClientWindow.java
License:BSD License
/** * Helper method to initialise this object. *///from w ww. j a va 2 s .c o m protected void init() { this.setStyleName("dashboard"); this.setModal(true); this.setWidth(800, Unit.PIXELS); this.setHeight(180, Unit.PIXELS); PropertysetItem item = new PropertysetItem(); item.addItemProperty(NewClientFieldGroup.NAME, new ObjectProperty<String>("")); item.addItemProperty(NewClientFieldGroup.KEY_LOCATION_QUERY_PROCESSOR_TYPE, new ObjectProperty<String>( "org.ikasan.mapping.keyQueryProcessor.impl.XPathKeyLocationQueryProcessor")); GridLayout form = new GridLayout(2, 4); form.setWidth(100, Unit.PERCENTAGE); form.setMargin(true); form.setSpacing(true); Label newClientLabel = new Label("New Mapping Configuration Client"); newClientLabel.setStyleName(ValoTheme.LABEL_HUGE); form.addComponent(newClientLabel, 0, 0, 1, 0); Label nameLabel = new Label("Name:"); nameLabel.setSizeUndefined(); form.addComponent(nameLabel, 0, 1); form.setComponentAlignment(nameLabel, Alignment.MIDDLE_RIGHT); nameField.addValidator(new StringLengthValidator("The name must not be blank!", 1, 256, true)); nameField.setValidationVisible(false); nameField.setStyleName("ikasan"); form.addComponent(nameField, 1, 1); Label keyLocationLabel = new Label("Key Location Query Processor Type:"); keyLocationLabel.setSizeUndefined(); form.addComponent(keyLocationLabel, 0, 2); form.setComponentAlignment(keyLocationLabel, Alignment.MIDDLE_RIGHT); TextField keyLocationQueryProcessorTypeField = new TextField(); keyLocationQueryProcessorTypeField.setStyleName("ikasan"); keyLocationQueryProcessorTypeField.setWidth(500, Unit.PIXELS); form.addComponent(keyLocationQueryProcessorTypeField, 1, 2); final NewClientFieldGroup binder = new NewClientFieldGroup(item, this.refreshGroup, this.mappingConfigurationService, this.systemEventService); binder.bind(nameField, "name"); binder.bind(keyLocationQueryProcessorTypeField, "keyLocationQueryProcessorType"); keyLocationQueryProcessorTypeField.setReadOnly(true); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button saveButton = new Button("Save"); saveButton.setStyleName(ValoTheme.BUTTON_SMALL); saveButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { try { nameField.validate(); } catch (InvalidValueException e) { nameField.setValidationVisible(true); return; } try { binder.commit(); UI.getCurrent().getNavigator().navigateTo("emptyPanel"); nameField.setValue(""); Notification.show("New Mapping Configuration Client Successfully Created!"); saveRequiredMonitor.setSaveRequired(false); close(); } catch (CommitException e) { Notification.show("An error has occurred saving a new client: " + e.getMessage()); } } }); buttons.addComponent(saveButton); Button cancelButton = new Button("Cancel"); cancelButton.setStyleName(ValoTheme.BUTTON_SMALL); cancelButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { UI.getCurrent().getNavigator().navigateTo("emptyPanel"); binder.discard(); saveRequiredMonitor.setSaveRequired(false); close(); } }); buttons.addComponent(cancelButton); form.addComponent(buttons, 0, 3, 1, 3); form.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER); this.setContent(form); }
From source file:org.ikasan.dashboard.ui.mappingconfiguration.window.NewMappingConfigurationContextWindow.java
License:BSD License
/** * Helper method to initialise this object. *///from w w w . j a v a 2 s .co m protected void init() { this.setStyleName("dashboard"); this.setModal(true); this.setWidth(500, Unit.PIXELS); this.setHeight(250, Unit.PIXELS); PropertysetItem item = new PropertysetItem(); item.addItemProperty(NewContextFieldGroup.NAME, new ObjectProperty<String>("")); item.addItemProperty(NewContextFieldGroup.DESCRIPTION, new ObjectProperty<String>("")); GridLayout form = new GridLayout(2, 4); form.setColumnExpandRatio(0, .15f); form.setColumnExpandRatio(1, .85f); form.setWidth(100, Unit.PERCENTAGE); form.setMargin(true); form.setSpacing(true); Label newTypeLabel = new Label("New Mapping Configuration Context"); newTypeLabel.setStyleName(ValoTheme.LABEL_HUGE); form.addComponent(newTypeLabel, 0, 0, 1, 0); Label nameLabel = new Label("Name:"); nameLabel.setSizeUndefined(); form.addComponent(nameLabel, 0, 1); form.setComponentAlignment(nameLabel, Alignment.MIDDLE_RIGHT); nameField.setStyleName("ikasan"); nameField.addValidator(new StringLengthValidator("The name must not be blank!", 1, 256, true)); nameField.setValidationVisible(false); nameField.setWidth(70, Unit.PERCENTAGE); form.addComponent(nameField, 1, 1); Label descriptionLabel = new Label("Description:"); descriptionLabel.setSizeUndefined(); form.addComponent(descriptionLabel, 0, 2); form.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT); descriptionField.setStyleName("ikasan"); descriptionField .addValidator(new StringLengthValidator("The description must not be blank!", 1, 256, true)); descriptionField.setValidationVisible(false); descriptionField.setWidth(90, Unit.PERCENTAGE); descriptionField.setRows(5); form.addComponent(descriptionField, 1, 2); final NewContextFieldGroup binder = new NewContextFieldGroup(item, this.refreshGroup, this.mappingConfigurationService, this.systemEventService); binder.bind(nameField, NewContextFieldGroup.NAME); binder.bind(descriptionField, NewContextFieldGroup.DESCRIPTION); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button saveButton = new Button("Save"); saveButton.setStyleName(ValoTheme.BUTTON_SMALL); saveButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { try { nameField.validate(); descriptionField.validate(); } catch (InvalidValueException e) { nameField.setValidationVisible(true); descriptionField.setValidationVisible(true); return; } try { binder.commit(); UI.getCurrent().getNavigator().navigateTo("emptyPanel"); nameField.setValue(""); descriptionField.setValue(""); Notification.show("New Mapping Configuration Context Successfully Created!"); saveRequiredMonitor.setSaveRequired(false); close(); } catch (CommitException e) { Notification.show("An error occurred saving a new context! " + e.getMessage(), Type.ERROR_MESSAGE); } } }); buttons.addComponent(saveButton); Button cancelButton = new Button("Cancel"); cancelButton.setStyleName(ValoTheme.BUTTON_SMALL); cancelButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { UI.getCurrent().getNavigator().navigateTo("emptyPanel"); binder.discard(); saveRequiredMonitor.setSaveRequired(false); close(); } }); buttons.addComponent(cancelButton); form.addComponent(buttons, 0, 3, 1, 3); form.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER); this.setContent(form); }
From source file:org.ikasan.dashboard.ui.mappingconfiguration.window.NewMappingConfigurationTypeWindow.java
License:BSD License
/** * Helper method to initialise this object. *//*from w w w . j av a2s . com*/ protected void init() { this.setStyleName("dashboard"); this.setModal(true); this.setWidth(500, Unit.PIXELS); this.setHeight(180, Unit.PIXELS); PropertysetItem item = new PropertysetItem(); item.addItemProperty(NewContextFieldGroup.NAME, new ObjectProperty<String>("")); GridLayout form = new GridLayout(2, 3); form.setColumnExpandRatio(0, .15f); form.setColumnExpandRatio(1, .85f); form.setWidth(100, Unit.PERCENTAGE); form.setMargin(true); form.setSpacing(true); Label newTypeLabel = new Label("New Mapping Configuration Type"); newTypeLabel.setStyleName(ValoTheme.LABEL_HUGE); form.addComponent(newTypeLabel, 0, 0, 1, 0); Label nameLabel = new Label("Name:"); nameLabel.setSizeUndefined(); form.addComponent(nameLabel, 0, 1); form.setComponentAlignment(nameLabel, Alignment.MIDDLE_RIGHT); nameField.setStyleName("ikasan"); nameField.addValidator(new StringLengthValidator("The name must not be blank!", 1, 256, true)); nameField.setValidationVisible(false); nameField.setWidth(70, Unit.PERCENTAGE); form.addComponent(nameField, 1, 1); final NewConfigurationTypeFieldGroup binder = new NewConfigurationTypeFieldGroup(item, this.refreshGroup, this.mappingConfigurationService, systemEventService); binder.bind(nameField, NewContextFieldGroup.NAME); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button saveButton = new Button("Save"); saveButton.setStyleName(ValoTheme.BUTTON_SMALL); saveButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { try { nameField.validate(); } catch (InvalidValueException e) { nameField.setValidationVisible(true); return; } try { binder.commit(); UI.getCurrent().getNavigator().navigateTo("emptyPanel"); nameField.setValue(""); Notification.show("New Mapping Configuration Type Successfully Created!"); saveRequiredMonitor.setSaveRequired(false); close(); } catch (CommitException e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); Notification.show("Cauget exception trying to save a new Mapping Configuration Type!", sw.toString(), Notification.Type.ERROR_MESSAGE); } } }); buttons.addComponent(saveButton); Button cancelButton = new Button("Cancel"); cancelButton.setStyleName(ValoTheme.BUTTON_SMALL); cancelButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { UI.getCurrent().getNavigator().navigateTo("emptyPanel"); binder.discard(); saveRequiredMonitor.setSaveRequired(false); close(); } }); buttons.addComponent(cancelButton); form.addComponent(buttons, 0, 2, 1, 2); form.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER); this.setContent(form); }
From source file:org.sensorhub.ui.GenericConfigForm.java
License:Mozilla Public License
protected Component buildTabs(final String propId, final ContainerProperty prop, final FieldGroup fieldGroup) { GridLayout layout = new GridLayout(); layout.setWidth(100.0f, Unit.PERCENTAGE); // title bar//from w w w . ja v a 2 s . c om HorizontalLayout titleBar = new HorizontalLayout(); titleBar.setMargin(new MarginInfo(true, false, false, false)); titleBar.setSpacing(true); String label = prop.getLabel(); if (label == null) label = DisplayUtils.getPrettyName((String) propId); Label sectionLabel = new Label(label); sectionLabel.setDescription(prop.getDescription()); sectionLabel.addStyleName(STYLE_H3); sectionLabel.addStyleName(STYLE_COLORED); titleBar.addComponent(sectionLabel); layout.addComponent(titleBar); // create one tab per item in container final MyBeanItemContainer<Object> container = prop.getValue(); final TabSheet tabs = new TabSheet(); tabs.setSizeFull(); int i = 1; for (Object itemId : container.getItemIds()) { MyBeanItem<Object> childBeanItem = (MyBeanItem<Object>) container.getItem(itemId); IModuleConfigForm subform = AdminUI.getInstance().generateForm(childBeanItem.getBean().getClass()); subform.build(null, childBeanItem); ((MarginHandler) subform).setMargin(new MarginInfo(true, false, true, false)); allForms.add(subform); Tab tab = tabs.addTab(subform, "Item #" + (i++)); tab.setClosable(true); // store item id so we can map a tab with the corresponding bean item ((AbstractComponent) subform).setData(itemId); } // draw icon on last tab to add new items tabs.addTab(new VerticalLayout(), "", UIConstants.ADD_ICON); // catch close event to delete item tabs.setCloseHandler(new CloseHandler() { private static final long serialVersionUID = 1L; @Override public void onTabClose(TabSheet tabsheet, Component tabContent) { final Tab tab = tabs.getTab(tabContent); final ConfirmDialog popup = new ConfirmDialog( "Are you sure you want to delete " + tab.getCaption() + "?</br>All settings will be lost."); popup.addCloseListener(new CloseListener() { private static final long serialVersionUID = 1L; @Override public void windowClose(CloseEvent e) { if (popup.isConfirmed()) { // retrieve id of item shown on tab AbstractComponent tabContent = (AbstractComponent) tab.getComponent(); Object itemId = tabContent.getData(); // remove from UI int deletedTabPos = tabs.getTabPosition(tab); tabs.removeTab(tab); tabs.setSelectedTab(deletedTabPos - 1); // remove from container container.removeItem(itemId); } } }); popup.setModal(true); AdminUI.getInstance().addWindow(popup); } }); // catch select event on '+' tab to add new item tabs.addSelectedTabChangeListener(new SelectedTabChangeListener() { private static final long serialVersionUID = 1L; public void selectedTabChange(SelectedTabChangeEvent event) { Component selectedTab = event.getTabSheet().getSelectedTab(); final Tab tab = tabs.getTab(selectedTab); final int selectedTabPos = tabs.getTabPosition(tab); // case of + tab to add new item if (tab.getCaption().equals("")) { tabs.setSelectedTab(selectedTabPos - 1); try { // show popup to select among available module types String title = "Please select the desired option"; Map<String, Class<?>> typeList = GenericConfigForm.this.getPossibleTypes(propId); ObjectTypeSelectionPopup popup = new ObjectTypeSelectionPopup(title, typeList, new ObjectTypeSelectionCallback() { public void typeSelected(Class<?> objectType) { try { // add new item to container MyBeanItem<Object> childBeanItem = container.addBean( objectType.newInstance(), ((String) propId) + PROP_SEP); // generate form for new item IModuleConfigForm subform = AdminUI.getInstance() .generateForm(childBeanItem.getBean().getClass()); subform.build(null, childBeanItem); ((MarginHandler) subform) .setMargin(new MarginInfo(true, false, true, false)); allForms.add(subform); // add new tab and select it Tab newTab = tabs.addTab(subform, "Item #" + (selectedTabPos + 1), null, selectedTabPos); newTab.setClosable(true); tabs.setSelectedTab(newTab); } catch (Exception e) { Notification.show("Error", e.getMessage(), Notification.Type.ERROR_MESSAGE); } } }); popup.setModal(true); AdminUI.getInstance().addWindow(popup); } catch (Exception e) { e.printStackTrace(); } } } }); // also register commit handler fieldGroup.addCommitHandler(new CommitHandler() { private static final long serialVersionUID = 1L; @Override public void preCommit(CommitEvent commitEvent) throws CommitException { } @Override public void postCommit(CommitEvent commitEvent) throws CommitException { // make sure new items are transfered to model prop.setValue(prop.getValue()); } }); layout.addComponent(tabs); return layout; }