blob: bec843ef15a77621062e4938d2357017ad1c0305 [file] [log] [blame]
/*
* 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 oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableDefinitionType;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.data.Buffered.SourceException;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.Validator.InvalidValueException;
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.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
public class VariableDefinitionEditorWindow 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 textFieldID;
/**
*
*/
private static final long serialVersionUID = 1L;
private final VariableDefinitionEditorWindow self = this;
private final VariableDefinitionType variable;
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.
*/
public VariableDefinitionEditorWindow(VariableDefinitionType variable) {
buildMainLayout();
//setCompositionRoot(mainLayout);
setContent(mainLayout);
//
// Save
//
this.variable = variable;
//
// Set our shortcuts
//
this.setCloseShortcut(KeyCode.ESCAPE);
//
// Initialize
//
this.initializeText();
this.initializeButton();
//
// Initial focus
//
this.textFieldID.focus();
}
protected void initializeText() {
//
// Initialize GUI properties
//
this.textFieldID.setImmediate(true);
//
// Listen to changes
//
this.textFieldID.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);
}
}
});
this.textFieldID.addValueChangeListener(new ValueChangeListener() {
private static final long serialVersionUID = 1L;
@Override
public void valueChange(ValueChangeEvent event) {
if (self.textFieldID.getValue() != null && self.textFieldID.getValue().isEmpty() == false) {
self.buttonSave.setEnabled(true);
} else {
self.buttonSave.setEnabled(false);
}
}
});
//
// Set the value
//
this.textFieldID.setValue(variable.getVariableId());
}
protected void initializeButton() {
this.buttonSave.setClickShortcut(KeyCode.ENTER);
this.buttonSave.addClickListener(new ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
try {
//
// Commit it
//
self.textFieldID.commit();
//
// Save it
//
self.variable.setVariableId(self.textFieldID.getValue());
self.isSaved = true;
//
// Close window
//
self.close();
} catch (SourceException | InvalidValueException e) { //NOPMD
// Vaadin will display error
// TODO - Verify that Vaadin will display error and update this
// inline documentation accordingly
}
}
});
}
public boolean isSaved() {
return this.isSaved;
}
public VariableDefinitionType getVariable() {
return this.variable;
}
@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");
// textFieldID
textFieldID = new TextField();
textFieldID.setCaption("Variable ID");
textFieldID.setImmediate(false);
textFieldID.setWidth("-1px");
textFieldID.setHeight("-1px");
textFieldID.setInvalidAllowed(false);
textFieldID.setRequired(true);
textFieldID.setNullRepresentation("");
mainLayout.addComponent(textFieldID);
// buttonSave
buttonSave = new Button();
buttonSave.setCaption("Save and Continue");
buttonSave.setImmediate(false);
buttonSave.setWidth("-1px");
buttonSave.setHeight("-1px");
mainLayout.addComponent(buttonSave);
mainLayout.setComponentAlignment(buttonSave, new Alignment(48));
return mainLayout;
}
}