Skip to content

Commit

Permalink
Delta viewer: references shown as icon + link (does nothing for now).
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 21, 2016
1 parent b65fdf1 commit 4ad80e9
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 8 deletions.
Expand Up @@ -48,12 +48,12 @@ public String getName() {
return sceneItemDto.getName();
}

public String getOldValue() {
return sceneItemOldValue != null ? sceneItemOldValue.getText() : null;
public SceneItemValue getOldValue() {
return sceneItemOldValue;
}

public String getNewValue() {
return sceneItemNewValue != null ? sceneItemNewValue.getText() : null;
public SceneItemValue getNewValue() {
return sceneItemNewValue;
}

public Integer getNumberOfLines() {
Expand Down
Expand Up @@ -19,8 +19,8 @@
<wicket:panel>
<tr>
<td style="vertical-align:middle" wicket:id="nameContainer"><span wicket:id="name"/></td>
<td wicket:id="oldValueContainer"><span wicket:id="oldValue"/></td>
<td wicket:id="newValueContainer"><span wicket:id="newValue"/></td>
<td wicket:id="oldValueContainer"><div wicket:id="oldValue"/></td>
<td wicket:id="newValueContainer"><div wicket:id="newValue"/></td>
</tr>
</wicket:panel>
</html>
Expand Up @@ -17,6 +17,7 @@
package com.evolveum.midpoint.web.component.prism.show;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.model.api.visualizer.SceneItemValue;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
Expand Down Expand Up @@ -68,11 +69,11 @@ public boolean isVisible() {
return getModelObject().isDelta();
}
});
oldValueCell.add(new Label(ID_OLD_VALUE, new PropertyModel<String>(getModel(), SceneItemLineDto.F_OLD_VALUE)));
oldValueCell.add(new SceneItemValuePanel(ID_OLD_VALUE, new PropertyModel<SceneItemValue>(getModel(), SceneItemLineDto.F_OLD_VALUE)));
add(oldValueCell);

WebMarkupContainer newValueCell = new WebMarkupContainer(ID_NEW_VALUE_CONTAINER);
newValueCell.add(new Label(ID_NEW_VALUE, new PropertyModel<String>(getModel(), SceneItemLineDto.F_NEW_VALUE)));
newValueCell.add(new SceneItemValuePanel(ID_NEW_VALUE, new PropertyModel<SceneItemValue>(getModel(), SceneItemLineDto.F_NEW_VALUE)));
newValueCell.add(new AttributeModifier("colspan", new AbstractReadOnlyModel<Integer>() {
@Override
public Integer getObject() {
Expand Down
@@ -0,0 +1,24 @@
<!--
~ 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.
-->

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<span wicket:id="icon"/>
<span wicket:id="label"/>
<span wicket:id="link"/>
</wicket:panel>
</html>
@@ -0,0 +1,117 @@
/*
* 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.prism.show;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.model.api.visualizer.SceneItemValue;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.web.component.data.column.ImagePanel;
import com.evolveum.midpoint.web.component.data.column.LinkPanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.util.ObjectTypeGuiDescriptor;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;

import javax.xml.namespace.QName;

/**
* TODO make this parametric (along with SceneItemValue)
* @author mederly
*/
public class SceneItemValuePanel extends BasePanel<SceneItemValue> {

private static final String ID_ICON = "icon";
private static final String ID_LABEL = "label";
private static final String ID_LINK = "link";

public SceneItemValuePanel(String id, IModel<SceneItemValue> model) {
super(id, model);
initLayout();
}

private void initLayout() {

final VisibleEnableBehaviour visibleIfReference = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
SceneItemValue object = getModelObject();
return object != null && object.getSourceValue() instanceof PrismReferenceValue;
}
};
final VisibleEnableBehaviour visibleIfNotReference = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
SceneItemValue object = getModelObject();
return object == null || !(object.getSourceValue() instanceof PrismReferenceValue);
}
};

final ImagePanel icon = new ImagePanel(ID_ICON, new IconModel(), new TitleModel());
icon.add(visibleIfReference);
add(icon);

final Label label = new Label(ID_LABEL, new LabelModel());
label.add(visibleIfNotReference);
add(label);

final LinkPanel<String> link = new LinkPanel<String>(ID_LINK, new LabelModel()) {
@Override
public void onClick(AjaxRequestTarget target) {
System.out.println("Clicked on " + getModelObject().getSourceValue());
super.onClick(target);
}
};
link.add(visibleIfReference);
add(link);
}

private ObjectTypeGuiDescriptor getObjectTypeDescriptor() {
SceneItemValue value = getModelObject();
if (value.getSourceValue() instanceof PrismReferenceValue) {
QName targetType = ((PrismReferenceValue) value.getSourceValue()).getTargetType();
return ObjectTypeGuiDescriptor.getDescriptor(ObjectTypes.getObjectTypeFromTypeQName(targetType));
} else {
return null;
}
}

private class IconModel extends AbstractReadOnlyModel<String> {
@Override
public String getObject() {
ObjectTypeGuiDescriptor guiDescriptor = getObjectTypeDescriptor();
return guiDescriptor != null ? guiDescriptor.getIcon() : ObjectTypeGuiDescriptor.ERROR_ICON;
}
}

private class TitleModel extends AbstractReadOnlyModel<String> {
@Override
public String getObject() {
ObjectTypeGuiDescriptor guiDescriptor = getObjectTypeDescriptor();
return guiDescriptor != null ? createStringResource(guiDescriptor.getLocalizationKey()).getObject() : null;
}
}

private class LabelModel extends AbstractReadOnlyModel<String> {
@Override
public String getObject() {
return getModelObject() != null ? getModelObject().getText() : null;
}
}
}

0 comments on commit 4ad80e9

Please sign in to comment.