Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Oct 7, 2015
2 parents f9006f1 + c031225 commit c80bda4
Show file tree
Hide file tree
Showing 43 changed files with 1,520 additions and 742 deletions.
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright (c) 2010-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">
<div class="info-box">
<div wicket:id="summaryIconBox" class="info-box-icon">
<span wicket:id="summaryIcon"/>
<img wicket:id="summaryPhoto" class="user-thumbnail"/>
</div>
<div class="info-box-content">
<span class="info-box-number">
<span wicket:id="summaryDisplayName"/> (<span wicket:id="summaryIdentifier"/>)
</span>
<span class="info-box-text">
<span wicket:id="summaryTitle"/>
</span>
</div>
</div>
</wicket:panel>
@@ -0,0 +1,117 @@
/**
* 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.
*/
package com.evolveum.midpoint.web.component;

import javax.xml.namespace.QName;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.resource.AbstractResource;
import org.apache.wicket.request.resource.ByteArrayResource;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.web.component.prism.ObjectWrapper;
import com.evolveum.midpoint.web.component.util.PrismPropertyWrapperModel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

/**
* @author semancik
*
*/
public abstract class FocusSummaryPanel<F extends FocusType> extends Panel {
private static final long serialVersionUID = -3755521482914447912L;

private static final String ID_ICON_BOX = "summaryIconBox";
private static final String ID_PHOTO = "summaryPhoto";
private static final String ID_ICON = "summaryIcon";
private static final String ID_DISPLAY_NAME = "summaryDisplayName";
private static final String ID_IDENTIFIER = "summaryIdentifier";
private static final String ID_TITLE = "summaryTitle";

private static final String ICON_BOX_CSS_CLASS = "info-box-icon";

public FocusSummaryPanel(String id, final IModel<ObjectWrapper<F>> model) {
super(id, model);

add(new Label(ID_DISPLAY_NAME, new PrismPropertyWrapperModel<>(model, getDisplayNamePropertyName())));
add(new Label(ID_IDENTIFIER, new PrismPropertyWrapperModel<>(model, getIdentifierPropertyName())));
if (getTitlePropertyName() == null) {
add(new Label(ID_TITLE, ""));
} else {
add(new Label(ID_TITLE, new PrismPropertyWrapperModel<>(model, getTitlePropertyName())));
}

WebMarkupContainer iconBox = new WebMarkupContainer(ID_ICON_BOX);
add(iconBox);

if (getIconBoxColorCssClass() != null) {
iconBox.add(new AttributeModifier("class", ICON_BOX_CSS_CLASS + " " + getIconBoxColorCssClass()));
}

Image img = new Image(ID_PHOTO, new AbstractReadOnlyModel<AbstractResource>() {

@Override
public AbstractResource getObject() {
byte[] jpegPhoto = model.getObject().getObject().asObjectable().getJpegPhoto();
if(jpegPhoto == null) {
return null;
} else {
return new ByteArrayResource("image/jpeg",jpegPhoto);
}
}
});
img.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible(){
return model.getObject().getObject().asObjectable().getJpegPhoto() != null;
}
});
iconBox.add(img);

Label icon = new Label(ID_ICON,"");
icon.add(new AttributeModifier("class", getIconCssClass()));
icon.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible(){
return model.getObject().getObject().asObjectable().getJpegPhoto() == null;
}
});
iconBox.add(icon);
}

protected abstract String getIconCssClass();

protected String getIconBoxColorCssClass() {
return null;
}

protected QName getIdentifierPropertyName() {
return FocusType.F_NAME;
}

protected abstract QName getDisplayNamePropertyName();

protected QName getTitlePropertyName() {
return null;
}

}
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2010-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.
*/

package com.evolveum.midpoint.web.component.menu;

import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import java.io.Serializable;

/**
* @author Viliam Repan (lazyman)
*/
public class BaseMenuItem implements Serializable {

private IModel<String> name;
private Class<? extends WebPage> page;
private PageParameters params;
private VisibleEnableBehaviour visibleEnable;
private Class<? extends WebPage>[] aliases;

public BaseMenuItem(IModel<String> name, Class<? extends WebPage> page) {
this(name, page, null, null);
}

public BaseMenuItem(IModel<String> name, Class<? extends WebPage> page,
PageParameters params, VisibleEnableBehaviour visibleEnable,
Class<? extends WebPage>... aliases) {
this.aliases = aliases;
this.name = name;
this.page = page;
this.params = params;
this.visibleEnable = visibleEnable;
}

/**
* @return Returns array of {@link WebPage} classes where this menu should be marked as <b>active</b>.
*/
public Class<? extends WebPage>[] getAliases() {
return aliases;
}

public IModel<String> getName() {
return name;
}

public Class<? extends WebPage> getPage() {
return page;
}

public PageParameters getParams() {
return params;
}

public VisibleEnableBehaviour getVisibleEnable() {
return visibleEnable;
}

public boolean isMenuActive(WebPage page) {
if (page == null) {
return false;
}

Class pageClass = page.getClass();

if (this.page == null) {
return false;
}

boolean isMenuActive = isMenuActive();

if (pageClass.equals(this.page)) {
return isMenuActive;
}

if (aliases == null) {
return false;
}

for (Class c : aliases) {
if (pageClass.equals(c)) {
return isMenuActive;
}
}

return false;
}

protected boolean isMenuActive() {
return true;
}
}
Expand Up @@ -17,25 +17,20 @@

