From 5890e0dc817aceb866959695ae7740a1b0ec6fa7 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Mon, 30 Mar 2009 09:57:04 +0000 Subject: [PATCH] LMS-787 GUI improved. SVN: 10468 --- .../client/web/client/application/Dict.java | 23 ++- .../model/VocabularyTermReplacementModel.java | 99 ----------- .../ui/vocabulary/VocabularyTermGrid.java | 154 ++++++++++++------ .../basic/dto/VocabularyTermReplacement.java | 6 +- .../cisd/openbis/public/common-dictionary.js | 6 +- 5 files changed, 130 insertions(+), 158 deletions(-) delete mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyTermReplacementModel.java 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 5c2d5cfa14f..6fd7ea13248 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 @@ -430,18 +430,29 @@ public abstract class Dict public static final String ADD_VOCABULARY_TERMS_OK_BUTTON = "add_vocabulary_terms_ok_button"; - public static final String VOCABULARY_TERMS_VALIDATION_MESSAGE = "vocabulary_terms_validation_message"; + public static final String VOCABULARY_TERMS_VALIDATION_MESSAGE = + "vocabulary_terms_validation_message"; public static final String DELETE_VOCABULARY_TERMS_BUTTON = "delete_vocabulary_terms_button"; - public static final String DELETE_VOCABULARY_TERMS_INVALID_TITLE = "delete_vocabulary_terms_invalid_title"; + public static final String DELETE_VOCABULARY_TERMS_INVALID_TITLE = + "delete_vocabulary_terms_invalid_title"; - public static final String DELETE_VOCABULARY_TERMS_INVALID_MESSAGE = "delete_vocabulary_terms_invalid_message"; + public static final String DELETE_VOCABULARY_TERMS_INVALID_MESSAGE = + "delete_vocabulary_terms_invalid_message"; - public static final String DELETE_VOCABULARY_TERMS_ORIGINAL_COLUMN = "delete_vocabulary_terms_original_column"; - - public static final String DELETE_VOCABULARY_TERMS_REPLACEMENT_COLUMN = "delete_vocabulary_terms_replacement_column"; + public static final String DELETE_VOCABULARY_TERMS_CONFIRMATION_TITLE = + "delete_vocabulary_terms_confirmation_title"; + public static final String DELETE_VOCABULARY_TERMS_CONFIRMATION_MESSAGE_NO_REPLACEMENTS_SINGULAR = + "delete_vocabulary_terms_confirmation_message_no_replacements_singular"; + + public static final String DELETE_VOCABULARY_TERMS_CONFIRMATION_MESSAGE_NO_REPLACEMENTS = + "delete_vocabulary_terms_confirmation_message_no_replacements"; + + public static final String DELETE_VOCABULARY_TERMS_CONFIRMATION_MESSAGE_FOR_REPLACEMENTS = + "delete_vocabulary_terms_confirmation_message_for_replacements"; + // // Project Browser // diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyTermReplacementModel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyTermReplacementModel.java deleted file mode 100644 index cf9d712e5b9..00000000000 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyTermReplacementModel.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import com.extjs.gxt.ui.client.data.ModelData; - -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTermReplacement; - -/** - * - * - * @author Franz-Josef Elmer - */ -public class VocabularyTermReplacementModel implements ModelData -{ - public static final String ORIGINAL_COLUMN = "original"; - public static final String REPLACEMENT_COLUMN = "replacement"; - - private static final long serialVersionUID = 1L; - - private final VocabularyTermReplacement termReplacement; - - public VocabularyTermReplacementModel(VocabularyTermReplacement termReplacement) - { - this.termReplacement = termReplacement; - } - - public final VocabularyTermReplacement getTermReplacement() - { - return termReplacement; - } - - @SuppressWarnings("unchecked") - public <X> X get(String property) - { - if (ORIGINAL_COLUMN.equals(property)) - { - return (X) termReplacement.getTerm(); - } - if (REPLACEMENT_COLUMN.equals(property)) - { - return (X) termReplacement.getReplacement(); - } - return null; - } - - public Map<String, Object> getProperties() - { - HashMap<String, Object> map = new HashMap<String, Object>(); - for (String key : getPropertyNames()) - { - map.put(key, get(key)); - } - return map; - } - - public Collection<String> getPropertyNames() - { - return Arrays.asList(ORIGINAL_COLUMN, REPLACEMENT_COLUMN); - } - - public <X> X remove(String property) - { - return null; - } - - public <X> X set(String property, X value) - { - X oldValue = get(property); - if (ORIGINAL_COLUMN.equals(property)) - { - termReplacement.setTerm((VocabularyTerm) value); - } else if (REPLACEMENT_COLUMN.equals(property)) - { - termReplacement.setReplacement((VocabularyTerm) value); - } - return oldValue; - } -} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java index c0a538a408f..5697bcc780b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java @@ -17,7 +17,6 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -26,19 +25,16 @@ import com.extjs.gxt.ui.client.Style.Scroll; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.ComponentEvent; import com.extjs.gxt.ui.client.event.KeyListener; +import com.extjs.gxt.ui.client.event.SelectionChangedEvent; +import com.extjs.gxt.ui.client.event.SelectionChangedListener; import com.extjs.gxt.ui.client.event.SelectionListener; -import com.extjs.gxt.ui.client.store.ListStore; import com.extjs.gxt.ui.client.widget.HorizontalPanel; import com.extjs.gxt.ui.client.widget.MessageBox; +import com.extjs.gxt.ui.client.widget.Text; +import com.extjs.gxt.ui.client.widget.VerticalPanel; import com.extjs.gxt.ui.client.widget.button.Button; -import com.extjs.gxt.ui.client.widget.form.LabelField; +import com.extjs.gxt.ui.client.widget.form.FormPanel; import com.extjs.gxt.ui.client.widget.form.TextArea; -import com.extjs.gxt.ui.client.widget.grid.CellEditor; -import com.extjs.gxt.ui.client.widget.grid.ColumnConfig; -import com.extjs.gxt.ui.client.widget.grid.ColumnData; -import com.extjs.gxt.ui.client.widget.grid.ColumnModel; -import com.extjs.gxt.ui.client.widget.grid.Grid; -import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer; import com.extjs.gxt.ui.client.widget.toolbar.AdapterToolItem; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; @@ -47,11 +43,13 @@ 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.BaseEntityModel; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyTermReplacementModel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyTermModel; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.IColumnDefinitionKind; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.VocabularyTermColDefKind; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.VocabularyTermSelectionWidget; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.AbstractSimpleBrowserGrid; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.DisposableComponent; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.ConfirmationDialog; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.SimpleDialog; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedAction; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig; @@ -226,15 +224,48 @@ public class VocabularyTermGrid extends AbstractSimpleBrowserGrid<VocabularyTerm selectedTerms.add(term.getCode()); if (model.getBaseObject().getTotalUsageCounter() > 0) { - VocabularyTermReplacement termTpBeReplaced = new VocabularyTermReplacement(); - termTpBeReplaced.setTerm(term); - termsToBeReplaced.add(termTpBeReplaced); + VocabularyTermReplacement termToBeReplaced = new VocabularyTermReplacement(); + termToBeReplaced.setTerm(term); + termsToBeReplaced.add(termToBeReplaced); } else { termsToBeDeleted.add(term); } } - if (termsToBeReplaced.isEmpty() == false) + deleteAndReplace(selectedTerms, termsToBeDeleted, termsToBeReplaced); + } + + private void deleteAndReplace(Set<String> selectedTerms, + final List<VocabularyTerm> termsToBeDeleted, + final List<VocabularyTermReplacement> termsToBeReplaced) + { + if (termsToBeReplaced.isEmpty()) + { + String title = viewContext.getMessage(Dict.DELETE_VOCABULARY_TERMS_CONFIRMATION_TITLE); + int size = termsToBeDeleted.size(); + String message; + if (size == 1) + { + message = + viewContext + .getMessage(Dict.DELETE_VOCABULARY_TERMS_CONFIRMATION_MESSAGE_NO_REPLACEMENTS_SINGULAR); + } else + { + message = + viewContext.getMessage( + Dict.DELETE_VOCABULARY_TERMS_CONFIRMATION_MESSAGE_NO_REPLACEMENTS, + size); + } + ConfirmationDialog confirmationDialog = new ConfirmationDialog(title, message) + { + @Override + protected void onYes() + { + deleteAndReplace(termsToBeDeleted, termsToBeReplaced); + } + }; + confirmationDialog.show(); + } else { List<VocabularyTerm> termsForReplacement = new ArrayList<VocabularyTerm>(); for (VocabularyTerm term : vocabulary.getTerms()) @@ -244,44 +275,71 @@ public class VocabularyTermGrid extends AbstractSimpleBrowserGrid<VocabularyTerm termsForReplacement.add(term); } } - if (termsForReplacement.size() == 1) - { - VocabularyTerm replacement = termsForReplacement.get(0); - for (VocabularyTermReplacement termToBeReplaced : termsToBeReplaced) + askForReplacements(termsToBeDeleted, termsToBeReplaced, termsForReplacement); + } + } + + private void askForReplacements(final List<VocabularyTerm> termsToBeDeleted, + final List<VocabularyTermReplacement> termsToBeReplaced, + List<VocabularyTerm> termsForReplacement) + { + VerticalPanel panel = new VerticalPanel(); + int totalNumber = termsToBeDeleted.size() + termsToBeReplaced.size(); + panel.add(new Text(viewContext.getMessage( + Dict.DELETE_VOCABULARY_TERMS_CONFIRMATION_MESSAGE_FOR_REPLACEMENTS, totalNumber))); + final FormPanel formPanel = new FormPanel(); + formPanel.setBorders(false); + formPanel.setHeaderVisible(false); + formPanel.setBodyBorder(false); + panel.add(formPanel); + String title = viewContext.getMessage(Dict.DELETE_VOCABULARY_TERMS_CONFIRMATION_TITLE); + String okButtonLable = viewContext.getMessage(Dict.ADD_VOCABULARY_TERMS_OK_BUTTON); + final SimpleDialog dialog = new SimpleDialog(panel, title, okButtonLable, viewContext); + dialog.setScrollMode(Scroll.AUTOY); + dialog.setWidth(420); + dialog.setEnableOfAcceptButton(false); + for (final VocabularyTermReplacement termToBeReplaced : termsToBeReplaced) + { + String term = termToBeReplaced.getTerm().getCode(); + final VocabularyTermSelectionWidget s = + new VocabularyTermSelectionWidget(getId() + term, term, termsForReplacement, + true); + s.addSelectionChangedListener(new SelectionChangedListener<VocabularyTermModel>() { - termToBeReplaced.setReplacement(replacement); - } - } else - { - ColumnConfig originalColumn = new ColumnConfig(); - originalColumn.setRenderer(new GridCellRenderer<VocabularyTermReplacementModel>() + @Override + public void selectionChanged(SelectionChangedEvent<VocabularyTermModel> se) { - public String render(VocabularyTermReplacementModel model, String property, - ColumnData config, int rowIndex, int colIndex, - ListStore<VocabularyTermReplacementModel> store) - { - VocabularyTermReplacementModel row = store.getAt(rowIndex); - return row.getTermReplacement().getTerm().getCode(); - } - }); - originalColumn.setHeader(viewContext.getMessage(Dict.DELETE_VOCABULARY_TERMS_ORIGINAL_COLUMN)); - originalColumn.setWidth(200); - - ColumnConfig replacementColumn = new ColumnConfig(); - replacementColumn.setHeader(viewContext.getMessage(Dict.DELETE_VOCABULARY_TERMS_REPLACEMENT_COLUMN)); - replacementColumn.setWidth(200); - replacementColumn.setEditor(new CellEditor(new LabelField())); - ColumnModel columnModel = new ColumnModel(Arrays.asList(originalColumn, replacementColumn)); - ListStore<VocabularyTermReplacementModel> store = new ListStore<VocabularyTermReplacementModel>(); - for (VocabularyTermReplacement termToBeReplaced : termsToBeReplaced) + VocabularyTermModel selectedItem = se.getSelectedItem(); + termToBeReplaced.setReplacement(selectedItem == null ? null : selectedItem + .getTerm()); + dialog.setEnableOfAcceptButton(formPanel.isValid()); + } + }); + formPanel.add(s); + } + dialog.setAcceptAction(new IDelegatedAction() + { + + public void execute() { - store.add(new VocabularyTermReplacementModel(termToBeReplaced)); + deleteAndReplace(termsToBeDeleted, termsToBeReplaced); } - Grid<VocabularyTermReplacementModel> replacementGrid = new Grid<VocabularyTermReplacementModel>(store, columnModel); - SimpleDialog dialog = new SimpleDialog(replacementGrid, "h", "o", viewContext); - dialog.setScrollMode(Scroll.AUTOY); - dialog.show(); - } + + }); + dialog.show(); + } + + private void deleteAndReplace(List<VocabularyTerm> termsToBeDeleted, + List<VocabularyTermReplacement> termsToBeReplaced) + { + for (VocabularyTerm vocabularyTerm : termsToBeDeleted) + { + System.out.println("delete " + vocabularyTerm.getCode()); + } + for (VocabularyTermReplacement replacemnet : termsToBeReplaced) + { + System.out.println(replacemnet.getTerm().getCode()+" -> "+replacemnet.getReplacement()); } + } } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTermReplacement.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTermReplacement.java index 82f21b15876..335cc2cdbb5 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTermReplacement.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTermReplacement.java @@ -26,7 +26,7 @@ import com.google.gwt.user.client.rpc.IsSerializable; public class VocabularyTermReplacement implements IsSerializable { private VocabularyTerm term; - private VocabularyTerm replacement; + private String replacement; public final VocabularyTerm getTerm() { @@ -38,12 +38,12 @@ public class VocabularyTermReplacement implements IsSerializable this.term = term; } - public final VocabularyTerm getReplacement() + public final String getReplacement() { return replacement; } - public final void setReplacement(VocabularyTerm replacement) + public final void setReplacement(String replacement) { this.replacement = replacement; } 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 c5f0d5679e6..cbcb13504ff 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 @@ -257,8 +257,10 @@ var common = { delete_vocabulary_terms_button: "Delete/Replace Terms", delete_vocabulary_terms_invalid_title: "Invalid Deletion", delete_vocabulary_terms_invalid_message: "Can not delete all terms. A vocabulary should have at least one term.", - delete_vocabulary_terms_original_column: "Term", - delete_vocabulary_terms_replacement_column: "Replacement", + delete_vocabulary_terms_confirmation_title: "Deletion of Vocabulary Terms", + delete_vocabulary_terms_confirmation_message_no_replacements_singular: "Do you want to delete the selected term?", + delete_vocabulary_terms_confirmation_message_no_replacements: "Do you want to delete the {0} selected terms?", + delete_vocabulary_terms_confirmation_message_for_replacements: "{0} terms will be deleted.\n\nThe terms below are used. They have to be replaced by one of the remaining terms.", // // Project Browser -- GitLab