// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.common.LanguageString;
import eu.etaxonomy.cdm.model.common.MultilanguageTextHelper;
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.store.StoreUtil;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
import eu.etaxonomy.taxeditor.ui.element.MultilanguageTextElement;
* @version 1.0
*/
public class TranslationWizardPage extends WizardPage{
-
- private static int TEXT_HEIGHT = 400;
-
- private Map<Language, LanguageString> multilanguageText;
+
+ private static int TEXT_HEIGHT = 400;
+
+ private final Map<Language, LanguageString> multilanguageText;
MultilanguageTextElement source;
-
- private CdmFormFactory formFactory;
+
+ private final CdmFormFactory formFactory;
private TermComboElement<Language> combo_sourceLanguage;
private TermComboElement<Language> combo_targetLanguage;
private LanguageStringWithLabelElement text_target;
-
+
/**
* <p>Constructor for TranslationWizardPage.</p>
*
Composite control = formFactory.createComposite(parent);
// control.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GREEN));
control.setLayout(LayoutConstants.LAYOUT(2, true));
-
+
Composite leftContainer = formFactory.createComposite(control);
leftContainer.setLayoutData(LayoutConstants.FILL());
leftContainer.setLayout(LayoutConstants.LAYOUT(1, false));
// leftContainer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
RootElement leftRoot = new RootElement(formFactory, leftContainer);
-
+
Composite rightContainer = formFactory.createComposite(control);
rightContainer.setLayoutData(LayoutConstants.FILL());
rightContainer.setLayout(LayoutConstants.LAYOUT(1, false));
// initialize with default language
setSource(CdmStore.getDefaultLanguage());
-
-
+
+
setControl(control);
}
-
+
/**
* @param defaultLanguage
*/
private void setSource(Language language) {
-
+
List<Language> languages = Arrays.asList(new Language[]{language});
-
+
LanguageString preferredLanguageString = MultilanguageTextHelper.getPreferredLanguageString(multilanguageText, languages);
-
+
if(preferredLanguageString != null){
combo_sourceLanguage.setSelection(preferredLanguageString.getLanguage());
text_source.setLanguageString(preferredLanguageString);
/**
- *
+ *
* @param element
*/
private void createLeftControls(ICdmFormElement element){
-
- combo_sourceLanguage = formFactory.createTermComboElement(Language.class, element, null, null, SWT.NULL);
+
+ combo_sourceLanguage = formFactory.createDefinedTermComboElement(TermType.Language, element, null, null, SWT.NULL);
combo_sourceLanguage.setTerms(getLanguages());
-
+
combo_sourceLanguage.addSelectionListener(new SelectionAdapter() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
text_source.setLanguageString(multilanguageText.get(combo_sourceLanguage.getSelection()));
}
});
-
+
LanguageString preferredLanguageString = MultilanguageTextHelper.getPreferredLanguageString(multilanguageText, getLanguages());
-
- text_source = formFactory.createLanguageStringWithLabelElement(element, null, preferredLanguageString, TEXT_HEIGHT, SWT.NULL);
+ if (preferredLanguageString == null){
+ preferredLanguageString = LanguageString.NewInstance("", PreferencesUtil.getGlobalLanguage());
+ }
+ text_source = formFactory.createLanguageStringWithLabelElement(element, null, preferredLanguageString, TEXT_HEIGHT, false, SWT.NULL);
// text_source.setEnabled(false);
text_source.setText(preferredLanguageString.getText());
}
-
+
/**
- *
+ *
* @param element
*/
private void createRightControls(ICdmFormElement element){
- combo_targetLanguage = formFactory.createTermComboElement(Language.class, element, null, null, SWT.NULL);
-
+ combo_targetLanguage = formFactory.createDefinedTermComboElement(TermType.Language, element, null, null, SWT.NULL);
+
combo_targetLanguage.addSelectionListener(new SelectionAdapter() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
@Override
public void widgetSelected(SelectionEvent e) {
Language language = combo_targetLanguage.getSelection();
-
+
if (language == null){
+ setPageComplete(false);
return;
}
-
+
setPageComplete(true);
LanguageString languageString;
-
+
if(multilanguageText.containsKey(language)){
languageString = multilanguageText.get(language);
}else{
languageString = LanguageString.NewInstance("", language);
}
-
+
text_target.setLanguageString(languageString);
}
});
-
- text_target = formFactory.createLanguageStringWithLabelElement(element, null, null, TEXT_HEIGHT, SWT.NULL);
-
+
+ text_target = formFactory.createLanguageStringWithLabelElement(element, null, null, TEXT_HEIGHT, false, SWT.NULL);
+
//
// The automated translation did rely on the Google Translate API. Unfortunately this service is not free anymore.
// See http://code.google.com/apis/language/translate/overview.html
// String text = text_source.getText();
// Language sourceLanguage = text_source.getLanguageString().getLanguage();
// Language targetLanguage = combo_targetLanguage.getSelection();
-//
+//
// if(targetLanguage == null){
// StoreUtil.warningDialog("Please select a target language", TranslationWizardPage.class, "Please select a language from the combo box at the right.");
// return;
// }
-//
+//
// translatedText = service.translate(text, sourceLanguage, targetLanguage);
// text_target.setText(translatedText);
// } catch (LanguageNotSupportedException e) {
// } catch (Exception e){
// StoreUtil.warningDialog("Error translating text", TranslationWizardPage.class, e.getMessage());
// }
-//
+//
// }
// });
}
-
+
/**
- *
+ *
* @return
*/
private List<Language> getLanguages(){
Set<Language> languageSet = MultilanguageTextHelper.getLanguages(multilanguageText);
-
+
List<Language> languageList = new ArrayList<Language>();
// protect against corrupt language sets
for (Language language : languageSet){
if (language != null){
languageList.add(language);
}else{
- StoreUtil.warningDialog("Empty languages", getClass(), "The multilanguage string contains invalid data. Please contact the administrator of you datasource.");
+ MessagingUtils.warningDialog("Empty languages", getClass(), "The multilanguage string contains invalid data. Please contact the administrator of you datasource.");
}
- }
-
+ }
+
return languageList;
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.DialogPage#dispose()
*/
}
/**
- * @return
- *
+ * @return
+ *
*/
public LanguageString getTargetLanguageString() {
return text_target.getLanguageString();