package cn.com.origin.autocodemanager.views.listcodeview;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;

import cn.com.origin.autocodemanager.common.AutoCodeManagerImageKey;
import cn.com.origin.autocodemanager.common.AutoCodeManagerPropertyName;
import cn.com.origin.autocodemanager.common.AutoCodeManangerConstants;
import cn.com.origin.autocodemanager.common.CacheImage;
import cn.com.origin.autocodemanager.common.dialog.AbstractCodeDialog;
import cn.com.origin.autocodemanager.common.tree.AbstractTreeData;

public class NewListPropertyNodeDialog extends AbstractCodeDialog {

	public NewListPropertyNodeDialog(Shell parentShell, CreateListCodeView codeListViewTree, String title, boolean isEdit) {
		super(parentShell, codeListViewTree, title, isEdit);
	}

	@Override
	protected Control createDialogArea(Composite parent) {
		Composite container = (Composite) super.createDialogArea(parent);
		Group nodeGroup = createCompositeGroup(container, "列表属性");
		createNodeComposite(nodeGroup);
		return container;
	}

	public void initNewCodeComposite(Composite composite) {
		createNewLabel(composite, "属性名称");
		nodeNameText = createNewText(composite, "");

		createNewLabel(composite, "备注");
		nodeDescriptionText = createNewText(composite, "");

	}

	// 检查节点和组是否为F空
	@Override
	protected void okPressed() {
		String nodename = nodeNameText.getText().trim();
		if (nodename == null || nodename.trim().length() == 0) {
			postMesssageBox("属性名称不能为空！");
			nodeNameText.setFocus();
			return;
		}
		AbstractTreeData rootData = treeViewOperation.getSelectedTreeNode(codeSegmentView.createView.treeViewer);
		 saveNewCodeNode(rootData, selectedComponent, createView.treeViewer, AutoCodeManagerPropertyName.ListPropertyNodeName, false);
		close();
	}

	// 设置对话框初始大小
	// @Override
	protected Point getInitialSize() {
		return new Point(400, 230);
	}

	// 设置对话框窗口标题和图标
	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(title);
		newShell.setImage(CacheImage.getINSTANCE().getImage(AutoCodeManangerConstants.AutoCodeMananger_APPLICATION_ID, AutoCodeManagerImageKey.LISTNODE_IMAGE));
	}

}
