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 Jun 22, 2016
2 parents 903dc49 + 3a57642 commit 336d883
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 77 deletions.
Expand Up @@ -44,7 +44,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

public class ObjectBrowserPanel<T extends ObjectType> extends BasePanel<T> implements Popupable{
public class ObjectBrowserPanel<O extends ObjectType> extends BasePanel<O> implements Popupable{

private static final long serialVersionUID = 1L;
private static final String ID_TYPE = "type";
Expand All @@ -58,12 +58,18 @@ public class ObjectBrowserPanel<T extends ObjectType> extends BasePanel<T> imple
private PageBase parentPage;
private ObjectFilter queryFilter;

public ObjectBrowserPanel(String id, final Class<T> type, List<QName> supportedTypes, boolean multiselect,
/**
* @param defaultType specifies type of the object that will be selected by default
*/
public ObjectBrowserPanel(String id, final Class<? extends O> defaultType, List<QName> supportedTypes, boolean multiselect,
PageBase parentPage) {
this(id, type, supportedTypes, multiselect, parentPage, null);
this(id, defaultType, supportedTypes, multiselect, parentPage, null);
}

public ObjectBrowserPanel(String id, final Class<T> type, List<QName> supportedTypes, boolean multiselect,
/**
* @param defaultType specifies type of the object that will be selected by default
*/
public ObjectBrowserPanel(String id, final Class<? extends O> defaultType, List<QName> supportedTypes, boolean multiselect,
PageBase parentPage, ObjectFilter queryFilter) {
super(id);
this.parentPage = parentPage;
Expand All @@ -73,15 +79,15 @@ public ObjectBrowserPanel(String id, final Class<T> type, List<QName> supportedT

@Override
protected QName load() {
return compileTimeClassToQName(type);
return compileTimeClassToQName(defaultType);
}

};

initLayout(type, supportedTypes, multiselect);
initLayout(defaultType, supportedTypes, multiselect);
}

private void initLayout(Class<T> type, final List<QName> supportedTypes, final boolean multiselect) {
private void initLayout(Class<? extends O> type, final List<QName> supportedTypes, final boolean multiselect) {

WebMarkupContainer typePanel = new WebMarkupContainer(ID_TYPE_PANEL);
typePanel.setOutputMarkupId(true);
Expand All @@ -101,7 +107,7 @@ public boolean isVisible() {
@Override
protected void onUpdate(AjaxRequestTarget target) {

ObjectListPanel<T> listPanel = (ObjectListPanel<T>) get(ID_TABLE);
ObjectListPanel<O> listPanel = (ObjectListPanel<O>) get(ID_TABLE);

listPanel = createObjectListPanel(qnameToCompileTimeClass(typeModel.getObject()),
multiselect);
Expand All @@ -111,7 +117,7 @@ protected void onUpdate(AjaxRequestTarget target) {
});
typePanel.add(typeSelect);

ObjectListPanel<T> listPanel = createObjectListPanel(type, multiselect);
ObjectListPanel<O> listPanel = createObjectListPanel(type, multiselect);
add(listPanel);

AjaxButton addButton = new AjaxButton(ID_BUTTON_ADD,
Expand All @@ -120,7 +126,7 @@ protected void onUpdate(AjaxRequestTarget target) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
List<T> selected = ((PopupObjectListPanel) getParent().get(ID_TABLE)).getSelectedObjects();
List<O> selected = ((PopupObjectListPanel) getParent().get(ID_TABLE)).getSelectedObjects();
QName type = ObjectBrowserPanel.this.typeModel.getObject();
ObjectBrowserPanel.this.addPerformed(target, type, selected);
}
Expand All @@ -138,21 +144,21 @@ public boolean isVisible() {
add(addButton);
}

protected void onClick(AjaxRequestTarget target, T focus) {
protected void onClick(AjaxRequestTarget target, O focus) {
parentPage.hideMainPopup(target);
}

protected void onSelectPerformed(AjaxRequestTarget target, T focus) {
protected void onSelectPerformed(AjaxRequestTarget target, O focus) {
parentPage.hideMainPopup(target);
}

private ObjectListPanel<T> createObjectListPanel(Class<T> type, final boolean multiselect) {
private ObjectListPanel<O> createObjectListPanel(Class<? extends O> type, final boolean multiselect) {

PopupObjectListPanel<T> listPanel = new PopupObjectListPanel<T>(ID_TABLE, type, multiselect,
PopupObjectListPanel<O> listPanel = new PopupObjectListPanel<O>(ID_TABLE, type, multiselect,
parentPage) {
private static final long serialVersionUID = 1L;
@Override
protected void onSelectPerformed(AjaxRequestTarget target, T object) {
protected void onSelectPerformed(AjaxRequestTarget target, O object) {
ObjectBrowserPanel.this.onSelectPerformed(target, object);
}

Expand All @@ -171,15 +177,15 @@ protected ObjectQuery addFilterToContentQuery(ObjectQuery query) {
return listPanel;
}

protected void addPerformed(AjaxRequestTarget target, QName type, List<T> selected) {
protected void addPerformed(AjaxRequestTarget target, QName type, List<O> selected) {
parentPage.hideMainPopup(target);
}

private Class qnameToCompileTimeClass(QName typeName) {
return parentPage.getPrismContext().getSchemaRegistry().getCompileTimeClassForObjectType(typeName);
}

private QName compileTimeClassToQName(Class<T> type) {
private QName compileTimeClassToQName(Class<? extends O> type) {
PrismObjectDefinition def = parentPage.getPrismContext().getSchemaRegistry()
.findObjectDefinitionByCompileTimeClass(type);
if (def == null) {
Expand Down
Expand Up @@ -72,7 +72,7 @@ public abstract class ObjectListPanel<O extends ObjectType> extends BasePanel<O>

private static final Trace LOGGER = TraceManager.getTrace(ObjectListPanel.class);

private Class<O> type;
private Class<? extends O> type;
private PageBase parentPage;

private LoadableModel<Search> searchModel;
Expand All @@ -85,7 +85,7 @@ public abstract class ObjectListPanel<O extends ObjectType> extends BasePanel<O>

private String addutionalBoxCssClasses;

public Class<O> getType() {
public Class<? extends O> getType() {
return type;
}

Expand All @@ -100,19 +100,25 @@ public Class<O> getType() {
storageMap.put(PageServices.class, SessionStorage.KEY_SERVICES);
}

public ObjectListPanel(String id, Class<O> type, TableId tableId, Collection<SelectorOptions<GetOperationOptions>> options,
/**
* @param defaultType specifies type of the object that will be selected by default. It can be changed.
*/
public ObjectListPanel(String id, Class<? extends O> defaultType, TableId tableId, Collection<SelectorOptions<GetOperationOptions>> options,
PageBase parentPage) {
super(id);
this.type = type;
this.type = defaultType;
this.parentPage = parentPage;
this.options = options;
this.tableId = tableId;
initLayout();
}

ObjectListPanel(String id, Class<O> type, boolean multiselect, PageBase parentPage) {
/**
* @param defaultType specifies type of the object that will be selected by default. It can be changed.
*/
ObjectListPanel(String id, Class<? extends O> defaultType, boolean multiselect, PageBase parentPage) {
super(id);
this.type = type;
this.type = defaultType;
this.parentPage = parentPage;
this.multiselect = multiselect;
initLayout();
Expand Down
@@ -1,3 +1,18 @@
/*
* 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.gui.api.component;

import java.util.List;
Expand All @@ -16,19 +31,25 @@
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

public abstract class PopupObjectListPanel<T extends ObjectType> extends ObjectListPanel<T> {
public abstract class PopupObjectListPanel<O extends ObjectType> extends ObjectListPanel<O> {
private static final long serialVersionUID = 1L;

public PopupObjectListPanel(String id, Class<T> type, boolean multiselect, PageBase parentPage) {
super(id, type, multiselect, parentPage);
/**
* @param defaultType specifies type of the object that will be selected by default
*/
public PopupObjectListPanel(String id, Class<? extends O> defaultType, boolean multiselect, PageBase parentPage) {
super(id, defaultType, multiselect, parentPage);

}

@Override
protected IColumn<SelectableBean<T>, String> createCheckboxColumn() {
protected IColumn<SelectableBean<O>, String> createCheckboxColumn() {
if (isMultiselect()) {
return new CheckBoxHeaderColumn<SelectableBean<T>>() {
return new CheckBoxHeaderColumn<SelectableBean<O>>() {
private static final long serialVersionUID = 1L;

@Override
protected void onUpdateRow(AjaxRequestTarget target, DataTable table, IModel<SelectableBean<T>> rowModel) {
protected void onUpdateRow(AjaxRequestTarget target, DataTable table, IModel<SelectableBean<O>> rowModel) {
super.onUpdateRow(target, table, rowModel);
onUpdateCheckbox(target);
};
Expand All @@ -44,14 +65,15 @@ protected void onUpdateHeader(AjaxRequestTarget target, boolean selected, DataTa
}

@Override
protected IColumn<SelectableBean<T>, String> createNameColumn() {
protected IColumn<SelectableBean<O>, String> createNameColumn() {
if (!isMultiselect()) {
return new LinkColumn<SelectableBean<T>>(createStringResource("ObjectType.name"),
return new LinkColumn<SelectableBean<O>>(createStringResource("ObjectType.name"),
ObjectType.F_NAME.getLocalPart(), SelectableBean.F_VALUE + ".name") {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target, IModel<SelectableBean<T>> rowModel) {
T object = rowModel.getObject().getValue();
public void onClick(AjaxRequestTarget target, IModel<SelectableBean<O>> rowModel) {
O object = rowModel.getObject().getValue();
onSelectPerformed(target, object);

}
Expand All @@ -65,11 +87,11 @@ public void onClick(AjaxRequestTarget target, IModel<SelectableBean<T>> rowModel
}

@Override
protected List<IColumn<SelectableBean<T>, String>> createColumns() {
protected List<IColumn<SelectableBean<O>, String>> createColumns() {
return ColumnUtils.getDefaultColumns(getType());
}

protected void onSelectPerformed(AjaxRequestTarget target, T object){
protected void onSelectPerformed(AjaxRequestTarget target, O object){

}

Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -119,6 +120,7 @@
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.DisplayableValue;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
Expand Down Expand Up @@ -296,6 +298,7 @@ public static boolean isAuthorized(Collection<String> actions) {
return false;
}

// TODO: move to util component
public static Integer safeLongToInteger(Long l) {
if (l == null) {
return null;
Expand All @@ -309,6 +312,7 @@ public static Integer safeLongToInteger(Long l) {
return (int) l.longValue();
}

// TODO: move to schema component
public static List<QName> createObjectTypeList() {
List<QName> types = new ArrayList<>(ObjectTypes.values().length);
for (ObjectTypes t : ObjectTypes.values()) {
Expand All @@ -317,6 +321,7 @@ public static List<QName> createObjectTypeList() {
return types;
}

// TODO: move to schema component
public static List<QName> createFocusTypeList() {
List<QName> focusTypeList = new ArrayList<>();

Expand All @@ -328,6 +333,7 @@ public static List<QName> createFocusTypeList() {
return focusTypeList;
}

// TODO: move to schema component
public static List<QName> createAbstractRoleTypeList() {
List<QName> focusTypeList = new ArrayList<>();

Expand All @@ -339,6 +345,7 @@ public static List<QName> createAbstractRoleTypeList() {
return focusTypeList;
}

// TODO: move to schema component
public static List<QName> createAssignableTypesList() {
List<QName> focusTypeList = new ArrayList<>();

Expand All @@ -349,6 +356,32 @@ public static List<QName> createAssignableTypesList() {

return focusTypeList;
}

/**
* Takes a collection of object types (classes) that may contain abstract types. Returns a collection
* that only contain concrete types.
* @param <O> common supertype for all the types in the collections
*
* TODO: move to schema component
*/
public static <O extends ObjectType> List<QName> resolveObjectTypesToQNames(Collection<Class<? extends O>> types, PrismContext prismContext) {
if (types == null) {
return null;
}
List<QName> concreteTypes = new ArrayList<>(types.size());
for (Class<? extends O> type: types) {
if (type == null || type.equals(ObjectType.class)) {
MiscUtil.addAllIfNotPresent(concreteTypes, WebComponentUtil.createObjectTypeList());
} else if (type.equals(FocusType.class)) {
MiscUtil.addAllIfNotPresent(concreteTypes, WebComponentUtil.createFocusTypeList());
} else if (type.equals(AbstractRoleType.class)) {
MiscUtil.addAllIfNotPresent(concreteTypes, WebComponentUtil.createAbstractRoleTypeList());
} else {
MiscUtil.addIfNotPresent(concreteTypes, WebComponentUtil.classToQName(prismContext, type));
}
}
return concreteTypes;
}

public static <T extends Enum> IModel<String> createLocalizedModelForEnum(T value, Component comp) {
String key = value != null ? value.getClass().getSimpleName() + "." + value.name() : "";
Expand Down Expand Up @@ -1673,5 +1706,6 @@ public static <O extends ObjectType> Class<? extends PageBase> getObjectDetailsP
} else {
throw new IllegalArgumentException("Cannot determine details page for "+type);
}
}
}

}

0 comments on commit 336d883

Please sign in to comment.