Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Dec 13, 2014
2 parents 458cbb9 + 47dbd04 commit ccf7e7a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 45 deletions.
Expand Up @@ -21,6 +21,7 @@
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
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.WebMarkupContainer;
import org.apache.wicket.markup.html.list.ListItem;
Expand Down Expand Up @@ -77,30 +78,14 @@ private void initLayout(final boolean inputEnabled, boolean prepareModel){
@Override
protected void populateItem(final ListItem<T> item) {

AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
autoCompleteSettings.setShowListOnEmptyInput(true);
AutoCompleteTextField<String> autoCompleteEditor = new AutoCompleteTextField<String>(ID_TEXT,
createTextModel(item.getModel())) {
createTextModel(item.getModel()), autoCompleteSettings) {

@Override
protected Iterator<String> getChoices(String input) {
if(Strings.isEmpty(input)){
List<String> emptyList = Collections.emptyList();
return emptyList.iterator();
}

List<T> list = createObjectList();
List<String> choices = new ArrayList<>(AUTO_COMPLETE_LIST_SIZE);

for(T object: list){
if(createAutoCompleteObjectLabel(object).toLowerCase().startsWith(input.toLowerCase())){
choices.add(createAutoCompleteObjectLabel(object));

if(choices.size() == AUTO_COMPLETE_LIST_SIZE){
break;
}
}
}

return choices.iterator();
return createAutocompleteObjectList(input);
}
};
autoCompleteEditor.add(createAutoCompleteValidator());
Expand All @@ -121,6 +106,35 @@ protected Iterator<String> getChoices(String input) {
add(repeater);
}

private Iterator<String> createAutocompleteObjectList(String input) {
List<T> list = createObjectList();
List<String> choices = new ArrayList<>(AUTO_COMPLETE_LIST_SIZE);

if(Strings.isEmpty(input)){
for(T object: list){
choices.add(createAutoCompleteObjectLabel(object));

if(choices.size() == AUTO_COMPLETE_LIST_SIZE){
break;
}
}

return choices.iterator();
}

for(T object: list){
if(createAutoCompleteObjectLabel(object).toLowerCase().startsWith(input.toLowerCase())){
choices.add(createAutoCompleteObjectLabel(object));

if(choices.size() == AUTO_COMPLETE_LIST_SIZE){
break;
}
}
}

return choices.iterator();
}

private void initButtons(WebMarkupContainer buttonGroup, final ListItem<T> item) {
AjaxLink add = new AjaxLink(ID_ADD) {

Expand Down
Expand Up @@ -20,6 +20,8 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.DiffUtil;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.logging.LoggingUtils;
Expand All @@ -45,6 +47,8 @@
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import java.util.Collection;

/**
* @author lazyman
*/
Expand All @@ -61,10 +65,13 @@ public class ConfigurationStep extends WizardStep {
private static final String ID_TEST_CONNECTION = "testConnection";

private IModel<PrismObject<ResourceType>> resourceModel;
private boolean isNewResource;
private IModel<ObjectWrapper> configurationProperties;

public ConfigurationStep(IModel<PrismObject<ResourceType>> resourceModel) {
public ConfigurationStep(IModel<PrismObject<ResourceType>> resourceModel, boolean isNewResource) {
this.resourceModel = resourceModel;
this.isNewResource = isNewResource;

this.configurationProperties = new LoadableModel<ObjectWrapper>(false) {

@Override
Expand Down Expand Up @@ -155,8 +162,14 @@ private void saveChanges() {

page.getPrismContext().adopt(newResource);

PrismObject<ResourceType> oldResource = WebModelUtils.loadObject(ResourceType.class, newResource.getOid(),
result, page);
PrismObject<ResourceType> oldResource;

if(isNewResource){
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
oldResource = WebModelUtils.loadObject(ResourceType.class, newResource.getOid(), options, result, page);
} else {
oldResource = WebModelUtils.loadObject(ResourceType.class, newResource.getOid(), result, page);
}

delta = DiffUtil.diff(oldResource, newResource);

Expand Down
Expand Up @@ -45,6 +45,7 @@
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.behavior.AttributeAppender;
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.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
Expand Down Expand Up @@ -337,30 +338,14 @@ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
addDisabledClassModifier(editorDependency);
editor.add(editorDependency);

AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
autoCompleteSettings.setShowListOnEmptyInput(true);
AutoCompleteTextField<String> editorObjectClass = new AutoCompleteTextField<String>(ID_EDITOR_OBJECT_CLASS,
new PropertyModel<String>(model, SchemaHandlingDto.F_SELECTED_OBJECT_CLASS)) {
new PropertyModel<String>(model, SchemaHandlingDto.F_SELECTED_OBJECT_CLASS), autoCompleteSettings) {

@Override
protected Iterator<String> getChoices(String input) {
if(Strings.isEmpty(input)){
List<String> emptyList = Collections.emptyList();
return emptyList.iterator();
}

List<QName> resourceObjectClassList = model.getObject().getObjectClassList();
List<String> choices = new ArrayList<>(AUTO_COMPLETE_LIST_SIZE);

for(QName q: resourceObjectClassList){
if(q.getLocalPart().toLowerCase().startsWith(input.toLowerCase())){
choices.add(q.getLocalPart());

if(choices.size() == AUTO_COMPLETE_LIST_SIZE){
break;
}
}
}

return choices.iterator();
return getObjectClassChoices(input);
}
};
editorObjectClass.add(createObjectClassValidator(new LoadableModel<List<QName>>(false) {
Expand Down Expand Up @@ -556,6 +541,35 @@ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
editor.add(credentialsTooltip);
}

private Iterator<String> getObjectClassChoices(String input) {
List<QName> resourceObjectClassList = model.getObject().getObjectClassList();
List<String> choices = new ArrayList<>(AUTO_COMPLETE_LIST_SIZE);

if(Strings.isEmpty(input)){
for(QName q: resourceObjectClassList){
choices.add(q.getLocalPart());

if(choices.size() == AUTO_COMPLETE_LIST_SIZE){
break;
}
}

return choices.iterator();
}

for(QName q: resourceObjectClassList){
if(q.getLocalPart().toLowerCase().startsWith(input.toLowerCase())){
choices.add(q.getLocalPart());

if(choices.size() == AUTO_COMPLETE_LIST_SIZE){
break;
}
}
}

return choices.iterator();
}

private void addDisabledClassModifier(Component component){
component.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {

Expand Down
Expand Up @@ -54,10 +54,15 @@ public class PageResourceWizard extends PageAdminResources {
private static final String ID_WIZARD = "wizard";
private IModel<PrismObject<ResourceType>> model;
private PageParameters parameters;
private boolean isNewResource;

public PageResourceWizard(PageParameters parameters) {
this.parameters = parameters;

if(!isResourceOidAvailable()){
isNewResource = true;
}

model = new LoadableModel<PrismObject<ResourceType>>(false) {

@Override
Expand All @@ -66,7 +71,6 @@ protected PrismObject<ResourceType> load() {
if (!isResourceOidAvailable()) {
ResourceType resource = new ResourceType();
PageResourceWizard.this.getPrismContext().adopt(resource);

return resource.asPrismObject();
}

Expand Down Expand Up @@ -140,7 +144,7 @@ protected String load() {
private void initLayout() {
WizardModel wizardModel = new WizardModel();
wizardModel.add(new NameStep(model));
wizardModel.add(new ConfigurationStep(model));
wizardModel.add(new ConfigurationStep(model, isNewResource));
wizardModel.add(new SchemaStep(model));
wizardModel.add(new SchemaHandlingStep(model));
wizardModel.add(new CapabilityStep(model));
Expand Down

0 comments on commit ccf7e7a

Please sign in to comment.