Commit 5c7f0c6c authored by Nugraha, Sigit's avatar Nugraha, Sigit
Browse files

Remove content language button if there is only one language

parent 087cf882
Pipeline #15002 passed with stage
in 1 minute and 51 seconds
package org.gesis.stardat.ui;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.shared.Registration;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.spring.annotation.SpringView;
import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.*;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.components.grid.HeaderRow;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.gesis.logger.GesisLogEvent;
......@@ -70,18 +75,11 @@ import org.vaadin.viritin.layouts.MCssLayout;
import org.vaadin.viritin.layouts.MPanel;
import org.vaadin.viritin.layouts.MVerticalLayout;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.shared.Registration;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.spring.annotation.SpringView;
import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.*;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.components.grid.HeaderRow;
import javax.annotation.PostConstruct;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@ViewScope
@SpringView( name = QuestionnaireEditorView.VIEW_NAME )
......@@ -1121,12 +1119,16 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
ArrayList<String> availableLanguages = null;
if ( item.getObject().getType().equals( DDIElement.STATEMENT ) )
{
if( SOURCE_LANG.contains( "en" ))
translateQuestion.setVisible( false );
availableLanguages = ((Statement) item.getObject()).getAvailableLanguages();
}
else
{
final QuestionConstruct questionConstruct = (QuestionConstruct) item.getObject();
SOURCE_LANG = questionConstruct.getQuestion().getLanguage();
if( SOURCE_LANG.contains( "en" ))
translateQuestion.setVisible( false );
availableLanguages = questionConstruct.getQuestion().getAvailableLanguages();
}
MVerticalLayout questionPrev = new MVerticalLayout().withFullWidth().withMargin( false );
......@@ -1135,34 +1137,33 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
MLabel htmlPrev = new MLabel().withFullWidth().withContentMode( ContentMode.HTML );
questionPrev.add( mCssButtonLayout, htmlPrev );
questionsPreview.add( questionPrev );
availableLanguages.forEach( lang ->
{
mCssButtonLayout.add( new MButton( Language.getIso3Map().get( lang ).getFormatted() )
.withListener(
clickEvent ->
{
mCssButtonLayout.forEach( c -> c.removeStyleName( "pressed" ) );
clickEvent.getButton().addStyleNames( "pressed" );
if ( item.getObject().getType().equals( DDIElement.STATEMENT ) )
{
mode = "statement";
htmlPrev.setValue( exportService.generatePreviewByTemplate( item,
((DDIEditor) UI.getCurrent()).getCurrentStudyUnit(),
((DDIEditor) UI.getCurrent()).getCurrentInstrument(),
((DDIEditor) UI.getCurrent()).getCurrentGroup(),
lang, mode ) );
}
else
if( availableLanguages.size() > 1 ) {
availableLanguages.forEach(lang ->
{
mCssButtonLayout.add(new MButton(Language.getIso3Map().get(lang).getFormatted())
.withListener(
clickEvent ->
{
mode = "question";
htmlPrev.setValue( exportService.generatePreviewByTemplate( item,
((DDIEditor) UI.getCurrent()).getCurrentStudyUnit(),
((DDIEditor) UI.getCurrent()).getCurrentInstrument(),
((DDIEditor) UI.getCurrent()).getCurrentGroup(),
lang, mode ) );
}
} ) );
} );
mCssButtonLayout.forEach(c -> c.removeStyleName("pressed"));
clickEvent.getButton().addStyleNames("pressed");
if (item.getObject().getType().equals(DDIElement.STATEMENT)) {
mode = "statement";
htmlPrev.setValue(exportService.generatePreviewByTemplate(item,
((DDIEditor) UI.getCurrent()).getCurrentStudyUnit(),
((DDIEditor) UI.getCurrent()).getCurrentInstrument(),
((DDIEditor) UI.getCurrent()).getCurrentGroup(),
lang, mode));
} else {
mode = "question";
htmlPrev.setValue(exportService.generatePreviewByTemplate(item,
((DDIEditor) UI.getCurrent()).getCurrentStudyUnit(),
((DDIEditor) UI.getCurrent()).getCurrentInstrument(),
((DDIEditor) UI.getCurrent()).getCurrentGroup(),
lang, mode));
}
}));
});
}
if ( mCssButtonLayout.getComponentCount() > 0 )
{
Component component = mCssButtonLayout.getComponent( 0 );
......@@ -1804,12 +1805,13 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
if ( success )
{
importElements( currentBasketWindow.getSelectedElements() );
}
}
else if ( goal.endsWith( "ImportElementWindow" ) )
{
entityService.importElements( toImport, getCurrentSequence(), getUi().getUser(), cw.getComment() );
setQuestionGridAfterRefresh();
}
else
{
......
......@@ -110,22 +110,24 @@ public class InterviewerInstructionForm extends MVerticalLayout
final ArrayList<String> availableLanguages = selectedInstruction.getAvailableLanguages();
mCssButtonLayout.removeAllComponents();
availableLanguages.forEach(lang -> {
mCssButtonLayout.add( new MButton( Language.getIso3Map().get( lang ).getFormatted() )
.withListener(
clickEvent -> {
mCssButtonLayout.forEach( c -> c.removeStyleName("pressed"));
clickEvent.getButton().addStyleNames("pressed");
selectedInstruction.setLanguage( lang );
htmlPreview.setValue(selectedInstruction.createPreview());
// set back to default language
selectedInstruction.setLanguage( SOURCE_LANG );
}
));
});
Component component = mCssButtonLayout.getComponent(0);
if( component != null )
component.addStyleNames("pressed");
if( availableLanguages.size() > 1 ) {
availableLanguages.forEach(lang -> {
mCssButtonLayout.add(new MButton(Language.getIso3Map().get(lang).getFormatted())
.withListener(
clickEvent -> {
mCssButtonLayout.forEach(c -> c.removeStyleName("pressed"));
clickEvent.getButton().addStyleNames("pressed");
selectedInstruction.setLanguage(lang);
htmlPreview.setValue(selectedInstruction.createPreview());
// set back to default language
selectedInstruction.setLanguage(SOURCE_LANG);
}
));
});
Component component = mCssButtonLayout.getComponent(0);
if( component != null )
component.addStyleNames("pressed");
}
htmlPreview.setValue(selectedInstruction.createPreview());
} else {
htmlPreview.setValue("");
......
package org.gesis.stardat.ui.view.question;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.*;
import org.gesis.stardat.DDIEditor;
import org.gesis.stardat.config.Constants;
import org.gesis.stardat.domain.enumeration.Language;
......@@ -28,10 +27,9 @@ import org.vaadin.viritin.label.MLabel;
import org.vaadin.viritin.layouts.MCssLayout;
import org.vaadin.viritin.layouts.MHorizontalLayout;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class QuestionAnswerPanel extends CustomComponent
{
......@@ -202,23 +200,25 @@ public class QuestionAnswerPanel extends CustomComponent
mCssButtonLayout.removeAllComponents();
String finalSOURCE_LANG = SOURCE_LANG;
availableLanguages.forEach( lang ->
{
mCssButtonLayout.add( new MButton( Language.getIso3Map().get( lang ).getFormatted() )
.withListener(
clickEvent ->
{
mCssButtonLayout.forEach( c -> c.removeStyleName( "pressed" ) );
clickEvent.getButton().addStyleNames( "pressed" );
selectedCodelist.setLanguage( lang );
htmlPreview.setValue( selectedCodelist.createPreview() );
// set back to default language
selectedCodelist.setLanguage( finalSOURCE_LANG );
} ) );
} );
Component component = mCssButtonLayout.getComponent( 0 );
if ( component != null )
component.addStyleNames( "pressed" );
if( availableLanguages.size() > 1 ) {
availableLanguages.forEach(lang ->
{
mCssButtonLayout.add(new MButton(Language.getIso3Map().get(lang).getFormatted())
.withListener(
clickEvent ->
{
mCssButtonLayout.forEach(c -> c.removeStyleName("pressed"));
clickEvent.getButton().addStyleNames("pressed");
selectedCodelist.setLanguage(lang);
htmlPreview.setValue(selectedCodelist.createPreview());
// set back to default language
selectedCodelist.setLanguage(finalSOURCE_LANG);
}));
});
Component component = mCssButtonLayout.getComponent( 0 );
if ( component != null )
component.addStyleNames( "pressed" );
}
htmlPreview.setValue( selectedCodelist.createPreview() );
}
else
......
......@@ -199,7 +199,7 @@ QuestionEdit.window.questionForm.nestedEntities.tabsheet.header.variable = Varia
QuestionEdit.window.questionForm.nestedEntities.variableForm.header.name = Name
QuestionEdit.window.questionForm.nestedEntities.variableForm.header.label = Label
QuestionEdit.window.questionForm.nestedEntities.variableForm.label.description = Double-click to edit
QuestionEdit.window.questionForm.nestedEntities.variableForm.button.new = Create variable
QuestionEdit.window.questionForm.nestedEntities.variableForm.button.new = Add variable
QuestionEdit.window.questionForm.nestedEntities.variableForm.button.del = Delete variable
QuestionEdit.window.questionForm.nestedEntities.variableForm.button.edit = Edit variable
......
......@@ -258,7 +258,7 @@ QuestionEdit.window.questionForm.nestedEntities.tabsheet.header.background = Bac
QuestionEdit.window.questionForm.nestedEntities.variableForm.header.name = Name
QuestionEdit.window.questionForm.nestedEntities.variableForm.header.label = Label
QuestionEdit.window.questionForm.nestedEntities.variableForm.label.description = Double-click to edit
QuestionEdit.window.questionForm.nestedEntities.variableForm.button.new = Create variable
QuestionEdit.window.questionForm.nestedEntities.variableForm.button.new = Add variable
QuestionEdit.window.questionForm.nestedEntities.variableForm.button.del = Delete variable
QuestionEdit.window.questionForm.nestedEntities.variableForm.button.edit = Edit variable
......
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