Skip to content

Commit

Permalink
search item fragments almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Aug 18, 2015
1 parent 5691957 commit 32bff1a
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 7 deletions.
@@ -1,6 +1,9 @@
package com.evolveum.midpoint.web.component.search;

import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismReferenceDefinition;
import com.evolveum.midpoint.util.DOMUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;

Expand All @@ -11,20 +14,27 @@
*/
public class SearchItem<T extends Serializable> implements Serializable {

public static final String F_VALUE = "value";
public static final String F_DISPLAY_VALUE = "displayValue";

public enum Type {
TEXT, BOOLEAN, ENUM, BROWSER
}

private Search search;

private Type type;
private ItemDefinition definition;
private T value;
private String displayValue;

public SearchItem(Search search, ItemDefinition definition) {
Validate.notNull(definition, "Item definition must not be null.");

if (!(definition instanceof PrismPropertyDefinition)
&& !(definition instanceof PrismReferenceDefinition)) {
throw new IllegalArgumentException("Unknown item definition type '" + definition + "'");
}

this.search = search;
this.definition = definition;
}
Expand All @@ -43,7 +53,20 @@ public String getName() {
}

public Type getType() {
return type;
if (definition instanceof PrismReferenceDefinition) {
return Type.BROWSER;
}

PrismPropertyDefinition def = (PrismPropertyDefinition) definition;
if (def.getAllowedValues() != null && !def.getAllowedValues().isEmpty()) {
return Type.ENUM;
}

if (DOMUtil.XSD_BOOLEAN.equals(def.getTypeName())) {
return Type.BOOLEAN;
}

return Type.TEXT;
}

public T getValue() {
Expand Down
Expand Up @@ -29,7 +29,7 @@
<div wicket:id="popover" class="popover fade bottom in">
<div class="arrow"></div>
<div class="popover-content">
<input wicket:id="text" type="text" class="form-control input-sm" style="width: auto;" size="25">
<div wicket:id="content"/>

<p style="margin: 0px; padding-top: 7px;">
<a wicket:id="update" class="btn btn-sm btn-success"/>
Expand All @@ -39,5 +39,25 @@
</div>
</wicket:panel>

<wicket:fragment wicket:id="text">
<input wicket:id="textInput" type="text" class="form-control input-sm" style="width: auto;" size="20">
</wicket:fragment>

<wicket:fragment wicket:id="combo">
<select wicket:id="comboInput" class="form-control input-sm" style="width: auto;"/>
</wicket:fragment>

<!--<wicket:fragment wicket:id="browser">-->
<!--<div class="form-group"></div>-->
<!--<div class="input-group input-group-sm">-->
<!--<input wicket:id="browserInput" type="text" class="form-control" style="width: auto;" size="20" disabled="true">-->
<!--<span class="input-group-btn">-->
<!--<a wicket:id="browse" class="btn btn-primary">-->
<!--<i class="fa fa-pencil-square-o"/>-->
<!--</a>-->
<!--</span>-->
<!--</div>-->
<!--</wicket:fragment>-->

</body>
</html>
Expand Up @@ -6,17 +6,25 @@
import com.evolveum.midpoint.web.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.component.util.BaseSimplePanel;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
* @author Viliam Repan (lazyman)
Expand All @@ -29,10 +37,16 @@ public class SearchItemPanel extends BaseSimplePanel<SearchItem> {
private static final String ID_LABEL = "label";
private static final String ID_DELETE_BUTTON = "deleteButton";
private static final String ID_POPOVER = "popover";
private static final String ID_TEXT = "text";
private static final String ID_UPDATE = "update";
private static final String ID_CLOSE = "close";

private static final String ID_CONTENT = "content";
private static final String ID_TEXT = "text";
private static final String ID_TEXT_INPUT = "textInput";
private static final String ID_COMBO = "combo";
private static final String ID_COMBO_INPUT = "comboInput";
private static final String ID_BROWSER = "browser";
private static final String ID_BROWSER_INPUT = "browserInput";
private static final String ID_BROWSE = "browse";

public SearchItemPanel(String id, IModel<SearchItem> model) {
super(id, model);
Expand Down Expand Up @@ -69,8 +83,9 @@ private void initPopover() {
popover.setOutputMarkupId(true);
add(popover);

TextField value = new TextField(ID_TEXT, new Model());
popover.add(value);
Fragment fragment = createPopoverFragment();
fragment.setRenderBodyOnly(true);
popover.add(fragment);

AjaxSubmitButton add = new AjaxSubmitButton(ID_UPDATE, createStringResource("SearchItemPanel.update")) {

Expand All @@ -97,6 +112,38 @@ public void onClick(AjaxRequestTarget target) {
popover.add(close);
}

private Fragment createPopoverFragment() {
Fragment fragment;
SearchItem item = getModelObject();

IModel value = new PropertyModel(getModel(), SearchItem.F_VALUE);
IModel<? extends List> choices = null;

// todo implement
switch (item.getType()) {
case BROWSER:
fragment = new BrowserFragment(ID_CONTENT, ID_BROWSER, this, value);
break;
case BOOLEAN:
//todo create choices model
case ENUM:
if (choices == null) {
//todo create choices model
List l = new ArrayList();
l.add("a");
l.add("b");
choices = new Model((Serializable) l);
}
fragment = new ComboFragment(ID_CONTENT, ID_COMBO, this, value, choices);
break;
case TEXT:
default:
fragment = new TextFragment(ID_CONTENT, ID_TEXT, this, value);
}

return fragment;
}

@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
Expand Down Expand Up @@ -161,4 +208,50 @@ private void deletePerformed(AjaxRequestTarget target) {
SearchPanel panel = findParent(SearchPanel.class);
panel.refreshForm(target);
}

private static class TextFragment<T extends Serializable> extends Fragment {

public TextFragment(String id, String markupId, MarkupContainer markupProvider,
IModel<T> value) {
super(id, markupId, markupProvider);

TextField input = new TextField(ID_TEXT_INPUT, value);
add(input);
}
}

private static class ComboFragment<T extends Serializable> extends Fragment {

public ComboFragment(String id, String markupId, MarkupContainer markupProvider,
IModel<T> value, IModel<List<T>> choices) {
super(id, markupId, markupProvider);

DropDownChoice input = new DropDownChoice(ID_COMBO_INPUT, value, choices);
add(input);
}
}

private static class BrowserFragment<T extends Serializable> extends Fragment {

public BrowserFragment(String id, String markupId, MarkupContainer markupProvider,
IModel<T> value) {
super(id, markupId, markupProvider);

TextField input = new TextField(ID_BROWSER_INPUT, value);
add(input);

AjaxLink browse = new AjaxLink(ID_BROWSE) {

@Override
public void onClick(AjaxRequestTarget target) {
browsePerformed(target);
}
};
add(browse);
}

private void browsePerformed(AjaxRequestTarget target) {
//todo implement
}
}
}

0 comments on commit 32bff1a

Please sign in to comment.