Skip to content

Commit

Permalink
Migrated page task to ObjectSummaryPanel.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Apr 1, 2016
1 parent 4d1f64a commit e337b7e
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 41 deletions.
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,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 @@ -15,7 +15,6 @@

public class ResourceSummaryPanel extends ObjectSummaryPanel<ResourceType>{


public ResourceSummaryPanel(String id, IModel<PrismObject<ResourceType>> model) {
super(id, model);

Expand Down
Expand Up @@ -48,6 +48,8 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.time.Duration;

Expand Down Expand Up @@ -152,7 +154,13 @@ private TaskDto prepareTaskDto(TaskType task, Task operationTask, OperationResul


protected void initLayout() {
final FocusSummaryPanel<TaskType> summaryPanel = new TaskSummaryPanel(ID_SUMMARY_PANEL, objectWrapperModel);
IModel<PrismObject<TaskType>> prismObjectModel = new AbstractReadOnlyModel<PrismObject<TaskType>>() {
@Override
public PrismObject<TaskType> getObject() {
return objectWrapperModel.getObject().getObject();
}
};
final TaskSummaryPanel summaryPanel = new TaskSummaryPanel(ID_SUMMARY_PANEL, prismObjectModel);
summaryPanel.setOutputMarkupId(true);
add(summaryPanel);

Expand Down
@@ -1,19 +1,3 @@
<!--
~ 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.
-->

<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2016 Evolveum
Expand All @@ -34,7 +18,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:extend>
<span wicket:id="summaryTagExecutionStatus"/>
<!--<span wicket:id="summaryTagExecutionStatus"/>-->
<span wicket:id="summaryTagResult"/>
</wicket:extend>
</body>
Expand Down
Expand Up @@ -16,11 +16,14 @@
package com.evolveum.midpoint.web.page.admin.server;

import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.task.api.TaskExecutionStatus;
import com.evolveum.midpoint.web.component.FocusSummaryPanel;
import com.evolveum.midpoint.web.component.ObjectSummaryPanel;
import com.evolveum.midpoint.web.component.prism.ObjectWrapper;
import com.evolveum.midpoint.web.component.util.SummaryTag;
import com.evolveum.midpoint.web.component.util.SummaryTagSimple;
import com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusIcon;
import com.evolveum.midpoint.web.page.admin.server.dto.TaskDto;
import com.evolveum.midpoint.web.page.admin.server.dto.TaskDtoExecutionStatus;
Expand All @@ -38,39 +41,39 @@
* @author mederly
*
*/
public class TaskSummaryPanel extends FocusSummaryPanel<TaskType> {
public class TaskSummaryPanel extends ObjectSummaryPanel<TaskType> {
private static final long serialVersionUID = -5077637168906420769L;

private static final String ID_TAG_EXECUTION_STATUS = "summaryTagExecutionStatus";
//private static final String ID_TAG_EXECUTION_STATUS = "summaryTagExecutionStatus";
private static final String ID_TAG_RESULT = "summaryTagResult";

public TaskSummaryPanel(String id, IModel<ObjectWrapper<TaskType>> model) {
public TaskSummaryPanel(String id, IModel<PrismObject<TaskType>> model) {
super(id, model);
SummaryTag<TaskType> tagResult = new SummaryTag<TaskType>(ID_TAG_RESULT, model) {

SummaryTagSimple<TaskType> tagExecutionStatus = new SummaryTagSimple<TaskType>(ID_FIRST_SUMMARY_TAG, model) {
@Override
protected void initialize(ObjectWrapper<TaskType> wrapper) {
OperationResultStatusType resultStatus = wrapper.getObject().asObjectable().getResultStatus();
String icon = OperationResultStatusIcon.parseOperationalResultStatus(resultStatus).getIcon();
protected void initialize(PrismObject<TaskType> taskObject) {
TaskType taskType = taskObject.asObjectable();
TaskDtoExecutionStatus status = TaskDtoExecutionStatus.fromTaskExecutionStatus(taskType.getExecutionStatus(), taskType.getNodeAsObserved() != null);
String icon = getIconForExecutionStatus(status);
setIconCssClass(icon);
setLabel(PageBase.createStringResourceStatic(TaskSummaryPanel.this, resultStatus).getString());
setLabel(PageBase.createStringResourceStatic(TaskSummaryPanel.this, status).getString());
// TODO setColor
}
};
addTag(tagResult);
box.add(tagExecutionStatus);

SummaryTag<TaskType> tagExecutionStatus = new SummaryTag<TaskType>(ID_TAG_EXECUTION_STATUS, model) {
SummaryTagSimple<TaskType> tagResult = new SummaryTagSimple<TaskType>(ID_TAG_RESULT, model) {
@Override
protected void initialize(ObjectWrapper<TaskType> wrapper) {
TaskType taskType = wrapper.getObject().asObjectable();
TaskDtoExecutionStatus status = TaskDtoExecutionStatus.fromTaskExecutionStatus(taskType.getExecutionStatus(), taskType.getNodeAsObserved() != null);
String icon = getIconForExecutionStatus(status);
protected void initialize(PrismObject<TaskType> taskObject) {
OperationResultStatusType resultStatus = taskObject.asObjectable().getResultStatus();
String icon = OperationResultStatusIcon.parseOperationalResultStatus(resultStatus).getIcon();
setIconCssClass(icon);
setLabel(PageBase.createStringResourceStatic(TaskSummaryPanel.this, status).getString());
setLabel(PageBase.createStringResourceStatic(TaskSummaryPanel.this, resultStatus).getString());
// TODO setColor
}
};
addTag(tagExecutionStatus);
addTag(tagResult);
}

private String getIconForExecutionStatus(TaskDtoExecutionStatus status) {
Expand Down Expand Up @@ -110,11 +113,6 @@ protected boolean isIdentifierVisible() {
return false;
}

@Override
protected boolean isActivationVisible() {
return false;
}

@Override
protected IModel<String> getTitleModel() {
return new AbstractReadOnlyModel<String>() {
Expand Down

0 comments on commit e337b7e

Please sign in to comment.