Skip to content
Permalink
Fetching contributors…
Cannot retrieve contributors at this time
324 lines (280 sloc) 11 KB
//#############################################################################
//# #
//# Copyright (C) <2014> <IMS MAXIMS> #
//# #
//# This program is free software: you can redistribute it and/or modify #
//# it under the terms of the GNU Affero General Public License as #
//# published by the Free Software Foundation, either version 3 of the #
//# License, or (at your option) any later version. #
//# #
//# This program is distributed in the hope that it will be useful, #
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
//# GNU Affero General Public License for more details. #
//# #
//# You should have received a copy of the GNU Affero General Public License #
//# along with this program. If not, see <http://www.gnu.org/licenses/>. #
//# #
//#############################################################################
//#EOH
// This code was generated by Alexie Ursache using IMS Development Environment (version 1.45 build 2389.16953)
// Copyright (C) 1995-2006 IMS MAXIMS plc. All rights reserved.
package ims.assessment.forms.userdefinedformsearch;
//This code was generated by Alexie Ursache using IMS Development Environment (version 1.42 build 2196.26417)
//Copyright (C) 1995-2006 IMS MAXIMS plc. All rights reserved.
import ims.assessment.forms.userdefinedformsearch.GenForm.GroupCriteriaEnumeration;
import ims.assessment.forms.userdefinedformsearch.GenForm.grdObjectsRow;
import ims.assessment.vo.GraphicAssessmentShortVo;
import ims.assessment.vo.GraphicAssessmentShortVoCollection;
import ims.assessment.vo.UserAssessmentShortVo;
import ims.assessment.vo.UserAssessmentShortVoCollection;
import ims.assessment.vo.UserDefinedObjectComponentVo;
import ims.assessment.vo.UserDefinedObjectComponentVoCollection;
import ims.core.vo.lookups.LookupHelper;
import ims.core.vo.lookups.PreActiveActiveInactiveStatus;
import ims.core.vo.lookups.UserDefinedAssessmentType;
import ims.core.vo.lookups.UserDefinedAssessmentTypeCollection;
import ims.framework.Control;
import ims.framework.enumerations.DialogResult;
import ims.framework.exceptions.FormOpenException;
import ims.vo.LookupInstVo;
import ims.vo.ValueObjectCollection;
public class Logic extends BaseLogic
{
protected void onFormOpen() throws FormOpenException
{
open();
}
protected void onBtnCancelClick() throws ims.framework.exceptions.PresentationLogicException
{
closeDialog(DialogResult.CANCEL);
}
protected void onBtnOKClick() throws ims.framework.exceptions.PresentationLogicException
{
populateDataFromScreen();
closeDialog(DialogResult.OK);
}
protected void onImbClearClick() throws ims.framework.exceptions.PresentationLogicException
{
form.txtSearchText().setValue("");
clearGrid();
enableContextMenu();
}
protected void onImbSearchClick() throws ims.framework.exceptions.PresentationLogicException
{
clearGrid();
UserDefinedAssessmentType type = form.cmbComponent().getValue();
PreActiveActiveInactiveStatus status = PreActiveActiveInactiveStatus.ACTIVE;
String name = getName();
if(type == null)
{
engine.showMessage("Please select a Component Type.");
form.cmbComponent().setFocus();
enableContextMenu();
return;
}
ValueObjectCollection voColl = null;
if (isUserAssessmentType(type))
{
voColl = domain.listAssessments(name, status, getUserDefinedTypes(type));
}
if (ifImageAssessmentType(type))
{
//WDEV-2432 - exclude MEDICALNOTING
voColl = domain.listGraphicAssessments(name, status, getUserDefinedTypes(type, UserDefinedAssessmentType.MEDICALNOTING));
}
if (voColl == null || voColl.size() == 0)
{
engine.showMessage("No Active " + type.toString() + " found for the Search Criteria Provided");
}
populateGrid(voColl);
enableContextMenu();
}
protected void onContextMenuItemClick(int menuItemID, Control sender)
{
switch (menuItemID)
{
case GenForm.ContextMenus.GenericGrid.Add :
selectAllGridRecord(true);
break;
case GenForm.ContextMenus.GenericGrid.Update :
selectAllGridRecord(false);
break;
}
}
// --------------- Private methods -----------
private void open()
{
setContextMenu();
enableContextMenu();
populateLookups();
}
private void setContextMenu()
{
form.txtSearchText().setFocus();
form.GroupCriteria().setValue(GroupCriteriaEnumeration.rdoBeginsWith);
form.cmbComponent().setValue(UserDefinedAssessmentType.ASSESSMENTTOOL);
form.getContextMenus().getGenericGridAddItem().setText("Select All");
form.getContextMenus().getGenericGridAddItem().setIcon(form.getImages().Core.TreeViewAdd);
form.getContextMenus().getGenericGridUpdateItem().setText("Deselect All");
form.getContextMenus().getGenericGridUpdateItem().setIcon(form.getImages().Core.TreeViewDelete);
}
private void enableContextMenu()
{
boolean hasRows = form.grdObjects().getRows().size() > 0;
form.getContextMenus().getGenericGridAddItem().setVisible(hasRows);
form.getContextMenus().getGenericGridUpdateItem().setVisible(hasRows);
}
private void populateLookups()
{
form.cmbComponent().clear();
//WDEV-1692 - Display first level one lookups
UserDefinedAssessmentTypeCollection lookupColl = LookupHelper.getUserDefinedAssessmentType(domain.getLookupService());
LookupInstVo[] lookupParents = lookupColl.getRoots();
for (int i = 0; lookupColl != null && i < lookupColl.size(); i++)
{
UserDefinedAssessmentType assessmentType = lookupColl.get(i);
if (lookupHasARootParent(lookupParents, assessmentType))
{
form.cmbComponent().newRow(lookupColl.get(i), lookupColl.get(i).toString(), lookupColl.get(i).getImage(), lookupColl.get(i).getColor());
}
}
}
private boolean lookupHasARootParent(LookupInstVo[] lookupParents, UserDefinedAssessmentType assessmentType)
{
if(lookupParents == null || assessmentType == null || assessmentType.getParent() == null)
return false;
for (int i = 0; i < lookupParents.length; i++)
{
if(lookupParents[i].equals(assessmentType.getParent()))
return true;
}
return false;
}
private void populateDataFromScreen()
{
UserDefinedObjectComponentVoCollection voColl = new UserDefinedObjectComponentVoCollection();
for (int i = 0; i < form.grdObjects().getRows().size(); i++)
{
if (form.grdObjects().getRows().get(i).getcolSelect())
{
UserDefinedObjectComponentVo voUserDefinedObjectComponent = new UserDefinedObjectComponentVo();
voUserDefinedObjectComponent.setActiveStatus(PreActiveActiveInactiveStatus.ACTIVE);
// Assessment Tool
Object objVo = form.grdObjects().getRows().get(i).getValue();
if (objVo instanceof UserAssessmentShortVo)
{
ims.assessment.vo.UserAssessmentVo voUserAssessment = domain.getUserAssessment(((UserAssessmentShortVo) objVo).getID_UserAssessment());
voUserDefinedObjectComponent.setUserAssessment(voUserAssessment);
}
// Graphic
if (objVo instanceof GraphicAssessmentShortVo)
{
ims.assessment.vo.GraphicAssessmentVo voGraphicAssessment = domain.getGraphicAssessment(((GraphicAssessmentShortVo) objVo).getID_GraphicAssessment());
voUserDefinedObjectComponent.setGraphic(voGraphicAssessment);
}
voColl.add(voUserDefinedObjectComponent);
}
}
form.getGlobalContext().Core.setUserDefinedObjectComponents(voColl);
}
private void closeDialog(DialogResult result)
{
engine.close(result);
}
private String getName()
{
String name = form.txtSearchText().getValue();
if (name != null)
name = name.trim();
if (name != null)
{
GroupCriteriaEnumeration criteria = form.GroupCriteria().getValue();
if (criteria != null)
{
if (criteria.equals(GroupCriteriaEnumeration.rdoBeginsWith))
name += '%';
if (criteria.equals(GroupCriteriaEnumeration.rdoContains))
name = '%' + name + '%';
}
}
return name;
}
private void populateGrid(ValueObjectCollection voColl)
{
if (voColl != null)
{
if (voColl instanceof UserAssessmentShortVoCollection)
{
UserAssessmentShortVoCollection voUserAssColl = (UserAssessmentShortVoCollection) voColl;
for (int i = 0; i < voUserAssColl.size(); i++)
{
addGriRow(voUserAssColl.get(i), voUserAssColl.get(i).getName());
}
}
if (voColl instanceof GraphicAssessmentShortVoCollection)
{
GraphicAssessmentShortVoCollection voGraphicAssColl = (GraphicAssessmentShortVoCollection) voColl;
for (int i = 0; i < voGraphicAssColl.size(); i++)
{
addGriRow(voGraphicAssColl.get(i), voGraphicAssColl.get(i).getName());
}
}
}
}
private void addGriRow(Object voObj, String name)
{
grdObjectsRow row = form.grdObjects().getRows().newRow();
row.setcolName(name);
row.setValue(voObj);
}
private void selectAllGridRecord(boolean value)
{
for (int i = 0; i < form.grdObjects().getRows().size(); i++)
{
form.grdObjects().getRows().get(i).setcolSelect(value);
}
}
private void clearGrid()
{
form.grdObjects().getRows().clear();
}
private boolean ifImageAssessmentType(UserDefinedAssessmentType type)
{
return (type != null && (type.equals(UserDefinedAssessmentType.ANNOTATEDIMAGEWITHQUESTIONS) || type.equals(UserDefinedAssessmentType.ANNOTATEDIMAGE) || type.equals(UserDefinedAssessmentType.ANNOTATEDIMAGEWITHREVIEWS)));
}
private boolean isUserAssessmentType(UserDefinedAssessmentType type)
{
return (type != null && (type.equals(UserDefinedAssessmentType.USERDEFINEDDATASHEET) || type.equals(UserDefinedAssessmentType.ASSESSMENTTOOL)));
}
private UserDefinedAssessmentTypeCollection getUserDefinedTypes(UserDefinedAssessmentType type)
{
return getUserDefinedTypes(type, null);
}
private UserDefinedAssessmentTypeCollection getUserDefinedTypes(UserDefinedAssessmentType type, UserDefinedAssessmentType excludedType)
{
UserDefinedAssessmentTypeCollection assTypeColl = new UserDefinedAssessmentTypeCollection();
if(type != null)
{
assTypeColl.add(type);
UserDefinedAssessmentTypeCollection udfColl = LookupHelper.getUserDefinedAssessmentType(domain.getLookupService());
for (int i = 0; i < udfColl.size(); i++)
{
UserDefinedAssessmentType lkpType = udfColl.get(i);
if(type.equals(lkpType))
{
//Add the children (if any) to the collection
for (int j = 0; lkpType.getChildInstances() != null && j < lkpType.getChildInstances().size(); j++)
{
UserDefinedAssessmentType userDefinedAssessmentType = (UserDefinedAssessmentType)lkpType.getChildInstances().get(j);
if(excludedType != null && excludedType.equals(userDefinedAssessmentType))
continue;
assTypeColl.add(userDefinedAssessmentType);
}
}
}
}
return assTypeColl;
}
// --------------- End Private methods -------
}
You can’t perform that action at this time.