| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| * |
| */ |
| |
| package org.apache.openaz.xacml.admin.view.windows; |
| |
| import com.vaadin.annotations.AutoGenerated; |
| import com.vaadin.data.Buffered.SourceException; |
| import com.vaadin.data.Validator.InvalidValueException; |
| import com.vaadin.data.validator.IntegerRangeValidator; |
| import com.vaadin.event.FieldEvents.TextChangeEvent; |
| import com.vaadin.event.FieldEvents.TextChangeListener; |
| import com.vaadin.event.ShortcutAction.KeyCode; |
| import com.vaadin.ui.Alignment; |
| import com.vaadin.ui.Button; |
| import com.vaadin.ui.Button.ClickEvent; |
| import com.vaadin.ui.Button.ClickListener; |
| // import com.vaadin.ui.CustomComponent; |
| import com.vaadin.ui.TextField; |
| import com.vaadin.ui.VerticalLayout; |
| import com.vaadin.ui.Window; |
| |
| public class ColumnSelectionWindow extends Window { |
| |
| /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */ |
| |
| @AutoGenerated |
| private VerticalLayout mainLayout; |
| @AutoGenerated |
| private Button buttonSave; |
| @AutoGenerated |
| private TextField textFieldColumn; |
| /** |
| * |
| */ |
| private static final long serialVersionUID = 1L; |
| private boolean isSaved = false; |
| private ColumnSelectionWindow self = this; |
| |
| /** |
| * The constructor should first build the main layout, set the |
| * composition root and then do any custom initialization. |
| * |
| * The constructor will not be automatically regenerated by the |
| * visual editor. |
| */ |
| public ColumnSelectionWindow(Integer value) { |
| buildMainLayout(); |
| //setCompositionRoot(mainLayout); |
| setContent(mainLayout); |
| // |
| // Initialize |
| // |
| this.initialize(); |
| // |
| // Set the value |
| // |
| if (value != null) { |
| this.textFieldColumn.setValue(value.toString()); |
| } else { |
| this.textFieldColumn.setValue(Integer.toString(0)); |
| } |
| // |
| // Shortcuts |
| // |
| this.setCloseShortcut(KeyCode.ESCAPE); |
| this.buttonSave.setClickShortcut(KeyCode.ENTER); |
| // |
| // Focus |
| // |
| this.textFieldColumn.focus(); |
| } |
| |
| protected void initialize() { |
| this.initializeText(); |
| this.initializeButton(); |
| } |
| |
| protected void initializeText() { |
| // |
| // Add a validator |
| // |
| this.textFieldColumn.addValidator(new IntegerRangeValidator("Please enter an integer greater than or equal to 0.", 0, null)); |
| // |
| // Respond to text changing to setup the button |
| // |
| this.textFieldColumn.addTextChangeListener(new TextChangeListener() { |
| private static final long serialVersionUID = 1L; |
| |
| @Override |
| public void textChange(TextChangeEvent event) { |
| if (event.getText() != null && event.getText().isEmpty() == false) { |
| self.buttonSave.setEnabled(true); |
| } else { |
| self.buttonSave.setEnabled(false); |
| } |
| } |
| }); |
| } |
| |
| protected void initializeButton() { |
| self.buttonSave.addClickListener(new ClickListener() { |
| private static final long serialVersionUID = 1L; |
| |
| @Override |
| public void buttonClick(ClickEvent event) { |
| try { |
| // |
| // Commit |
| // |
| self.textFieldColumn.commit(); |
| // |
| // If we get here, the value is valid. |
| // Mark ourselves as saved and close the window |
| // |
| self.isSaved = true; |
| self.close(); |
| } catch (SourceException | InvalidValueException e) { //NOPMD |
| // |
| // Vaadin will display error |
| // |
| } |
| } |
| }); |
| } |
| |
| public boolean isSaved() { |
| return this.isSaved; |
| } |
| |
| public Integer getColumn() { |
| try { |
| return Integer.parseInt(this.textFieldColumn.getValue()); |
| } catch (NumberFormatException e) { |
| return null; |
| } |
| } |
| |
| @AutoGenerated |
| private VerticalLayout buildMainLayout() { |
| // common part: create layout |
| mainLayout = new VerticalLayout(); |
| mainLayout.setImmediate(false); |
| mainLayout.setWidth("-1px"); |
| mainLayout.setHeight("-1px"); |
| mainLayout.setMargin(true); |
| mainLayout.setSpacing(true); |
| |
| // top-level component properties |
| setWidth("-1px"); |
| setHeight("-1px"); |
| |
| // textFieldColumn |
| textFieldColumn = new TextField(); |
| textFieldColumn.setCaption("Column"); |
| textFieldColumn.setImmediate(false); |
| textFieldColumn.setDescription("0-based index into CSV line"); |
| textFieldColumn.setWidth("-1px"); |
| textFieldColumn.setHeight("-1px"); |
| textFieldColumn.setRequired(true); |
| textFieldColumn.setInputPrompt("Eg. ‘0'"); |
| mainLayout.addComponent(textFieldColumn); |
| |
| // buttonSave |
| buttonSave = new Button(); |
| buttonSave.setCaption("Save"); |
| buttonSave.setImmediate(false); |
| buttonSave.setWidth("-1px"); |
| buttonSave.setHeight("-1px"); |
| mainLayout.addComponent(buttonSave); |
| mainLayout.setComponentAlignment(buttonSave, new Alignment(48)); |
| |
| return mainLayout; |
| } |
| |
| } |