Skip to content

Commit

Permalink
Reworking QName editor and working with association and attribute ref…
Browse files Browse the repository at this point in the history
…erences in RW.
  • Loading branch information
Erik Suta committed Dec 17, 2014
1 parent b7a0f58 commit eaa7340
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 127 deletions.
Expand Up @@ -20,18 +20,18 @@

<dl class="dl-horizontal">
<dt>
<label><wicket:message key="QNameEditor.label.attribute" /></label>
<i wicket:id="attributeTooltip" wicket:message="title:QNameEditor.tooltip.attribute"/>
<label wicket:id="localPartLabel"></label>
<i wicket:id="localPartTooltip" />
</dt>
<dd>
<input wicket:id="attribute" type="text" class="form-control input-sm"/>
<input wicket:id="localPart" type="text" class="form-control input-sm"/>
</dd>
</dl>

<dl class="dl-horizontal">
<dt>
<label><wicket:message key="QNameEditor.label.namespace" /></label>
<i wicket:id="namespaceTooltip" wicket:message="title:QNameEditor.tooltip.namespace"/>
<label wicket:id="namespaceLabel"></label>
<i wicket:id="namespaceTooltip" />
</dt>
<dd>
<select wicket:id="namespace" class="form-control input-sm"></select>
Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
Expand All @@ -33,13 +34,23 @@
* */
public class QNameEditorPanel extends SimplePanel<QName>{

private static final String ID_ATTRIBUTE = "attribute";
private static final String ID_LOCAL_PART = "localPart";
private static final String ID_NAMESPACE = "namespace";
private static final String ID_T_ATTRIBUTE = "attributeTooltip";
private static final String ID_LOCAL_PART_LABEL = "localPartLabel";
private static final String ID_NAMESPACE_LABEL = "namespaceLabel";
private static final String ID_T_LOCAL_PART = "localPartTooltip";
private static final String ID_T_NAMESPACE = "namespaceTooltip";

public QNameEditorPanel(String id, IModel<QName> model){
this(id, model, "QNameEditor.label.localPart", "QNameEditor.tooltip.localPart",
"QNameEditor.label.namespace", "QNameEditor.tooltip.namespace");
}

public QNameEditorPanel(String id, IModel<QName> model, String localPartLabelKey, String localPartTooltipKey,
String namespaceLabelKey, String namespaceTooltipKey){
super(id, model);

initLayout(localPartLabelKey, localPartTooltipKey, namespaceLabelKey, namespaceTooltipKey);
}

@Override
Expand All @@ -54,14 +65,24 @@ public IModel<QName> getModel() {
return model;
}

@Override
protected void initLayout(){
protected void initLayout(String localPartLabelKey, String localPartTooltipKey,
String namespaceLabelKey, String namespaceTooltipKey){

TextField attribute = new TextField<>(ID_ATTRIBUTE, new PropertyModel<String>(getModel(), "localPart"));
attribute.setOutputMarkupId(true);
attribute.setOutputMarkupPlaceholderTag(true);
attribute.setRequired(true);
add(attribute);
Label localPartLabel = new Label(ID_LOCAL_PART_LABEL, getString(localPartLabelKey));
localPartLabel.setOutputMarkupId(true);
localPartLabel.setOutputMarkupPlaceholderTag(true);
add(localPartLabel);

Label namespaceLabel = new Label(ID_NAMESPACE_LABEL, getString(namespaceLabelKey));
namespaceLabel.setOutputMarkupId(true);
namespaceLabel.setOutputMarkupPlaceholderTag(true);
add(namespaceLabel);

TextField localPart = new TextField<>(ID_LOCAL_PART, new PropertyModel<String>(getModel(), "localPart"));
localPart.setOutputMarkupId(true);
localPart.setOutputMarkupPlaceholderTag(true);
localPart.setRequired(isLocalPartRequired());
add(localPart);

DropDownChoice namespace = new DropDownChoice<>(ID_NAMESPACE, new PropertyModel<String>(getModel(), "namespaceURI"),
prepareNamespaceList());
Expand All @@ -71,17 +92,23 @@ protected void initLayout(){
namespace.setRequired(true);
add(namespace);

Label attrTooltip = new Label(ID_T_ATTRIBUTE);
attrTooltip.add(new InfoTooltipBehavior());
attrTooltip.setOutputMarkupPlaceholderTag(true);
add(attrTooltip);
Label localPartTooltip = new Label(ID_T_LOCAL_PART);
localPartTooltip.add(new AttributeAppender("data-original-title", getString(localPartTooltipKey)));
localPartTooltip.add(new InfoTooltipBehavior());
localPartTooltip.setOutputMarkupPlaceholderTag(true);
add(localPartTooltip);

Label namespaceTooltip = new Label(ID_T_NAMESPACE);
namespaceTooltip.add(new AttributeAppender("data-original-title", getString(namespaceTooltipKey)));
namespaceTooltip.add(new InfoTooltipBehavior());
namespaceTooltip.setOutputMarkupPlaceholderTag(true);
add(namespaceTooltip);
}

/**
* Override to provide custom list of namespaces
* for QName editor
* */
protected List<String> prepareNamespaceList(){
List<String> list = new ArrayList<>();

Expand All @@ -93,7 +120,10 @@ protected List<String> prepareNamespaceList(){
return list;
}

// public boolean isRequired(){
// return false;
// }
/**
* Should localPart of QName be required?
* */
public boolean isLocalPartRequired(){
return false;
}
}
Expand Up @@ -14,5 +14,17 @@
# limitations under the License.
#

QNameEditor.label.attribute=Ref. attribute
QNameEditor.label.namespace=Ref. namespace
QNameEditor.label.localPart=Local part name
QNameEditor.label.namespace=Namespace
QNameEditor.tooltip.localPart=Local part of QName
QNameEditor.tooltip.namespace=Namespace of QName

SchemaHandlingStep.attribute.label.attributeName=Attribute name
SchemaHandlingStep.attribute.label.attributeNamespace=Attribute namespace
SchemaHandlingStep.attribute.tooltip.attributeLocalPart=TODO: SchemaHandlingStep.attribute.tooltip.attributeLocalPart
SchemaHandlingStep.attribute.tooltip.attributeNamespace=TODO: SchemaHandlingStep.attribute.tooltip.attributeNamespace

SchemaHandlingStep.association.label.associationName=Association name
SchemaHandlingStep.association.label.associationNamespace=Association namespace
SchemaHandlingStep.association.tooltip.associationLocalPart=TODO: SchemaHandlingStep.association.tooltip.associationLocalPart
SchemaHandlingStep.association.tooltip.associationNamespace=TODO: SchemaHandlingStep.association.tooltip.associationNamespace
Expand Up @@ -115,27 +115,7 @@ <h4 class="panel-title">
<div id="other" class="panel-collapse collapse in">
<div class="panel-body">

<dl wicket:id="schemaRefPanel" class="dl-horizontal">
<dt>
<label><wicket:message key="ResourceAssociationEditor.label.reference" /></label>
<i wicket:id="referenceTooltip" wicket:message="title:SchemaHandlingStep.attribute.tooltip.reference"/>
</dt>
<dd>
<select wicket:id="referenceSelect" class="form-control input-sm"></select>
</dd>
</dl>

<div wicket:id="nonSchemaReferencePanel" />

<dl class="dl-horizontal">
<dt>
<label><wicket:message key="ResourceAssociationEditor.label.allow" /></label>
<i wicket:id="allowTooltip" wicket:message="title:SchemaHandlingStep.attribute.tooltip.allow"/>
</dt>
<dd>
<input wicket:id="allowRef" type="checkbox" value="checked"/>
</dd>
</dl>
<div wicket:id="associationAttributePanel" />

<dl class="dl-horizontal">
<dt>
Expand Down
Expand Up @@ -29,7 +29,6 @@
import com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextPanel;
import com.evolveum.midpoint.web.component.input.QNameEditorPanel;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.component.wizard.resource.component.schemahandling.modal.LimitationsEditorDialog;
import com.evolveum.midpoint.web.component.wizard.resource.component.schemahandling.modal.MappingEditorDialog;
import com.evolveum.midpoint.web.component.wizard.resource.dto.MappingTypeDto;
Expand All @@ -39,10 +38,8 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.*;
import org.apache.wicket.model.AbstractReadOnlyModel;
Expand Down Expand Up @@ -71,10 +68,7 @@ public class ResourceAssociationEditor extends SimplePanel<ResourceObjectAssocia
private static final String ID_VALUE_ATTRIBUTE = "valueAttribute";
private static final String ID_EXPLICIT_REF_INTEGRITY = "explicitRefIntegrity";

private static final String ID_SCHEMA_REF_PANEL = "schemaRefPanel";
private static final String ID_NON_SCHEMA_REF_PANEL = "nonSchemaReferencePanel";
private static final String ID_REFERENCE_SELECT = "referenceSelect";
private static final String ID_REFERENCE_ALLOW = "allowRef";
private static final String ID_ASSOCIATION_ATTRIBUTE_PANEL = "associationAttributePanel";
private static final String ID_DISPLAY_NAME = "displayName";
private static final String ID_DESCRIPTION = "description";
private static final String ID_EXCLUSIVE_STRONG = "exclusiveStrong";
Expand All @@ -90,8 +84,6 @@ public class ResourceAssociationEditor extends SimplePanel<ResourceObjectAssocia
private static final String ID_MODAL_LIMITATIONS = "limitationsEditor";
private static final String ID_MODAL_MAPPING = "mappingEditor";

private static final String ID_T_REF = "referenceTooltip";
private static final String ID_T_ALLOW = "allowTooltip";
private static final String ID_T_LIMITATIONS = "limitationsTooltip";
private static final String ID_T_EXCLUSIVE_STRONG = "exclusiveStrongTooltip";
private static final String ID_T_TOLERANT = "tolerantTooltip";
Expand All @@ -110,7 +102,6 @@ public class ResourceAssociationEditor extends SimplePanel<ResourceObjectAssocia

private PrismObject<ResourceType> resource;
private ResourceObjectTypeDefinitionType objectType;
private boolean nonSchemaRefValueAllowed = false;

public ResourceAssociationEditor(String id, IModel<ResourceObjectAssociationType> model,
ResourceObjectTypeDefinitionType objectType, PrismObject<ResourceType> resource){
Expand Down Expand Up @@ -205,78 +196,13 @@ public String getIdValue(QName object, int index) {
new PropertyModel<Boolean>(getModel(), "explicitReferentialIntegrity"));
add(explicitRefIntegrity);

QNameEditorPanel nonSchemaRefPanel = new QNameEditorPanel(ID_NON_SCHEMA_REF_PANEL, new PropertyModel<QName>(getModel(), "ref"));

QNameEditorPanel nonSchemaRefPanel = new QNameEditorPanel(ID_ASSOCIATION_ATTRIBUTE_PANEL, new PropertyModel<QName>(getModel(), "ref"),
"SchemaHandlingStep.association.label.associationName", "SchemaHandlingStep.association.tooltip.associationLocalPart",
"SchemaHandlingStep.association.label.associationNamespace", "SchemaHandlingStep.association.tooltip.associationNamespace");
nonSchemaRefPanel.setOutputMarkupId(true);
nonSchemaRefPanel.setOutputMarkupPlaceholderTag(true);
nonSchemaRefPanel.add(new VisibleEnableBehaviour(){

@Override
public boolean isVisible() {
return nonSchemaRefValueAllowed;
}
});
add(nonSchemaRefPanel);

WebMarkupContainer schemaRefPanel = new WebMarkupContainer(ID_SCHEMA_REF_PANEL);
schemaRefPanel.setOutputMarkupId(true);
schemaRefPanel.setOutputMarkupPlaceholderTag(true);
schemaRefPanel.add(new VisibleEnableBehaviour(){

@Override
public boolean isVisible() {
return !nonSchemaRefValueAllowed;
}
});
add(schemaRefPanel);

Label refTooltip = new Label(ID_T_REF);
refTooltip.add(new InfoTooltipBehavior());
refTooltip.setOutputMarkupId(true);
refTooltip.setOutputMarkupId(true);
schemaRefPanel.add(refTooltip);

DropDownChoice refSelect = new DropDownChoice<>(ID_REFERENCE_SELECT, new PropertyModel<QName>(getModel(), "ref"),
new AbstractReadOnlyModel<List<QName>>() {

@Override
public List<QName> getObject() {
return loadObjectReferences(true);
}
}, new IChoiceRenderer<QName>() {

@Override
public Object getDisplayValue(QName object) {
return prepareReferenceDisplayValue(object);
}

@Override
public String getIdValue(QName object, int index) {
return Integer.toString(index);
}
});
refSelect.setOutputMarkupId(true);
refSelect.setOutputMarkupPlaceholderTag(true);
refSelect.add(new VisibleEnableBehaviour(){

@Override
public boolean isVisible() {
return !nonSchemaRefValueAllowed;
}

});
schemaRefPanel.add(refSelect);

CheckBox allowNonSchema = new CheckBox(ID_REFERENCE_ALLOW, new PropertyModel<Boolean>(this, "nonSchemaRefValueAllowed"));
allowNonSchema.add(new AjaxFormComponentUpdatingBehavior("onchange") {

@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(get(ID_SCHEMA_REF_PANEL), get(ID_NON_SCHEMA_REF_PANEL));
}
});
add(allowNonSchema);

TextField displayName = new TextField<>(ID_DISPLAY_NAME, new PropertyModel<String>(getModel(), "displayName"));
add(displayName);

Expand Down Expand Up @@ -417,10 +343,6 @@ protected void editPerformed(AjaxRequestTarget target, MappingType object){
integrityTooltip.add(new InfoTooltipBehavior());
add(integrityTooltip);

Label allowTooltip = new Label(ID_T_ALLOW);
allowTooltip.add(new InfoTooltipBehavior());
add(allowTooltip);

Label limitationsTooltip = new Label(ID_T_LIMITATIONS);
limitationsTooltip.add(new InfoTooltipBehavior());
add(limitationsTooltip);
Expand Down
Expand Up @@ -122,7 +122,9 @@ public String getObject() {
});
add(label);

QNameEditorPanel nonSchemaRefPanel = new QNameEditorPanel(ID_NON_SCHEMA_REF_PANEL, new PropertyModel<QName>(getModel(), "ref"));
QNameEditorPanel nonSchemaRefPanel = new QNameEditorPanel(ID_NON_SCHEMA_REF_PANEL, new PropertyModel<QName>(getModel(), "ref"),
"SchemaHandlingStep.attribute.label.attributeName", "SchemaHandlingStep.attribute.tooltip.attributeLocalPart",
"SchemaHandlingStep.attribute.label.attributeNamespace", "SchemaHandlingStep.attribute.tooltip.attributeNamespace");

nonSchemaRefPanel.setOutputMarkupId(true);
nonSchemaRefPanel.setOutputMarkupPlaceholderTag(true);
Expand Down

0 comments on commit eaa7340

Please sign in to comment.