Skip to content
Snippets Groups Projects
Commit 30dcbe9a authored by buczekp's avatar buczekp
Browse files

[LMS-1676] introduced SampleChooserButton for sample registration/edition

SVN: 17383
parent 5a183d57
No related branches found
No related tags found
No related merge requests found
Showing
with 226 additions and 18 deletions
...@@ -500,6 +500,8 @@ public abstract class Dict ...@@ -500,6 +500,8 @@ public abstract class Dict
public static final String GENERATED_FROM_SAMPLE = "generated_from_sample"; 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"; public static final String PART_OF_SAMPLE = "part_of_sample";
// //
......
...@@ -21,7 +21,7 @@ import java.util.Set; ...@@ -21,7 +21,7 @@ import java.util.Set;
import com.extjs.gxt.ui.client.widget.form.TriggerField; 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; private static final int TEXT_CHOOSER_FIELD_WIDTH = 342;
...@@ -40,7 +40,7 @@ public abstract class ChosenEntitySetter<T> extends TriggerField<String> ...@@ -40,7 +40,7 @@ public abstract class ChosenEntitySetter<T> extends TriggerField<String>
listeners.add(listener); listeners.add(listener);
} }
void setChosenEntity(T entityOrNull) public void setChosenEntity(T entityOrNull)
{ {
if (entityOrNull != null) if (entityOrNull != null)
{ {
......
...@@ -45,7 +45,8 @@ class EntityChooserDialog<T> extends SimpleDialog ...@@ -45,7 +45,8 @@ class EntityChooserDialog<T> extends SimpleDialog
private final IDelegatedAction onCancelAction; private final IDelegatedAction onCancelAction;
public EntityChooserDialog(DisposableEntityChooser<T> entityBrowser, 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), super(entityBrowser.getComponent(), title, messageProvider.getMessage(Dict.BUTTON_CHOOSE),
messageProvider); messageProvider);
...@@ -79,7 +80,7 @@ class EntityChooserDialog<T> extends SimpleDialog ...@@ -79,7 +80,7 @@ class EntityChooserDialog<T> extends SimpleDialog
} }
private static <T> IDelegatedAction createAcceptAction( private static <T> IDelegatedAction createAcceptAction(
final ChosenEntitySetter<T> chosenEntitySetter, final IChosenEntitySetter<T> chosenEntitySetter,
final DisposableEntityChooser<T> entityBrowser) final DisposableEntityChooser<T> entityBrowser)
{ {
return new IDelegatedAction() return new IDelegatedAction()
...@@ -94,7 +95,8 @@ class EntityChooserDialog<T> extends SimpleDialog ...@@ -94,7 +95,8 @@ class EntityChooserDialog<T> extends SimpleDialog
} }
private static <T> IDelegatedAction createCancelAction( private static <T> IDelegatedAction createCancelAction(
final ChosenEntitySetter<T> chosenEntitySetter, final IDisposableComponent entityBrowser) final IChosenEntitySetter<T> chosenEntitySetter,
final IDisposableComponent entityBrowser)
{ {
return new IDelegatedAction() return new IDelegatedAction()
{ {
......
...@@ -17,9 +17,7 @@ ...@@ -17,9 +17,7 @@
package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field; package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field;
/** /**
* * @author Franz-Josef Elmer
*
* @author Franz-Josef Elmer
*/ */
public interface IChosenEntityListener<T> public interface IChosenEntityListener<T>
{ {
......
/*
* 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);
}
/*
* 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);
}
}
...@@ -25,6 +25,7 @@ var generic = { ...@@ -25,6 +25,7 @@ var generic = {
instance_sample: "Shared", instance_sample: "Shared",
generated_from_sample: "Parent", generated_from_sample: "Parent",
add_parent: "Add Parent",
part_of_sample: "Container", part_of_sample: "Container",
parents: "Parents", parents: "Parents",
......
...@@ -36,8 +36,10 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework. ...@@ -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.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.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.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.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.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.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.file.AttachmentsFileFieldManager;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.FieldUtil; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.FieldUtil;
...@@ -84,7 +86,7 @@ abstract public class AbstractGenericSampleRegisterEditForm extends ...@@ -84,7 +86,7 @@ abstract public class AbstractGenericSampleRegisterEditForm extends
protected SampleChooserFieldAdaptor container; protected SampleChooserFieldAdaptor container;
protected SampleChooserFieldAdaptor parent; protected SampleChooserButtonAdaptor parentButton;
protected ParentSamplesArea parentsArea; protected ParentSamplesArea parentsArea;
...@@ -176,7 +178,7 @@ abstract public class AbstractGenericSampleRegisterEditForm extends ...@@ -176,7 +178,7 @@ abstract public class AbstractGenericSampleRegisterEditForm extends
new ArrayList<DatabaseModificationAwareField<?>>(); new ArrayList<DatabaseModificationAwareField<?>>();
fields.add(wrapUnaware(experimentField.getField())); fields.add(wrapUnaware(experimentField.getField()));
fields.add(groupSelectionWidget.asDatabaseModificationAware()); fields.add(groupSelectionWidget.asDatabaseModificationAware());
fields.add(wrapUnaware(parent.getField())); fields.add(wrapUnaware(parentButton.getField()));
fields.add(wrapUnaware(parentsArea)); fields.add(wrapUnaware(parentsArea));
fields.add(wrapUnaware(container.getField())); fields.add(wrapUnaware(container.getField()));
return fields; return fields;
...@@ -210,15 +212,15 @@ abstract public class AbstractGenericSampleRegisterEditForm extends ...@@ -210,15 +212,15 @@ abstract public class AbstractGenericSampleRegisterEditForm extends
new GroupSelectionWidget(viewContext, getId(), true, false, initialGroupCodeOrNull); new GroupSelectionWidget(viewContext, getId(), true, false, initialGroupCodeOrNull);
FieldUtil.markAsMandatory(groupSelectionWidget); FieldUtil.markAsMandatory(groupSelectionWidget);
groupSelectionWidget.setFieldLabel(viewContext.getMessage(Dict.GROUP)); groupSelectionWidget.setFieldLabel(viewContext.getMessage(Dict.GROUP));
parent = parentButton =
SampleChooserField.create(viewContext.getMessage(Dict.GENERATED_FROM_SAMPLE), SampleChooserButton.create(viewContext.getMessage(Dict.PARENTS), viewContext
false, null, true, false, false, viewContext.getCommonViewContext(), .getMessage(Dict.ADD_PARENT), true, false, false, viewContext
getId() + ID_SUFFIX_PARENT, .getCommonViewContext(), getId() + ID_SUFFIX_PARENT,
SampleTypeDisplayID.SAMPLE_REGISTRATION_PARENT_CHOOSER SampleTypeDisplayID.SAMPLE_REGISTRATION_PARENT_CHOOSER
.withSuffix(getSampleTypeCode())); .withSuffix(getSampleTypeCode()));
parentsArea = new ParentSamplesArea(viewContext, simpleId); parentsArea = new ParentSamplesArea(viewContext, simpleId);
SampleChooserField parentChooserField = parent.getChooserField(); SampleChooserButton parentChooserButton = parentButton.getChooserButton();
parentChooserField.addChosenEntityListener(new IChosenEntityListener<Sample>() parentChooserButton.addChosenEntityListener(new IChosenEntityListener<Sample>()
{ {
public void entityChosen(Sample entity) public void entityChosen(Sample entity)
{ {
...@@ -276,7 +278,7 @@ abstract public class AbstractGenericSampleRegisterEditForm extends ...@@ -276,7 +278,7 @@ abstract public class AbstractGenericSampleRegisterEditForm extends
boolean showContainer = sampleType.isShowContainer(); boolean showContainer = sampleType.isShowContainer();
boolean showParents = sampleType.isShowParents(); boolean showParents = sampleType.isShowParents();
FieldUtil.setVisibility(showContainer, container.getField()); FieldUtil.setVisibility(showContainer, container.getField());
FieldUtil.setVisibility(showParents, parent.getField(), parentsArea); FieldUtil.setVisibility(showParents, parentButton.getField(), parentsArea);
} }
private String getSampleTypeCode() private String getSampleTypeCode()
......
...@@ -32,7 +32,7 @@ final class ParentSamplesArea extends SamplesArea ...@@ -32,7 +32,7 @@ final class ParentSamplesArea extends SamplesArea
public ParentSamplesArea(IMessageProvider messageProvider, String idPrefix) public ParentSamplesArea(IMessageProvider messageProvider, String idPrefix)
{ {
super(messageProvider.getMessage(Dict.SAMPLES_LIST)); super(messageProvider.getMessage(Dict.SAMPLES_LIST));
this.setFieldLabel(messageProvider.getMessage(Dict.PARENTS)); setLabelSeparator("");
setId(createId(idPrefix)); setId(createId(idPrefix));
} }
......
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