From 9da28041969a913760100ae146f8f98ca481a0f7 Mon Sep 17 00:00:00 2001 From: juanf <juanf> Date: Mon, 6 May 2013 12:10:43 +0000 Subject: [PATCH] SP-624 BIS-398: Ordering Bugfix, Null Pointer Bugfix and more error control. Ongoing work. SVN: 29006 --- .../entity_type/AbstractEntityTypeGrid.java | 2 +- .../ui/entity_type/NewEntityTypeForm.java | 21 ++-- .../PropertyTypeAssignmentGrid.java | 100 ++++++++++-------- .../basic/dto/NewETNewPTAssigments.java | 62 +++++++---- 4 files changed, 108 insertions(+), 77 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/entity_type/AbstractEntityTypeGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/entity_type/AbstractEntityTypeGrid.java index 05f566ecbaa..ca17db89a1c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/entity_type/AbstractEntityTypeGrid.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/entity_type/AbstractEntityTypeGrid.java @@ -86,7 +86,7 @@ abstract public class AbstractEntityTypeGrid<T extends EntityType> extends Typed final EntityKind entityKind = getEntityKindOrNull(); - Button buttonNew = new TextToolItem("New", + Button buttonNew = new TextToolItem(viewContext.getMessage(Dict.ADD_NEW_TYPE_BUTTON)+"V2", new SelectionListener<ButtonEvent>() { @Override diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/entity_type/NewEntityTypeForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/entity_type/NewEntityTypeForm.java index 7f3d0cf3975..ec49711f5a8 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/entity_type/NewEntityTypeForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/entity_type/NewEntityTypeForm.java @@ -6,6 +6,7 @@ import java.util.List; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericConstants; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.CompositeDatabaseModificationObserver; import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.DatabaseModificationAwareComponent; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.BorderLayoutDataFactory; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.DataSetKindSelectionWidget; @@ -81,13 +82,12 @@ public class NewEntityTypeForm extends ContentPanel initForm(); } - public static DatabaseModificationAwareComponent create(EntityKind kind, - final IViewContext<ICommonClientServiceAsync> viewContext) + public static DatabaseModificationAwareComponent create(EntityKind kind, final IViewContext<ICommonClientServiceAsync> viewContext) { NewEntityTypeForm form = new NewEntityTypeForm(kind, viewContext); - return new DatabaseModificationAwareComponent(form, null); + return new DatabaseModificationAwareComponent(form,new CompositeDatabaseModificationObserver()); } - + private void initForm() { @@ -179,6 +179,8 @@ public class NewEntityTypeForm extends ContentPanel { //Update Entity Type setEntityFromForm(); + //To order of the ordinals for the database start at 0 + newTypeWithAssigments.updateOrdinalToDBOrder(); //Update Entity Type Code at the Property Types for(NewPTNewAssigment assigment:newTypeWithAssigments.getAssigments()) { assigment.getAssignment().setEntityTypeCode(newTypeWithAssigments.getEntity().getCode()); @@ -205,7 +207,7 @@ public class NewEntityTypeForm extends ContentPanel switch (kind) { case SAMPLE: - SampleType toSaveSample = new SampleType(); + SampleType toSaveSample = (SampleType) newTypeWithAssigments.getEntity(); toSaveSample.setCode((String) formFields.get(0).getValue()); toSaveSample.setDescription((String) formFields.get(1).getValue()); toSaveSample.setValidationScript((Script) formFields.get(2).getValue()); @@ -219,7 +221,7 @@ public class NewEntityTypeForm extends ContentPanel newTypeWithAssigments.setEntity(toSaveSample); break; case DATA_SET: - DataSetType toSaveDataSet = new DataSetType(); + DataSetType toSaveDataSet = (DataSetType) newTypeWithAssigments.getEntity(); toSaveDataSet.setCode((String) formFields.get(0).getValue()); toSaveDataSet.setDescription((String) formFields.get(1).getValue()); toSaveDataSet.setValidationScript((Script) formFields.get(2).getValue()); @@ -230,14 +232,14 @@ public class NewEntityTypeForm extends ContentPanel newTypeWithAssigments.setEntity(toSaveDataSet); break; case EXPERIMENT: - ExperimentType toSaveExperiment = new ExperimentType(); + ExperimentType toSaveExperiment = (ExperimentType) newTypeWithAssigments.getEntity(); toSaveExperiment.setCode((String) formFields.get(0).getValue()); toSaveExperiment.setDescription((String) formFields.get(1).getValue()); toSaveExperiment.setValidationScript((Script) formFields.get(2).getValue()); newTypeWithAssigments.setEntity(toSaveExperiment); break; case MATERIAL: - MaterialType toSaveMaterial = new MaterialType(); + MaterialType toSaveMaterial = (MaterialType) newTypeWithAssigments.getEntity(); toSaveMaterial.setCode((String) formFields.get(0).getValue()); toSaveMaterial.setDescription((String) formFields.get(1).getValue()); toSaveMaterial.setValidationScript((Script) formFields.get(2).getValue()); @@ -254,6 +256,9 @@ public class NewEntityTypeForm extends ContentPanel String message = "Error"; if (throwable instanceof UserFailureException) { + //In case it fails the order of the properties need to be the one at the grid + newTypeWithAssigments.updateOrdinalToGridOrder(); + //Show error message UserFailureException userException = (UserFailureException) throwable; String details = GWTUtils.translateToHtmlLineBreaks(userException.getMessage()); if (details != null) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentGrid.java index 88c0675d1fa..a3f22030302 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentGrid.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentGrid.java @@ -217,7 +217,8 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert // // Buttons used by the in memory grid form to create new entity types // - if (newTypeWithAssigments != null) { + if (newTypeWithAssigments != null) + { final EntityType addEntity = this.entity; final Button addButton = new Button(viewContext.getMessage(Dict.BUTTON_ADD, ""), @@ -239,17 +240,20 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert }); addButton.setId(GRID_ID + "-add"); addButton(addButton); - - Button removeButton = createSelectedItemButton("remove", new ISelectedEntityInvoker<BaseEntityModel<TableModelRowWithObject<EntityTypePropertyType<?>>>>() - { - @Override - public void invoke(BaseEntityModel<TableModelRowWithObject<EntityTypePropertyType<?>>> selectedItem,boolean keyPressed) - { - final EntityTypePropertyType<?> etpt = selectedItem.getBaseObject().getObjectOrNull(); - (new InMemoryGridRemoveCallback()).callback(etpt); - } - }); + Button removeButton = + createSelectedItemButton("remove", + new ISelectedEntityInvoker<BaseEntityModel<TableModelRowWithObject<EntityTypePropertyType<?>>>>() + { + @Override + public void invoke(BaseEntityModel<TableModelRowWithObject<EntityTypePropertyType<?>>> selectedItem, + boolean keyPressed) + { + final EntityTypePropertyType<?> etpt = selectedItem.getBaseObject().getObjectOrNull(); + (new InMemoryGridRemoveCallback()).callback(etpt); + } + + }); removeButton.setId(GRID_ID + "-remove"); addButton(removeButton); } @@ -276,7 +280,7 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert addButton.setId(GRID_ID + "-add"); addButton(addButton); } - + // // Buttons used by the entity types grids and propertyes browser // @@ -326,25 +330,35 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert releaseButton.setId(GRID_ID + "-release"); addButton(releaseButton); } - + addEntityOperationsSeparator(); } - - public class InMemoryGridRemoveCallback { - public void callback(final EntityTypePropertyType<?> etpt) { + + public class InMemoryGridRemoveCallback + { + public void callback(final EntityTypePropertyType<?> etpt) + { String codeToDelete = etpt.getPropertyType().getCode(); newTypeWithAssigments.refreshOrderDelete(codeToDelete); refresh(); } } - - public class InMemoryGridAddCallback { - public void callback(boolean isExixtingPropertyType, PropertyType propertyType, NewETPTAssignment assignment) { + + public class InMemoryGridAddCallback + { + public void callback(boolean isExixtingPropertyType, PropertyType propertyType, NewETPTAssignment assignment) + { NewPTNewAssigment newPTNewAssigment = new NewPTNewAssigment(); newPTNewAssigment.setExistingPropertyType(isExixtingPropertyType); newPTNewAssigment.setPropertyType(propertyType); newPTNewAssigment.setAssignment(assignment); - newTypeWithAssigments.refreshOrderAdd(newPTNewAssigment); + try + { + newTypeWithAssigments.refreshOrderAdd(newPTNewAssigment); + } catch (Exception ex) + { + MessageBox.alert("Error", ex.getMessage(), null); + } refresh(); } } @@ -363,12 +377,9 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert private Window createEditDialog(final EntityTypePropertyType<?> etpt) { final EntityKind entityKind = etpt.getEntityKind(); - final String entityTypeCode = etpt.getEntityType().getCode(); + final String entityTypeCode = (etpt.getEntityType() != null)?etpt.getEntityType().getCode():null; final String propertyTypeCode = etpt.getPropertyType().getCode(); - - final String title = - viewContext.getMessage(Dict.EDIT_PROPERTY_TYPE_ASSIGNMENT_TITLE, - entityKind.getDescription(), entityTypeCode, propertyTypeCode); + final String title = viewContext.getMessage(Dict.EDIT_PROPERTY_TYPE_ASSIGNMENT_TITLE, entityKind.getDescription(), entityTypeCode, propertyTypeCode); return new AbstractRegistrationDialog(viewContext, title, postRegistrationCallback) { @@ -402,8 +413,7 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert loading = new Label(viewContext.getMessage(Dict.LOAD_IN_PROGRESS)); addField(loading); - viewContext.getCommonService().listPropertyTypeAssignments( - etpt.getEntityType(), + viewContext.getCommonService().listPropertyTypeAssignments(etpt.getEntityType(), new AbstractAsyncCallback<List<EntityTypePropertyType<?>>>(viewContext) { @Override @@ -418,27 +428,24 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert private void initFields(List<EntityTypePropertyType<?>> etpts) { + //Mandatory Field originalIsMandatory = etpt.isMandatory(); - - mandatoryCheckbox = - new CheckBoxField(viewContext.getMessage(Dict.MANDATORY), false); + mandatoryCheckbox = new CheckBoxField(viewContext.getMessage(Dict.MANDATORY), false); mandatoryCheckbox.setValue(originalIsMandatory); - if (script != null) { mandatoryCheckbox.setVisible(false); } addField(mandatoryCheckbox); - scriptChooser = - createScriptChooserField(viewContext, script != null ? script.getName() + //Script Field + scriptChooser = createScriptChooserField(viewContext, script != null ? script.getName() : null, script != null, script != null ? script.getScriptType() : null, entityKind); addField(scriptChooser); - shownInEditViewCheckBox = - new CheckBoxField(viewContext.getMessage(Dict.SHOWN_IN_EDIT_VIEW), - false); + //Show in edit views Field + shownInEditViewCheckBox = new CheckBoxField(viewContext.getMessage(Dict.SHOWN_IN_EDIT_VIEW), false); shownInEditViewCheckBox.setValue(etpt.isShownInEditView()); if (false == etpt.isManaged()) { @@ -447,8 +454,8 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert } addField(shownInEditViewCheckBox); - showRawValuesCheckBox = - new CheckBoxField(viewContext.getMessage(Dict.SHOW_RAW_VALUE), false); + //Show raw values Field + showRawValuesCheckBox = new CheckBoxField(viewContext.getMessage(Dict.SHOW_RAW_VALUE), false); showRawValuesCheckBox.setValue(etpt.getShowRawValue()); if (false == etpt.isManaged()) { @@ -460,12 +467,14 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert // default value needs to be specified only if currently property is optional if (originalIsMandatory == false) { - defaultValueField = - PropertyFieldFactory.createField(etpt.getPropertyType(), false, - viewContext.getMessage(Dict.DEFAULT_UPDATE_VALUE), - "default_value_field", null, viewContext).get(); - defaultValueField.setToolTip(viewContext - .getMessage(Dict.DEFAULT_UPDATE_VALUE_TOOLTIP)); + defaultValueField = PropertyFieldFactory.createField( + etpt.getPropertyType(), + false, + viewContext.getMessage(Dict.DEFAULT_UPDATE_VALUE), + "default_value_field", + null, + viewContext).get(); + defaultValueField.setToolTip(viewContext.getMessage(Dict.DEFAULT_UPDATE_VALUE_TOOLTIP)); addField(defaultValueField); mandatoryCheckbox.addListener(Events.Change, new Listener<FieldEvent>() @@ -690,7 +699,8 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert viewContext.getService().listPropertyTypeAssignments(resultSetConfig, entity, extendedCallback); } else { - viewContext.getService().listPropertyTypeAssignmentsFromBrowser(resultSetConfig, newTypeWithAssigments.getEntity(), newTypeWithAssigments.getAssigments(), extendedCallback); + viewContext.getService().listPropertyTypeAssignmentsFromBrowser(resultSetConfig, newTypeWithAssigments.getEntity(), + newTypeWithAssigments.getAssigments(), extendedCallback); } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewETNewPTAssigments.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewETNewPTAssigments.java index 876ba84d3b4..97c591d6ce4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewETNewPTAssigments.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewETNewPTAssigments.java @@ -29,36 +29,30 @@ public class NewETNewPTAssigments implements Serializable this.assigments = assigments; } - - public void refreshOrderDelete(String code) { - // - // Delete Code - Internal/External List - // + public void updateOrdinalToDBOrder() { + // Update Ordinal - Internal/External List for(int i = 0; i < entity.getAssignedPropertyTypes().size(); i++) { - if(entity.getAssignedPropertyTypes().get(i).getPropertyType().getCode().equals(code)) { - entity.getAssignedPropertyTypes().remove(i); - assigments.remove(i); - break; - } + entity.getAssignedPropertyTypes().get(i).setOrdinal((long) i); + assigments.get(i).getAssignment().setOrdinal((long) i); } - - // + } + + public void updateOrdinalToGridOrder() { // Update Ordinal - Internal/External List - // for(int i = 0; i < entity.getAssignedPropertyTypes().size(); i++) { entity.getAssignedPropertyTypes().get(i).setOrdinal((long) i + 1); assigments.get(i).getAssignment().setOrdinal((long) i + 1); } } - public void refreshOrderAdd(NewPTNewAssigment newAssigment) { - int insertPos = 0; - - if(assigments.isEmpty()) { - insertPos = 0; - } else { - insertPos = newAssigment.getAssignment().getOrdinal().intValue(); + public void refreshOrderAdd(NewPTNewAssigment newAssigment) throws Exception { + if(isAssigmentFound(newAssigment)) { + throw new Exception("A property can't be assigned twice."); } + + // Update Ordinal - Internal/External List + updateOrdinalToDBOrder(); + int insertPos = newAssigment.getAssignment().getOrdinal().intValue(); // // Update Lists - This Reorder the items due to an insert @@ -89,14 +83,36 @@ public class NewETNewPTAssigments implements Serializable //External List assigments.add(insertPos, newAssigment); - // // Update Ordinal - Internal/External List + updateOrdinalToGridOrder(); + } + + public void refreshOrderDelete(String code) { + // Update Ordinal - Internal/External List + updateOrdinalToDBOrder(); + + // + // Delete Code - Internal/External List // for(int i = 0; i < entity.getAssignedPropertyTypes().size(); i++) { - entity.getAssignedPropertyTypes().get(i).setOrdinal((long) i + 1); - assigments.get(i).getAssignment().setOrdinal((long) i + 1); + if(entity.getAssignedPropertyTypes().get(i).getPropertyType().getCode().equals(code)) { + entity.getAssignedPropertyTypes().remove(i); + assigments.remove(i); + break; + } } + // Update Ordinal - Internal/External List + updateOrdinalToGridOrder(); + } + + public boolean isAssigmentFound(NewPTNewAssigment assigment) { + for(NewPTNewAssigment assigmentFound:assigments) { + if(assigmentFound.getPropertyType().getCode().equals(assigment.getPropertyType().getCode())) { + return true; + } + } + return false; } public static EntityTypePropertyType<?> getEntityTypePropertyType(EntityKind kind, NewPTNewAssigment propertyTypeAsg) { -- GitLab