/** * Create origin area with information about selection and original language * * @param parent parent composite * @param comboListener translator combo listener * @param schema android localization schema */ private void createFromArea( Composite parent, ComboListener comboListener, ILocalizationSchema schema) { Group languageFromGroup = new Group(parent, SWT.SHADOW_ETCHED_OUT); languageFromGroup.setText(Messages.TranslationDialog_From); languageFromGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); languageFromGroup.setLayout(new GridLayout(3, false)); /* * Selected cells / text */ // TODO: decide whether to show or now the selected text /* * Label labelFrom = new Label(languageFromGroup, SWT.NONE); * labelFrom.setText(Messages.TranslationDialog_SelectedText); * * Label labelFromText = new Label(languageFromGroup, SWT.NONE); * labelFromText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, * false, 2, 1)); String selectedText = ""; for (String text : * this.selectedCells) { selectedText += text + "\n"; } * labelFromText.setText(selectedText); */ /* * Language selection */ Label fromText = new Label(languageFromGroup, SWT.NONE); fromText.setText(Messages.TranslationDialog_FromLanguage); String selectedLanguage = schema.getISO639LangFromID(this.selectedColumn); // check if ISO639 exists selectedLanguage = ((LanguagesUtil.getLanguageName(selectedLanguage) != null) ? selectedLanguage : null); String defaultLanguage = PreferencesManager.getInstance() .getProjectPreferencesManager(this.project) .getDefaultLanguageForColumn(this.selectedColumn); fromCombo = LanguagesUtil.createLanguagesCombo( (Composite) languageFromGroup, selectedLanguage, defaultLanguage, schema); fromCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); fromCombo.addSelectionListener(comboListener); LanguagesUtil.createImageStatus(languageFromGroup, selectedLanguage); }
public void widgetSelected(SelectionEvent e) { if (e.getSource() == fromCombo) { if (!fromCombo.getText().equals(LanguagesUtil.getComboSeparator())) { fromLanguage = fromCombo.getText(); if (!fromLanguage.equals(LanguagesUtil.getComboSeparator())) { // update default language PreferencesManager.getInstance() .getProjectPreferencesManager(project) .setDefaultLanguageForColumn( selectedColumn, LanguagesUtil.getLanguageID(fromLanguage)); } } else { fromLanguage = null; } } else if (e.getSource() == translatorsCombo) { translator = translatorsCombo.getText(); TranslatorManager.getInstance().setTranslatorBranding(translator, translatorBrandingImage); } validateSelection(); }
/** * Create translators group and combo * * @param parent parent composite * @param comboListener translator combo listener */ private void createTranslatorArea(Composite parent, ComboListener comboListener) { Group translatorGroup = new Group(parent, SWT.SHADOW_ETCHED_OUT); translatorGroup.setText(Messages.Translator_Text); translatorGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); translatorGroup.setLayout(new GridLayout(2, false)); Label translatorText = new Label(translatorGroup, SWT.NONE); translatorText.setText(Messages.Service_Text); translatorsCombo = LanguagesUtil.createTranslatorsCombo((Composite) translatorGroup); translatorsCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); translatorsCombo.addSelectionListener(comboListener); }
/** * Create destination area with information about destination columns and languages * * @param parent parent composite * @param schema android localization schema */ private void createToArea(Composite parent, ILocalizationSchema schema) { Group languageToGroup = new Group(parent, SWT.SHADOW_ETCHED_OUT); languageToGroup.setText(Messages.TranslationDialog_To); languageToGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); languageToGroup.setLayout(new GridLayout(4, false)); if (this.columns.length <= 2) { Label noColumns = new Label(languageToGroup, SWT.NONE); noColumns.setText(Messages.TranslationDialog_NoColumns); } /* * Destination Columns */ this.destinationColumns = new ArrayList<DestinationColumn>(); int i = 0; for (TableColumn column : this.columns) { if ((i > 0) && (!column.getText().equals(this.selectedColumn))) { // checkbox Button checkbox = new Button(languageToGroup, SWT.CHECK); checkbox.setSelection(true); // label Label label = new Label(languageToGroup, SWT.NONE); label.setText(column.getText()); // languages combo String selectedLanguage = schema.getISO639LangFromID(column.getText()); // check if ISO639 exists selectedLanguage = ((LanguagesUtil.getLanguageName(selectedLanguage) != null) ? selectedLanguage : null); String defaultLanguage = PreferencesManager.getInstance() .getProjectPreferencesManager(this.project) .getDefaultLanguageForColumn(column.getText()); DestinationColumn destColumn = new DestinationColumn(checkbox, true, column.getText(), selectedLanguage); checkbox.setData(destColumn); checkbox.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ((DestinationColumn) ((Button) e.getSource()).getData()) .setSelected(((Button) e.getSource()).getSelection()); validateSelection(); } }); Combo languagesCombo = LanguagesUtil.createLanguagesCombo( languageToGroup, selectedLanguage, defaultLanguage, schema); destColumn.setLang(LanguagesUtil.getLanguageID(languagesCombo.getText())); languagesCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); languagesCombo.setData(destColumn); languagesCombo.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String selectedText = ((Combo) e.getSource()).getText(); if (!selectedText.equals(LanguagesUtil.getComboSeparator())) { ((DestinationColumn) ((Combo) e.getSource()).getData()) .setLang(LanguagesUtil.getLanguageID(selectedText)); // update default language PreferencesManager.getInstance() .getProjectPreferencesManager(project) .setDefaultLanguageForColumn( ((DestinationColumn) ((Combo) e.getSource()).getData()).getText(), LanguagesUtil.getLanguageID(selectedText)); } else { ((DestinationColumn) ((Combo) e.getSource()).getData()).setLang(null); } validateSelection(); } }); // status image LanguagesUtil.createImageStatus(languageToGroup, selectedLanguage); destinationColumns.add(destColumn); } i++; } /* * Select and Deselect All buttons */ Composite buttonsArea = new Composite(languageToGroup, SWT.NONE); buttonsArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); buttonsArea.setLayout(new GridLayout(2, true)); Button selectAllButton = new Button(buttonsArea, SWT.PUSH); selectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); selectAllButton.setText(Messages.TranslationDialog_SelectAll); selectAllButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { for (DestinationColumn destColumn : destinationColumns) { destColumn.setSelected(true); } validateSelection(); } }); Button deselectAllButton = new Button(buttonsArea, SWT.PUSH); deselectAllButton.setText(Messages.TranslationDialog_DeselectAll); deselectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); deselectAllButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { for (DestinationColumn destColumn : destinationColumns) { destColumn.setSelected(false); } validateSelection(); } }); }
/** * Get the original language * * @return the original language of the word(s) being translated */ public String getFromLanguage() { return LanguagesUtil.getLanguageID(fromLanguage); }