Skip to content
Snippets Groups Projects
Commit 9da28041 authored by juanf's avatar juanf
Browse files

SP-624 BIS-398: Ordering Bugfix, Null Pointer Bugfix and more error control. Ongoing work.

SVN: 29006
parent f11c81c6
No related branches found
No related tags found
No related merge requests found
...@@ -86,7 +86,7 @@ abstract public class AbstractEntityTypeGrid<T extends EntityType> extends Typed ...@@ -86,7 +86,7 @@ abstract public class AbstractEntityTypeGrid<T extends EntityType> extends Typed
final EntityKind entityKind = getEntityKindOrNull(); final EntityKind entityKind = getEntityKindOrNull();
Button buttonNew = new TextToolItem("New", Button buttonNew = new TextToolItem(viewContext.getMessage(Dict.ADD_NEW_TYPE_BUTTON)+"V2",
new SelectionListener<ButtonEvent>() new SelectionListener<ButtonEvent>()
{ {
@Override @Override
......
...@@ -6,6 +6,7 @@ import java.util.List; ...@@ -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.ICommonClientServiceAsync;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericConstants; 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.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.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.BorderLayoutDataFactory;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.DataSetKindSelectionWidget; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.DataSetKindSelectionWidget;
...@@ -81,13 +82,12 @@ public class NewEntityTypeForm extends ContentPanel ...@@ -81,13 +82,12 @@ public class NewEntityTypeForm extends ContentPanel
initForm(); initForm();
} }
public static DatabaseModificationAwareComponent create(EntityKind kind, public static DatabaseModificationAwareComponent create(EntityKind kind, final IViewContext<ICommonClientServiceAsync> viewContext)
final IViewContext<ICommonClientServiceAsync> viewContext)
{ {
NewEntityTypeForm form = new NewEntityTypeForm(kind, viewContext); NewEntityTypeForm form = new NewEntityTypeForm(kind, viewContext);
return new DatabaseModificationAwareComponent(form, null); return new DatabaseModificationAwareComponent(form,new CompositeDatabaseModificationObserver());
} }
private void initForm() private void initForm()
{ {
...@@ -179,6 +179,8 @@ public class NewEntityTypeForm extends ContentPanel ...@@ -179,6 +179,8 @@ public class NewEntityTypeForm extends ContentPanel
{ {
//Update Entity Type //Update Entity Type
setEntityFromForm(); setEntityFromForm();
//To order of the ordinals for the database start at 0
newTypeWithAssigments.updateOrdinalToDBOrder();
//Update Entity Type Code at the Property Types //Update Entity Type Code at the Property Types
for(NewPTNewAssigment assigment:newTypeWithAssigments.getAssigments()) { for(NewPTNewAssigment assigment:newTypeWithAssigments.getAssigments()) {
assigment.getAssignment().setEntityTypeCode(newTypeWithAssigments.getEntity().getCode()); assigment.getAssignment().setEntityTypeCode(newTypeWithAssigments.getEntity().getCode());
...@@ -205,7 +207,7 @@ public class NewEntityTypeForm extends ContentPanel ...@@ -205,7 +207,7 @@ public class NewEntityTypeForm extends ContentPanel
switch (kind) switch (kind)
{ {
case SAMPLE: case SAMPLE:
SampleType toSaveSample = new SampleType(); SampleType toSaveSample = (SampleType) newTypeWithAssigments.getEntity();
toSaveSample.setCode((String) formFields.get(0).getValue()); toSaveSample.setCode((String) formFields.get(0).getValue());
toSaveSample.setDescription((String) formFields.get(1).getValue()); toSaveSample.setDescription((String) formFields.get(1).getValue());
toSaveSample.setValidationScript((Script) formFields.get(2).getValue()); toSaveSample.setValidationScript((Script) formFields.get(2).getValue());
...@@ -219,7 +221,7 @@ public class NewEntityTypeForm extends ContentPanel ...@@ -219,7 +221,7 @@ public class NewEntityTypeForm extends ContentPanel
newTypeWithAssigments.setEntity(toSaveSample); newTypeWithAssigments.setEntity(toSaveSample);
break; break;
case DATA_SET: case DATA_SET:
DataSetType toSaveDataSet = new DataSetType(); DataSetType toSaveDataSet = (DataSetType) newTypeWithAssigments.getEntity();
toSaveDataSet.setCode((String) formFields.get(0).getValue()); toSaveDataSet.setCode((String) formFields.get(0).getValue());
toSaveDataSet.setDescription((String) formFields.get(1).getValue()); toSaveDataSet.setDescription((String) formFields.get(1).getValue());
toSaveDataSet.setValidationScript((Script) formFields.get(2).getValue()); toSaveDataSet.setValidationScript((Script) formFields.get(2).getValue());
...@@ -230,14 +232,14 @@ public class NewEntityTypeForm extends ContentPanel ...@@ -230,14 +232,14 @@ public class NewEntityTypeForm extends ContentPanel
newTypeWithAssigments.setEntity(toSaveDataSet); newTypeWithAssigments.setEntity(toSaveDataSet);
break; break;
case EXPERIMENT: case EXPERIMENT:
ExperimentType toSaveExperiment = new ExperimentType(); ExperimentType toSaveExperiment = (ExperimentType) newTypeWithAssigments.getEntity();
toSaveExperiment.setCode((String) formFields.get(0).getValue()); toSaveExperiment.setCode((String) formFields.get(0).getValue());
toSaveExperiment.setDescription((String) formFields.get(1).getValue()); toSaveExperiment.setDescription((String) formFields.get(1).getValue());
toSaveExperiment.setValidationScript((Script) formFields.get(2).getValue()); toSaveExperiment.setValidationScript((Script) formFields.get(2).getValue());
newTypeWithAssigments.setEntity(toSaveExperiment); newTypeWithAssigments.setEntity(toSaveExperiment);
break; break;
case MATERIAL: case MATERIAL:
MaterialType toSaveMaterial = new MaterialType(); MaterialType toSaveMaterial = (MaterialType) newTypeWithAssigments.getEntity();
toSaveMaterial.setCode((String) formFields.get(0).getValue()); toSaveMaterial.setCode((String) formFields.get(0).getValue());
toSaveMaterial.setDescription((String) formFields.get(1).getValue()); toSaveMaterial.setDescription((String) formFields.get(1).getValue());
toSaveMaterial.setValidationScript((Script) formFields.get(2).getValue()); toSaveMaterial.setValidationScript((Script) formFields.get(2).getValue());
...@@ -254,6 +256,9 @@ public class NewEntityTypeForm extends ContentPanel ...@@ -254,6 +256,9 @@ public class NewEntityTypeForm extends ContentPanel
String message = "Error"; String message = "Error";
if (throwable instanceof UserFailureException) 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; UserFailureException userException = (UserFailureException) throwable;
String details = GWTUtils.translateToHtmlLineBreaks(userException.getMessage()); String details = GWTUtils.translateToHtmlLineBreaks(userException.getMessage());
if (details != null) if (details != null)
......
...@@ -217,7 +217,8 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert ...@@ -217,7 +217,8 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert
// //
// Buttons used by the in memory grid form to create new entity types // 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 EntityType addEntity = this.entity;
final Button addButton = final Button addButton =
new Button(viewContext.getMessage(Dict.BUTTON_ADD, ""), new Button(viewContext.getMessage(Dict.BUTTON_ADD, ""),
...@@ -239,17 +240,20 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert ...@@ -239,17 +240,20 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert
}); });
addButton.setId(GRID_ID + "-add"); addButton.setId(GRID_ID + "-add");
addButton(addButton); 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"); removeButton.setId(GRID_ID + "-remove");
addButton(removeButton); addButton(removeButton);
} }
...@@ -276,7 +280,7 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert ...@@ -276,7 +280,7 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert
addButton.setId(GRID_ID + "-add"); addButton.setId(GRID_ID + "-add");
addButton(addButton); addButton(addButton);
} }
// //
// Buttons used by the entity types grids and propertyes browser // Buttons used by the entity types grids and propertyes browser
// //
...@@ -326,25 +330,35 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert ...@@ -326,25 +330,35 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert
releaseButton.setId(GRID_ID + "-release"); releaseButton.setId(GRID_ID + "-release");
addButton(releaseButton); addButton(releaseButton);
} }
addEntityOperationsSeparator(); addEntityOperationsSeparator();
} }
public class InMemoryGridRemoveCallback { public class InMemoryGridRemoveCallback
public void callback(final EntityTypePropertyType<?> etpt) { {
public void callback(final EntityTypePropertyType<?> etpt)
{
String codeToDelete = etpt.getPropertyType().getCode(); String codeToDelete = etpt.getPropertyType().getCode();
newTypeWithAssigments.refreshOrderDelete(codeToDelete); newTypeWithAssigments.refreshOrderDelete(codeToDelete);
refresh(); refresh();
} }
} }
public class InMemoryGridAddCallback { public class InMemoryGridAddCallback
public void callback(boolean isExixtingPropertyType, PropertyType propertyType, NewETPTAssignment assignment) { {
public void callback(boolean isExixtingPropertyType, PropertyType propertyType, NewETPTAssignment assignment)
{
NewPTNewAssigment newPTNewAssigment = new NewPTNewAssigment(); NewPTNewAssigment newPTNewAssigment = new NewPTNewAssigment();
newPTNewAssigment.setExistingPropertyType(isExixtingPropertyType); newPTNewAssigment.setExistingPropertyType(isExixtingPropertyType);
newPTNewAssigment.setPropertyType(propertyType); newPTNewAssigment.setPropertyType(propertyType);
newPTNewAssigment.setAssignment(assignment); newPTNewAssigment.setAssignment(assignment);
newTypeWithAssigments.refreshOrderAdd(newPTNewAssigment); try
{
newTypeWithAssigments.refreshOrderAdd(newPTNewAssigment);
} catch (Exception ex)
{
MessageBox.alert("Error", ex.getMessage(), null);
}
refresh(); refresh();
} }
} }
...@@ -363,12 +377,9 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert ...@@ -363,12 +377,9 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert
private Window createEditDialog(final EntityTypePropertyType<?> etpt) private Window createEditDialog(final EntityTypePropertyType<?> etpt)
{ {
final EntityKind entityKind = etpt.getEntityKind(); 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 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) return new AbstractRegistrationDialog(viewContext, title, postRegistrationCallback)
{ {
...@@ -402,8 +413,7 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert ...@@ -402,8 +413,7 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert
loading = new Label(viewContext.getMessage(Dict.LOAD_IN_PROGRESS)); loading = new Label(viewContext.getMessage(Dict.LOAD_IN_PROGRESS));
addField(loading); addField(loading);
viewContext.getCommonService().listPropertyTypeAssignments( viewContext.getCommonService().listPropertyTypeAssignments(etpt.getEntityType(),
etpt.getEntityType(),
new AbstractAsyncCallback<List<EntityTypePropertyType<?>>>(viewContext) new AbstractAsyncCallback<List<EntityTypePropertyType<?>>>(viewContext)
{ {
@Override @Override
...@@ -418,27 +428,24 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert ...@@ -418,27 +428,24 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert
private void initFields(List<EntityTypePropertyType<?>> etpts) private void initFields(List<EntityTypePropertyType<?>> etpts)
{ {
//Mandatory Field
originalIsMandatory = etpt.isMandatory(); originalIsMandatory = etpt.isMandatory();
mandatoryCheckbox = new CheckBoxField(viewContext.getMessage(Dict.MANDATORY), false);
mandatoryCheckbox =
new CheckBoxField(viewContext.getMessage(Dict.MANDATORY), false);
mandatoryCheckbox.setValue(originalIsMandatory); mandatoryCheckbox.setValue(originalIsMandatory);
if (script != null) if (script != null)
{ {
mandatoryCheckbox.setVisible(false); mandatoryCheckbox.setVisible(false);
} }
addField(mandatoryCheckbox); addField(mandatoryCheckbox);
scriptChooser = //Script Field
createScriptChooserField(viewContext, script != null ? script.getName() scriptChooser = createScriptChooserField(viewContext, script != null ? script.getName()
: null, script != null, script != null ? script.getScriptType() : null, script != null, script != null ? script.getScriptType()
: null, entityKind); : null, entityKind);
addField(scriptChooser); addField(scriptChooser);
shownInEditViewCheckBox = //Show in edit views Field
new CheckBoxField(viewContext.getMessage(Dict.SHOWN_IN_EDIT_VIEW), shownInEditViewCheckBox = new CheckBoxField(viewContext.getMessage(Dict.SHOWN_IN_EDIT_VIEW), false);
false);
shownInEditViewCheckBox.setValue(etpt.isShownInEditView()); shownInEditViewCheckBox.setValue(etpt.isShownInEditView());
if (false == etpt.isManaged()) if (false == etpt.isManaged())
{ {
...@@ -447,8 +454,8 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert ...@@ -447,8 +454,8 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert
} }
addField(shownInEditViewCheckBox); addField(shownInEditViewCheckBox);
showRawValuesCheckBox = //Show raw values Field
new CheckBoxField(viewContext.getMessage(Dict.SHOW_RAW_VALUE), false); showRawValuesCheckBox = new CheckBoxField(viewContext.getMessage(Dict.SHOW_RAW_VALUE), false);
showRawValuesCheckBox.setValue(etpt.getShowRawValue()); showRawValuesCheckBox.setValue(etpt.getShowRawValue());
if (false == etpt.isManaged()) if (false == etpt.isManaged())
{ {
...@@ -460,12 +467,14 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert ...@@ -460,12 +467,14 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert
// default value needs to be specified only if currently property is optional // default value needs to be specified only if currently property is optional
if (originalIsMandatory == false) if (originalIsMandatory == false)
{ {
defaultValueField = defaultValueField = PropertyFieldFactory.createField(
PropertyFieldFactory.createField(etpt.getPropertyType(), false, etpt.getPropertyType(),
viewContext.getMessage(Dict.DEFAULT_UPDATE_VALUE), false,
"default_value_field", null, viewContext).get(); viewContext.getMessage(Dict.DEFAULT_UPDATE_VALUE),
defaultValueField.setToolTip(viewContext "default_value_field",
.getMessage(Dict.DEFAULT_UPDATE_VALUE_TOOLTIP)); null,
viewContext).get();
defaultValueField.setToolTip(viewContext.getMessage(Dict.DEFAULT_UPDATE_VALUE_TOOLTIP));
addField(defaultValueField); addField(defaultValueField);
mandatoryCheckbox.addListener(Events.Change, new Listener<FieldEvent>() mandatoryCheckbox.addListener(Events.Change, new Listener<FieldEvent>()
...@@ -690,7 +699,8 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert ...@@ -690,7 +699,8 @@ public class PropertyTypeAssignmentGrid extends TypedTableGrid<EntityTypePropert
viewContext.getService().listPropertyTypeAssignments(resultSetConfig, entity, extendedCallback); viewContext.getService().listPropertyTypeAssignments(resultSetConfig, entity, extendedCallback);
} else } else
{ {
viewContext.getService().listPropertyTypeAssignmentsFromBrowser(resultSetConfig, newTypeWithAssigments.getEntity(), newTypeWithAssigments.getAssigments(), extendedCallback); viewContext.getService().listPropertyTypeAssignmentsFromBrowser(resultSetConfig, newTypeWithAssigments.getEntity(),
newTypeWithAssigments.getAssigments(), extendedCallback);
} }
} }
......
...@@ -29,36 +29,30 @@ public class NewETNewPTAssigments implements Serializable ...@@ -29,36 +29,30 @@ public class NewETNewPTAssigments implements Serializable
this.assigments = assigments; this.assigments = assigments;
} }
public void updateOrdinalToDBOrder() {
public void refreshOrderDelete(String code) { // Update Ordinal - Internal/External List
//
// Delete Code - Internal/External List
//
for(int i = 0; i < entity.getAssignedPropertyTypes().size(); i++) { for(int i = 0; i < entity.getAssignedPropertyTypes().size(); i++) {
if(entity.getAssignedPropertyTypes().get(i).getPropertyType().getCode().equals(code)) { entity.getAssignedPropertyTypes().get(i).setOrdinal((long) i);
entity.getAssignedPropertyTypes().remove(i); assigments.get(i).getAssignment().setOrdinal((long) i);
assigments.remove(i);
break;
}
} }
}
//
public void updateOrdinalToGridOrder() {
// Update Ordinal - Internal/External List // Update Ordinal - Internal/External List
//
for(int i = 0; i < entity.getAssignedPropertyTypes().size(); i++) { for(int i = 0; i < entity.getAssignedPropertyTypes().size(); i++) {
entity.getAssignedPropertyTypes().get(i).setOrdinal((long) i + 1); entity.getAssignedPropertyTypes().get(i).setOrdinal((long) i + 1);
assigments.get(i).getAssignment().setOrdinal((long) i + 1); assigments.get(i).getAssignment().setOrdinal((long) i + 1);
} }
} }
public void refreshOrderAdd(NewPTNewAssigment newAssigment) { public void refreshOrderAdd(NewPTNewAssigment newAssigment) throws Exception {
int insertPos = 0; if(isAssigmentFound(newAssigment)) {
throw new Exception("A property can't be assigned twice.");
if(assigments.isEmpty()) {
insertPos = 0;
} else {
insertPos = newAssigment.getAssignment().getOrdinal().intValue();
} }
// Update Ordinal - Internal/External List
updateOrdinalToDBOrder();
int insertPos = newAssigment.getAssignment().getOrdinal().intValue();
// //
// Update Lists - This Reorder the items due to an insert // Update Lists - This Reorder the items due to an insert
...@@ -89,14 +83,36 @@ public class NewETNewPTAssigments implements Serializable ...@@ -89,14 +83,36 @@ public class NewETNewPTAssigments implements Serializable
//External List //External List
assigments.add(insertPos, newAssigment); assigments.add(insertPos, newAssigment);
//
// Update Ordinal - Internal/External List // 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++) { for(int i = 0; i < entity.getAssignedPropertyTypes().size(); i++) {
entity.getAssignedPropertyTypes().get(i).setOrdinal((long) i + 1); if(entity.getAssignedPropertyTypes().get(i).getPropertyType().getCode().equals(code)) {
assigments.get(i).getAssignment().setOrdinal((long) i + 1); 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) { public static EntityTypePropertyType<?> getEntityTypePropertyType(EntityKind kind, NewPTNewAssigment propertyTypeAsg) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment