Skip to content

Commit

Permalink
LookupTable implementation in GUI - in PrismObjectPanel forms, not co…
Browse files Browse the repository at this point in the history
…mpletely finished yet.
  • Loading branch information
erik committed Apr 1, 2015
1 parent 8deea1a commit 1ffb615
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 43 deletions.
@@ -0,0 +1,22 @@
<!--
~ Copyright (c) 2010-2013 Evolveum
~
~ Licensed 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.
-->

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<input wicket:id="input" class="form-control input-sm" type="text"/>
</wicket:panel>
</html>
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2010-2013 Evolveum
*
* Licensed 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 com.evolveum.midpoint.web.component.input;

import com.evolveum.midpoint.web.component.prism.InputPanel;
import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings;
import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.model.IModel;

import java.util.Iterator;

/**
* @author shood
* */
public abstract class AutoCompleteTextPanel<T> extends InputPanel {

private static final String ID_INPUT = "input";

public AutoCompleteTextPanel(String id, IModel<T> model) {
this(id, model, String.class);
}

public AutoCompleteTextPanel(String id, IModel<T> model, Class clazz) {
super(id);

AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
autoCompleteSettings.setShowListOnEmptyInput(true);
final AutoCompleteTextField<T> input = new AutoCompleteTextField<T>(ID_INPUT, model, autoCompleteSettings) {

@Override
protected Iterator<T> getChoices(String input) {
return getIterator(input);
}
};
input.setType(clazz);
add(input);
}

/**
* This method takes care of retrieving an iterator over all
* options that can be completed. The generation of options can be
* affected by using current users input in 'input' variable.
* */
public abstract Iterator<T> getIterator(String input);

@Override
public FormComponent getBaseFormComponent() {
return (FormComponent) get(ID_INPUT);
}
}
Expand Up @@ -18,6 +18,7 @@

