Commit 992de093 authored by Nugraha, Sigit's avatar Nugraha, Sigit
Browse files

Update multi-language for Answers

parent 32d446fa
Pipeline #15344 passed with stage
in 2 minutes and 34 seconds
......@@ -332,7 +332,7 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
: null,
currentSelectedQuestionRow != null ? currentSelectedQuestionRow.getSequence() : 1,
codeLists, interviewerInstructions, concepts,
this, entityService, masterSequence, eventBus ) );
this, entityService, masterSequence, eventBus, configurationService ) );
} );
newQuestionGrid = itemNew.addItem( I18N.get( "menuItem.NewMatrixQuestion" ),
......@@ -346,7 +346,7 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
: null,
currentSelectedQuestionRow != null ? currentSelectedQuestionRow.getSequence() : 1,
codeLists, interviewerInstructions, concepts,
this, entityService, masterSequence, eventBus ) );
this, entityService, masterSequence, eventBus, configurationService ) );
} );
newStatement = itemNew.addItem( I18N.get( "menuItem.NewStatement" ),
......@@ -376,7 +376,7 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
command ->
{
ManageAnswerCategorieWindow macw = new ManageAnswerCategorieWindow( eventBus,
entityService, codeLists );
entityService, codeLists, configurationService );
UI.getCurrent().addWindow( macw );
} );
......@@ -643,7 +643,7 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
new QuestionWindow( (QuestionConstruct) currentSelectedQuestionRow.getObject(),
currentSelectedQuestionRow.getSequence(),
codeLists, interviewerInstructions, concepts, this,
cacheService, entityService, eventBus ) );
cacheService, entityService, eventBus, this.configurationService ) );
}
}
else
......
......@@ -14,6 +14,7 @@ import org.gesis.stardat.entity.QuestionConstruct;
import org.gesis.stardat.events.EditorEvent;
import org.gesis.stardat.events.EditorEvent.EventType;
import org.gesis.stardat.security.DDIEditorSecurityUtils;
import org.gesis.stardat.service.ConfigurationService;
import org.gesis.stardat.service.EntityCreationService;
import org.gesis.stardat.service.I18N;
import org.gesis.stardat.ui.windows.AnswerSchemeWindow;
......@@ -57,9 +58,11 @@ public class QuestionAnswerPanel extends CustomComponent
private MCssLayout mCssButtonLayout = new MCssLayout().withFullWidth().withStyleName( "t-a-right" );
private final ConfigurationService configService;
public QuestionAnswerPanel( List<CodeList> codeLists, QuestionConstruct construct,
EntityCreationService entityService, TextField answersField, UIEventBus eventBus,
String eventBusTopic )
String eventBusTopic, ConfigurationService configService )
{
this.codeLists = codeLists;
this.construct = construct;
......@@ -67,6 +70,7 @@ public class QuestionAnswerPanel extends CustomComponent
this.answersField = answersField;
this.eventBus = eventBus;
this.eventBusTopic = eventBusTopic;
this.configService = configService;
if ( this.eventBusTopic.equals( QuestionVariableWindow.WINDOW_NAME ) )
answerSchemeType = "ValueSchemeWindow";
......@@ -328,7 +332,7 @@ public class QuestionAnswerPanel extends CustomComponent
private void openAnswerTranslate( Button.ClickEvent clickEvent )
{
AnswerSchemeWindowTranslate asw = new AnswerSchemeWindowTranslate( answerSchemeType );
AnswerSchemeWindowTranslate asw = new AnswerSchemeWindowTranslate( answerSchemeType, this.configService );
CodeList cl = answerGrid.getSelectedItems().iterator().next();
asw.load( cl );
UI.getCurrent().addWindow( asw );
......
package org.gesis.stardat.ui.view.question;
import java.util.ArrayList;
import java.util.List;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.Notification;
import com.vaadin.ui.themes.ValoTheme;
import org.gesis.stardat.entity.CodeList;
import org.gesis.stardat.entity.ExternalControlledVocabularyReference;
import org.gesis.stardat.entity.QuestionConstruct;
import org.gesis.stardat.entity.Variable;
import org.gesis.stardat.events.EditorEvent;
import org.gesis.stardat.security.DDIEditorSecurityUtils;
import org.gesis.stardat.service.ConfigurationService;
import org.gesis.stardat.service.EntityCreationService;
import org.gesis.stardat.service.I18N;
import org.gesis.stardat.ui.utils.QuestionWindowUtils;
......@@ -21,12 +25,7 @@ import org.vaadin.viritin.fields.MTextField;
import org.vaadin.viritin.label.MLabel;
import org.vaadin.viritin.layouts.MCssLayout;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.Notification;
import com.vaadin.ui.themes.ValoTheme;
import java.util.List;
public class QuestionVariableWindow extends BaseStoreCancelWindow
{
......@@ -57,9 +56,10 @@ public class QuestionVariableWindow extends BaseStoreCancelWindow
private MTextField derivationTf = new MTextField();
private MTextField noteTf = new MTextField();
private final ConfigurationService configService;
public QuestionVariableWindow( String windowName, QuestionWindow questionWindow )
public QuestionVariableWindow( String windowName, QuestionWindow questionWindow,
ConfigurationService configService)
{
super( windowName, new CssLayout() );
this.questionWindow = questionWindow;
......@@ -67,6 +67,7 @@ public class QuestionVariableWindow extends BaseStoreCancelWindow
this.construct = questionWindow.getConstruct();
this.eventBus = questionWindow.getEventBus();
this.entityService = questionWindow.getEntityService();
this.configService = configService;
setWidth( "1024px" );
setHeight( "500px" );
......@@ -206,7 +207,8 @@ public class QuestionVariableWindow extends BaseStoreCancelWindow
.withFullWidth()
.add( componentGroup, showEditButton );
QuestionAnswerPanel questionAnswerPanel = new QuestionAnswerPanel(codeLists, construct, entityService, answersField, eventBus, QuestionVariableWindow.WINDOW_NAME);
QuestionAnswerPanel questionAnswerPanel = new QuestionAnswerPanel(codeLists, construct, entityService, answersField,
eventBus, QuestionVariableWindow.WINDOW_NAME, this.configService);
createRowSection( fLQuestion, answersFieldLabel, inputComponentLayout );
......
package org.gesis.stardat.ui.view.question;
import java.util.*;
import java.util.stream.Collectors;
import com.vaadin.data.HasValue.ValueChangeListener;
import com.vaadin.data.TreeData;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.data.provider.TreeDataProvider;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.*;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.themes.ValoTheme;
import org.gesis.stardat.DDIEditor;
import org.gesis.stardat.entity.*;
import org.gesis.stardat.events.EditorEvent;
import org.gesis.stardat.helper.TriggerableWindowMaster;
import org.gesis.stardat.security.DDIEditorSecurityUtils;
import org.gesis.stardat.service.ConfigurationService;
import org.gesis.stardat.service.EntityCreationService;
import org.gesis.stardat.service.I18N;
import org.gesis.stardat.service.QuestionCacheService;
......@@ -34,15 +41,8 @@ import org.vaadin.viritin.label.MLabel;
import org.vaadin.viritin.layouts.MCssLayout;
import org.vaadin.viritin.layouts.MHorizontalLayout;
import com.vaadin.data.HasValue.ValueChangeListener;
import com.vaadin.data.TreeData;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.data.provider.TreeDataProvider;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.*;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.themes.ValoTheme;
import java.util.*;
import java.util.stream.Collectors;
public class QuestionWindow extends BaseStoreCancelWindow implements Translatable, TriggerableWindowMaster
{
......@@ -152,19 +152,21 @@ public class QuestionWindow extends BaseStoreCancelWindow implements Translatabl
private Sequence masterSequence;
private final ConfigurationService configService;
public QuestionWindow( QuestionConstruct construct, int sequence,
List<CodeList> codeLists, List<InterviewerInstruction> interviewerInstructions, List<Concept> concepts,
TriggerableWindowMaster master, QuestionCacheService cacheService, EntityCreationService entityService,
UIEventBus eventBus )
UIEventBus eventBus, ConfigurationService configService )
{
this( construct, null, sequence, codeLists, interviewerInstructions, concepts, master,
entityService, null, eventBus );
entityService, null, eventBus, configService );
}
public QuestionWindow( QuestionConstruct construct, QuestionConstruct constructPrevSibling, int sequence,
List<CodeList> codeLists, List<InterviewerInstruction> interviewerInstructions, List<Concept> concepts,
TriggerableWindowMaster master, EntityCreationService entityService,
Sequence masterSequence, UIEventBus eventBus )
Sequence masterSequence, UIEventBus eventBus, ConfigurationService configService )
{
super( WINDOW_NAME, new CssLayout() );
setWidth( "1024px" );
......@@ -180,6 +182,7 @@ public class QuestionWindow extends BaseStoreCancelWindow implements Translatabl
this.entityService = entityService;
this.masterSequence = masterSequence;
this.eventBus = eventBus;
this.configService = configService;
this.codeCategoryGrid = new CodeCategoryGrid( this );
......@@ -419,7 +422,7 @@ public class QuestionWindow extends BaseStoreCancelWindow implements Translatabl
{
if ( e.getMouseEventDetails().isDoubleClick() && e.getItem() != null )
{
QuestionVariableWindow vEditWindow = new QuestionVariableWindow( QUESTION_VARIABLE_WINDOW, this );
QuestionVariableWindow vEditWindow = new QuestionVariableWindow( QUESTION_VARIABLE_WINDOW, this, this.configService );
vEditWindow.setVariable( e.getItem() );
UI.getCurrent().addWindow( vEditWindow );
}
......@@ -435,7 +438,7 @@ public class QuestionWindow extends BaseStoreCancelWindow implements Translatabl
"+ " + I18N.get( "QuestionEdit.window.questionForm.nestedEntities.variableForm.button.new" ) );
newVariableButton.addClickListener( e ->
{
QuestionVariableWindow vEditWindow = new QuestionVariableWindow( QUESTION_VARIABLE_WINDOW, this );
QuestionVariableWindow vEditWindow = new QuestionVariableWindow( QUESTION_VARIABLE_WINDOW, this, this.configService );
// new variable
Variable newVariable = new Variable();
newVariable.init( "VS", construct.getContainerId(), construct.getDialect() );
......@@ -484,7 +487,7 @@ public class QuestionWindow extends BaseStoreCancelWindow implements Translatabl
bEdit.addClickListener( e ->
{
QuestionVariableWindow vEditWindow = new QuestionVariableWindow( QUESTION_VARIABLE_WINDOW, this );
QuestionVariableWindow vEditWindow = new QuestionVariableWindow( QUESTION_VARIABLE_WINDOW, this , this.configService);
vEditWindow.setVariable( variable );
UI.getCurrent().addWindow( vEditWindow );
} );
......@@ -608,7 +611,7 @@ public class QuestionWindow extends BaseStoreCancelWindow implements Translatabl
QuestionAnswerPanel questionAnswerPanel = new QuestionAnswerPanel( codeLists, getConstruct(),
getEntityService(),
answersField, eventBus, QuestionWindow.WINDOW_NAME );
answersField, eventBus, QuestionWindow.WINDOW_NAME, this.configService );
createRowSection( fLQuestion, answersFieldLabel, inputComponentLayout );
......
......@@ -4,11 +4,11 @@ import com.vaadin.ui.*;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.components.grid.HeaderRow;
import org.gesis.stardat.DDIEditor;
import org.gesis.stardat.config.Constants;
import org.gesis.stardat.domain.enumeration.Language;
import org.gesis.stardat.entity.Category;
import org.gesis.stardat.entity.Code;
import org.gesis.stardat.entity.CodeList;
import org.gesis.stardat.service.ConfigurationService;
import org.gesis.stardat.service.I18N;
import org.gesis.stardat.ui.view.component.AnswerGridTranslate;
import org.vaadin.spring.i18n.support.Translatable;
......@@ -16,6 +16,7 @@ import org.vaadin.viritin.layouts.MCssLayout;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
/**
......@@ -44,8 +45,11 @@ public class AnswerSchemeWindowTranslate extends BaseStoreCancelWindow implement
private ArrayList<Answer> answers = new ArrayList<>();
private final ConfigurationService configService;
public AnswerSchemeWindowTranslate( String windowName )
public AnswerSchemeWindowTranslate( String windowName,
ConfigurationService configService)
{
super( windowName, new MCssLayout().withFullWidth() ); // Set window caption
center();
......@@ -53,6 +57,7 @@ public class AnswerSchemeWindowTranslate extends BaseStoreCancelWindow implement
setHeight( "800px" );
setModal( true );
answerGrid = new AnswerGridTranslate( this );
this.configService = configService;
initComponents();
......@@ -77,14 +82,46 @@ public class AnswerSchemeWindowTranslate extends BaseStoreCancelWindow implement
updateMessageStrings( getLocale() );
}
@SuppressWarnings( "unchecked" )
public void load( CodeList codeList )
{
setCurrentCodeList( codeList );
final String sourceLanguage = currentCodeList.getCategoryScheme().getLanguage();
final ArrayList<String> translatedLanguages = currentCodeList.getCategoryScheme().getAvailableLanguages();
final List<Language> enableLanguagesByIso3 = configService.getEnableLanguagesByIso3();
enableLanguagesByIso3.remove(Language.getByIso3(sourceLanguage));
languageComboBox.setItemCaptionGenerator( l -> translatedLanguages.contains( l.getIso3() ) ? l.getFormatted() + " - translated" : l.getFormatted() );
languageComboBox.setItems(enableLanguagesByIso3);
final String SOURCE_LANG = currentCodeList.getCategoryScheme().getLanguage();
answerTitle.setValue( codeList.getLabel() );
answerDescription.setValue( codeList.getDescription() );
currentCodeList.getCategoryScheme().setLanguage( SOURCE_LANG );
if(!enableLanguagesByIso3.isEmpty()){
languageComboBox.setSelectedItem(enableLanguagesByIso3.get(0));
updateFormLabels( enableLanguagesByIso3.get(0).getIso());
fillComponents( enableLanguagesByIso3.get(0).getIso3() );
}
languageComboBox.addSelectionListener(event -> {
updateFormLabels( event.getValue().getIso());
fillComponents( event.getValue().getIso3() );
});
}
private void initComponents()
{
languageComboBox.setItems(Language.ENGLISH);
languageComboBox.setCaption(I18N.get( "checkbox.language" ));
languageComboBox.setWidth("240px");
languageComboBox.setTextInputAllowed( false );
languageComboBox.setEmptySelectionAllowed( false );
languageComboBox.setSelectedItem(Language.ENGLISH);
setNameAndInstructionLabel(languageComboBox);
answerTitle = new TextField( "Antwort Title" );
answerTitle.setReadOnly( true);
answerTitle.setWidth( "200px" );
......@@ -97,41 +134,33 @@ public class AnswerSchemeWindowTranslate extends BaseStoreCancelWindow implement
answerDescription.setWidth( "200px" );
answerDescriptionLang = new TextArea( I18N.get(windowName + ".answer.description.translate"));
answerDescriptionLang.setWidth( "200px" );
languageComboBox.addSelectionListener(event -> {
answerTitleLang.setCaption("Antwort Title "+ "("+ languageComboBox.getSelectedItem().get().getIso()+")");
answerDescriptionLang.setCaption("Beschreibung "+ "("+ languageComboBox.getSelectedItem().get().getIso()+")");
});
answerGrid.setCaption( "Doppelklick zum Editieren" );
TextField codeField = new TextField();
TextField categoryField = new TextField();
categoryField.setReadOnly( true );
TextField categoryFieldEnglish = new TextField();
TextField categoryFieldTranslation = new TextField();
answerGrid.removeAllColumns();
answerGrid.addColumn( Answer::getCode ).setEditorComponent( codeField, Answer::setCode ).setExpandRatio( 1 );
answerGrid.addColumn( Answer::getCategory ).setEditorComponent( categoryField, Answer::setCategory )
.setExpandRatio( 1 );
answerGrid.addColumn( Answer::getCategoryTranslate ).setEditorComponent( categoryFieldEnglish, Answer::setCategoryTranslate )
.setExpandRatio( 1 );
answerGrid.addColumn( Answer::getCategoryTranslate ).setEditorComponent( categoryFieldTranslation, Answer::setCategoryTranslate )
.setExpandRatio( 1 ).setId( "translate" );
answerGrid.getEditor().setEnabled( true );
answerGrid.setSelectionMode( SelectionMode.SINGLE );
}
private void setNameAndInstructionLabel(ComboBox<Language> language) {
private void updateFormLabels( String langIso ) {
answerTitleLang.setCaption(I18N.get(windowName + ".form.editAnswer.label.answer.title")+ " ("+ langIso+")");
answerDescriptionLang.setCaption(I18N.get(windowName + ".form.editAnswer.label.answer.descr")+ " ("+ langIso+")");
answerGrid.getColumn("translate").setCaption( I18N.get( windowName + ".table.column1.title" )+ " ("+ langIso+")" );
}
@SuppressWarnings( "unchecked" )
public void load( CodeList codeList )
private void fillComponents( String langIso3 )
{
setCurrentCodeList( codeList );
final String SOURCE_LANG = currentCodeList.getCategoryScheme().getLanguage();
answers.clear();
answerTitle.setValue( codeList.getLabel() );
answerDescription.setValue( codeList.getDescription() );
final String SOURCE_LANG = currentCodeList.getCategoryScheme().getLanguage();
ArrayList<Category> categories = currentCodeList.getCategoryScheme().getCategory();
ArrayList<Code> codes = currentCodeList.getCode();
......@@ -144,10 +173,11 @@ public class AnswerSchemeWindowTranslate extends BaseStoreCancelWindow implement
answers.add( answer );
i++;
}
currentCodeList.setLanguage( Constants.ENGLISH_LANGUAGE );
currentCodeList.getCategoryScheme().setLanguage( Constants.ENGLISH_LANGUAGE );
answerTitleLang.setValue( codeList.getLabel() );
answerDescriptionLang.setValue( codeList.getDescription() );
currentCodeList.setLanguage( langIso3 );
currentCodeList.getCategoryScheme().setLanguage( langIso3 );
answerTitleLang.setValue( getCurrentCodeList().getLabel() );
answerDescriptionLang.setValue( getCurrentCodeList().getDescription() );
// fill answer with english category
categories = currentCodeList.getCategoryScheme().getCategory();
......@@ -255,8 +285,8 @@ public class AnswerSchemeWindowTranslate extends BaseStoreCancelWindow implement
{
setShouldStore( true );
final String SOURCE_LANG = currentCodeList.getCategoryScheme().getLanguage();
currentCodeList.setLanguage( Constants.ENGLISH_LANGUAGE );
currentCodeList.getCategoryScheme().setLanguage( Constants.ENGLISH_LANGUAGE );
currentCodeList.setLanguage( languageComboBox.getValue().getIso3() );
currentCodeList.getCategoryScheme().setLanguage( languageComboBox.getValue().getIso3() );
currentCodeList.setLabel( answerTitleLang.getValue() );
currentCodeList.setDescription( answerDescriptionLang.getValue() );
currentCodeList.getCategoryScheme().setLabel( answerTitleLang.getValue() );
......@@ -312,7 +342,6 @@ public class AnswerSchemeWindowTranslate extends BaseStoreCancelWindow implement
answerGrid.getColumns().get( 0 ).setId( "0" );
answerGrid.getColumns().get( 1 ).setId( "1" );
answerGrid.getColumns().get( 2 ).setId( "2" );
HeaderRow headerRow = answerGrid.getDefaultHeaderRow();
headerRow.getCell( "0" )
.setHtml( "<div title='" + I18N.get( windowName + ".table.column0.hint1" ) + " "
......@@ -324,11 +353,6 @@ public class AnswerSchemeWindowTranslate extends BaseStoreCancelWindow implement
+ I18N.get( windowName + ".table.column1.title" ) + " "
+ I18N.get( windowName + ".table.column0.hint2" ) + "'>"
+ I18N.get( windowName + ".table.column1.title" ) + "</div>" );
headerRow.getCell( "2" )
.setHtml( "<div title='" + I18N.get( windowName + ".table.column0.hint1" ) + " "
+ I18N.get( windowName + ".table.column2.title" ) + " "
+ I18N.get( windowName + ".table.column0.hint2" ) + "'>"
+ I18N.get( windowName + ".table.column2.title" ) + "</div>" );
caption = I18N.get( windowName + ".form.editAnswer.label.answer.title" );
answerTitle.setCaption( caption );
......
package org.gesis.stardat.ui.windows;
import java.util.List;
import java.util.Locale;
import org.gesis.stardat.entity.CodeList;
import org.gesis.stardat.events.EditorEvent;
import org.gesis.stardat.service.ConfigurationService;
import org.gesis.stardat.service.EntityCreationService;
import org.gesis.stardat.service.I18N;
import org.gesis.stardat.service.QuestionCacheService;
import org.gesis.stardat.ui.QuestionnaireEditorView;
import org.gesis.stardat.ui.forms.AnswerCategoriesForm;
import org.gesis.stardat.ui.view.question.QuestionAnswerPanel;
import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.EventBus.UIEventBus;
import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import org.vaadin.spring.i18n.support.Translatable;
import org.vaadin.viritin.fields.MTextField;
import org.vaadin.viritin.layouts.MCssLayout;
import org.vaadin.viritin.layouts.MWindow;
import com.vaadin.ui.Window;
import java.util.List;
import java.util.Locale;
public class ManageAnswerCategorieWindow extends MWindow implements Translatable
{
......@@ -30,7 +26,8 @@ public class ManageAnswerCategorieWindow extends MWindow implements Translatable
private MTextField answersField = new MTextField();
public ManageAnswerCategorieWindow( UIEventBus eventBus,
EntityCreationService entityService, List<CodeList> codeLists )
EntityCreationService entityService, List<CodeList> codeLists,
ConfigurationService configService)
{
super( I18N.get( ManageAnswerCategorieWindow.WINDOW_NAME + ".title") );
......@@ -40,7 +37,8 @@ public class ManageAnswerCategorieWindow extends MWindow implements Translatable
.withStyleName("answer-tf-search")
.withPlaceholder( I18N.get( ManageAnswerCategorieWindow.WINDOW_NAME + ".textfield.search" ));
QuestionAnswerPanel questionAnswerPanel = new QuestionAnswerPanel(codeLists, null, entityService, answersField, eventBus, ManageAnswerCategorieWindow.WINDOW_NAME);
QuestionAnswerPanel questionAnswerPanel = new QuestionAnswerPanel(codeLists, null, entityService,
answersField, eventBus, ManageAnswerCategorieWindow.WINDOW_NAME, configService);
questionAnswerPanel.setWidth("100%");
layoutContent
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment