ItEr28S12ClasificacionTraballoItEr27S12 : Correction in Management of criterion types and criterion.

This commit is contained in:
Susana Montes Pedreira 2009-10-01 15:36:23 +02:00 committed by Javier Moran Rua
parent ba9ffbb232
commit 5ffe3b53fd
6 changed files with 97 additions and 37 deletions

View file

@ -23,6 +23,7 @@ package org.navalplanner.web.resources.criterion;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.validator.InvalidValue;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.CriterionType;
@ -193,12 +194,16 @@ public class CriterionAdminController_V2 extends GenericForwardComposer {
}
public void saveAndClose(){
save();
close();
try{
save();
close();
} catch (ValidationException e) {}
}
public void saveAndContinue(){
save();
try{
save();
} catch (ValidationException e) {}
}
public void close(){
@ -206,12 +211,16 @@ public class CriterionAdminController_V2 extends GenericForwardComposer {
Util.reloadBindings(listing);
}
private void save() {
private void save() throws ValidationException{
try {
criterionsModel_V2.saveCriterionType();
messagesForUser.showMessage(Level.INFO, _("CriterionType and it`s criterions saved"));
} catch (ValidationException e) {
messagesForUser.showInvalidValues(e);
for (InvalidValue invalidValue : e.getInvalidValues()) {
String message = invalidValue.getPropertyName()+" : "+invalidValue.getMessage();
messagesForUser.showMessage(Level.INFO,message);
}
throw e;
}
}

View file

@ -24,8 +24,10 @@ import java.util.Iterator;
import java.util.Set;
import static org.navalplanner.web.I18nHelper._;
import org.apache.commons.lang.Validate;
import org.hibernate.validator.InvalidValue;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.web.common.IMessagesForUser;
import org.navalplanner.web.common.Level;
import org.navalplanner.web.common.MessagesForUser;
import org.navalplanner.web.common.Util;
import org.zkoss.zk.ui.Component;
@ -104,7 +106,9 @@ public class CriterionTreeController extends GenericForwardComposer {
}
Treecell cellForName = new Treecell();
cellForName.appendChild(Util.bind(new Textbox(),
Textbox textboxName= new Textbox();
textboxName.setWidth("400px");
cellForName.appendChild(Util.bind(textboxName,
new Util.Getter<String>() {
@Override
@ -191,23 +195,22 @@ public class CriterionTreeController extends GenericForwardComposer {
}
});
Button indentbutton = new Button("", "/common/img/ico_derecha1.png");
indentbutton.setHoverImage("/common/img/ico_derecha.png");
Button indentbutton = createButtonIndent();
indentbutton.setParent(tcOperations);
indentbutton.setSclass("icono");
indentbutton.addEventListener(Events.ON_CLICK, new EventListener() {
if(getModel().getCriterionType().allowHierarchy()){
indentbutton.addEventListener(Events.ON_CLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
getModel().indent(criterionForThisRow);
reloadTree();
}
});
});
}
Button unindentbutton = new Button("", "/common/img/ico_izq1.png");
unindentbutton.setHoverImage("/common/img/ico_izq.png");
Button unindentbutton = createButtonUnindent();
unindentbutton.setParent(tcOperations);
unindentbutton.setSclass("icono");
unindentbutton.addEventListener(Events.ON_CLICK,
if(getModel().getCriterionType().allowHierarchy()){
unindentbutton.addEventListener(Events.ON_CLICK,
new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
@ -215,6 +218,7 @@ public class CriterionTreeController extends GenericForwardComposer {
reloadTree();
}
});
}
Button removebutton = createButtonRemove(criterionForThisRow);
removebutton.setParent(tcOperations);
@ -242,23 +246,45 @@ public class CriterionTreeController extends GenericForwardComposer {
}
}
private Button createButtonRemove(CriterionDTO criterion){
String urlIcono;
String urlHoverImage;
String toolTipText;
if(criterion.isNewObject()){
urlIcono = "/common/img/ico_borrar1.png";
urlHoverImage = "/common/img/ico_borrar.png";
toolTipText = "Delete";
private Button createButtonUnindent(){
Button unindentbutton;
if( this.criterionsModel.getCriterionType().allowHierarchy()){
unindentbutton = new Button("", "/common/img/ico_izq1.png");
unindentbutton.setHoverImage("/common/img/ico_izq.png");
unindentbutton.setTooltiptext(_("Unindent"));
}else{
urlIcono = "/common/img/ico_borrar_out.png";
urlHoverImage = "/common/img/ico_borrar.png";
toolTipText = "Not deletable";
unindentbutton = new Button("", "/common/img/ico_derecha_out.png");
unindentbutton.setTooltiptext(_("Not Unindent"));
}
unindentbutton.setSclass("icono");
return unindentbutton;
}
private Button createButtonIndent(){
Button indentbutton;
if( this.criterionsModel.getCriterionType().allowHierarchy()){
indentbutton = new Button("", "/common/img/ico_derecha1.png");
indentbutton.setHoverImage("/common/img/ico_derecha.png");
indentbutton.setTooltiptext(_("Indent"));
}else{
indentbutton = new Button("", "/common/img/ico_derecha_out.png");
indentbutton.setTooltiptext(_("Not indent"));
}
indentbutton.setSclass("icono");
return indentbutton;
}
private Button createButtonRemove(CriterionDTO criterion){
Button removebutton;
if(criterion.isNewObject()){
removebutton = new Button("", "/common/img/ico_borrar1.png");
removebutton.setHoverImage("/common/img/ico_borrar.png");
removebutton.setTooltiptext(_("Delete"));
}else{
removebutton = new Button("", "/common/img/ico_borrar_out.png");
removebutton.setTooltiptext(_("Not deletable"));
}
Button removebutton = new Button("", urlIcono);
removebutton.setHoverImage(urlHoverImage);
removebutton.setSclass("icono");
removebutton.setTooltiptext(_(toolTipText));
return removebutton;
}
@ -288,7 +314,6 @@ public class CriterionTreeController extends GenericForwardComposer {
Treerow to = (Treerow) dropedIn;
CriterionDTO toNode = (CriterionDTO) ((Treeitem) to.getParent())
.getValue();
getModel().move(fromNode, toNode,0);
}
reloadTree();
@ -305,7 +330,9 @@ public class CriterionTreeController extends GenericForwardComposer {
}
reloadTree();
} catch (ValidationException e) {
messagesForUser.showInvalidValues(e);
for (InvalidValue invalidValue : e.getInvalidValues()) {
messagesForUser.showMessage(Level.INFO,invalidValue.getMessage());
}
}
}

View file

@ -85,6 +85,10 @@ public class CriterionTreeModel implements ICriterionTreeModel{
}
}
public CriterionType getCriterionType(){
return criterionType;
}
public CriterionTreeModel(CriterionType criterionType) {
this.criterionType = criterionType ;
criterionRootDTO = new CriterionDTO();
@ -215,7 +219,13 @@ public class CriterionTreeModel implements ICriterionTreeModel{
@Override
public void move(CriterionDTO toBeMoved, CriterionDTO destination,int position) {
moveImpl(toBeMoved, destination,position);
if(isGreatInHierarchy(toBeMoved,destination)){
System.out.println("******************************* RETURN ********************************");
return;
}
if(criterionType.allowHierarchy()){
moveImpl(toBeMoved, destination,position);
}
}
@Override
@ -414,4 +424,16 @@ public class CriterionTreeModel implements ICriterionTreeModel{
criterion.setActive(criterionDTO.isActive());
}
private boolean isGreatInHierarchy(CriterionDTO parent,CriterionDTO child){
return find(child,getChildren(parent));
}
private boolean find(CriterionDTO child,List<CriterionDTO> children){
if(children.indexOf(child) >= 0)
return true;
for(CriterionDTO criterionDTO : children){
return find(child,getChildren(criterionDTO));
}
return false;
}
}

View file

@ -37,7 +37,9 @@ import org.zkoss.zul.TreeModel;
*/
public interface ICriterionTreeModel {
public TreeModel asTree();
TreeModel asTree();
CriterionType getCriterionType();
void addCriterion(String name);

View file

@ -28,13 +28,13 @@
<tabpanel>
<grid fixedLayout="true" width="800px">
<columns>
<column width="300px"/>
<column width="400px"/>
<column width="400px"/>
</columns>
<rows>
<row>
<label value="${i18n:_('Name')}" />
<textbox value="@{controller.criterionType.name}"/>
<textbox width="390px" value="@{controller.criterionType.name}"/>
</row>
<row>
<label value="${i18n:_('Multiple values per resource')}"/>
@ -53,7 +53,7 @@
<row>
<label value="${i18n:_('Description')}" />
<textbox value="@{controller.criterionType.description}" rows="3" width="300px"/>
<textbox value="@{controller.criterionType.description}" rows="3" width="390px"/>
</row>
</rows>
</grid>

View file

@ -57,7 +57,7 @@
id="confirmDisabledHierarchy" title="${i18n:_('Warning')}" sizable="true"
position="center">
<vbox align = "center">
<label value = "Disenable the Hierarchy property flatten the tree."/>
<label value = "Disable the Hierarchy to order flatten the tree."/>
<label value = "Continue?"/>
<hbox align = "center">
<button label="${i18n:_('Ok')}"