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 334edcd09d001e744875d27082228129afa76f98..2e4449e12a303ede333d1ad262ca42cdccf21881 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 @@ -500,6 +500,8 @@ public abstract class Dict public static final String GENERATED_FROM_SAMPLE = "generated_from_sample"; + public static final String ADD_PARENT = "add_parent"; + public static final String PART_OF_SAMPLE = "part_of_sample"; // diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/ChosenEntitySetter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/ChosenEntitySetter.java index d7e86361191a633db097b1712e559bc886884393..fa4c4f2075d5b54adc065d8896a876f60d4f37d6 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/ChosenEntitySetter.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/ChosenEntitySetter.java @@ -21,7 +21,7 @@ import java.util.Set; import com.extjs.gxt.ui.client.widget.form.TriggerField; -public abstract class ChosenEntitySetter<T> extends TriggerField<String> +abstract class ChosenEntitySetter<T> extends TriggerField<String> implements IChosenEntitySetter<T> { private static final int TEXT_CHOOSER_FIELD_WIDTH = 342; @@ -40,7 +40,7 @@ public abstract class ChosenEntitySetter<T> extends TriggerField<String> listeners.add(listener); } - void setChosenEntity(T entityOrNull) + public void setChosenEntity(T entityOrNull) { if (entityOrNull != null) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/EntityChooserDialog.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/EntityChooserDialog.java index 9343b26b15e19eb7bc2f17489b07d578fd57a1b4..5a0635560e04f5a5d8f29c8fd14a7e7dcc891b25 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/EntityChooserDialog.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/EntityChooserDialog.java @@ -45,7 +45,8 @@ class EntityChooserDialog<T> extends SimpleDialog private final IDelegatedAction onCancelAction; public EntityChooserDialog(DisposableEntityChooser<T> entityBrowser, - ChosenEntitySetter<T> chosenEntitySetter, String title, IMessageProvider messageProvider) + IChosenEntitySetter<T> chosenEntitySetter, String title, + IMessageProvider messageProvider) { super(entityBrowser.getComponent(), title, messageProvider.getMessage(Dict.BUTTON_CHOOSE), messageProvider); @@ -79,7 +80,7 @@ class EntityChooserDialog<T> extends SimpleDialog } private static <T> IDelegatedAction createAcceptAction( - final ChosenEntitySetter<T> chosenEntitySetter, + final IChosenEntitySetter<T> chosenEntitySetter, final DisposableEntityChooser<T> entityBrowser) { return new IDelegatedAction() @@ -94,7 +95,8 @@ class EntityChooserDialog<T> extends SimpleDialog } private static <T> IDelegatedAction createCancelAction( - final ChosenEntitySetter<T> chosenEntitySetter, final IDisposableComponent entityBrowser) + final IChosenEntitySetter<T> chosenEntitySetter, + final IDisposableComponent entityBrowser) { return new IDelegatedAction() { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/IChosenEntityListener.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/IChosenEntityListener.java index 63155ba6034c16802052031c702dbaf871791619..5b9f8dd1c3a9f5ffe57d5c97982fcd1db8d2454c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/IChosenEntityListener.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/IChosenEntityListener.java @@ -17,9 +17,7 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field; /** - * - * - * @author Franz-Josef Elmer + * @author Franz-Josef Elmer */ public interface IChosenEntityListener<T> { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/IChosenEntitySetter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/IChosenEntitySetter.java new file mode 100644 index 0000000000000000000000000000000000000000..f85f45014e557f265786b0e9a14560853a5b99ee --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/IChosenEntitySetter.java @@ -0,0 +1,25 @@ +/* + * Copyright 2009 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.field; + +/** + * @author Piotr Buczek + */ +public interface IChosenEntitySetter<T> +{ + public void setChosenEntity(T entityOrNull); +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/SampleChooserButton.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/SampleChooserButton.java new file mode 100644 index 0000000000000000000000000000000000000000..34629acc32d67b1a8d61e6623cfd6ece9bea973f --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/SampleChooserButton.java @@ -0,0 +1,178 @@ +/* + * 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.field; + +import java.util.LinkedHashSet; +import java.util.Set; + +import com.extjs.gxt.ui.client.event.ButtonEvent; +import com.extjs.gxt.ui.client.event.SelectionListener; +import com.extjs.gxt.ui.client.widget.button.Button; +import com.extjs.gxt.ui.client.widget.form.AdapterField; +import com.extjs.gxt.ui.client.widget.form.Field; + +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.framework.SampleTypeDisplayID; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.DisposableEntityChooser; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.SampleBrowserGrid; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; + +/** + * ` A button for selecting a sample from a list. + * + * @author Piotr Buczek + */ +public class SampleChooserButton extends Button implements IChosenEntitySetter<Sample> +{ + public interface SampleChooserButtonAdaptor + { + Field<?> getField(); + + SampleChooserButton getChooserButton(); + + /** @return the sample identifier (as a string) which is set as a field value */ + String getValue(); + } + + private final Set<IChosenEntityListener<Sample>> listeners = + new LinkedHashSet<IChosenEntityListener<Sample>>(); + + /** + * Creates a text field with the additional browse button which allow to choose a sample from + * the list. + */ + public static SampleChooserButtonAdaptor create(final String labelField, + final String buttonText, final boolean addShared, boolean addAll, + final boolean excludeWithoutExperiment, + final IViewContext<ICommonClientServiceAsync> viewContext, + SampleTypeDisplayID sampleTypeDisplayID) + { + return create(labelField, buttonText, addShared, addAll, excludeWithoutExperiment, + viewContext, null, sampleTypeDisplayID); + + } + + public static SampleChooserButtonAdaptor create(final String labelField, + final String buttonText, final boolean addShared, final boolean addAll, + final boolean excludeWithoutExperiment, + final IViewContext<ICommonClientServiceAsync> viewContext, String idOrNull, + final SampleTypeDisplayID sampleTypeDisplayID) + { + final SampleChooserButton chooserButton = new SampleChooserButton(viewContext, buttonText); + chooserButton.addSelectionListener(new SelectionListener<ButtonEvent>() + { + + @Override + public void componentSelected(ButtonEvent ce) + { + browse(viewContext, chooserButton, addShared, addAll, excludeWithoutExperiment, + sampleTypeDisplayID); + } + + }); + if (idOrNull != null) + { + chooserButton.setId(idOrNull); + } + final SampleChooserButtonAdaptor adaptor = asSampleChooserFieldAdaptor(chooserButton); + Field<?> field = adaptor.getField(); + field.setFieldLabel(labelField); + return adaptor; + } + + private static SampleChooserButtonAdaptor asSampleChooserFieldAdaptor( + final SampleChooserButton chooserButton) + { + final Field<?> chooserField = new AdapterField(chooserButton); + return new SampleChooserButtonAdaptor() + { + public Field<?> getField() + { + return chooserField; + } + + public SampleChooserButton getChooserButton() + { + return chooserButton; + } + + public String getValue() + { + return chooserButton.getValue(); + } + + }; + } + + private static void browse(final IViewContext<ICommonClientServiceAsync> viewContext, + final IChosenEntitySetter<Sample> chooserSampleSetter, final boolean addShared, + boolean addAll, final boolean excludeWithoutExperiment, + SampleTypeDisplayID sampleTypeDisplayID) + { + DisposableEntityChooser<Sample> browser = + SampleBrowserGrid.createChooser(viewContext, addShared, addAll, + excludeWithoutExperiment, sampleTypeDisplayID); + String title = viewContext.getMessage(Dict.TITLE_CHOOSE_SAMPLE); + new EntityChooserDialog<Sample>(browser, chooserSampleSetter, title, viewContext).show(); + } + + // ------------------ + + // @Override + public String renderEntity(Sample entityOrNull) + { + return entityOrNull.getIdentifier(); + } + + private SampleChooserButton(final IViewContext<ICommonClientServiceAsync> viewContext, + final String buttonText) + { + super(buttonText); + } + + public void setChosenEntity(Sample entityOrNull) + { + if (entityOrNull != null) + { + setValue(renderEntity(entityOrNull)); + } + for (IChosenEntityListener<Sample> listener : listeners) + { + listener.entityChosen(entityOrNull); + } + } + + private String value; + + public String getValue() + { + return value; + } + + public void setValue(String value) + { + this.value = value; + } + + public void addChosenEntityListener(IChosenEntityListener<Sample> listener) + { + listeners.add(listener); + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/public/generic-dictionary.js b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/public/generic-dictionary.js index ac49fb910099e39872156c2ff9565e0d53e2de01..da71a6b8c3eb5921ea3591fccec8c2757d06eb5d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/public/generic-dictionary.js +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/public/generic-dictionary.js @@ -25,6 +25,7 @@ var generic = { instance_sample: "Shared", generated_from_sample: "Parent", + add_parent: "Add Parent", part_of_sample: "Container", parents: "Parents", diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/AbstractGenericSampleRegisterEditForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/AbstractGenericSampleRegisterEditForm.java index ec96b78c1556d70039b5623831f8230b409de965..73204a133462d1d1adedbc690d6ef1a6dd53cbcf 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/AbstractGenericSampleRegisterEditForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/AbstractGenericSampleRegisterEditForm.java @@ -36,8 +36,10 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework. import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.GroupSelectionWidget; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.ExperimentChooserField; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.IChosenEntityListener; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.SampleChooserButton; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.SampleChooserField; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.ExperimentChooserField.ExperimentChooserFieldAdaptor; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.SampleChooserButton.SampleChooserButtonAdaptor; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.SampleChooserField.SampleChooserFieldAdaptor; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.file.AttachmentsFileFieldManager; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.FieldUtil; @@ -84,7 +86,7 @@ abstract public class AbstractGenericSampleRegisterEditForm extends protected SampleChooserFieldAdaptor container; - protected SampleChooserFieldAdaptor parent; + protected SampleChooserButtonAdaptor parentButton; protected ParentSamplesArea parentsArea; @@ -176,7 +178,7 @@ abstract public class AbstractGenericSampleRegisterEditForm extends new ArrayList<DatabaseModificationAwareField<?>>(); fields.add(wrapUnaware(experimentField.getField())); fields.add(groupSelectionWidget.asDatabaseModificationAware()); - fields.add(wrapUnaware(parent.getField())); + fields.add(wrapUnaware(parentButton.getField())); fields.add(wrapUnaware(parentsArea)); fields.add(wrapUnaware(container.getField())); return fields; @@ -210,15 +212,15 @@ abstract public class AbstractGenericSampleRegisterEditForm extends new GroupSelectionWidget(viewContext, getId(), true, false, initialGroupCodeOrNull); FieldUtil.markAsMandatory(groupSelectionWidget); groupSelectionWidget.setFieldLabel(viewContext.getMessage(Dict.GROUP)); - parent = - SampleChooserField.create(viewContext.getMessage(Dict.GENERATED_FROM_SAMPLE), - false, null, true, false, false, viewContext.getCommonViewContext(), - getId() + ID_SUFFIX_PARENT, + parentButton = + SampleChooserButton.create(viewContext.getMessage(Dict.PARENTS), viewContext + .getMessage(Dict.ADD_PARENT), true, false, false, viewContext + .getCommonViewContext(), getId() + ID_SUFFIX_PARENT, SampleTypeDisplayID.SAMPLE_REGISTRATION_PARENT_CHOOSER .withSuffix(getSampleTypeCode())); parentsArea = new ParentSamplesArea(viewContext, simpleId); - SampleChooserField parentChooserField = parent.getChooserField(); - parentChooserField.addChosenEntityListener(new IChosenEntityListener<Sample>() + SampleChooserButton parentChooserButton = parentButton.getChooserButton(); + parentChooserButton.addChosenEntityListener(new IChosenEntityListener<Sample>() { public void entityChosen(Sample entity) { @@ -276,7 +278,7 @@ abstract public class AbstractGenericSampleRegisterEditForm extends boolean showContainer = sampleType.isShowContainer(); boolean showParents = sampleType.isShowParents(); FieldUtil.setVisibility(showContainer, container.getField()); - FieldUtil.setVisibility(showParents, parent.getField(), parentsArea); + FieldUtil.setVisibility(showParents, parentButton.getField(), parentsArea); } private String getSampleTypeCode() diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/ParentSamplesArea.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/ParentSamplesArea.java index 594762dbcdf332372367356e5e90d84a0a50ee51..55fbbc9ab59fafab62d4da7c20ddb0949f0dd4a4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/ParentSamplesArea.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/ParentSamplesArea.java @@ -32,7 +32,7 @@ final class ParentSamplesArea extends SamplesArea public ParentSamplesArea(IMessageProvider messageProvider, String idPrefix) { super(messageProvider.getMessage(Dict.SAMPLES_LIST)); - this.setFieldLabel(messageProvider.getMessage(Dict.PARENTS)); + setLabelSeparator(""); setId(createId(idPrefix)); }