diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java index bd0f6fe4cfe0b28eb778021355a2762dc2b90003..d257d3d45a6ce566d0544e1c539f36bb36190478 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java @@ -38,6 +38,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Sample; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SampleType; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SearchableEntity; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TableExportCriteria; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; /** * Asynchronous version of {@link ICommonClientService}. @@ -142,7 +143,7 @@ public interface ICommonClientServiceAsync extends IClientServiceAsync public void listDataTypes(final AsyncCallback<List<DataType>> asyncCallback); /** @see ICommonClientService#listDataTypes() */ - public void listVocabularies(final AsyncCallback<List<DataType>> asyncCallback); + public void listVocabularies(final AsyncCallback<List<Vocabulary>> asyncCallback); /** @see ICommonClientService#assignPropertyType(EntityKind, String, String, boolean, String) */ public void assignPropertyType(EntityKind entityKind, String propertyTypeCode, diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java index cbfeb90b297bb58688fc1ebd7176c0056d56d388..00a615769faecfc6501c80d38aa916f72d1ff268 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java @@ -194,8 +194,6 @@ public abstract class Dict public static final String DATA_TYPE = "data_type"; - public static final String CONTROLLED_VOCABULARY = "controlled_vocabulary"; - public static final String DESCRIPTION = "description"; public static final String SAMPLE_TYPES = "sample_types"; @@ -206,12 +204,16 @@ public abstract class Dict public static final String IS_MANDATORY = "is_mandatory"; + public static final String PROPERTY_TYPE = "property_type"; + public static final String PROPERTY_TYPE_CODE = "property_type_code"; public static final String ASSIGNED_TO = "assigned_to"; public static final String TYPE_OF = "type_of"; + public static final String VOCABULARY = "vocabulary"; + public static final String VOCABULARY_TERMS = "vocabulary_terms"; public static final String VOCABULARY_TERMS_EMPTY = "vocabulary_terms_empty"; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/SearchableEntityModel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/SearchableEntityModel.java index 79036564d0ecb6a0e19850f52e68a40e0e3e6c69..1aa57c8eca28c19061228f7eb2240031b6a8b26e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/SearchableEntityModel.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/SearchableEntityModel.java @@ -36,7 +36,7 @@ public final class SearchableEntityModel extends BaseModelData private static final long serialVersionUID = 1L; - public SearchableEntityModel() + private SearchableEntityModel() { } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyModel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyModel.java new file mode 100644 index 0000000000000000000000000000000000000000..e826306745eb56107e6fa62058534cf198c18ad5 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyModel.java @@ -0,0 +1,68 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.openbis.generic.client.web.client.application.model; + +import java.util.ArrayList; +import java.util.List; + +import com.extjs.gxt.ui.client.data.BaseModelData; + +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; + +/** + * A {@link BaseModelData} extension suitable for {@link Vocabulary}. + * + * @author Christian Ribeaud + */ +public final class VocabularyModel extends BaseModelData +{ + public static final String NEW_VOCABULARY_CODE = "(New Vocabulary)"; + + private static final long serialVersionUID = 1L; + + private VocabularyModel() + { + } + + public VocabularyModel(final Vocabulary vocabulary) + { + assert vocabulary != null : "Unspecified data type."; + set(ModelDataPropertyNames.CODE, vocabulary.getCode()); + set(ModelDataPropertyNames.OBJECT, vocabulary); + } + + public final static VocabularyModel createNewVocabularyVocabularyModel() + { + final VocabularyModel model = new VocabularyModel(); + model.set(ModelDataPropertyNames.CODE, NEW_VOCABULARY_CODE); + model.set(ModelDataPropertyNames.OBJECT, null); + return model; + } + + public final static List<VocabularyModel> convert(final List<Vocabulary> vocabularies) + { + assert vocabularies != null : "Unspecified vocabularies."; + final List<VocabularyModel> vocabularyModels = + new ArrayList<VocabularyModel>(vocabularies.size()); + for (final Vocabulary vocabulary : vocabularies) + { + vocabularyModels.add(new VocabularyModel(vocabulary)); + } + return vocabularyModels; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/DataTypeSelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/DataTypeSelectionWidget.java index f5180cdf2e2863bd892210ab42345c52c359ec88..37d36bcb2be6ad7964ac6519c5b01ab0f2443079 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/DataTypeSelectionWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/DataTypeSelectionWidget.java @@ -44,16 +44,21 @@ public final class DataTypeSelectionWidget extends ComboBox<DataTypeModel> private final IViewContext<ICommonClientServiceAsync> viewContext; - public DataTypeSelectionWidget(final IViewContext<ICommonClientServiceAsync> viewContext) + public DataTypeSelectionWidget(final IViewContext<ICommonClientServiceAsync> viewContext, + final boolean mandatory) { this.viewContext = viewContext; setId(ID); - setEmptyText(viewContext.getMessage(Dict.COMBO_BOX_EMPTY, "data types")); setDisplayField(ModelDataPropertyNames.CODE); setEditable(false); setEnabled(false); setWidth(100); setFieldLabel(viewContext.getMessage(Dict.DATA_TYPE)); + if (mandatory) + { + setLabelSeparator(GenericConstants.MANDATORY_LABEL_SEPARATOR); + setAllowBlank(false); + } setStore(new ListStore<DataTypeModel>()); } @@ -104,12 +109,15 @@ public final class DataTypeSelectionWidget extends ComboBox<DataTypeModel> final ListStore<DataTypeModel> dataTypeStore = getStore(); dataTypeStore.removeAll(); dataTypeStore.add(DataTypeModel.convert(result)); + setEnabled(true); if (dataTypeStore.getCount() > 0) { - setEnabled(true); - setValue(dataTypeStore.getAt(0)); setEmptyText(viewContext.getMessage(Dict.COMBO_BOX_CHOOSE, "data type")); + } else + { + setEmptyText(viewContext.getMessage(Dict.COMBO_BOX_EMPTY, "data types")); } + applyEmptyText(); } } } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java index 21a87845131cb79004bc34bc6d165280a00853c7..b973aebb5bfe273a87f4b51341cebcacb52adbee 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java @@ -81,7 +81,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer private ExperimentTypeSelectionWidget experimentTypeSelectionWidget; - private PropertyTypeSelectionWidget propertyTypeSelectionWidget; + PropertyTypeSelectionWidget propertyTypeSelectionWidget; private Field<?> defaultValueField; @@ -320,8 +320,8 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer if (formPanel.isValid()) { viewContext.getService().assignPropertyType(entityKind, - propertyTypeSelectionWidget.tryGetSelectedPropertyTypeCode(), - getSelectedEntityCode(), getMandatoryCheckbox().getValue(), getDefaultValue(), + propertyTypeSelectionWidget.tryGetSelectedPropertyTypeCode(), getSelectedEntityCode(), + getMandatoryCheckbox().getValue(), getDefaultValue(), new AssignPropertyTypeCallback(viewContext)); } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeBrowser.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeBrowser.java index 6cdb550d434cd74e12685708ff2a2b52258ab99b..487e320b40e27606140b78ea8812dda5ce995ae1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeBrowser.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeBrowser.java @@ -92,7 +92,7 @@ public class PropertyTypeBrowser extends ContentPanel configs.add(ColumnConfigFactory.createDefaultColumnConfig(viewContext .getMessage(Dict.DATA_TYPE), ModelDataPropertyNames.DATA_TYPE)); configs.add(ColumnConfigFactory.createDefaultColumnConfig(viewContext - .getMessage(Dict.CONTROLLED_VOCABULARY), + .getMessage(Dict.VOCABULARY), ModelDataPropertyNames.CONTROLLED_VOCABULARY)); configs.add(ColumnConfigFactory.createDefaultColumnConfig(viewContext .getMessage(Dict.DESCRIPTION), ModelDataPropertyNames.DESCRIPTION)); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistration.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistration.java index 698dd7ca81ded6ef8dcb3172101676d5e290889f..9c44eda8a61673b34178326bf05756947d5ec792 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistration.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistration.java @@ -16,17 +16,10 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type; -import java.util.ArrayList; -import java.util.List; - import com.extjs.gxt.ui.client.Events; import com.extjs.gxt.ui.client.event.SelectionChangedEvent; import com.extjs.gxt.ui.client.event.SelectionChangedListener; import com.extjs.gxt.ui.client.widget.LayoutContainer; -import com.extjs.gxt.ui.client.widget.form.FieldSet; -import com.extjs.gxt.ui.client.widget.form.TextArea; -import com.extjs.gxt.ui.client.widget.form.Validator; -import com.extjs.gxt.ui.client.widget.layout.FormLayout; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; @@ -36,15 +29,15 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewConte import ch.systemsx.cisd.openbis.generic.client.web.client.application.InfoBoxCallbackListener; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.DataTypeModel; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.ModelDataPropertyNames; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyModel; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.AbstractRegistrationForm; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.CodeField; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.VarcharField; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.StringUtils; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DataType; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DataTypeCode; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; -import ch.systemsx.cisd.openbis.generic.client.web.client.dto.VocabularyTerm; /** * A {@link LayoutContainer} extension for registering a new property type. @@ -54,29 +47,23 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.dto.VocabularyTerm; // TODO 2008-12-28, Christian Ribeaud: Add 'USER.' as label just before the field. public final class PropertyTypeRegistration extends AbstractRegistrationForm { - private final static String DOT_EXTENDED_CODE_PATTERN = "^[a-zA-Z0-9_\\-\\.]+$"; - private static final String PREFIX = "property-type-registration"; public static final String ID_PREFIX = GenericConstants.ID_PREFIX + PREFIX; - private final IViewContext<ICommonClientServiceAsync> viewContext; - - private CodeField codeField; + final IViewContext<ICommonClientServiceAsync> viewContext; - private VarcharField labelField; + private CodeField propertyTypeCodeField; - private VarcharField descriptionField; + private VarcharField propertyTypeLabelField; - private CodeField vocabularyField; - - private VarcharField vocabularyDescription; + private VarcharField propertyTypeDescriptionField; private DataTypeSelectionWidget dataTypeSelectionWidget; - private TextArea vocabularyTermsField; + private VocabularySelectionWidget vocabularySelectionWidget; - private FieldSet vocabularyFieldSet; + private VocabularyRegistrationFieldSet vocabularyRegistrationFieldSet; public PropertyTypeRegistration(final IViewContext<ICommonClientServiceAsync> viewContext) { @@ -85,99 +72,49 @@ public final class PropertyTypeRegistration extends AbstractRegistrationForm addFields(); } - private final static List<String> getTerms(final String value) - { - final String[] split = value.split("[,\n\r\t\f ]"); - final List<String> terms = new ArrayList<String>(); - for (final String text : split) - { - if (StringUtils.isBlank(text) == false) - { - terms.add(text); - } - } - return terms; - } - - private final void setVocabularyFieldSetVisible(final boolean visible) - { - vocabularyField.setVisible(visible); - vocabularyField.setAllowBlank(!visible); - vocabularyField.reset(); - vocabularyTermsField.setVisible(visible); - vocabularyTermsField.setAllowBlank(!visible); - vocabularyTermsField.reset(); - vocabularyDescription.setVisible(visible); - vocabularyDescription.reset(); - vocabularyFieldSet.setVisible(visible); - } - - private final FieldSet createFieldSet() + private final VocabularyRegistrationFieldSet createVocabularyRegistrationFieldSet() { - final FieldSet fieldSet = new FieldSet(); - fieldSet.setHeading(viewContext.getMessage(Dict.CONTROLLED_VOCABULARY)); - fieldSet.setLayout(createFormLayout()); - fieldSet.setWidth(labelWidth + fieldWitdh); + final VocabularyRegistrationFieldSet fieldSet = + new VocabularyRegistrationFieldSet(viewContext, labelWidth, fieldWitdh - 40); fieldSet.setVisible(false); return fieldSet; } - private final FormLayout createFormLayout() - { - final FormLayout formLayout = new FormLayout(); - formLayout.setLabelWidth(labelWidth); - formLayout.setDefaultWidth(fieldWitdh - 40); - return formLayout; - } - private final CodeField createCodeField() { - return new CodeField(viewContext, viewContext.getMessage(Dict.CODE), - DOT_EXTENDED_CODE_PATTERN); + return new CodeField(viewContext, viewContext.getMessage(Dict.CODE), CodeField.CODE_PATTERN); } private final void addFields() { - formPanel.add(codeField = createCodeField()); + formPanel.add(propertyTypeCodeField = createCodeField()); // TODO 2008-12-28, Christian Ribeaud: Find a generic way to handle this. - codeField.addListener(Events.Focus, new AbstractRegistrationForm.InfoBoxResetListener( - infoBox)); - formPanel.add(labelField = createLabelField()); - formPanel.add(descriptionField = + propertyTypeCodeField.addListener(Events.Focus, + new AbstractRegistrationForm.InfoBoxResetListener(infoBox)); + formPanel.add(propertyTypeLabelField = createPropertyTypeLabelField()); + formPanel.add(propertyTypeDescriptionField = createDescriptionField(viewContext.getMessage(Dict.DESCRIPTION), true)); - formPanel.add(dataTypeSelectionWidget = new DataTypeSelectionWidget(viewContext)); - formPanel.add(vocabularyFieldSet = createFieldSet()); - vocabularyFieldSet.add(vocabularyField = createCodeField()); - vocabularyFieldSet.add(vocabularyDescription = - createDescriptionField(viewContext.getMessage(Dict.DESCRIPTION), false)); - vocabularyFieldSet.add(vocabularyTermsField = createVocabularyTermsTextArea()); - dataTypeSelectionWidget - .addSelectionChangedListener(new SelectionChangedListener<DataTypeModel>() - { - - // - // SelectionChangedListener - // - - @Override - public final void selectionChanged( - final SelectionChangedEvent<DataTypeModel> se) - { - final DataTypeModel selectedItem = se.getSelectedItem(); - final boolean visible; - if (selectedItem != null) - { - visible = - selectedItem.get(ModelDataPropertyNames.CODE).equals( - DataTypeCode.CONTROLLEDVOCABULARY.name()); - } else - { - visible = false; - } - setVocabularyFieldSetVisible(visible); - } - - }); + formPanel.add(dataTypeSelectionWidget = createDataTypeSelectionWidget()); + vocabularyRegistrationFieldSet = createVocabularyRegistrationFieldSet(); + formPanel.add(vocabularySelectionWidget = createVocabularySelectionWidget()); + formPanel.add(vocabularyRegistrationFieldSet); + } + + private final DataTypeSelectionWidget createDataTypeSelectionWidget() + { + final DataTypeSelectionWidget selectionWidget = + new DataTypeSelectionWidget(viewContext, true); + selectionWidget.addSelectionChangedListener(new DataTypeSelectionChangedListener()); + return selectionWidget; + } + + private final VocabularySelectionWidget createVocabularySelectionWidget() + { + final VocabularySelectionWidget selectionWidget = + new VocabularySelectionWidgetForPropertyTypeRegistration(viewContext, + vocabularyRegistrationFieldSet); + selectionWidget.setVisible(false); + return selectionWidget; } private final VarcharField createDescriptionField(final String descriptionLabel, @@ -188,7 +125,7 @@ public final class PropertyTypeRegistration extends AbstractRegistrationForm return varcharField; } - private final VarcharField createLabelField() + private final VarcharField createPropertyTypeLabelField() { final VarcharField varcharField = new VarcharField(viewContext.getMessage(Dict.LABEL), true); @@ -196,76 +133,28 @@ public final class PropertyTypeRegistration extends AbstractRegistrationForm return varcharField; } - private final TextArea createVocabularyTermsTextArea() - { - final TextArea textArea = new TextArea(); - final String fieldLabel = viewContext.getMessage(Dict.VOCABULARY_TERMS); - VarcharField.configureField(textArea, fieldLabel, true); - textArea.setEmptyText(viewContext.getMessage(Dict.VOCABULARY_TERMS_EMPTY)); - textArea.setValidator(new Validator<String, TextArea>() - { - - // - // Validator - // - - public final String validate(final TextArea field, final String value) - { - if (StringUtils.isBlank(value)) - { - return null; - } - final List<String> terms = getTerms(value); - if (terms.size() == 0) - { - return null; - } - for (final String term : terms) - { - if (term.matches(CodeField.CODE_PATTERN) == false) - { - return viewContext.getMessage(Dict.INVALID_CODE_MESSAGE, "Term '" - + term + "'"); - } - } - return null; - } - - }); - return textArea; - } - - private final static String appendUserOrNot(final String value) - { - if (value.toLowerCase().startsWith("user.")) - { - return value; - } - return "USER." + value; - } - private final PropertyType createPropertyType() { final PropertyType propertyType = new PropertyType(); - propertyType.setCode(appendUserOrNot(codeField.getValue())); - propertyType.setLabel(labelField.getValue()); - propertyType.setDescription(descriptionField.getValue()); + propertyType.setCode(PropertyType.USER_NAMESPACE_CODE_PREPEND + + propertyTypeCodeField.getValue()); + propertyType.setLabel(propertyTypeLabelField.getValue()); + propertyType.setDescription(propertyTypeDescriptionField.getValue()); final DataType selectedDataType = dataTypeSelectionWidget.tryGetSelectedDataType(); propertyType.setDataType(selectedDataType); if (DataTypeCode.CONTROLLEDVOCABULARY.equals(selectedDataType.getCode())) { - final Vocabulary vocabulary = new Vocabulary(); - vocabulary.setCode(appendUserOrNot(vocabularyField.getValue())); - vocabulary.setDescription(StringUtils.trimToNull(vocabularyDescription.getValue())); - List<VocabularyTerm> vocabularyTerms = new ArrayList<VocabularyTerm>(); - for (final String termCode : getTerms(vocabularyTermsField.getValue())) + final VocabularyModel vocabulary = + GWTUtils.tryGetSingleSelectedModel(vocabularySelectionWidget); + if (VocabularyModel.NEW_VOCABULARY_CODE.equals(vocabulary + .get(ModelDataPropertyNames.CODE))) { - final VocabularyTerm vocabularyTerm = new VocabularyTerm(); - vocabularyTerm.setCode(termCode); - vocabularyTerms.add(vocabularyTerm); + propertyType.setVocabulary(vocabularyRegistrationFieldSet.createVocabulary()); + } else + { + propertyType.setVocabulary((Vocabulary) vocabulary + .get(ModelDataPropertyNames.OBJECT)); } - vocabulary.setTerms(vocabularyTerms); - propertyType.setVocabulary(vocabulary); } return propertyType; } @@ -286,6 +175,33 @@ public final class PropertyTypeRegistration extends AbstractRegistrationForm // Helper classes // + private final class DataTypeSelectionChangedListener extends + SelectionChangedListener<DataTypeModel> + { + + // + // SelectionChangedListener + // + + @Override + public final void selectionChanged(final SelectionChangedEvent<DataTypeModel> se) + { + final DataTypeModel selectedItem = se.getSelectedItem(); + final boolean visible; + if (selectedItem != null) + { + visible = + selectedItem.get(ModelDataPropertyNames.CODE).equals( + DataTypeCode.CONTROLLEDVOCABULARY.name()); + } else + { + vocabularySelectionWidget.reset(); + visible = false; + } + vocabularySelectionWidget.setVisible(visible); + } + } + private final class PropertyTypeRegistrationCallback extends AbstractAsyncCallback<Void> { private final PropertyType propertyType; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeSelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeSelectionWidget.java index 237eb0954946d5ad3b753c2a91a132fe57e3c5a7..ec7c79b90d0852bac770ef29a354e6162bfe635c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeSelectionWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeSelectionWidget.java @@ -24,10 +24,12 @@ import com.google.gwt.user.client.Element; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; 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.model.ModelDataPropertyNames; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.PropertyTypeModel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.PropertyType; /** @@ -51,25 +53,14 @@ public final class PropertyTypeSelectionWidget extends ComboBox<PropertyTypeMode setDisplayField(ModelDataPropertyNames.CODE); setEditable(false); setWidth(180); - setFieldLabel("Property type"); + setFieldLabel(viewContext.getMessage(Dict.PROPERTY_TYPE)); setStore(new ListStore<PropertyTypeModel>()); } - /** - * Returns the property type code currently selected. - * - * @return <code>null</code> if nothing is selected yet. - */ public final String tryGetSelectedPropertyTypeCode() { - final List<PropertyTypeModel> selection = getSelection(); - final int size = selection.size(); - if (size > 0) - { - assert size == 1 : "Selection is empty."; - return selection.get(0).get(ModelDataPropertyNames.CODE); - } - return null; + final PropertyType propertyType = tryGetSelectedPropertyType(); + return propertyType == null ? null : propertyType.getCode(); } /** @@ -79,14 +70,7 @@ public final class PropertyTypeSelectionWidget extends ComboBox<PropertyTypeMode */ public final PropertyType tryGetSelectedPropertyType() { - final List<PropertyTypeModel> selection = getSelection(); - final int size = selection.size(); - if (size > 0) - { - assert size == 1 : "Selection is empty."; - return selection.get(0).get(ModelDataPropertyNames.OBJECT); - } - return null; + return GWTUtils.tryGetSingleSelected(this); } @Override @@ -121,10 +105,10 @@ public final class PropertyTypeSelectionWidget extends ComboBox<PropertyTypeMode if (propertyTypeStore.getCount() > 0) { setEnabled(true); - setEmptyText("Choose property type..."); + setEmptyText(viewContext.getMessage(Dict.COMBO_BOX_CHOOSE, "property type")); } else { - setEmptyText("- No property types found -"); + setEmptyText(viewContext.getMessage(Dict.COMBO_BOX_EMPTY, "property types")); } applyEmptyText(); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyRegistrationFieldSet.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyRegistrationFieldSet.java new file mode 100644 index 0000000000000000000000000000000000000000..5749480fe2b9fb9cb808ccc1511a8e1cd90bde4a --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyRegistrationFieldSet.java @@ -0,0 +1,136 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type; + +import java.util.ArrayList; +import java.util.List; + +import com.extjs.gxt.ui.client.widget.form.FieldSet; +import com.extjs.gxt.ui.client.widget.form.TextArea; +import com.extjs.gxt.ui.client.widget.layout.FormLayout; + +import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.CodeField; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.VarcharField; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.StringUtils; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.PropertyType; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.VocabularyTerm; + +/** + * A {@link FieldSet} extension for registering vocabulary. + * + * @author Christian Ribeaud + */ +public final class VocabularyRegistrationFieldSet extends FieldSet +{ + private CodeField vocabularyCodeField; + + private VarcharField vocabularyDescriptionField; + + private TextArea vocabularyTermsField; + + private final IViewContext<ICommonClientServiceAsync> viewContext; + + private final int labelWidth; + + private final int fieldWith; + + VocabularyRegistrationFieldSet(final IViewContext<ICommonClientServiceAsync> viewContext, + final int labelWidth, final int fieldWidth) + { + this.viewContext = viewContext; + this.labelWidth = labelWidth; + this.fieldWith = fieldWidth; + setHeading(viewContext.getMessage(Dict.VOCABULARY)); + setLayout(createFormLayout()); + setWidth(labelWidth + fieldWidth + 40); + add(vocabularyCodeField = createCodeField()); + add(vocabularyDescriptionField = + createDescriptionField(viewContext.getMessage(Dict.DESCRIPTION), false)); + add(vocabularyTermsField = createVocabularyTermsField()); + } + + private final FormLayout createFormLayout() + { + final FormLayout formLayout = new FormLayout(); + formLayout.setLabelWidth(labelWidth); + formLayout.setDefaultWidth(fieldWith); + return formLayout; + } + + private final CodeField createCodeField() + { + return new CodeField(viewContext, viewContext.getMessage(Dict.CODE), CodeField.CODE_PATTERN); + } + + private final VarcharField createDescriptionField(final String descriptionLabel, + final boolean mandatory) + { + final VarcharField varcharField = new VarcharField(descriptionLabel, mandatory); + varcharField.setMaxLength(80); + return varcharField; + } + + private final TextArea createVocabularyTermsField() + { + final TextArea textArea = new TextArea(); + final String fieldLabel = viewContext.getMessage(Dict.VOCABULARY_TERMS); + VarcharField.configureField(textArea, fieldLabel, true); + textArea.setEmptyText(viewContext.getMessage(Dict.VOCABULARY_TERMS_EMPTY)); + textArea.setValidator(new VocabularyTermValidator(viewContext)); + return textArea; + } + + final Vocabulary createVocabulary() + { + final Vocabulary vocabulary = new Vocabulary(); + vocabulary + .setCode(PropertyType.USER_NAMESPACE_CODE_PREPEND + vocabularyCodeField.getValue()); + vocabulary.setDescription(StringUtils.trimToNull(vocabularyDescriptionField.getValue())); + final List<VocabularyTerm> vocabularyTerms = new ArrayList<VocabularyTerm>(); + for (final String termCode : VocabularyTermValidator.getTerms(vocabularyTermsField + .getValue())) + { + final VocabularyTerm vocabularyTerm = new VocabularyTerm(); + vocabularyTerm.setCode(termCode); + vocabularyTerms.add(vocabularyTerm); + } + vocabulary.setTerms(vocabularyTerms); + return vocabulary; + } + + // + // FieldSet + // + + @Override + public final void setVisible(final boolean visible) + { + vocabularyCodeField.setVisible(visible); + vocabularyCodeField.setAllowBlank(!visible); + vocabularyCodeField.reset(); + vocabularyDescriptionField.setVisible(visible); + vocabularyDescriptionField.reset(); + vocabularyTermsField.setVisible(visible); + vocabularyTermsField.setAllowBlank(!visible); + vocabularyTermsField.reset(); + super.setVisible(visible); + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidget.java new file mode 100644 index 0000000000000000000000000000000000000000..4c6666580522476000d27d49b673af54a0062db7 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidget.java @@ -0,0 +1,126 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type; + +import java.util.List; + +import com.extjs.gxt.ui.client.store.ListStore; +import com.extjs.gxt.ui.client.widget.form.ComboBox; + +import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; +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.model.ModelDataPropertyNames; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyModel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; + +/** + * A {@link ComboBox} extension for selecting a {@link Vocabulary}. + * + * @author Christian Ribeaud + */ +public class VocabularySelectionWidget extends ComboBox<VocabularyModel> +{ + private static final String PREFIX = "vocabulary-select"; + + public static final String ID = GenericConstants.ID_PREFIX + PREFIX; + + private final IViewContext<ICommonClientServiceAsync> viewContext; + + public VocabularySelectionWidget(final IViewContext<ICommonClientServiceAsync> viewContext) + { + this.viewContext = viewContext; + setId(ID); + setDisplayField(ModelDataPropertyNames.CODE); + setEnabled(false); + setEditable(false); + setWidth(100); + setFieldLabel(viewContext.getMessage(Dict.VOCABULARY)); + setStore(new ListStore<VocabularyModel>()); + } + + /** + * Returns the {@link Vocabulary} currently selected. + * + * @return <code>null</code> if nothing is selected yet. + */ + public final Vocabulary tryGetSelectedVocabulary() + { + return GWTUtils.tryGetSingleSelected(this); + } + + private final void loadVocabularies() + { + viewContext.getService().listVocabularies(new ListVocabulariesCallback(viewContext)); + } + + /** + * Refreshes the store with given list of {@link Vocabulary}. + */ + protected void refreshStore(final List<Vocabulary> result) + { + final ListStore<VocabularyModel> vocabularyStore = getStore(); + vocabularyStore.removeAll(); + vocabularyStore.add(VocabularyModel.convert(result)); + setEnabled(true); + if (vocabularyStore.getCount() > 0) + { + setEmptyText(viewContext.getMessage(Dict.COMBO_BOX_CHOOSE, "vocabulary")); + } else + { + setEmptyText(viewContext.getMessage(Dict.COMBO_BOX_EMPTY, "vocabularies")); + } + applyEmptyText(); + } + + // + // ComboBox + // + + @Override + protected final void afterRender() + { + super.afterRender(); + loadVocabularies(); + } + + // + // Helper classes + // + + public final class ListVocabulariesCallback extends AbstractAsyncCallback<List<Vocabulary>> + { + ListVocabulariesCallback(final IViewContext<ICommonClientServiceAsync> viewContext) + { + super(viewContext); + } + + // + // AbstractAsyncCallback + // + + @Override + protected final void process(final List<Vocabulary> result) + { + refreshStore(result); + } + + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidgetForPropertyTypeRegistration.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidgetForPropertyTypeRegistration.java new file mode 100644 index 0000000000000000000000000000000000000000..2d7798e5bed7adcb82fe1868522f37a5e4f6cfb3 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidgetForPropertyTypeRegistration.java @@ -0,0 +1,78 @@ +package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type; + +import java.util.List; + +import com.extjs.gxt.ui.client.event.SelectionChangedEvent; +import com.extjs.gxt.ui.client.event.SelectionChangedListener; + +import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.ModelDataPropertyNames; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyModel; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; + +/** + * A small {@link VocabularySelectionWidget} extension suitable for <i>Property Type</i> + * registration. + * + * @author Christian Ribeaud + */ +final class VocabularySelectionWidgetForPropertyTypeRegistration extends VocabularySelectionWidget +{ + private final VocabularyRegistrationFieldSet vocabularyRegistrationFieldSet; + + VocabularySelectionWidgetForPropertyTypeRegistration( + final IViewContext<ICommonClientServiceAsync> viewContext, + final VocabularyRegistrationFieldSet vocabularyRegistrationFieldSet) + { + super(viewContext); + assert vocabularyRegistrationFieldSet != null : "Unspecified VocabularyRegistrationFieldSet"; + this.vocabularyRegistrationFieldSet = vocabularyRegistrationFieldSet; + addSelectionChangedListener(new SelectionChangedListener<VocabularyModel>() + { + + // + // SelectionChangedListener + // + + @Override + public final void selectionChanged(final SelectionChangedEvent<VocabularyModel> se) + { + final VocabularyModel selectedItem = se.getSelectedItem(); + final boolean visible; + if (selectedItem != null) + { + visible = + selectedItem.get(ModelDataPropertyNames.CODE).equals( + VocabularyModel.NEW_VOCABULARY_CODE); + } else + { + visible = false; + } + vocabularyRegistrationFieldSet.setVisible(visible); + } + }); + + } + + // + // VocabularySelectionWidget + // + + @Override + public final void setVisible(final boolean visible) + { + super.setVisible(visible); + if (visible == false && isRendered()) + { + vocabularyRegistrationFieldSet.setVisible(visible); + } + } + + @Override + protected final void refreshStore(final List<Vocabulary> result) + { + super.refreshStore(result); + getStore().insert(VocabularyModel.createNewVocabularyVocabularyModel(), 0); + } +} \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyTermValidator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyTermValidator.java new file mode 100644 index 0000000000000000000000000000000000000000..18501451cdb75962572d77ef8e6482cc568c60a5 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyTermValidator.java @@ -0,0 +1,67 @@ +package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type; + +import java.util.ArrayList; +import java.util.List; + +import com.extjs.gxt.ui.client.widget.form.TextArea; +import com.extjs.gxt.ui.client.widget.form.Validator; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.CodeField; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.StringUtils; + +/** + * A {@link Validator} implementation which validates vocabulary terms in a text area. + * + * @author Christian Ribeaud + */ +final class VocabularyTermValidator implements Validator<String, TextArea> +{ + + private final IMessageProvider messageProvider; + + VocabularyTermValidator(final IMessageProvider messageProvider) + { + this.messageProvider = messageProvider; + } + + final static List<String> getTerms(final String value) + { + final String[] split = value.split("[,\n\r\t\f ]"); + final List<String> terms = new ArrayList<String>(); + for (final String text : split) + { + if (StringUtils.isBlank(text) == false) + { + terms.add(text); + } + } + return terms; + } + + // + // Validator + // + + public final String validate(final TextArea field, final String value) + { + if (StringUtils.isBlank(value)) + { + return null; + } + final List<String> terms = VocabularyTermValidator.getTerms(value); + if (terms.size() == 0) + { + return null; + } + for (final String term : terms) + { + if (term.matches(CodeField.CODE_PATTERN) == false) + { + return messageProvider.getMessage(Dict.INVALID_CODE_MESSAGE, "Term '" + term + "'"); + } + } + return null; + } +} \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java index a747684d8dd4296481be05ce444d07f87d90e195..7f22afeb318454bc4f5bc73c211603af8bd058eb 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java @@ -119,18 +119,18 @@ public final class GWTUtils final ColumnConfig columnConfig = columnModel.getColumn(i); if (columnConfig.isHidden() == false) { - // TODO 2008-12-28, Christian Ribeaud: This sometimes throws an exception. - // grid.setAutoExpandColumn(columnConfig.getId()); + grid.setAutoExpandColumn(columnConfig.getId()); return; } } } /** - * Tries to return the selected object (saved as {@link ModelDataPropertyNames#OBJECT} in the - * model) from the given {@link ComboBox}. + * Tries to return the selected {@link ModelData} from the given {@link ComboBox}. + * + * @returns <code>null</code> if nothing is selected. */ - public final static <T extends ModelData, O> O tryGetSingleSelected(final ComboBox<T> comboBox) + public final static <T extends ModelData> T tryGetSingleSelectedModel(final ComboBox<T> comboBox) { assert comboBox != null : "Unspecified combo box."; final List<T> selection = comboBox.getSelection(); @@ -138,8 +138,21 @@ public final class GWTUtils if (size > 0) { assert size == 1 : "Only one item must be selected."; - return selection.get(0).get(ModelDataPropertyNames.OBJECT); + return selection.get(0); } return null; } + + /** + * Tries to return the selected object (saved as {@link ModelDataPropertyNames#OBJECT} in the + * model) from the given {@link ComboBox}. + * + * @returns <code>null</code> if nothing is selected. + */ + @SuppressWarnings("unchecked") + public final static <T extends ModelData, O> O tryGetSingleSelected(final ComboBox<T> comboBox) + { + final T selectedModel = tryGetSingleSelectedModel(comboBox); + return (O) (selectedModel != null ? selectedModel.get(ModelDataPropertyNames.OBJECT) : null); + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/PropertyType.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/PropertyType.java index ee3609f0507a1fc4ef5567fbd070dbc643bd2d51..7d37960aff752d0cd1f8ebd7a4fad7b6f86ee2da 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/PropertyType.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/PropertyType.java @@ -20,11 +20,18 @@ import java.util.List; import com.google.gwt.user.client.rpc.IsSerializable; +import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE; + /** + * The <i>GWT</i> pendant to {@link PropertyTypePE}. + * * @author Izabela Adamczyk */ public class PropertyType extends Code<PropertyType> implements IsSerializable { + + public final static String USER_NAMESPACE_CODE_PREPEND = "USER."; + /** * Only used for displaying/viewing. With <code>managedInternally</code> is unambiguous * (meaning that <code>simpleCode</code> alone could be not unique). diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractVocabularyBusinessObject.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractVocabularyBusinessObject.java new file mode 100644 index 0000000000000000000000000000000000000000..54767cd5ba6e15c7e0644499021ae9713982e764 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractVocabularyBusinessObject.java @@ -0,0 +1,65 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.openbis.generic.server.business.bo; + +import org.springframework.dao.DataAccessException; + +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.VocabularyTerm; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; +import ch.systemsx.cisd.openbis.generic.shared.dto.Session; +import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyTermPE; + +/** + * An <i>abtract</i> {@link AbstractBusinessObject} extension which creates a {@link VocabularyPE} + * in the database out of a given {@link Vocabulary}. + * + * @author Christian Ribeaud + */ +abstract class AbstractVocabularyBusinessObject extends AbstractBusinessObject +{ + AbstractVocabularyBusinessObject(IDAOFactory daoFactory, Session session) + { + super(daoFactory, session); + } + + final VocabularyPE createVocabulary(final Vocabulary vocabulary) + { + final VocabularyPE vocabularyPE = new VocabularyPE(); + vocabularyPE.setCode(vocabulary.getCode()); + vocabularyPE.setDescription(vocabulary.getDescription()); + vocabularyPE.setDatabaseInstance(getHomeDatabaseInstance()); + vocabularyPE.setRegistrator(findRegistrator()); + for (final VocabularyTerm term : vocabulary.getTerms()) + { + final VocabularyTermPE vocabularyTermPE = new VocabularyTermPE(); + vocabularyTermPE.setCode(term.getCode()); + vocabularyTermPE.setRegistrator(findRegistrator()); + vocabularyPE.addTerm(vocabularyTermPE); + } + try + { + getVocabularyDAO().createVocabulary(vocabularyPE); + } catch (final DataAccessException e) + { + throwException(e, String.format("Vocabulary '%s'.", vocabularyPE.getCode())); + } + return vocabularyPE; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBO.java index 9136850c46b09cb177afc7d9549b80c06229a150..00a1a126b085334e49133c90d32f33846dc1d1a4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBO.java @@ -20,14 +20,11 @@ import org.springframework.dao.DataAccessException; import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.PropertyType; -import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; -import ch.systemsx.cisd.openbis.generic.client.web.client.dto.VocabularyTerm; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.shared.dto.DataTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.Session; import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyTermPE; import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityDataType; /** @@ -35,8 +32,8 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityDataType; * * @author Christian Ribeaud */ -// TODO 2008-12-16, Christian Ribeaud: Write an Unit test of this class. -public final class PropertyTypeBO extends AbstractBusinessObject implements IPropertyTypeBO +public final class PropertyTypeBO extends AbstractVocabularyBusinessObject implements + IPropertyTypeBO { private PropertyTypePE propertyTypePE; @@ -45,32 +42,8 @@ public final class PropertyTypeBO extends AbstractBusinessObject implements IPro super(daoFactory, session); } - private final VocabularyPE createVocabulary(final Vocabulary vocabulary) - { - final VocabularyPE vocabularyPE = new VocabularyPE(); - vocabularyPE.setCode(vocabulary.getCode()); - vocabularyPE.setDescription(vocabulary.getDescription()); - vocabularyPE.setDatabaseInstance(getHomeDatabaseInstance()); - vocabularyPE.setRegistrator(findRegistrator()); - for (final VocabularyTerm term : vocabulary.getTerms()) - { - final VocabularyTermPE vocabularyTermPE = new VocabularyTermPE(); - vocabularyTermPE.setCode(term.getCode()); - vocabularyTermPE.setRegistrator(findRegistrator()); - vocabularyPE.addTerm(vocabularyTermPE); - } - try - { - getVocabularyDAO().createVocabulary(vocabularyPE); - } catch (final DataAccessException e) - { - throwException(e, String.format("Property type '%s'.", propertyTypePE.getCode())); - } - return vocabularyPE; - } - // - // IPropertyTypeBO + // AbstractVocabularyBusinessObject // public final void define(final PropertyType propertyType) throws UserFailureException diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js index 1b1a6a775533d43033a3135cf886005320c58b3e..effa70b81a5d28a72a9b4472588cd73977f91781 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js +++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js @@ -117,15 +117,16 @@ var common = { label: "Label", data_type: "Data type", - controlled_vocabulary: "Controlled vocabulary", description: "Description", sample_types: "Sample types", material_types: "Material types", experiment_types: "Experiment types", is_mandatory: "Mandatory?", + property_type: "Property type", property_type_code: "Property type code", assigned_to: "Assigned to", type_of: "Type of", + vocabulary: "Vocabulary", vocabulary_terms: "Terms", vocabulary_terms_empty: "White space or comma separated list", mandatory: "Mandatory", diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/GroupBOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/GroupBOTest.java index 9a90674cfce12c7c64e2ff357e528572589f1c5d..858229f7fe4286a2476ea33d21f91a4b02348da1 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/GroupBOTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/GroupBOTest.java @@ -39,7 +39,6 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE; */ public final class GroupBOTest { - private BufferedAppender logRecorder; private Mockery context; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBOTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c46bb0c7d74f1877bc1ce69fcb7b6859d07e922f --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBOTest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.openbis.generic.server.business.bo; + +/** + * Test cases for corresponding {@link PropertyTypeBO} class. + * + * @author Christian Ribeaud + */ +// TODO 2008-12-16, Christian Ribeaud: Complete test. +public final class PropertyTypeBOTest +{ + +}