package com.interpress_project.modernshare.client.view.preference;

import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.widgets.Composite;

import com.interpress_project.modernshare.client.controller.model.PropertyManager;

public class PasswordEditor extends StringFieldEditor {
	/**
	 * UsernameEditor
	 * @param arg0
	 * @param arg1
	 * @param arg2
	 */
	public PasswordEditor(String arg0, String arg1, Composite arg2) {
		super(arg0, arg1, arg2);
	}

	/**
	 * doLoad
	 */
	protected void doLoad() {
		PropertyManager propmgr = PropertyManager.getInstance();
		String password = propmgr.getPassword();
		setStringValue(password);
	}

	/**
	 * doStore
	 */
	protected void doStore() {
		PropertyManager propmgr = PropertyManager.getInstance();
		String password = getStringValue();
		propmgr.setPassword(password);
	}

	/**
	 * doCheckState
	 */
	protected boolean doCheckState() {
		return checkState();
	}

	/**
	 * checkState
	 */
	protected boolean checkState() {
		String val = this.getStringValue();
		if (val.length() == 0) {
			showErrorMessage("パスワードを指定します。");
			return false;
		}
		showErrorMessage(null);
		return true;
	}
}
