Skip to content

Commit

Permalink
new assignment popup panel (Resource tab)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Jun 21, 2018
1 parent 4d96108 commit f4a48e0
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 36 deletions.
Expand Up @@ -78,7 +78,7 @@ protected void onUpdateCheckbox(AjaxRequestTarget target) {

@Override
protected IModel<Boolean> getCheckBoxEnableModel(IModel<SelectableBean<O>> rowModel){
return getObjectSelectCheckBoxEnableModel();
return getObjectSelectCheckBoxEnableModel(rowModel);
}

@Override
Expand Down Expand Up @@ -128,7 +128,7 @@ protected List getSelectedObjectsList(){
return objectListPanel.getSelectedObjects();
}

protected IModel<Boolean> getObjectSelectCheckBoxEnableModel(){
protected IModel<Boolean> getObjectSelectCheckBoxEnableModel(IModel<SelectableBean<O>> rowModel){
return Model.of(true);
}

Expand Down
Expand Up @@ -8,10 +8,7 @@
import com.evolveum.midpoint.web.component.TabbedPanel;
import com.evolveum.midpoint.web.component.dialog.Popupable;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
Expand Down Expand Up @@ -41,7 +38,7 @@ public class AssignmentPopup<O extends ObjectType> extends BasePanel implements
private FocusTypeAssignmentPopupTabPanel orgsTabPanel;
private FocusTypeAssignmentPopupTabPanel servicesTabPanel;
private FocusTypeAssignmentPopupTabPanel usersTabPanel;
private FocusTypeAssignmentPopupTabPanel resourcesTabPanel;
private ResourceTypeAssignmentPopupTabPanel resourcesTabPanel;


public AssignmentPopup(String id){
Expand Down Expand Up @@ -112,6 +109,22 @@ public void onClick(AjaxRequestTarget target) {
newAssignmentsList.add(newAssignment);
});
}
if (resourcesTabPanel != null){
List<ResourceType> selectedResourcces = resourcesTabPanel.getSelectedObjectsList();
String intent = resourcesTabPanel.getIntentValue();
ShadowKindType kind = resourcesTabPanel.getKindValue();
selectedResourcces.forEach(selectedResource -> {
ConstructionType constructionType = new ConstructionType();
ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(selectedResource);
constructionType.setResourceRef(ref);
constructionType.setKind(kind);
constructionType.setIntent(intent);

AssignmentType newAssignment = new AssignmentType();
newAssignment.setConstruction(constructionType);
newAssignmentsList.add(newAssignment);
});
}
addPerformed(target, newAssignmentsList);

}
Expand Down Expand Up @@ -207,21 +220,33 @@ public String getCount() {
}
});

// tabs.add(
// new CountablePanelTab(getPageBase().createStringResource("ObjectTypes.RESOURCE"), authorization) {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public WebMarkupContainer createPanel(String panelId) {
// return new FocusTypeAssignmentPopupTabPanel(panelId, ObjectTypes.RESOURCE);
// }
//
// @Override
// public String getCount() {
// return "0";
// }
// });
tabs.add(
new CountablePanelTab(getPageBase().createStringResource("ObjectTypes.RESOURCE"), authorization) {

private static final long serialVersionUID = 1L;

@Override
public WebMarkupContainer createPanel(String panelId) {
resourcesTabPanel = new ResourceTypeAssignmentPopupTabPanel(panelId){
private static final long serialVersionUID = 1L;

@Override
protected void onSelectionPerformed(AjaxRequestTarget target){
super.onSelectionPerformed(target);
tabLabelPanelUpdate(target);
}
};
return resourcesTabPanel;
}

@Override
public String getCount() {
if (resourcesTabPanel == null){
return "0";
}
return Integer.toString(resourcesTabPanel.getObjectListPanel().getSelectedObjectsCount());
}
});

return tabs;
}
Expand Down
Expand Up @@ -23,14 +23,13 @@
<label><wicket:message key="AssignmentPanel.newAssignmentParameters" /></label>
</div>
</div>
<div class="row">
<div wicket:id="relationContainer" class="row">
<div class="form-group col-md-12">
<div class="col-md-3" wicket:id="relationContainer">
<div>
<wicket:message key="AssignmentEditorPanel.relation"/>
</div>
<div class="col-md-1" >
<div><wicket:message key="AssignmentEditorPanel.relation"/></div>
</div>
<div class="col-md-3" >
<span wicket:id="relation"/>