import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.page.admin.PageAdmin;
import org.apache.wicket.model.IModel;

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

/**
* @author Viliam Repan (lazyman)
*/
public class MainMenuItem implements Serializable {
public class MainMenuItem extends BaseMenuItem {

public static final String F_ITEMS = "items";
public static final String F_ICON_CLASS = "iconClass";

private String iconClass;
private IModel<String> name;
private Class<? extends PageBase> page;
private VisibleEnableBehaviour visibleEnable;
private List<MenuItem> items;

public MainMenuItem(String iconClass, IModel<String> name) {
Expand All @@ -46,17 +41,16 @@ public MainMenuItem(String iconClass, IModel<String> name, Class<? extends PageB
this(iconClass, name, page, null);
}

public MainMenuItem(String iconClass, IModel<String> name, Class<? extends PageBase> page, List<MenuItem> items) {
public MainMenuItem(String iconClass, IModel<String> name, Class<? extends PageBase> page,
List<MenuItem> items) {
this(iconClass, name, page, items, null);
}

public MainMenuItem(String iconClass, IModel<String> name, Class<? extends PageBase> page,
List<MenuItem> items, VisibleEnableBehaviour visibleEnable) {
super(name, page, null, visibleEnable);
this.iconClass = iconClass;
this.items = items;
this.name = name;
this.page = page;
this.visibleEnable = visibleEnable;
}

public String getIconClass() {
Expand All @@ -69,16 +63,4 @@ public List<MenuItem> getItems() {
}
return items;
}

public IModel<String> getName() {
return name;
}

public VisibleEnableBehaviour getVisibleEnable() {
return visibleEnable;
}

public Class<? extends PageBase> getPage() {
return page;
}
}
Expand Up @@ -20,6 +20,7 @@
import com.evolveum.midpoint.web.security.SecurityUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
Expand Down Expand Up @@ -59,15 +60,12 @@ protected void initLayout() {

@Override
public String getObject() {
Class page = getPage().getClass();

Class type = menu.getPage();
if (type != null && page.isAssignableFrom(type)) {
if (menu.isMenuActive((WebPage) getPage())) {
return "active";
}

for (MenuItem item : menu.getItems()) {
if (item.getPage() != null && page.isAssignableFrom(item.getPage())) {
if (item.isMenuActive((WebPage) getPage())) {
return "active";
}
}
Expand Down Expand Up @@ -127,14 +125,11 @@ private void createSubmenu(final ListItem<MenuItem> listItem) {

@Override
public String getObject() {
Class page = getPage().getClass();
Class type = menu.getPage();

return page.isAssignableFrom(type) ? "active" : null;
return menu.isMenuActive((WebPage) getPage()) ? "active" : null;
}
}));

BookmarkablePageLink subLink = new BookmarkablePageLink(ID_SUB_LINK, menu.getPage());
BookmarkablePageLink subLink = new BookmarkablePageLink(ID_SUB_LINK, menu.getPage(), menu.getParams());
listItem.add(subLink);

Label subLabel = new Label(ID_SUB_LABEL, menu.getName());
Expand All @@ -144,7 +139,25 @@ public String getObject() {

@Override
public boolean isVisible() {
return SecurityUtils.isMenuAuthorized(listItem.getModelObject());
MenuItem mi = listItem.getModelObject();

boolean visible = true;
if (mi.getVisibleEnable() != null) {
visible = mi.getVisibleEnable().isVisible();
}

return visible && SecurityUtils.isMenuAuthorized(mi);
}

@Override
public boolean isEnabled() {
MenuItem mi = listItem.getModelObject();

if (mi.getVisibleEnable() == null) {
return true;
}

return mi.getVisibleEnable().isEnabled();
}
});
}
Expand Down

0 comments on commit c80bda4

Please sign in to comment.