import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.PageBase;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand All @@ -37,14 +38,16 @@
public class PrismContainerPanel extends Panel {

private boolean showHeader;
private PageBase pageBase;

public PrismContainerPanel(String id, IModel<ContainerWrapper> model, Form form) {
this(id, model, true, form);
this(id, model, true, form, null);
}

public PrismContainerPanel(String id, final IModel<ContainerWrapper> model, boolean showHeader, Form form) {
public PrismContainerPanel(String id, final IModel<ContainerWrapper> model, boolean showHeader, Form form, PageBase pageBase) {
super(id);
this.showHeader = showHeader;
this.pageBase = pageBase;

add(new AttributeAppender("class", new Model<>("attributeComponent"), " "));
add(new VisibleEnableBehaviour() {
Expand Down Expand Up @@ -90,14 +93,18 @@ public boolean isVisible() {

@Override
protected void populateItem(ListItem<PropertyWrapper> item) {
item.add(new PrismPropertyPanel("property", item.getModel(), form));
item.add(new PrismPropertyPanel("property", item.getModel(), form, pageBase));
item.add(AttributeModifier.append("class", createStyleClassModel(item.getModel())));
}
};
properties.setReuseItems(true);
add(properties);
}

protected PageBase getPageBase(){
return pageBase;
}

private IModel<String> createStyleClassModel(final IModel<PropertyWrapper> wrapper) {
return new AbstractReadOnlyModel<String>() {

Expand Down
Expand Up @@ -20,6 +20,7 @@
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.resource.img.ImgResources;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
Expand Down Expand Up @@ -60,11 +61,13 @@ public class PrismObjectPanel extends Panel {
private static final String ID_HEADER = "header";

private boolean showHeader = true;
private PageBase pageBase;

public PrismObjectPanel(String id, IModel<ObjectWrapper> model, ResourceReference image, Form form) {
public PrismObjectPanel(String id, IModel<ObjectWrapper> model, ResourceReference image, Form form, PageBase pageBase) {
super(id);
setOutputMarkupId(true);

this.pageBase = pageBase;
initLayout(model, image, form);
}

Expand Down Expand Up @@ -306,7 +309,7 @@ protected IModel<List<ContainerWrapper>> createContainerModel(IModel<ObjectWrapp
}

protected void createContainerPanel(ListItem<ContainerWrapper> item, Form form){
item.add(new PrismContainerPanel("container", item.getModel(), form));
item.add(new PrismContainerPanel("container", item.getModel(), true, form, pageBase));
}

protected IModel<String> createDisplayName(IModel<ObjectWrapper> model) {
Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.util.LoadableModel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
Expand Down Expand Up @@ -55,8 +56,11 @@ public class PrismPropertyPanel extends Panel {
private static final String ID_HELP = "help";
private static final String ID_LABEL_CONTAINER = "labelContainer";

public PrismPropertyPanel(String id, final IModel<PropertyWrapper> model, Form form) {
private PageBase pageBase;

public PrismPropertyPanel(String id, final IModel<PropertyWrapper> model, Form form, PageBase pageBase) {
super(id);
this.pageBase = pageBase;

setOutputMarkupId(true);
add(new VisibleEnableBehaviour() {
Expand Down Expand Up @@ -147,7 +151,7 @@ public boolean isVisible() {

@Override
protected void populateItem(final ListItem<ValueWrapper> item) {
PrismValuePanel panel = new PrismValuePanel("value", item.getModel(), label, form, getValueCssClass(), getInputCssClass());
PrismValuePanel panel = new PrismValuePanel("value", item.getModel(), label, form, getValueCssClass(), getInputCssClass(), pageBase);
item.add(panel);
item.add(AttributeModifier.append("class", createStyleClassModel(item.getModel())));

Expand Down
Expand Up @@ -16,39 +16,29 @@

package com.evolveum.midpoint.web.component.prism;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.xml.XsdTypeMapper;
import com.evolveum.midpoint.schema.DeltaConvertor;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.RetrieveOption;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.input.DatePanel;
import com.evolveum.midpoint.web.component.input.PasswordPanel;
import com.evolveum.midpoint.web.component.input.TextAreaPanel;
import com.evolveum.midpoint.web.component.input.TextDetailsPanel;
import com.evolveum.midpoint.web.component.input.TextPanel;
import com.evolveum.midpoint.web.component.input.TriStateComboPanel;
import com.evolveum.midpoint.web.component.input.UploadPanel;
import com.evolveum.midpoint.web.component.input.*;
import com.evolveum.midpoint.web.component.model.delta.DeltaDto;
import com.evolveum.midpoint.web.component.model.delta.ModificationsPanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.util.DateValidator;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.web.util.WebModelUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.midpoint.xml.ns.model.workflow.common_forms_3.AssignmentCreationApprovalFormType;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
Expand All @@ -75,6 +65,7 @@
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
Expand All @@ -86,11 +77,14 @@ public class PrismValuePanel extends Panel {
private static final String ID_VALUE_CONTAINER = "valueContainer";

private IModel<ValueWrapper> model;
private PageBase pageBase;

public PrismValuePanel(String id, IModel<ValueWrapper> model, IModel<String> label, Form form,
String valueCssClass, String inputCssClass){
String valueCssClass, String inputCssClass, PageBase pageBase){
super(id);
Validate.notNull(model, "Property value model must not be null.");
Validate.notNull(pageBase, "The reference to page base must not be null.");
this.pageBase = pageBase;
this.model = model;

initLayout(label, form, valueCssClass, inputCssClass);
Expand Down Expand Up @@ -410,9 +404,33 @@ public String createAssociationTooltip(){
} else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(model, baseExpression));
} else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
InputPanel inputPanel = new TextPanel<>(id, new PropertyModel<String>(model, baseExpression + ".orig"), String.class);

InputPanel inputPanel;
PrismPropertyDefinition def = property.getDefinition();

if(def.getValueEnumerationRef() != null){
PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
String lookupTableUid = valueEnumerationRef.getOid();
OperationResult result = new OperationResult("loadLookupTable");

// GetOperationOptions retrieveOption = GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE);
// Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(retrieveOption);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
final PrismObject<LookupTableType> lookupTable = WebModelUtils.loadObject(LookupTableType.class,
lookupTableUid, options, result, pageBase);

inputPanel = new AutoCompleteTextPanel<String>(id, new PropertyModel<String>(model, baseExpression + ".orig"), String.class) {

@Override
public Iterator<String> getIterator(String input) {
return prepareAutoCompleteList(input, lookupTable).iterator();
}
};

} else {
inputPanel = new TextPanel<>(id, new PropertyModel<String>(model, baseExpression + ".orig"), String.class);
}

if (ObjectType.F_NAME.equals(def.getName()) || UserType.F_FULL_NAME.equals(def.getName())) {
inputPanel.getBaseFormComponent().setRequired(true);
}
Expand Down Expand Up @@ -471,19 +489,75 @@ public DeltaDto getObject() {
}

if (isEnum(property)) {
return WebMiscUtil.createEnumPanel(definition, id, new PropertyModel<>(model, baseExpression), this);

return WebMiscUtil.createEnumPanel(definition, id, new PropertyModel<>(model, baseExpression), this);
}
// // default QName validation is a bit weird, so let's treat QNames as strings [TODO finish this - at the parsing side]
// if (type == QName.class) {
// type = String.class;
// }
panel = new TextPanel<>(id, new PropertyModel<String>(model, baseExpression), type);

PrismPropertyDefinition def = property.getDefinition();

if(def.getValueEnumerationRef() != null){
PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
String lookupTableUid = valueEnumerationRef.getOid();
OperationResult result = new OperationResult("loadLookupTable");

// GetOperationOptions retrieveOption = GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE);
// Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(retrieveOption);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
final PrismObject<LookupTableType> lookupTable = WebModelUtils.loadObject(LookupTableType.class,
lookupTableUid, options, result, pageBase);

panel = new AutoCompleteTextPanel<String>(id, new PropertyModel<String>(model, baseExpression), type) {

@Override
public Iterator<String> getIterator(String input) {
return prepareAutoCompleteList(input, lookupTable).iterator();
}
};

} else {
panel = new TextPanel<>(id, new PropertyModel<String>(model, baseExpression), type);
}
}

return panel;
}

private List<String> prepareAutoCompleteList(String input, PrismObject<LookupTableType> lookupTable){
List<String> values = new ArrayList<>();

if(lookupTable == null){
return values;
}

List<LookupTableRowType> rows = lookupTable.asObjectable().getRow();

if(input == null || input.isEmpty()){
for(LookupTableRowType row: rows){
values.add(WebMiscUtil.getOrigStringFromPoly(row.getLabel()));

if(values.size() > 10){
return values;
}
}
} else {
for(LookupTableRowType row: rows){
if(WebMiscUtil.getOrigStringFromPoly(row.getLabel()).startsWith(input)){
values.add(WebMiscUtil.getOrigStringFromPoly(row.getLabel()));
}

if(values.size() > 10){
return values;
}
}
}

return values;
}

private boolean isEnum(PrismProperty property){
PrismPropertyDefinition definition = property.getDefinition();
//// Object realValue = property.getAnyRealValue();
Expand Down
Expand Up @@ -99,7 +99,7 @@ private void initLayout() {
form.setOutputMarkupId(true);
add(form);

final PrismObjectPanel configuration = new PrismObjectPanel(ID_CONFIGURATION, configurationProperties, null, null);
final PrismObjectPanel configuration = new PrismObjectPanel(ID_CONFIGURATION, configurationProperties, null, null, getPageBase());
form.add(configuration);

AjaxSubmitButton testConnection = new AjaxSubmitButton(ID_TEST_CONNECTION,
Expand Down

0 comments on commit 1ffb615

Please sign in to comment.