</div>
</div>
</div>
Expand Down
@@ -0,0 +1,46 @@
<!--
~ Copyright (c) 2010-2018 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:extend>
<div class="form-inline search-form">
<div class="row">
<div class="col-md-4">
<label><wicket:message key="AssignmentPanel.newAssignmentParameters" /></label>
</div>
</div>
<div class="row">
<div wicket:id="kindContainer" class="form-group col-md-5">
<div class="col-md-3" >
<div><wicket:message key="TypedAssignablePanel.Kind"/></div>
</div>
<div class="col-md-6" >
<span wicket:id="kind"/>
</div>
</div>
<div wicket:id="intentContainer" class="form-group col-md-5">
<div class="col-md-3" >
<div><wicket:message key="TypedAssignablePanel.Intent"/></div>
</div>
<div class="col-md-6" >
<span wicket:id="intent"/>
</div>
</div>
</div>
</div>
</wicket:extend>
</html>
@@ -0,0 +1,217 @@
/*
* Copyright (c) 2010-2018 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.gui.api.component;

import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.assignment.RelationTypes;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;

/**
* Created by honchar
*/
public class ResourceTypeAssignmentPopupTabPanel extends AbstractAssignmentPopupTabPanel<ResourceType>{

private static final long serialVersionUID = 1L;

private static final String ID_KIND_CONTAINER = "kindContainer";
private static final String ID_INTENT_CONTAINER = "intentContainer";
private static final String ID_KIND = "kind";
private static final String ID_INTENT = "intent";

private LoadableModel<List<String>> intentValues;
private String intentValue = "";

private static final String DOT_CLASS = ResourceTypeAssignmentPopupTabPanel.class.getName();
private static final Trace LOGGER = TraceManager.getTrace(ResourceTypeAssignmentPopupTabPanel.class);

public ResourceTypeAssignmentPopupTabPanel(String id){
super(id, ObjectTypes.RESOURCE);
}

@Override
protected void initParametersPanel(){
initModels();

WebMarkupContainer kindContainer = new WebMarkupContainer(ID_KIND_CONTAINER);
kindContainer.setOutputMarkupId(true);
add(kindContainer);

DropDownChoicePanel<ShadowKindType> kindSelector = WebComponentUtil.createEnumPanel(ShadowKindType.class, ID_KIND,
WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), Model.of(ShadowKindType.ACCOUNT),
ResourceTypeAssignmentPopupTabPanel.this, false);
kindSelector.setOutputMarkupId(true);
kindSelector.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1L;

@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(getIntentDropDown());
}
});
kindSelector.getBaseFormComponent().add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;

@Override
public boolean isEnabled(){
return getSelectedObjectsList() != null && getSelectedObjectsList().size() > 0;
}
});
kindSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
kindSelector.setOutputMarkupPlaceholderTag(true);
kindContainer.add(kindSelector);

WebMarkupContainer intentContainer = new WebMarkupContainer(ID_INTENT_CONTAINER);
intentContainer.setOutputMarkupId(true);
add(intentContainer);

DropDownChoicePanel<String> intentSelector = new DropDownChoicePanel<String>(ID_INTENT,
new IModel<String>() {
private static final long serialVersionUID = 1L;

@Override
public String getObject() {
return intentValue;
}

@Override
public void setObject(String s) {
intentValue = s;
}

@Override
public void detach() {

}
}, intentValues);
intentSelector.getBaseFormComponent().add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;

@Override
public boolean isEnabled(){
return getSelectedObjectsList() != null && getSelectedObjectsList().size() > 0;
}
});
intentSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
intentSelector.setOutputMarkupId(true);
intentSelector.setOutputMarkupPlaceholderTag(true);
intentContainer.add(intentSelector);

}

private DropDownChoicePanel getIntentDropDown(){
return (DropDownChoicePanel)get(ID_INTENT_CONTAINER).get(ID_INTENT);
}

private DropDownChoicePanel<ShadowKindType> getKindDropDown(){
return (DropDownChoicePanel<ShadowKindType>)get(ID_KIND_CONTAINER).get(ID_KIND);
}

private void initModels(){
intentValues = new LoadableModel<List<String>>(true) {
private static final long serialVersionUID = 1L;

@Override
protected List<String> load() {
List<String> availableIntentValues = new ArrayList<>();
PopupObjectListPanel resourcesListPanel = getObjectListPanel();
if (resourcesListPanel != null) {
List<ResourceType> selectedResources = resourcesListPanel.getSelectedObjects();
if (selectedResources != null && selectedResources.size() > 0) {
ResourceType selectedResource = selectedResources.get(0);

try {
RefinedResourceSchema refinedSchema = RefinedResourceSchema.getRefinedSchema(selectedResource.asPrismObject());
if (refinedSchema != null) {
ShadowKindType kind = (ShadowKindType) getKindDropDown().getBaseFormComponent().getModelObject();
List<? extends RefinedObjectClassDefinition> definitions = refinedSchema.getRefinedDefinitions(kind);
for (RefinedObjectClassDefinition def : definitions) {
availableIntentValues.add(def.getIntent());
}
}
} catch (SchemaException ex) {
LOGGER.error("Cannot get refined resource schema for resource {}. {}", selectedResource.getName().getOrig(), ex.getLocalizedMessage());
}

}
}
if (availableIntentValues.size() > 0){
intentValue = availableIntentValues.get(0);
}
return availableIntentValues;
}
};
// intentValueModel = new IModel<String>() {
// @Override
// public String getObject() {
// return intent != null ? intent :
// (intentValues.getObject().size() > 0 ?
// intentValues.getObject().get(0) : "default");
// }
//
// @Override
// public void setObject(String s) {
// intent = s;
// }
//
// @Override
// public void detach() {
//
// }
// };
}

public String getIntentValue(){
return intentValue;
}

public ShadowKindType getKindValue(){
return getKindDropDown().getModel().getObject();
}

@Override
protected void onSelectionPerformed(AjaxRequestTarget target){
target.add(getObjectListPanel());
}

@Override
protected IModel<Boolean> getObjectSelectCheckBoxEnableModel(IModel<SelectableBean<ResourceType>> rowModel){
List selectedObjects = getSelectedObjectsList();
return Model.of(selectedObjects == null || selectedObjects.size() == 0
|| (rowModel != null && rowModel.getObject() != null && rowModel.getObject().isSelected()));
}
}

0 comments on commit f4a48e0

Please sign in to comment.