Java tutorial
/* * 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 org.apache.openaz.xacml.admin.jpa.Obadvice; import org.apache.openaz.xacml.admin.view.fields.OaExpressionsField; import com.vaadin.addon.jpacontainer.EntityItem; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.Property.ValueChangeListener; import com.vaadin.data.fieldgroup.FieldGroup; import com.vaadin.data.fieldgroup.FieldGroup.CommitException; import com.vaadin.data.fieldgroup.PropertyId; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.FormLayout; import com.vaadin.ui.OptionGroup; import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; import com.vaadin.ui.Window; public class ObadviceEditorWindow extends Window { /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */ private static final long serialVersionUID = 1L; private ObadviceEditorWindow self = this; private FormLayout mainLayout = new FormLayout(); @PropertyId("type") OptionGroup typeOption = new OptionGroup("Type"); @PropertyId("xacmlId") TextField xacmlID = new TextField("Obligation Id"); @PropertyId("description") TextArea descriptionField = new TextArea("Description"); @PropertyId("fulfillOn") OptionGroup fulfillOption = new OptionGroup("Fullfill On"); @PropertyId("obadviceExpressions") OaExpressionsField expressionsField; //Table tableExpressions = new Table("Attribute Assignments"); Button saveButton = new Button("Save"); private FieldGroup fieldGroup = null; private final EntityItem<Obadvice> obad; private boolean isSaved = false; /** * 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. * @param caption */ public ObadviceEditorWindow(EntityItem<Obadvice> obad) { this.setContent(mainLayout); // // Save // this.obad = obad; // // Initialize main layout // this.mainLayout.setMargin(true); this.mainLayout.setWidth("-1px"); // // Initialize components // this.typeOption.setNullSelectionAllowed(false); this.typeOption.setImmediate(true); this.typeOption.setDescription("Select whether this is an obligation or advice"); this.typeOption.addItem("Obligation"); this.typeOption.addItem("Advice"); this.fulfillOption.setNullSelectionAllowed(true); this.fulfillOption .setDescription("Optionally restrict the use of the obligation/advice to a Permit or a Deny"); this.fulfillOption.addItem("Permit"); this.fulfillOption.addItem("Deny"); this.descriptionField.setNullRepresentation(""); this.expressionsField = new OaExpressionsField(this.obad); // // Add our form components // this.mainLayout.addComponent(this.typeOption); this.mainLayout.addComponent(this.fulfillOption); this.mainLayout.addComponent(this.xacmlID); this.mainLayout.addComponent(this.descriptionField); this.mainLayout.addComponent(this.expressionsField); // this.mainLayout.addComponent(this.tableExpressions); this.mainLayout.addComponent(this.saveButton); // // Now bind those fields to the data // this.fieldGroup = new FieldGroup(obad); this.fieldGroup.bindMemberFields(this); // // Finish setting up // this.initializeButtons(); this.initializeOptions(); // // Set focus // this.xacmlID.focus(); } private void initializeButtons() { this.saveButton.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { try { fieldGroup.commit(); self.isSaved = true; self.close(); } catch (CommitException e) { e.printStackTrace(); } } }); } private void initializeOptions() { self.setIDCaption(); this.typeOption.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 1L; @Override public void valueChange(ValueChangeEvent event) { self.setIDCaption(); } }); } private void setIDCaption() { String value = (String) self.typeOption.getValue(); if (value.equals("Obligation")) { self.xacmlID.setCaption("Obligation Id"); } else { self.xacmlID.setCaption("Advice Id"); } } public boolean isSaved() { return this.isSaved; } public void discard() { // // May be discarded automatically?? // this.fieldGroup.discard(); } }