Java tutorial
/* //Copyright (C) 2006 NTT DATA Corporation This program is free software; you can redistribute it and/or Modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ package com.clustercontrol.jobmanagement.composite; import org.eclipse.jface.dialogs.IDialogConstants; 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.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowData; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import com.clustercontrol.ClusterControlPlugin; import com.clustercontrol.bean.DataRangeConstant; import com.clustercontrol.bean.RequiredFieldColorConstant; import com.clustercontrol.bean.SizeConstant; import com.clustercontrol.composite.action.StringVerifyListener; import com.clustercontrol.dialog.ScopeTreeDialog; import com.clustercontrol.dialog.ValidateResult; import com.clustercontrol.jobmanagement.bean.ProcessingMethodConstant; import com.clustercontrol.jobmanagement.util.JobDialogUtil; import com.clustercontrol.repository.FacilityPath; import com.clustercontrol.util.HinemosMessage; import com.clustercontrol.util.Messages; import com.clustercontrol.util.WidgetTestUtil; import com.clustercontrol.ws.jobmanagement.JobFileInfo; import com.clustercontrol.ws.repository.FacilityInfo; import com.clustercontrol.ws.repository.FacilityTreeItem; /** * ????? * * @version 4.0.0 * @since 2.0.0 */ public class FileComposite extends Composite { /** ? */ private Text m_srcScope = null; /** ? */ private Text m_srcFile = null; /** ? */ private Text m_destScope = null; /** ? */ private Text m_destDirectory = null; /** */ private Button m_agentUser = null; /** ? */ private Button m_specifyUser = null; /** */ private Text m_user = null; /** ?? */ private Button m_srcScopeSelect = null; /** ?? */ private Button m_destScopeSelect = null; /** ???? */ private Button m_allNode = null; /** 1?? */ private Button m_oneNode = null; /** ?? */ private Button m_compressionCondition = null; /** ??? */ private Button m_checkFileCondition = null; /** ?ID */ private String m_srcFacilityId = null; /** ? */ private String m_srcFacilityPath = null; /** ?ID */ private String m_destFacilityId = null; /** ? */ private String m_destFacilityPath = null; /** ? */ private JobFileInfo m_jobFileInfo = null; /** */ private Shell m_shell = null; /** ID */ private String m_ownerRoleId = null; /** ??? */ private String m_managerName = null; /** * * * @param parent ? * @param style * * @see org.eclipse.swt.SWT * @see org.eclipse.swt.widgets.Composite#Composite(Composite parent, int style) * @see #initialize() */ public FileComposite(Composite parent, int style) { super(parent, style); initialize(); m_shell = this.getShell(); } /** * ????? */ private void initialize() { this.setLayout(JobDialogUtil.getParentLayout()); // ? Group fileTransferFromgroup = new Group(this, SWT.NONE); fileTransferFromgroup.setText(Messages.getString("forward.source")); fileTransferFromgroup.setLayout(new GridLayout(3, false)); // ? Label srcScopeTitle = new Label(fileTransferFromgroup, SWT.NONE); srcScopeTitle.setText(Messages.getString("scope") + " : "); srcScopeTitle.setLayoutData(new GridData(100, SizeConstant.SIZE_LABEL_HEIGHT)); // ? this.m_srcScope = new Text(fileTransferFromgroup, SWT.BORDER | SWT.READ_ONLY); WidgetTestUtil.setTestId(this, "m_srcScope", this.m_srcScope); this.m_srcScope.setLayoutData(new GridData(200, SizeConstant.SIZE_TEXT_HEIGHT)); this.m_srcScope.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent arg0) { update(); } }); // ?? this.m_srcScopeSelect = new Button(fileTransferFromgroup, SWT.NONE); WidgetTestUtil.setTestId(this, "m_srcScopeSelect", this.m_srcScopeSelect); this.m_srcScopeSelect.setText(Messages.getString("refer")); this.m_srcScopeSelect.setLayoutData(new GridData(80, SizeConstant.SIZE_BUTTON_HEIGHT)); this.m_srcScopeSelect.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ScopeTreeDialog dialog = new ScopeTreeDialog(m_shell, m_managerName, m_ownerRoleId); // ?????? dialog.setSelectNodeOnly(true); if (dialog.open() == IDialogConstants.OK_ID) { FacilityTreeItem selectItem = dialog.getSelectItem(); FacilityInfo info = selectItem.getData(); FacilityPath path = new FacilityPath(ClusterControlPlugin.getDefault().getSeparator()); m_srcFacilityPath = path.getPath(selectItem); m_srcFacilityId = info.getFacilityId(); m_srcScope.setText(m_srcFacilityPath); } } }); // ? Label fileTitle = new Label(fileTransferFromgroup, SWT.NONE); fileTitle.setText(Messages.getString("file") + " : "); fileTitle.setLayoutData(new GridData(100, SizeConstant.SIZE_LABEL_HEIGHT)); // ? this.m_srcFile = new Text(fileTransferFromgroup, SWT.BORDER); WidgetTestUtil.setTestId(this, "m_srcFile", this.m_srcFile); this.m_srcFile.setLayoutData(new GridData(200, SizeConstant.SIZE_TEXT_HEIGHT)); this.m_srcFile.addVerifyListener(new StringVerifyListener(DataRangeConstant.VARCHAR_4096)); this.m_srcFile.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent arg0) { update(); } }); // ? Group fileTransferTogroup = new Group(this, SWT.NONE); fileTransferTogroup.setText(Messages.getString("forward.destination")); fileTransferTogroup.setLayout(new GridLayout(3, false)); // ? Label destScopeTitle = new Label(fileTransferTogroup, SWT.NONE); destScopeTitle.setText(Messages.getString("scope") + " : "); destScopeTitle.setLayoutData(new GridData(100, SizeConstant.SIZE_LABEL_HEIGHT)); // ? this.m_destScope = new Text(fileTransferTogroup, SWT.BORDER | SWT.READ_ONLY); WidgetTestUtil.setTestId(this, "m_destScope", m_destScope); this.m_destScope.setLayoutData(new GridData(200, SizeConstant.SIZE_TEXT_HEIGHT)); this.m_destScope.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent arg0) { update(); } }); // ?? m_destScopeSelect = new Button(fileTransferTogroup, SWT.NONE); WidgetTestUtil.setTestId(this, "m_destScopeSelect", m_destScopeSelect); m_destScopeSelect.setText(Messages.getString("refer")); m_destScopeSelect.setLayoutData(new GridData(80, SizeConstant.SIZE_BUTTON_HEIGHT)); m_destScopeSelect.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ScopeTreeDialog dialog = new ScopeTreeDialog(m_shell, m_managerName, m_ownerRoleId); if (dialog.open() == IDialogConstants.OK_ID) { FacilityTreeItem selectItem = dialog.getSelectItem(); FacilityInfo info = selectItem.getData(); FacilityPath path = new FacilityPath(ClusterControlPlugin.getDefault().getSeparator()); m_destFacilityPath = path.getPath(selectItem); m_destFacilityId = info.getFacilityId(); m_destScope.setText(m_destFacilityPath); } } }); // ?? Group methodGroup = new Group(fileTransferTogroup, SWT.NONE); methodGroup.setText(Messages.getString("process.method")); methodGroup.setLayout(new RowLayout()); methodGroup.setLayoutData(new GridData()); ((GridData) methodGroup.getLayoutData()).horizontalSpan = 3; // ???? m_allNode = new Button(methodGroup, SWT.RADIO); WidgetTestUtil.setTestId(this, "m_allNode", m_allNode); m_allNode.setText(Messages.getString("forward.all.nodes")); m_allNode.setLayoutData(new RowData(220, SizeConstant.SIZE_BUTTON_HEIGHT)); // ?? m_oneNode = new Button(methodGroup, SWT.RADIO); WidgetTestUtil.setTestId(this, "m_oneNode", m_oneNode); m_oneNode.setText(Messages.getString("forward.one.node")); m_oneNode.setLayoutData(new RowData(250, SizeConstant.SIZE_BUTTON_HEIGHT)); // ? Label forwardDirTitle = new Label(fileTransferTogroup, SWT.NONE); forwardDirTitle.setText(Messages.getString("directory") + " : "); forwardDirTitle.setLayoutData(new GridData(100, SizeConstant.SIZE_LABEL_HEIGHT)); // ? this.m_destDirectory = new Text(fileTransferTogroup, SWT.BORDER); WidgetTestUtil.setTestId(this, "m_destDirectory", m_destDirectory); this.m_destDirectory.setLayoutData(new GridData(200, SizeConstant.SIZE_TEXT_HEIGHT)); this.m_destDirectory.addVerifyListener(new StringVerifyListener(DataRangeConstant.VARCHAR_4096)); this.m_destDirectory.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent arg0) { update(); } }); // dummy new Label(fileTransferTogroup, SWT.NONE); // ?Composite Composite fileTransfarComposite = new Composite(this, SWT.NONE); fileTransfarComposite.setLayout(new RowLayout()); // ???? this.m_compressionCondition = new Button(fileTransfarComposite, SWT.CHECK); WidgetTestUtil.setTestId(this, "m_compressionCondition", this.m_compressionCondition); this.m_compressionCondition.setText(Messages.getString("forward.compression.file")); this.m_compressionCondition.setLayoutData(new RowData(220, SizeConstant.SIZE_BUTTON_HEIGHT)); // ????? this.m_checkFileCondition = new Button(fileTransfarComposite, SWT.CHECK); WidgetTestUtil.setTestId(this, "m_checkFileCondition", this.m_checkFileCondition); this.m_checkFileCondition.setText(Messages.getString("forward.file.check")); this.m_checkFileCondition.setLayoutData(new RowData(220, SizeConstant.SIZE_BUTTON_HEIGHT)); // Group fileEffectiveUserGroup = new Group(this, SWT.NONE); fileEffectiveUserGroup.setText(Messages.getString("effective.user")); fileEffectiveUserGroup.setLayout(new GridLayout(2, false)); // this.m_agentUser = new Button(fileEffectiveUserGroup, SWT.RADIO); WidgetTestUtil.setTestId(this, "m_agentUser", this.m_agentUser); this.m_agentUser.setText(Messages.getString("agent.user")); this.m_agentUser.setLayoutData(new GridData(200, SizeConstant.SIZE_BUTTON_HEIGHT)); ((GridData) this.m_agentUser.getLayoutData()).horizontalSpan = 2; this.m_agentUser.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { Button check = (Button) e.getSource(); WidgetTestUtil.setTestId(this, null, check); if (check.getSelection()) { m_specifyUser.setSelection(false); m_user.setEditable(false); } update(); } @Override public void widgetDefaultSelected(SelectionEvent e) { } }); // ? this.m_specifyUser = new Button(fileEffectiveUserGroup, SWT.RADIO); WidgetTestUtil.setTestId(this, "m_specifyUser", this.m_specifyUser); this.m_specifyUser.setText(Messages.getString("specified.user")); this.m_specifyUser.setLayoutData(new GridData(200, SizeConstant.SIZE_BUTTON_HEIGHT)); this.m_specifyUser.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { Button check = (Button) e.getSource(); WidgetTestUtil.setTestId(this, null, check); if (check.getSelection()) { m_agentUser.setSelection(false); m_user.setEditable(true); } update(); } @Override public void widgetDefaultSelected(SelectionEvent e) { } }); // ? this.m_user = new Text(fileEffectiveUserGroup, SWT.BORDER); WidgetTestUtil.setTestId(this, "m_user", this.m_user); this.m_user.setLayoutData(new GridData(250, SizeConstant.SIZE_TEXT_HEIGHT)); this.m_user.addVerifyListener(new StringVerifyListener(DataRangeConstant.VARCHAR_64)); this.m_user.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent arg0) { update(); } }); } /** * ? * */ @Override public void update() { // if ("".equals(this.m_srcScope.getText())) { this.m_srcScope.setBackground(RequiredFieldColorConstant.COLOR_REQUIRED); } else { this.m_srcScope.setBackground(RequiredFieldColorConstant.COLOR_UNREQUIRED); } if ("".equals(this.m_srcFile.getText())) { this.m_srcFile.setBackground(RequiredFieldColorConstant.COLOR_REQUIRED); } else { this.m_srcFile.setBackground(RequiredFieldColorConstant.COLOR_UNREQUIRED); } if (m_specifyUser.getSelection() && "".equals(this.m_user.getText())) { this.m_user.setBackground(RequiredFieldColorConstant.COLOR_REQUIRED); } else { this.m_user.setBackground(RequiredFieldColorConstant.COLOR_UNREQUIRED); } if ("".equals(this.m_destScope.getText())) { this.m_destScope.setBackground(RequiredFieldColorConstant.COLOR_REQUIRED); } else { this.m_destScope.setBackground(RequiredFieldColorConstant.COLOR_UNREQUIRED); } if ("".equals(this.m_destDirectory.getText())) { this.m_destDirectory.setBackground(RequiredFieldColorConstant.COLOR_REQUIRED); } else { this.m_destDirectory.setBackground(RequiredFieldColorConstant.COLOR_UNREQUIRED); } } /** * ???????? * * @see com.clustercontrol.jobmanagement.bean.JobFileInfo */ public void reflectFileInfo() { // ? m_srcScope.setText(""); m_srcFile.setText(""); m_destScope.setText(""); m_destDirectory.setText(""); m_allNode.setSelection(true); m_compressionCondition.setSelection(false); m_checkFileCondition.setSelection(false); m_agentUser.setSelection(true); m_specifyUser.setSelection(false); m_user.setText(""); m_user.setEditable(false); if (m_jobFileInfo != null) { //? m_srcFacilityPath = m_jobFileInfo.getSrcScope(); m_srcFacilityId = m_jobFileInfo.getSrcFacilityID(); if (m_srcFacilityPath != null && m_srcFacilityPath.length() > 0) { m_srcScope.setText(m_srcFacilityPath); } //? if (m_jobFileInfo.getSrcFile() != null && m_jobFileInfo.getSrcFile().length() > 0) { m_srcFile.setText(m_jobFileInfo.getSrcFile()); } //? m_destFacilityPath = HinemosMessage.replace(m_jobFileInfo.getDestScope()); m_destFacilityId = m_jobFileInfo.getDestFacilityID(); if (m_destFacilityPath != null && m_destFacilityPath.length() > 0) { m_destScope.setText(m_destFacilityPath); } //? if (m_jobFileInfo.getDestDirectory() != null && m_jobFileInfo.getDestDirectory().length() > 0) { m_destDirectory.setText(m_jobFileInfo.getDestDirectory()); } //? if (m_jobFileInfo.getProcessingMethod() == ProcessingMethodConstant.TYPE_ALL_NODE) { m_allNode.setSelection(true); m_oneNode.setSelection(false); } else { m_allNode.setSelection(false); m_oneNode.setSelection(true); } // m_compressionCondition.setSelection(m_jobFileInfo.isCompressionFlg()); //?? m_checkFileCondition.setSelection(m_jobFileInfo.isCheckFlg()); // if (m_jobFileInfo.isSpecifyUser().booleanValue()) { m_specifyUser.setSelection(true); m_agentUser.setSelection(false); m_user.setEditable(true); } else { m_specifyUser.setSelection(false); m_agentUser.setSelection(true); m_user.setEditable(false); } if (m_jobFileInfo.getUser() != null && m_jobFileInfo.getUser().length() > 0) { m_user.setText(m_jobFileInfo.getUser()); } } } /** * ???? * * @param jobFileInfo ? */ public void setFileInfo(JobFileInfo jobFileInfo) { m_jobFileInfo = jobFileInfo; } /** * ???? * * @return ? */ public JobFileInfo getFileInfo() { return m_jobFileInfo; } /** * ??????? * * @return ?? * * @see com.clustercontrol.jobmanagement.bean.JobFileInfo */ public ValidateResult createFileInfo() { ValidateResult result = null; //???? m_jobFileInfo = new JobFileInfo(); //?? if (m_srcFacilityId != null && m_srcFacilityId.length() > 0) { m_jobFileInfo.setSrcFacilityID(m_srcFacilityId); m_jobFileInfo.setSrcScope(m_srcFacilityPath); } else { result = new ValidateResult(); result.setValid(false); result.setID(Messages.getString("message.hinemos.1")); result.setMessage(Messages.getString("forward.source") + Messages.getString("message.hinemos.3")); return result; } //? if (m_srcFile.getText().length() > 0) { m_jobFileInfo.setSrcFile(m_srcFile.getText()); } else { result = new ValidateResult(); result.setValid(false); result.setID(Messages.getString("message.hinemos.1")); result.setMessage(Messages.getString("forward.source") + Messages.getString("message.job.45")); return result; } //? m_jobFileInfo.setSrcWorkDir(""); //?? if (m_destFacilityId != null && m_destFacilityId.length() > 0) { m_jobFileInfo.setDestFacilityID(m_destFacilityId); m_jobFileInfo.setDestScope(m_destFacilityPath); } else { result = new ValidateResult(); result.setValid(false); result.setID(Messages.getString("message.hinemos.1")); result.setMessage(Messages.getString("forward.destination") + Messages.getString("message.hinemos.3")); return result; } //? if (m_destDirectory.getText().length() > 0) { m_jobFileInfo.setDestDirectory(m_destDirectory.getText()); // ???????? } else if (m_destDirectory.getText().length() <= 0) { result = new ValidateResult(); result.setValid(false); result.setID(Messages.getString("message.hinemos.1")); result.setMessage(Messages.getString("forward.destination") + Messages.getString("message.job.46")); return result; } //? m_jobFileInfo.setDestWorkDir(""); //?? if (m_allNode.getSelection()) { m_jobFileInfo.setProcessingMethod(ProcessingMethodConstant.TYPE_ALL_NODE); } else { m_jobFileInfo.setProcessingMethod(ProcessingMethodConstant.TYPE_RETRY); } // m_jobFileInfo.setCompressionFlg(m_compressionCondition.getSelection()); //?? m_jobFileInfo.setCheckFlg(m_checkFileCondition.getSelection()); //? if (m_agentUser.getSelection()) { m_jobFileInfo.setSpecifyUser(false); } else { if (m_user.getText().length() > 0) { m_jobFileInfo.setSpecifyUser(true); m_jobFileInfo.setUser(m_user.getText()); } else { result = new ValidateResult(); result.setValid(false); result.setID(Messages.getString("message.hinemos.1")); result.setMessage(Messages.getString("message.job.5")); return result; } } return null; } public void setOwnerRoleId(String ownerRoleId) { this.m_ownerRoleId = ownerRoleId; this.m_destScope.setText(""); this.m_destFacilityId = null; this.m_srcScope.setText(""); this.m_srcFacilityId = null; } public void setManagerName(String managerName) { this.m_managerName = managerName; } /** * ?????? */ @Override public void setEnabled(boolean enabled) { m_srcScope.setEditable(false); m_srcFile.setEditable(enabled); m_destScope.setEditable(false); m_destDirectory.setEditable(enabled); m_agentUser.setEnabled(enabled); m_specifyUser.setEnabled(enabled); m_user.setEditable(m_specifyUser.getSelection() && enabled); m_srcScopeSelect.setEnabled(enabled); m_destScopeSelect.setEnabled(enabled); m_allNode.setEnabled(enabled); m_oneNode.setEnabled(enabled); m_compressionCondition.setEnabled(enabled); m_checkFileCondition.setEnabled(enabled); } }