-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
detaching models for list pages (e.g. All users, All roles, ...)
- Loading branch information
Showing
23 changed files
with
354 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/model/SelectableObjectModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (C) 2021 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
package com.evolveum.midpoint.gui.impl.model; | ||
|
||
import com.evolveum.midpoint.gui.api.page.PageBase; | ||
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils; | ||
import com.evolveum.midpoint.prism.PrismObject; | ||
import com.evolveum.midpoint.schema.GetOperationOptions; | ||
import com.evolveum.midpoint.schema.SelectorOptions; | ||
import com.evolveum.midpoint.schema.result.OperationResult; | ||
import com.evolveum.midpoint.task.api.Task; | ||
import com.evolveum.midpoint.web.component.util.SelectableBean; | ||
import com.evolveum.midpoint.web.component.util.SelectableBeanImpl; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; | ||
|
||
import org.apache.wicket.model.LoadableDetachableModel; | ||
|
||
import java.util.Collection; | ||
|
||
public abstract class SelectableObjectModel<O extends ObjectType> extends LoadableDetachableModel<O> implements SelectableRowModel<O> { | ||
|
||
private String oid; | ||
private Class<O> type; | ||
|
||
private Collection<SelectorOptions<GetOperationOptions>> options; | ||
|
||
private boolean selected; | ||
|
||
public SelectableObjectModel(O object, Collection<SelectorOptions<GetOperationOptions>> options) { | ||
super(object); | ||
this.options = options; | ||
this.oid = object.getOid(); | ||
this.type = (Class<O>) object.getClass(); | ||
} | ||
|
||
// @Override | ||
// protected O load() { | ||
// PageBase pageBase = getPageBase(); | ||
// Task task = pageBase.createSimpleTask("load object"); | ||
// OperationResult result = task.getResult(); | ||
// PrismObject<O> object = WebModelServiceUtils.loadObject(type, oid, pageBase, task, result); | ||
// result.computeStatusIfUnknown(); | ||
// SelectableBeanImpl selectableBean; | ||
// if (object != null) { | ||
// selectableBean = new SelectableBeanImpl<>(object.asObjectable()); | ||
// selectableBean.setSelected(selected); | ||
// } else { | ||
// selectableBean = new SelectableBeanImpl<>(null); | ||
// } | ||
// selectableBean.setResult(result); | ||
//// return selectableBean; | ||
// return object.asObjectable(); | ||
// } | ||
|
||
@Override | ||
protected void onDetach() { | ||
if (isAttached()) { | ||
O object = getObject(); | ||
// selected = seletableBean.isSelected(); | ||
// O object = seletableBean.getValue(); | ||
if (object != null) { | ||
oid = object.getOid(); | ||
type = (Class<O>) object.getClass(); | ||
} | ||
} | ||
} | ||
|
||
// protected PageBase getPageBase() { | ||
// throw new UnsupportedOperationException("Must be implemented in caller."); | ||
// } | ||
|
||
public void setSelected(boolean selected) { | ||
this.selected = selected; | ||
} | ||
|
||
public boolean isSelected() { | ||
return selected; | ||
} | ||
|
||
public String getOid() { | ||
if (isAttached()) { | ||
getObject().getOid(); | ||
} | ||
return oid; | ||
} | ||
|
||
public Class<O> getType() { | ||
if (isAttached()) { | ||
getObject().getClass(); | ||
} | ||
return type; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/model/SelectableRowModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.evolveum.midpoint.gui.impl.model; | ||
|
||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.model.LoadableDetachableModel; | ||
|
||
public interface SelectableRowModel<T> extends IModel<T> { | ||
|
||
boolean isSelected(); | ||
void setSelected(boolean selected); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/util/TableUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.evolveum.midpoint.gui.impl.util; | ||
|
||
import com.evolveum.midpoint.gui.impl.model.SelectableObjectModel; | ||
import com.evolveum.midpoint.web.component.data.SelectableDataTable; | ||
|
||
import com.evolveum.midpoint.web.component.util.SelectableBean; | ||
|
||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; | ||
|
||
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable; | ||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.util.visit.IVisit; | ||
import org.apache.wicket.util.visit.IVisitor; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TableUtil { | ||
|
||
public static <T extends ObjectType> List<SelectableBean<T>> getSelectedModels(DataTable table) { | ||
List<SelectableBean<T>> objects = new ArrayList<>(); | ||
table.visitChildren(SelectableDataTable.SelectableRowItem.class, new IVisitor<SelectableDataTable.SelectableRowItem<SelectableBean<T>>, Void>() { | ||
|
||
@Override | ||
public void component(SelectableDataTable.SelectableRowItem<SelectableBean<T>> row, IVisit<Void> visit) { | ||
if (row.getModelObject().isSelected()) { | ||
objects.add(row.getModel().getObject()); | ||
} | ||
// SelectableObjectModel<T> model = (SelectableObjectModel<T>) row.getModel(); | ||
// if (model.isSelected()) { | ||
// objects.add((SelectableObjectModel<T>) row.getModel()); | ||
// } | ||
} | ||
}); | ||
return objects; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.