Skip to content

Commit

Permalink
a way to repalce loooooong if-else
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Oct 10, 2018
1 parent 79de7fb commit 04508f1
Show file tree
Hide file tree
Showing 11 changed files with 1,206 additions and 2 deletions.
Expand Up @@ -30,6 +30,7 @@
import com.evolveum.midpoint.gui.api.util.ModelServiceLocator;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.impl.factory.GuiComponentRegistry;
import com.evolveum.midpoint.model.api.*;
import com.evolveum.midpoint.model.api.expr.MidpointFunctions;
import com.evolveum.midpoint.model.api.validator.ResourceValidator;
Expand Down Expand Up @@ -158,6 +159,7 @@
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.util.string.StringValue;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

Expand Down Expand Up @@ -300,6 +302,8 @@ public abstract class PageBase extends WebPage implements ModelServiceLocator {

@SpringBean
private MidpointFunctions midpointFunctions;

@SpringBean private GuiComponentRegistry registry;

private List<Breadcrumb> breadcrumbs;

Expand Down Expand Up @@ -542,6 +546,10 @@ public ModelInteractionService getModelInteractionService() {
protected ModelDiagnosticService getModelDiagnosticService() {
return modelDiagnosticService;
}

public GuiComponentRegistry getRegistry() {
return registry;
}

public CacheDispatcher getCacheDispatcher() {
return cacheDispatcher;
Expand Down
@@ -0,0 +1,16 @@
package com.evolveum.midpoint.gui.impl.factory;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.web.component.prism.InputPanel;
import com.evolveum.midpoint.web.component.prism.ValueWrapper;

public interface GuiComponentFactory {

// public void register();

public <T> boolean match(ValueWrapper<T> valueWrapper);

public <T> Panel createPanel(String id, IModel<ValueWrapper<T>> model, String baseExpression);
}
@@ -0,0 +1,12 @@
package com.evolveum.midpoint.gui.impl.factory;

import com.evolveum.midpoint.web.component.prism.ItemWrapper;
import com.evolveum.midpoint.web.component.prism.ValueWrapper;

public interface GuiComponentRegistry {

public void addToRegistry(GuiComponentFactory factory);

public <T> GuiComponentFactory findFactory(ValueWrapper<T> valueWrapper);

}
@@ -0,0 +1,22 @@
package com.evolveum.midpoint.gui.impl.factory;

import java.util.ArrayList;
import java.util.List;

import com.evolveum.midpoint.web.component.prism.ValueWrapper;

public class GuiComponentRegistryImpl implements GuiComponentRegistry {

List<GuiComponentFactory> guiComponentFactories = new ArrayList<>();

@Override
public void addToRegistry(GuiComponentFactory factory) {
guiComponentFactories.add(factory);
}

@Override
public <T> GuiComponentFactory findFactory(ValueWrapper<T> valueWrapper) {
return guiComponentFactories.stream().filter(f -> f.match(valueWrapper)).findFirst().get();
}

}
@@ -0,0 +1,36 @@
package com.evolveum.midpoint.gui.impl.factory;

import javax.annotation.PostConstruct;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.web.component.LockoutStatusPanel;
import com.evolveum.midpoint.web.component.prism.ValueWrapper;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;

@Component
public class LockoutStatusPanelFactory implements GuiComponentFactory {

@Autowired GuiComponentRegistry registry;

// @Override
@PostConstruct
public void register() {
registry.addToRegistry(this);
}

@Override
public <T> boolean match(ValueWrapper<T> valueWrapper) {
return ActivationType.F_LOCKOUT_STATUS.equals(valueWrapper.getItem().getItemDefinition().getName());
}

@Override
public <T> Panel createPanel(String id, IModel<ValueWrapper<T>> model, String baseExpression) {
return new LockoutStatusPanel(id, model.getObject(), new PropertyModel<>(model, baseExpression));
}

}
@@ -0,0 +1,36 @@
<!--
~ Copyright (c) 2010-2017 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>
<div wicket:id="valueContainer" class="row">
<div wicket:id="input" class="col-xs-10"/>

<div class="col-xs-2">
<span class="btn-group">
<!-- <a class="btn btn-danger btn-sm" wicket:id="removeButton"><i class="glyphicon glyphicon-minus"/></a>
<a class="btn btn-success btn-sm" wicket:id="addButton"><i class="glyphicon glyphicon-plus"/></a> -->
<a class="btn btn-box-tool" wicket:id="removeButton"><i class="fa fa-minus-circle"/></a>
<a class="btn btn-box-tool" wicket:id="addButton"><i class="fa fa-plus-circle"/></a>
</span>
</div>
</div>
<div class="row">
<span wicket:id="feedback" class="text-danger"/>
</div>
</wicket:panel>
</html>

0 comments on commit 04508f1

Please sign in to comment.