Skip to content

Commit

Permalink
archetype implementation for creating new list object (not finished)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Jan 17, 2019
1 parent 5f2d0f1 commit 4c32757
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 53 deletions.
Expand Up @@ -15,9 +15,11 @@
*/
package com.evolveum.midpoint.gui.api.component;

import java.io.Serializable;
import java.util.*;

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.web.component.MultifunctionalButton;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.Component;
Expand All @@ -36,11 +38,9 @@
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.model.api.ModelAuthorizationAction;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AjaxIconButton;
Expand All @@ -55,13 +55,9 @@
/**
* @author katkav
*/
public abstract class MainObjectListPanel<O extends ObjectType> extends ObjectListPanel<O> {
public abstract class MainObjectListPanel<O extends ObjectType, S extends Serializable> extends ObjectListPanel<O> {
private static final long serialVersionUID = 1L;

private static final String ID_REFRESH = "refresh";
private static final String ID_NEW_OBJECT = "newObject";
private static final String ID_IMPORT_OBJECT = "importObject";
private static final String ID_EXPORT_DATA = "exportData";
private static final String ID_BUTTON_BAR = "buttonBar";
private static final String ID_BUTTON_REPEATER = "buttonsRepeater";
private static final String ID_BUTTON = "button";
Expand Down Expand Up @@ -118,7 +114,7 @@ protected boolean isClickable(IModel<SelectableBean<O>> rowModel) {

protected abstract void objectDetailsPerformed(AjaxRequestTarget target, O object);

protected abstract void newObjectPerformed(AjaxRequestTarget target);
protected void newObjectPerformed(AjaxRequestTarget target, S collectionView){}

@Override
protected WebMarkupContainer createTableButtonToolbar(String id) {
Expand All @@ -127,18 +123,40 @@ protected WebMarkupContainer createTableButtonToolbar(String id) {

protected List<Component> createToolbarButtonsList(String buttonId){
List<Component> buttonsList = new ArrayList<>();
AjaxIconButton newObjectIcon = new AjaxIconButton(buttonId, new Model<>(GuiStyleConstants.CLASS_ADD_NEW_OBJECT),
createStringResource("MainObjectListPanel.newObject")) {

// AjaxIconButton newObjectIcon = new AjaxIconButton(buttonId, new Model<>(GuiStyleConstants.CLASS_ADD_NEW_OBJECT),
// createStringResource("MainObjectListPanel.newObject")) {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public void onClick(AjaxRequestTarget target) {
// newObjectPerformed(target);
// }
// };
// newObjectIcon.add(AttributeAppender.append("class", "btn btn-success btn-sm"));
// buttonsList.add(newObjectIcon);

MultifunctionalButton<S> createNewObjectButton =
new MultifunctionalButton<S>(buttonId){
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
newObjectPerformed(target);
protected List<S> getAdditionalButtonsObjects(){
return getNewObjectInfluencesList();
}

@Override
protected void buttonClickPerformed(AjaxRequestTarget target, S influencingObject){
newObjectPerformed(target, influencingObject);
}

@Override
protected String getDefaultButtonStyle(){
return getNewObjectButtonStyle();
}
};
newObjectIcon.add(AttributeAppender.append("class", "btn btn-success btn-sm"));
buttonsList.add(newObjectIcon);
buttonsList.add(createNewObjectButton);


AjaxIconButton refreshIcon = new AjaxIconButton(buttonId, new Model<>(GuiStyleConstants.CLASS_RECONCILE),
createStringResource("MainObjectListPanel.refresh")) {
Expand Down Expand Up @@ -231,11 +249,19 @@ private boolean isRawOrNoFetchOption(Collection<SelectorOptions<GetOperationOpti
return false;
}

protected List<S> getNewObjectInfluencesList(){
return new ArrayList<>();
}

protected String getNewObjectButtonStyle(){
return GuiStyleConstants.CLASS_ADD_NEW_OBJECT;
}

private static class ButtonBar extends Fragment {

private static final long serialVersionUID = 1L;

public <O extends ObjectType> ButtonBar(String id, String markupId, MainObjectListPanel<O> markupProvider, List<Component> buttonsList) {
public <O extends ObjectType, S extends Serializable> ButtonBar(String id, String markupId, MainObjectListPanel<O, S> markupProvider, List<Component> buttonsList) {
super(id, markupId, markupProvider);

initLayout(buttonsList);
Expand Down
Expand Up @@ -2546,7 +2546,7 @@ public static boolean getElementVisibility(UserInterfaceElementVisibilityType vi
}

public static <AR extends AbstractRoleType> IModel<String> createAbstractRoleConfirmationMessage(String actionName,
ColumnMenuAction action, MainObjectListPanel<AR> abstractRoleTable, PageBase pageBase) {
ColumnMenuAction action, MainObjectListPanel<AR, CompiledObjectCollectionView> abstractRoleTable, PageBase pageBase) {
List<AR> selectedRoles = new ArrayList<>();
if (action.getRowModel() == null) {
selectedRoles.addAll(abstractRoleTable.getSelectedObjects());
Expand Down
Expand Up @@ -16,6 +16,7 @@

package com.evolveum.midpoint.gui.impl.component.icon;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -26,7 +27,7 @@
/**
* @author skublik
*/
public class CompositedIcon {
public class CompositedIcon implements Serializable{

private String basicIcon;
private List<String> layerIcons;
Expand Down
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright (c) 2010-2019 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">
<button wicket:id="mainButton" type="button" class="btn btn-success btn-sm dropdown-toggle" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
</button>
<ul class="dropdown-menu">
<li>
<div wicket:id="additionalButton" class="btn btn-sm" />
</li>
</ul>
</wicket:panel>
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2010-2019 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.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.impl.component.AjaxCompositedIconButton;
import com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder;
import com.evolveum.midpoint.gui.impl.component.icon.IconCssStyle;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.Model;

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

/**
* Created by honchar
*/
public class MultifunctionalButton<S extends Serializable> extends BasePanel<S> {

private static String ID_MAIN_BUTTON = "mainButton";
private static String ID_BUTTON = "additionalButton";

public MultifunctionalButton(String id){
super(id);
}

@Override
protected void onInitialize(){
super.onInitialize();
initLayout();
}

private void initLayout(){
List<S> additionalButtons = getAdditionalButtonsObjects();

CompositedIconBuilder builder = new CompositedIconBuilder();
builder.setBasicIcon(getDefaultButtonStyle(), IconCssStyle.IN_ROW_STYLE, "")
.appendLayerIcon(GuiStyleConstants.CLASS_PLUS_CIRCLE, IconCssStyle.BOTTOM_RIGHT_STYLE, "green");

AjaxCompositedIconButton mainButton = new AjaxCompositedIconButton(ID_MAIN_BUTTON, builder.build(),
createStringResource("MainObjectListPanel.newObject")) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
if (!additionalButtonsExist()){
buttonClickPerformed(target, null);
}
}
};
add(mainButton);

RepeatingView buttonsPanel = new RepeatingView(ID_BUTTON);
buttonsPanel.add(new VisibleBehaviour(() -> additionalButtonsExist()));
add(buttonsPanel);

if (additionalButtons != null){
additionalButtons.forEach(additionalButtonObject -> {
AjaxIconButton newObjectIcon = new AjaxIconButton(buttonsPanel.newChildId(), new Model<>(GuiStyleConstants.CLASS_ASSIGN),
createStringResource("MainObjectListPanel.newObject")) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
buttonClickPerformed(target, additionalButtonObject);
}

@Override
public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) {
super.onComponentTagBody(markupStream, openTag);
}
};
newObjectIcon.add(AttributeAppender.append("class", "btn btn-success btn-sm"));
buttonsPanel.add(newObjectIcon);
});
}
}

protected String getDefaultButtonStyle(){
return "";
}

protected void buttonClickPerformed(AjaxRequestTarget target, S buttonObject){

}

private boolean additionalButtonsExist(){
List additionalButtons = getAdditionalButtonsObjects();
return additionalButtons != null && additionalButtons.size() > 0;
}

protected List<S> getAdditionalButtonsObjects(){
return new ArrayList<>();
}


}
Expand Up @@ -21,6 +21,7 @@
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.QueryFactory;
Expand Down Expand Up @@ -67,7 +68,8 @@ protected void onInitialize(){
}

private void initLayout() {
MainObjectListPanel<F> userListPanel = new MainObjectListPanel<F>(ID_PERSONAS_TABLE,
MainObjectListPanel<F, CompiledObjectCollectionView> userListPanel =
new MainObjectListPanel<F, CompiledObjectCollectionView>(ID_PERSONAS_TABLE,
(Class<F>) FocusType.class, null, null, getPageBase()) {
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -121,7 +123,7 @@ protected void objectDetailsPerformed(AjaxRequestTarget target, F object) {
}

@Override
protected void newObjectPerformed(AjaxRequestTarget target) {
protected void newObjectPerformed(AjaxRequestTarget target, CompiledObjectCollectionView collectionView) {
}

@Override
Expand Down
Expand Up @@ -19,6 +19,8 @@
import com.evolveum.midpoint.gui.api.component.MainObjectListPanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

import java.io.Serializable;

/**
* Common functionality for "focus list" pages or panels - e.g. roles, services; in the future also users and maybe orgs.
* Intended to be used e.g. for FocusListInlineMenuHelper.
Expand All @@ -28,8 +30,8 @@
* @author mederly
*/
@FunctionalInterface
public interface FocusListComponent<F extends FocusType> {
public interface FocusListComponent<F extends FocusType, S extends Serializable> {

MainObjectListPanel<F> getObjectListPanel();
MainObjectListPanel<F, S> getObjectListPanel();

}
Expand Up @@ -79,7 +79,7 @@ protected void initLayout() {

private void initTable(Form mainForm) {
StringValue collectionNameParameter = getCollectionNameParameterValue();
MainObjectListPanel<O> userListPanel = new MainObjectListPanel<O>(ID_TABLE,
MainObjectListPanel<O, CompiledObjectCollectionView> userListPanel = new MainObjectListPanel<O, CompiledObjectCollectionView>(ID_TABLE,
getType(), collectionNameParameter == null || collectionNameParameter.isEmpty() ?
getTableId() : UserProfileStorage.TableId.COLLECTION_VIEW_TABLE, getQueryOptions(), this) {
private static final long serialVersionUID = 1L;
Expand All @@ -100,10 +100,21 @@ protected void objectDetailsPerformed(AjaxRequestTarget target, O object) {
}

@Override
protected void newObjectPerformed(AjaxRequestTarget target) {
protected void newObjectPerformed(AjaxRequestTarget target, CompiledObjectCollectionView collectionView) {
newObjectActionPerformed(target);
}

@Override
protected List<CompiledObjectCollectionView> getNewObjectInfluencesList(){
return getCompiledUserProfile().findAllApplicableObjectCollectionViews(getType());
}

@Override
protected String getNewObjectButtonStyle(){
return WebComponentUtil.createDefaultBlackIcon(WebComponentUtil.classToQName(PageAdminObjectList.this.getPrismContext(),
getType()));
}

@Override
protected ObjectQuery createContentQuery() {
ObjectQuery contentQuery = super.createContentQuery();
Expand Down Expand Up @@ -199,8 +210,8 @@ protected Form getMainForm(){
return (Form) get(ID_MAIN_FORM);
}

public MainObjectListPanel<O> getObjectListPanel() {
return (MainObjectListPanel<O>) get(createComponentPath(ID_MAIN_FORM, ID_TABLE));
public MainObjectListPanel<O, CompiledObjectCollectionView> getObjectListPanel() {
return (MainObjectListPanel<O, CompiledObjectCollectionView>) get(createComponentPath(ID_MAIN_FORM, ID_TABLE));
}


Expand Down

0 comments on commit 4c32757

Please sign in to comment.