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
semancik committed Apr 1, 2016
2 parents b8c2ab0 + 7386497 commit 4b5651d
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 82 deletions.
3 changes: 3 additions & 0 deletions config/initial-objects/040-role-enduser.xml
Expand Up @@ -86,5 +86,8 @@
<type>RoleType</type>
</object>
</authorization>
<authorization>
<action>http://midpoint.evolveum.com/xml/ns/public/security/authorization-ui-3#selfRequestRole</action>
</authorization>
<roleType>system</roleType>
</role>
Expand Up @@ -79,6 +79,7 @@
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.visit.IVisit;
import org.apache.wicket.util.visit.IVisitor;
import org.joda.time.format.DateTimeFormat;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
Expand Down Expand Up @@ -635,7 +636,19 @@ public static String formatDate(String format, Date date) {
return dateFormat.format(date);
}

public static boolean isActivationEnabled(PrismObject object) {
public static String getLocalizedDatePattern(String style){
return DateTimeFormat.patternForStyle(style, getCurrentLocale());
}

public static Locale getCurrentLocale(){
Locale locale = Session.get().getLocale();
if (locale == null){
locale = Locale.getDefault();
}
return locale;
}

public static boolean isActivationEnabled(PrismObject object) {
Validate.notNull(object);

PrismContainer activation = object.findContainer(UserType.F_ACTIVATION); // this
Expand Down
Expand Up @@ -3,6 +3,7 @@
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.web.component.util.SummaryTag;
import com.evolveum.midpoint.web.component.util.SummaryTagSimple;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.model.PrismPropertyRealValueFromPrismObjectModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
Expand Down Expand Up @@ -133,6 +134,10 @@ public void addTag(SummaryTag<O> tag) {
box.add(tag);
}

public void addTag(SummaryTagSimple<O> tag) {
box.add(tag);
}

protected abstract String getIconCssClass();

protected abstract String getIconBoxAdditionalCssClass();
Expand Down
@@ -0,0 +1,88 @@
/*
* 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;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import org.apache.wicket.datetime.DateConverter;
import org.apache.wicket.datetime.PatternDateConverter;
import org.apache.wicket.datetime.markup.html.basic.DateLabel;
import org.apache.wicket.model.IModel;

import java.util.Date;

/**
* Created by honchar
* Component for displaying date value as a label
* By default (if no converter is set) the date is formatted
* according to the client's locale, timezone (not implemented yet),
* with applying long style for date and long style for time.
*/
public class DateLabelComponent extends DateLabel {

public static final String SHORT_SHORT_STYLE = "SS"; //short style for date, short style for time
public static final String MEDIUM_MEDIUM_STYLE = "MM"; //medium style for date, medium style for time
public static final String LONG_LONG_STYLE = "LL"; //long style for date, long style for time
public static final String FULL_FULL_STYLE = "FF"; //full style for date, full style for time
public static final String SHORT_MEDIUM_STYLE = "SM"; //short style for date, medium style for time
public static final String SHORT_LONG_STYLE = "SL"; //short style for date, long style for time
public static final String SHORT_FULL_STYLE = "SF"; //short style for date, full style for time
public static final String SHORT_NOTIME_STYLE = "S-"; //short style for date, no time
public static final String MEDIUM_SHORT_STYLE = "MS"; //medium style for date, short style for time
public static final String MEDIUM_LONG_STYLE = "ML"; //medium style for date, long style for time
public static final String MEDIUM_FULL_STYLE = "MF"; //medium style for date, full style for time
public static final String MEDIUM_NOTIME_STYLE = "M-"; //medium style for date, no time
public static final String LONG_SHORT_STYLE = "LS"; //long style for date, short style for time
public static final String LONG_MEDIUM_STYLE = "LM"; //long style for date, medium style for time
public static final String LONG_FULL_STYLE = "LF"; //long style for date, full style for time
public static final String LONG_NOTIME_STYLE = "L-"; //long style for date, no time
public static final String FULL_SHORT_STYLE = "FS"; //full style for date, short style for time
public static final String FULL_MEDIUM_STYLE = "FM"; //full style for date, medium style for time
public static final String FULL_LONG_STYLE = "FL"; //full style for date, long style for time
public static final String FULL_NOTIME_STYLE = "F-"; //full style for date, no time
public static final String NODATE_SHORT_STYLE = "-S"; //no date, short style for time
public static final String NODATE_MEDIUM_STYLE = "-M"; //no date, medium style for time
public static final String NODATE_LONG_STYLE = "-L"; //no date, long style for time
public static final String NODATE_FULL_STYLE = "-F"; //no date, full style for time

public DateLabelComponent(String id, IModel<Date> model){
this(id, model, (DateConverter) null);
}

public DateLabelComponent(String id, IModel<Date> model, DateConverter converter){
this(id, model, converter, null, "", "");
}

public DateLabelComponent(String id, IModel<Date> model, String style){
this(id, model, null, style, "", "");
}

public DateLabelComponent(String id, IModel<Date> model, DateConverter converter, String style,
String beforeDateText, String afterDateText){
super(id, model, converter == null ?
new PatternDateConverter(WebComponentUtil.getLocalizedDatePattern(style == null ? LONG_LONG_STYLE : style), true ) : converter);

setBefore(beforeDateText);
setAfter(afterDateText);
}

public void setBeforeTextOnDateNull(String nullDateText){
if (getModel().getObject() == null){
setBefore(nullDateText);
}
}
}

Expand Up @@ -97,9 +97,9 @@ public PagePreviewChanges(ModelContext<? extends ObjectType> modelContext, Model
LOGGER.info("Creating context DTO for secondary deltas:\n{}", DebugUtil.debugDump(secondaryScenes));

final WrapperScene primaryScene = new WrapperScene(primaryScenes,
primaryDeltas.size() != 1 ? "PagePreviewChanges.primaryChangesMore" : "PagePreviewChanges.primaryChangesOne", primaryDeltas.size());
primaryScenes.size() != 1 ? "PagePreviewChanges.primaryChangesMore" : "PagePreviewChanges.primaryChangesOne", primaryScenes.size());
final WrapperScene secondaryScene = new WrapperScene(secondaryScenes,
secondaryDeltas.size() != 1 ? "PagePreviewChanges.secondaryChangesMore" : "PagePreviewChanges.secondaryChangesOne", secondaryDeltas.size());
secondaryScenes.size() != 1 ? "PagePreviewChanges.secondaryChangesMore" : "PagePreviewChanges.secondaryChangesOne", secondaryScenes.size());
final SceneDto primarySceneDto = new SceneDto(primaryScene);
final SceneDto secondarySceneDto = new SceneDto(secondaryScene);
primaryDeltasModel = new AbstractReadOnlyModel<SceneDto>() {
Expand Down
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright (c) 2015 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.
-->
<wicket:panel xmlns:wicket="http://wicket.apache.org">
<span class="summary-tag"><span class="summary-tag-icon"><span wicket:id="summaryTagIcon"/></span> <span wicket:id="summaryTagLabel"/><wicket:child /></span>
</wicket:panel>
@@ -0,0 +1,137 @@
/*
* 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.util;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;

/**
* The same as SummaryTag, but based on PrismObject model, not ObjectWrapper one.
* TODO fix somehow
*
* @author semancik
* @author mederly
*/
public abstract class SummaryTagSimple<O extends ObjectType> extends Panel {

private static final String ID_TAG_ICON = "summaryTagIcon";
private static final String ID_TAG_LABEL = "summaryTagLabel";

private boolean initialized = false;
private String iconCssClass;
private String label;
private String color = null;
private boolean hideTag = false;

public SummaryTagSimple(String id, final IModel<PrismObject<O>> model) {
super(id, model);

Label tagIcon = new Label(ID_TAG_ICON, "");
tagIcon.add(new AttributeModifier("class", new SummaryTagModel<String>(model) {
@Override
protected String getValue() {
return getIconCssClass();
}
}));
add(tagIcon);

add(new Label(ID_TAG_LABEL, new SummaryTagModel<String>(model) {
@Override
protected String getValue() {
return getLabel();
}
}));

add(new AttributeModifier("style", new SummaryTagModel<String>(model) {
@Override
protected String getValue() {
if (getColor() == null) {
return null;
}
return "color: " + getColor();
}
}));

add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible(){
if (!initialized) {
initialize(model.getObject());
}
return !isHideTag();
}
});
}

public String getIconCssClass() {
return iconCssClass;
}

public void setIconCssClass(String iconCssClass) {
this.iconCssClass = iconCssClass;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public boolean isHideTag() {
return hideTag;
}

public void setHideTag(boolean hideTag) {
this.hideTag = hideTag;
}

protected abstract void initialize(PrismObject<O> object);

abstract class SummaryTagModel<T> extends AbstractReadOnlyModel<T> {

IModel<PrismObject<O>> objectModel;

public SummaryTagModel(IModel<PrismObject<O>> objectModel) {
this.objectModel = objectModel;
}

@Override
public T getObject() {
if (!initialized) {
initialize(objectModel.getObject());
}
return getValue();
}

protected abstract T getValue();

}
}
Expand Up @@ -19,6 +19,7 @@
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.page.admin.home.dto.PersonalInfoDto;
import com.evolveum.midpoint.web.security.SecurityUtils;
Expand All @@ -27,10 +28,13 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

import org.apache.commons.lang.StringUtils;
import org.apache.wicket.datetime.PatternDateConverter;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;

import java.util.Date;

/**
* @author lazyman
*/
Expand Down Expand Up @@ -85,16 +89,15 @@ private PersonalInfoDto loadPersonalInfo() {

@Override
protected void initLayout() {
Label lastLoginDate = new Label(ID_LAST_LOGIN_DATE, new AbstractReadOnlyModel<String>() {
DateLabelComponent lastLoginDate = new DateLabelComponent(ID_LAST_LOGIN_DATE, new AbstractReadOnlyModel<Date>() {

@Override
public String getObject() {
public Date getObject() {
PersonalInfoDto dto = getModel().getObject();

return dto.getLastLoginDate() != null ? WebComponentUtil.formatDate(dto.getLastLoginDate()) :
PersonalInfoPanel.this.getString("PersonalInfoPanel.never");
return dto == null ? null : dto.getLastLoginDate();
}
});
}, DateLabelComponent.LONG_MEDIUM_STYLE);
lastLoginDate.setBeforeTextOnDateNull(PersonalInfoPanel.this.getString("PersonalInfoPanel.never"));
add(lastLoginDate);

Label lastLoginFrom = new Label(ID_LAST_LOGIN_FROM, new AbstractReadOnlyModel<String>() {
Expand All @@ -109,16 +112,15 @@ public String getObject() {
});
add(lastLoginFrom);

Label lastFailDate = new Label(ID_LAST_FAIL_DATE, new AbstractReadOnlyModel<String>() {
DateLabelComponent lastFailDate = new DateLabelComponent(ID_LAST_FAIL_DATE, new AbstractReadOnlyModel<Date>() {

@Override
public String getObject() {
public Date getObject() {
PersonalInfoDto dto = getModel().getObject();

return dto.getLastFailDate() != null ? WebComponentUtil.formatDate(dto.getLastFailDate()) :
PersonalInfoPanel.this.getString("PersonalInfoPanel.never");
return dto == null ? null : dto.getLastFailDate();
}
});
}, DateLabelComponent.LONG_MEDIUM_STYLE);
lastFailDate.setBeforeTextOnDateNull(PersonalInfoPanel.this.getString("PersonalInfoPanel.never"));
add(lastFailDate);

Label lastFailFrom = new Label(ID_LAST_FAIL_FROM, new AbstractReadOnlyModel<String>() {
Expand Down

0 comments on commit 4b5651d

Please sign in to comment.