org.apache.openaz.xacml.admin.view.windows.RenamePolicyFileWindow.java Source code

Java tutorial

Introduction

Here is the source code for org.apache.openaz.xacml.admin.view.windows.RenamePolicyFileWindow.java

Source

/*
 *  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.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 RenamePolicyFileWindow 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 textFieldFilename;
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private RenamePolicyFileWindow self = this;
    private String newFilename = null;

    /**
     * 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 RenamePolicyFileWindow(String currentFilename) {
        buildMainLayout();
        //setCompositionRoot(mainLayout);
        setContent(mainLayout);
        this.setCloseShortcut(KeyCode.ESCAPE);
        //
        // Initialize the text field
        //
        this.textFieldFilename.setValue(currentFilename);
        this.textFieldFilename.setImmediate(true);
        this.textFieldFilename.addTextChangeListener(new TextChangeListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void textChange(TextChangeEvent event) {
                if (event.getText() == null || event.getText().isEmpty()) {
                    self.buttonSave.setEnabled(false);
                } else {
                    self.buttonSave.setEnabled(true);
                }
            }
        });
        //
        // Initialize the button
        //
        this.buttonSave.setClickShortcut(KeyCode.ENTER);
        this.buttonSave.addClickListener(new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(ClickEvent event) {
                //
                // Save the value
                //
                self.newFilename = self.textFieldFilename.getValue();
                //
                // Make sure it ends with .xml
                //
                if (self.newFilename.endsWith(".xml") == false) {
                    self.newFilename = self.newFilename + ".xml";
                }
                //
                // Close the window
                //
                self.close();
            }
        });
        this.textFieldFilename.focus();
    }

    public String getNewFilename() {
        return this.newFilename;
    }

    @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");

        // textFieldFilename
        textFieldFilename = new TextField();
        textFieldFilename.setCaption("Policy File Name");
        textFieldFilename.setImmediate(false);
        textFieldFilename.setWidth("-1px");
        textFieldFilename.setHeight("-1px");
        mainLayout.addComponent(textFieldFilename);

        // buttonSave
        buttonSave = new Button();
        buttonSave.setCaption("Save");
        buttonSave.setImmediate(false);
        buttonSave.setWidth("-1px");
        buttonSave.setHeight("-1px");
        mainLayout.addComponent(buttonSave);
        mainLayout.setComponentAlignment(buttonSave, new Alignment(24));

        return mainLayout;
    }

}