--- /dev/null
+/*
+ * Common
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Changhyun Lee <changhyun1.lee@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.common.ui.dialog;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.SelectionStatusDialog;
+import org.tizen.common.CommonPlugin;
+import org.tizen.common.util.StringUtil;
+
+/**
+ * LocaleDialog for Tizen Configuration Editor.
+ *
+ * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core)
+ */
+public class LocaleDialog extends SelectionStatusDialog {
+
+ private static final String DEFAULT_LOCALE = "en-gb";
+ private static final String[] WRT_LOCALE_LISTS = {
+ "ar-ae",
+ "hy-am",
+ "az-az",
+ "eu-es",
+ "bg-bg",
+ "ca-es",
+ "zh-cn",
+ "zh-hk",
+ "zh-sg",
+ "zh-tw",
+ "hr-hr",
+ "cs-cz",
+ "da-dk",
+ "nl-nl",
+ "en-ph",
+ "en-gb",
+ "en-us",
+ "et-ee",
+ "fi-fi",
+ "fr-fr",
+ "fr-ca",
+ "gl-es",
+ "ka-ge",
+ "de-de",
+ "el-gr",
+ "hi-in",
+ "hu-hu",
+ "is-is",
+ "ga-ie",
+ "it-it",
+ "ja-jp",
+ "kk-kz",
+ "ko-kr",
+ "lv-lv",
+ "lt-lt",
+ "mk-mk",
+ "nb-no",
+ "pl-pl",
+ "pt-pt",
+ "pt-br",
+ "ro-ro",
+ "ru-ru",
+ "sr-rs",
+ "sk-sk",
+ "sl-si",
+ "es-es",
+ "es-mx",
+ "sv-se",
+ "tr-tr",
+ "uk-ua",
+ "uz-uz"
+ };
+
+ private String locale;
+ private String name;
+ private Combo localeCombo;
+ private Text nameText;
+ private Set<String> filter;
+
+ public LocaleDialog( Shell parentShell, HashMap<String, String> locales ) {
+ super(parentShell);
+ filter = new HashSet<String>();
+ for ( String lang : locales.keySet() ) {
+ filter.add( lang );
+ }
+ }
+
+ @Override
+ protected void computeResult() {
+ locale = localeCombo.getText();
+ name = nameText.getText().trim();
+ }
+
+ @Override
+ protected Control createDialogArea( Composite parent ) {
+ Composite composite = new Composite( parent, SWT.NONE );
+ composite.setLayout( new GridLayout( 2, false ) );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ gd.widthHint = 400; // make IStatus msg visible
+ composite.setLayoutData( gd );
+ applyDialogFont( composite );
+
+ // Locale
+ Label label = new Label( composite, SWT.NONE );
+ label.setText( "Locale:" );
+ label.setLayoutData( new GridData( SWT.RIGHT, SWT.CENTER, false, false, 1, 1 ) );
+ localeCombo = new Combo( composite, SWT.READ_ONLY );
+ for ( String locale : WRT_LOCALE_LISTS ) {
+ if ( !filter.contains( locale ) ) {
+ localeCombo.add( locale );
+ }
+ }
+ localeCombo.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( SelectionEvent e ) {
+ validate();
+ }
+ });
+
+ if ( filter.contains( DEFAULT_LOCALE ) ) {
+ localeCombo.select( 0 );
+ } else {
+ localeCombo.setText( DEFAULT_LOCALE );
+ }
+ localeCombo.setLayoutData( new GridData( SWT.FILL, GridData.CENTER, false, false, 1, 1 ) );
+
+ // Name
+ label = new Label( composite, SWT.NONE );
+ label.setText( "Name:" );
+ label.setLayoutData( new GridData( SWT.RIGHT, SWT.CENTER, false, false, 1, 1 ) );
+ nameText = new Text( composite,SWT.BORDER );
+ nameText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 1, 1 ) );
+ nameText.addModifyListener( new ModifyListener() {
+ @Override
+ public void modifyText( ModifyEvent e ) {
+ validate();
+ }
+ });
+ nameText.setFocus();
+
+ // Edit Mode
+ if ( !StringUtil.isEmpty( locale ) && !StringUtil.isEmpty( name ) ) {
+ localeCombo.add( locale );
+ localeCombo.setText( locale );
+ nameText.setText( name );
+ }
+
+ setHelpAvailable( false );
+ validate();
+
+ return composite;
+ }
+
+ protected void validate() {
+ computeResult();
+ IStatus status = null;
+ if ( locale.length() == 0 ) {
+ status = new Status( IStatus.ERROR, CommonPlugin.PLUGIN_ID, "Select a locale" );
+ } else if ( name.length() == 0 ) {
+ status = new Status( IStatus.ERROR, CommonPlugin.PLUGIN_ID, "Enter a name" );
+ } else {
+ status = new Status( IStatus.OK, CommonPlugin.PLUGIN_ID, null );
+ }
+ updateStatus(status);
+ }
+
+ public void editLocale( String locale, String name ) {
+ this.locale = locale;
+ this.name = name;
+ }
+
+ public String getLocale() {
+ return locale;
+ }
+
+ public void setLocale( String locale ) {
+ this.locale = locale;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName( String name ) {
+ this.name = name;
+ }
+
+}