blob: d7bfeb052cf292e04fba4291641765e1daca9d1c [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.ApplyType;
import com.vaadin.annotations.AutoGenerated;
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.OptionGroup;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
public class ExpressionSelectionWindow extends Window {
public static String OPTION_APPLY = "Apply";
public static String OPTION_VALUE = "Attribute Value";
public static String OPTION_DESIGNATOR = "Attribute Designator";
public static String OPTION_SELECTOR = "Attribute Selector";
public static String OPTION_VARIABLE = "Variable Reference";
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
@AutoGenerated
private VerticalLayout mainLayout;
@AutoGenerated
private Button buttonSave;
@AutoGenerated
private OptionGroup optionGroupExpression;
/**
*
*/
private static final long serialVersionUID = 1L;
private final ExpressionSelectionWindow self = this;
boolean isSaved = false;
String selection = 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.
* @param parentApply
*/
// TODO - Refactor. Unused formal parameter parentApply. Either determine
// whether this is unnecessary and remove it (including removing it from all
// constructor consumers), or use it.
// NOTE: parentApply was originally used by passing to private initializeOption method.
// However, the parameter was unused by that method also.
// Setting to NOPMD for now.
public ExpressionSelectionWindow(ApplyType parentApply, boolean isAttributeAssignment, boolean mustBeBag, boolean mustBeValue) { //NOPMD
buildMainLayout();
//setCompositionRoot(mainLayout);
setContent(mainLayout);
//
// Set our shortcuts
//
this.setCloseShortcut(KeyCode.ESCAPE);
//
// Finish GUI initialization
//
// this.initializeOption(parentApply, isAttributeAssignment, mustBeBag, mustBeValue);
this.initializeOption(isAttributeAssignment, mustBeBag, mustBeValue);
this.initializeButtons();
}
// private void initializeOption(ApplyType parentApply, boolean isAttributeAssignment, boolean mustBeBag, boolean mustBeValue) {
private void initializeOption(boolean isAttributeAssignment, boolean mustBeBag, boolean mustBeValue) {
// if (!isAttributeAssignment) {
this.optionGroupExpression.addItem(OPTION_APPLY);
// }
if (!mustBeBag || mustBeValue) {
this.optionGroupExpression.addItem(OPTION_VALUE);
}
if (mustBeBag || !mustBeValue) {
this.optionGroupExpression.addItem(OPTION_DESIGNATOR);
this.optionGroupExpression.addItem(OPTION_SELECTOR);
}
this.optionGroupExpression.addItem(OPTION_VARIABLE);
//
// Default Selection
//
if (!isAttributeAssignment) {
this.optionGroupExpression.select(OPTION_APPLY);
} else {
if (!mustBeBag || mustBeValue) {
this.optionGroupExpression.select(OPTION_VALUE);
} else {
this.optionGroupExpression.select(OPTION_DESIGNATOR);
}
}
}
private void initializeButtons() {
this.buttonSave.addClickListener(new ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
self.isSaved = true;
self.selection = self.optionGroupExpression.getValue().toString();
self.close();
}
});
}
public String getSelection() {
if (this.isSaved == false) {
return null;
}
return this.selection;
}
@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");
// optionGroupExpression
optionGroupExpression = new OptionGroup();
optionGroupExpression
.setCaption("Select One Of The Following Types of Expressions");
optionGroupExpression.setImmediate(false);
optionGroupExpression.setWidth("-1px");
optionGroupExpression.setHeight("-1px");
mainLayout.addComponent(optionGroupExpression);
// buttonSave
buttonSave = new Button();
buttonSave.setCaption("Select");
buttonSave.setImmediate(false);
buttonSave.setWidth("-1px");
buttonSave.setHeight("-1px");
mainLayout.addComponent(buttonSave);
mainLayout.setComponentAlignment(buttonSave, new Alignment(24));
return mainLayout;
}
}