Skip to content

Commit

Permalink
More steps with summary panel. Summary tag componentized.
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Oct 9, 2015
1 parent 8747b95 commit 9fdd132
Show file tree
Hide file tree
Showing 17 changed files with 562 additions and 109 deletions.
Expand Up @@ -32,8 +32,11 @@
</span>
</span>
<span class="summary-tag-box">
<span class="summary-tag"><span class="summary-tag-icon"><span wicket:id="summaryTagActivationIcon"/></span> <span wicket:id="summaryTagActivationLabel"/></span>
<span class="summary-tag"><span class="summary-tag-icon"><span wicket:id="summaryTagSecurityIcon"/></span> <span wicket:id="summaryTagSecurityLabel"/></span>
<span wicket:id="summaryTagActivation"/>
<span wicket:id="summaryTagSecurity"/>

<wicket:child />

</span>
</span>
</div>
Expand Down
Expand Up @@ -30,7 +30,11 @@
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.ReadOnlyWrapperModel;
import com.evolveum.midpoint.web.component.util.SummaryTag;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

/**
Expand All @@ -48,14 +52,15 @@ public abstract class FocusSummaryPanel<F extends FocusType> extends Panel {
private static final String ID_IDENTIFIER = "summaryIdentifier";
private static final String ID_TITLE = "summaryTitle";
private static final String ID_ORGANIZATION = "summaryOrganization";
private static final String ID_TAG_ACTIVATION_ICON = "summaryTagActivationIcon";
private static final String ID_TAG_ACTIVATION_LABEL = "summaryTagActivationLabel";
private static final String ID_TAG_SECURITY_ICON = "summaryTagSecurityIcon";
private static final String ID_TAG_SECURITY_LABEL = "summaryTagSecurityLabel";
private static final String ID_TAG_ACTIVATION = "summaryTagActivation";
private static final String ID_TAG_SECURITY = "summaryTagSecurity";

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

protected static final String ICON_CLASS_ACTIVATION_ACTIVE = "fa fa-check";
protected static final String ICON_CLASS_ACTIVATION_INACTIVE = "fa fa-times";

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

Expand All @@ -71,19 +76,38 @@ public FocusSummaryPanel(String id, final IModel<ObjectWrapper<F>> model) {
} else {
box.add(new Label(ID_TITLE, new PrismPropertyWrapperModel<>(model, getTitlePropertyName())));
}
box.add(new Label(ID_ORGANIZATION, "TODO"));

Label tagActivationIcon = new Label(ID_TAG_ACTIVATION_ICON, "");
tagActivationIcon.add(new AttributeModifier("class", "fa fa-check"));
box.add(tagActivationIcon);
box.add(new Label(ID_TAG_ACTIVATION_LABEL, "TODO"));

Label tagSecurityIcon = new Label(ID_TAG_SECURITY_ICON, "");
tagSecurityIcon.add(new AttributeModifier("class", "fa fa-shield"));
box.add(tagSecurityIcon);
box.add(new Label(ID_TAG_SECURITY_LABEL, "TODO"));
box.add(new Label(ID_ORGANIZATION, "TODO: Organization"));

SummaryTag<F> tagActivation = new SummaryTag<F>(ID_TAG_ACTIVATION, model) {
@Override
protected void initialize(ReadOnlyWrapperModel<F> model) {
ActivationType activation = model.getObjectType().getActivation();
if (activation == null) {
setIconCssClass(ICON_CLASS_ACTIVATION_ACTIVE);
setLabel("Active");
setColor("green");
} else if (activation.getEffectiveStatus() == ActivationStatusType.ENABLED) {
setIconCssClass(ICON_CLASS_ACTIVATION_ACTIVE);
setLabel("Active");
setColor("green");
} else {
setIconCssClass(ICON_CLASS_ACTIVATION_INACTIVE);
setLabel("Inactive");
setColor("red");
}
}
};
box.add(tagActivation);

SummaryTag<F> tagSecurity = new SummaryTag<F>(ID_TAG_SECURITY, model) {
@Override
protected void initialize(ReadOnlyWrapperModel<F> model) {
setIconCssClass("fa fa-shield");
setLabel("TODO");
}
};
box.add(tagSecurity);

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

Expand Down
@@ -0,0 +1,68 @@
/*
* 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.util;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.prism.ObjectWrapper;
import com.evolveum.midpoint.web.page.error.PageError;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

import org.apache.commons.lang.Validate;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.model.IModel;

import javax.xml.namespace.QName;

/**
* @author semancik
*/
public abstract class AbstractWrapperModel<O extends ObjectType> implements IModel {

private IModel<ObjectWrapper<O>> wrapperModel;

public AbstractWrapperModel(IModel<ObjectWrapper<O>> wrapperModel) {
Validate.notNull(wrapperModel, "Wrapper model must not be null.");
this.wrapperModel = wrapperModel;
}

public IModel<ObjectWrapper<O>> getWrapperModel() {
return wrapperModel;
}

public ObjectWrapper<O> getWrapper() {
return wrapperModel.getObject();
}

public O getObjectType() {
return wrapperModel.getObject().getObject().asObjectable();
}

public PrismObject<O> getPrismObject() {
return wrapperModel.getObject().getObject();
}

@Override
public void detach() {
}

}
Expand Up @@ -39,31 +39,27 @@
* @author lazyman
* @author semancik
*/
public class PrismPropertyWrapperModel<O extends ObjectType> implements IModel {
public class PrismPropertyWrapperModel<O extends ObjectType> extends AbstractWrapperModel<O> {

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

private IModel<ObjectWrapper<O>> model;
private ItemPath path;

public PrismPropertyWrapperModel(IModel<ObjectWrapper<O>> model, QName item) {
this(model, new ItemPath(item));
}

public PrismPropertyWrapperModel(IModel<ObjectWrapper<O>> model, ItemPath path) {
Validate.notNull(model, "Prism object model must not be null.");
super(model);
Validate.notNull(path, "Item path must not be null.");

this.model = model;
this.path = path;
}

@Override
public Object getObject() {
PrismObject<O> object = model.getObject().getObject();
PrismProperty property;
try {
property = object.findOrCreateProperty(path);
property = getPrismObject().findOrCreateProperty(path);
} catch (SchemaException ex) {
LoggingUtils.logException(LOGGER, "Couldn't create property in path {}", ex, path);
//todo show message in page error [lazyman]
Expand All @@ -76,8 +72,7 @@ public Object getObject() {
@Override
public void setObject(Object object) {
try {
PrismObject<O> obj = model.getObject().getObject();
PrismProperty property = obj.findOrCreateProperty(path);
PrismProperty property = getPrismObject().findOrCreateProperty(path);

if (object != null) {
PrismPropertyDefinition def = property.getDefinition();
Expand Down
@@ -0,0 +1,51 @@
/*
* 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.util;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.prism.ObjectWrapper;
import com.evolveum.midpoint.web.page.error.PageError;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

import org.apache.commons.lang.Validate;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.model.IModel;

import javax.xml.namespace.QName;

/**
* @author semancik
*/
public abstract class ReadOnlyWrapperModel<O extends ObjectType> extends AbstractWrapperModel<O> {

public ReadOnlyWrapperModel(IModel<ObjectWrapper<O>> wrapperModel) {
super(wrapperModel);
}

@Override
public void setObject(Object object) {
throw new UnsupportedOperationException("Model " + getClass() +
" does not support setObject(Object)");
}

}
@@ -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,113 @@
/**
* 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.util;

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.IModel;

import com.evolveum.midpoint.web.component.prism.ObjectWrapper;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

/**
* @author semancik
*
*/
public abstract class SummaryTag<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;

public SummaryTag(String id, final IModel<ObjectWrapper<O>> model) {
super(id, model);

Label tagIcon = new Label(ID_TAG_ICON, "");
tagIcon.add(new AttributeModifier("class", new SummaryTagWrapperModel(model) {
@Override
protected Object getValue() {
return getIconCssClass();
}
}));
add(tagIcon);

add(new Label(ID_TAG_LABEL, new SummaryTagWrapperModel(model) {
@Override
protected Object getValue() {
return getLabel();
}
}));

add(new AttributeModifier("style", new SummaryTagWrapperModel(model) {
@Override
protected Object getValue() {
if (getColor() == null) {
return null;
}
return "color: " + getColor();
}
}));
}

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;
}

protected abstract void initialize(ReadOnlyWrapperModel<O> model);

abstract class SummaryTagWrapperModel extends ReadOnlyWrapperModel<O> {

public SummaryTagWrapperModel(IModel<ObjectWrapper<O>> wrapperModel) {
super(wrapperModel);
}

@Override
public Object getObject() {
if (!initialized) {
initialize(this);
}
return getValue();
}

protected abstract Object getValue();

}
}

0 comments on commit 9fdd132

Please sign in to comment.