Skip to content

Commit

Permalink
AceEditor in RW.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jun 9, 2016
1 parent 4f330b9 commit cd0d83c
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 10 deletions.
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<span class="control-label" wicket:id="labelContainer">
<label wicket:id="label"/>
<i wicket:id="tooltip"/>
</span>

<div wicket:id="textWrapper">
<textarea class="form-control input-sm" rows="2" wicket:id="text"></textarea>
</div>
</wicket:panel>
</html>
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2010-2016 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.form;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.web.component.AceEditor;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

/**
* @author lazyman
*/
public class AceEditorFormGroup extends BasePanel<String> {

private static final String ID_TEXT = "text";
private static final String ID_TEXT_WRAPPER = "textWrapper";
private static final String ID_LABEL_CONTAINER = "labelContainer";
private static final String ID_LABEL = "label";
private static final String ID_TOOLTIP = "tooltip";

private static final int DEFAULT_NUMBER_OF_ROWS = 2;

public AceEditorFormGroup(String id, IModel<String> value, IModel<String> label, String labelSize, String textSize) {
this(id, value, label, labelSize, textSize, false);
}

public AceEditorFormGroup(String id, IModel<String> value, IModel<String> label, String labelSize, String textSize,
boolean required) {
this(id, value, label, labelSize, textSize, required, DEFAULT_NUMBER_OF_ROWS);
}

public AceEditorFormGroup(String id, IModel<String> value, IModel<String> label, String labelSize, String textSize,
boolean required, int rowNumber){
this(id, value, label, null, false, labelSize, textSize, required, rowNumber);
}

public AceEditorFormGroup(String id, IModel<String> value, IModel<String> label, String tooltipKey,
boolean isTooltipInModal, String labelSize, String textSize, boolean required, int rowNumber){
super(id, value);

initLayout(label, tooltipKey, isTooltipInModal, labelSize, textSize, required, rowNumber);
}

private void initLayout(IModel<String> label, final String tooltipKey, boolean isTooltipInModal, String labelSize,
String textSize, boolean required, int rowNumber) {
WebMarkupContainer labelContainer = new WebMarkupContainer(ID_LABEL_CONTAINER);
add(labelContainer);

Label l = new Label(ID_LABEL, label);
if (StringUtils.isNotEmpty(labelSize)) {
labelContainer.add(AttributeAppender.prepend("class", labelSize));
}
labelContainer.add(l);

Label tooltipLabel = new Label(ID_TOOLTIP, new Model<>());
tooltipLabel.add(new AttributeAppender("data-original-title", new AbstractReadOnlyModel<String>() {

@Override
public String getObject() {
return getString(tooltipKey);
}
}));
tooltipLabel.add(new InfoTooltipBehavior(isTooltipInModal));
tooltipLabel.add(new VisibleEnableBehaviour() {

@Override
public boolean isVisible() {
return tooltipKey != null;
}
});
tooltipLabel.setOutputMarkupId(true);
tooltipLabel.setOutputMarkupPlaceholderTag(true);
labelContainer.add(tooltipLabel);

WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
if (StringUtils.isNotEmpty(textSize)) {
textWrapper.add(AttributeAppender.prepend("class", textSize));
}
add(textWrapper);

AceEditor text = new AceEditor(ID_TEXT, getModel());
text.add(new AttributeModifier("rows", rowNumber));
text.setOutputMarkupId(true);
text.setRequired(required);
text.setLabel(label);
text.add(AttributeAppender.replace("placeholder", label));
textWrapper.add(text);
}

public void setRows(int rows) {
TextArea area = (TextArea) get(createComponentPath(ID_TEXT_WRAPPER, ID_TEXT));
area.add(AttributeModifier.replace("rows", rows));
}
}
Expand Up @@ -23,6 +23,7 @@
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AceEditor;
import com.evolveum.midpoint.web.component.input.dto.ExpressionTypeDto;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.resources.PageResourceWizard;
Expand Down Expand Up @@ -100,6 +101,8 @@ protected ExpressionTypeDto load() {
protected void initLayout(PageResourceWizard parentPage) {
parentPage.addEditingEnabledBehavior(this);

setOutputMarkupId(true);

loadDtoModel();

Label descriptionLabel = new Label(ID_LABEL_DESCRIPTION, createStringResource(getDescriptionLabelKey()));
Expand All @@ -123,7 +126,8 @@ protected void initLayout(PageResourceWizard parentPage) {
@Override
protected void onUpdate(AjaxRequestTarget target) {
dtoModel.getObject().updateExpressionType();
target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
//target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
target.add(ExpressionEditorPanel.this); // because of ACE editor
}
});
type.setOutputMarkupId(true);
Expand Down Expand Up @@ -154,7 +158,8 @@ public boolean isVisible(){
@Override
protected void onUpdate(AjaxRequestTarget target) {
dtoModel.getObject().updateExpressionLanguage();
target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
//target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
target.add(ExpressionEditorPanel.this); // because of ACE editor
}
});
language.setNullValid(false);
Expand Down Expand Up @@ -196,7 +201,7 @@ protected void onUpdate(AjaxRequestTarget target) {
Label expressionLabel = new Label(ID_LABEL_EXPRESSION, createStringResource(getExpressionLabelKey()));
add(expressionLabel);

TextArea expression = new TextArea<>(ID_EXPRESSION, new PropertyModel<String>(dtoModel, ExpressionTypeDto.F_EXPRESSION));
AceEditor expression = new AceEditor(ID_EXPRESSION, new PropertyModel<String>(dtoModel, ExpressionTypeDto.F_EXPRESSION));
expression.setOutputMarkupId(true);
//parentPage.addEditingEnabledBehavior(expression);
add(expression);
Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AceEditor;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -88,7 +89,7 @@ protected void initLayout(NonEmptyModel<Boolean> readOnlyModel) {
description.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
add(description);

TextArea<String> clause = new TextArea<>(ID_FILTER_CLAUSE, clauseStringModel);
AceEditor clause = new AceEditor(ID_FILTER_CLAUSE, clauseStringModel);
clause.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
add(clause);

Expand Down
Expand Up @@ -23,6 +23,7 @@

import com.evolveum.midpoint.gui.api.model.NonEmptyModel;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.web.component.form.*;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
Expand Down Expand Up @@ -52,10 +53,6 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.component.form.CheckFormGroup;
import com.evolveum.midpoint.web.component.form.DropDownFormGroup;
import com.evolveum.midpoint.web.component.form.TextAreaFormGroup;
import com.evolveum.midpoint.web.component.form.TextFormGroup;
import com.evolveum.midpoint.web.component.form.multivalue.MultiValueDropDownPanel;
import com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextPanel;
import com.evolveum.midpoint.web.component.input.ObjectReferenceChoiceRenderer;
Expand Down Expand Up @@ -395,7 +392,7 @@ protected void onUpdate(AjaxRequestTarget target) {
});
form.add(expressionGeneratePolicy);

TextAreaFormGroup expression = new TextAreaFormGroup(ID_EXPRESSION,
AceEditorFormGroup expression = new AceEditorFormGroup(ID_EXPRESSION,
new PropertyModel<String>(model, MappingTypeDto.F_EXPRESSION),
createStringResource("MappingEditorDialog.label.expression"),
"SchemaHandlingStep.mapping.tooltip.expression", true, ID_LABEL_SIZE, ID_INPUT_SIZE, false,
Expand Down Expand Up @@ -505,7 +502,7 @@ protected void onUpdate(AjaxRequestTarget target) {
});
form.add(conditionGeneratePolicy);

TextAreaFormGroup condition = new TextAreaFormGroup(ID_CONDITION,
AceEditorFormGroup condition = new AceEditorFormGroup(ID_CONDITION,
new PropertyModel<String>(model, MappingTypeDto.F_CONDITION),
createStringResource("MappingEditorDialog.label.condition"),
"SchemaHandlingStep.mapping.tooltip.condition", true, ID_LABEL_SIZE, ID_INPUT_SIZE, false,
Expand Down

0 comments on commit cd0d83c

Please sign in to comment.