Java tutorial
/* Copyright (C) 2016 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.customtrap.dialog; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; 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.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import com.clustercontrol.bean.HinemosModuleConstant; import com.clustercontrol.bean.RequiredFieldColorConstant; import com.clustercontrol.monitor.bean.ConvertValueConstant; import com.clustercontrol.monitor.bean.ConvertValueMessage; import com.clustercontrol.monitor.run.dialog.CommonMonitorNumericDialog; import com.clustercontrol.monitor.util.MonitorSettingEndpointWrapper; import com.clustercontrol.util.HinemosMessage; import com.clustercontrol.util.Messages; import com.clustercontrol.util.WidgetTestUtil; import com.clustercontrol.ws.monitor.CustomTrapCheckInfo; import com.clustercontrol.ws.monitor.InvalidRole_Exception; import com.clustercontrol.ws.monitor.MonitorDuplicate_Exception; import com.clustercontrol.ws.monitor.MonitorInfo; /** * ?<br/> * * @version 6.0.0 * @since 6.0.0 */ public class MonitorCustomTrapDialog extends CommonMonitorNumericDialog { // private static Log m_log = LogFactory.getLog(MonitorCustomTrapDialog.class); // ----- instance ----- // private Text textKeypattern = null; // ? /** ?? */ private Combo m_comboConvertValue = null; /** * (?)<br/> * * @param parent * ? */ public MonitorCustomTrapDialog(Shell parent) { super(parent, null); } /** * ()<br/> * * @param parent * ?? * @param managerName * ??? * @param monitorId * ???ID * @param updateFlg * ????true:?false:? */ public MonitorCustomTrapDialog(Shell parent, String managerName, String monitorId, boolean updateFlg) { super(parent, managerName); this.managerName = managerName; this.monitorId = monitorId; this.updateFlg = updateFlg; } /** * ???<br/> * * @param parent * ??? */ @Override protected void customizeDialog(Composite parent) { // Local Variables Label label = null; // ???? GridData gridData = null; // ???? // ??? item1 = Messages.getString("select.value"); item2 = Messages.getString("select.value"); // ? this.m_unregistered = true; super.customizeDialog(parent); // ? shell.setText(Messages.getString("dialog.monitor.customtrap.edit")); // ????? this.m_monitorRule.setRunIntervalEnabled(false); Composite compositeKey = new Composite(groupRule, SWT.NONE); WidgetTestUtil.setTestId(this, "compositeKey", compositeKey); GridLayout layout = new GridLayout(1, true); layout.marginWidth = 0; layout.marginHeight = BASIC_MARGIN; layout.numColumns = 15; compositeKey.setLayout(layout); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); gridData.horizontalSpan = BASIC_UNIT; compositeKey.setLayoutData(gridData); // () label = new Label(compositeKey, SWT.NONE); WidgetTestUtil.setTestId(this, "keypatterntest", label); gridData = new GridData(); gridData.horizontalSpan = WIDTH_TITLE; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; label.setLayoutData(gridData); label.setText(Messages.getString("monitor.customtrap.target.key") + " : "); // () this.textKeypattern = new Text(compositeKey, SWT.BORDER); WidgetTestUtil.setTestId(this, "textKeypattern", textKeypattern); gridData = new GridData(); gridData.horizontalSpan = 8; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; this.textKeypattern.setLayoutData(gridData); this.textKeypattern.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent arg0) { update(); } }); // ?? label = new Label(compositeKey, SWT.NONE); gridData = new GridData(); gridData.horizontalSpan = WIDTH_TITLE; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; label.setLayoutData(gridData); label.setText(Messages.getString("convert.value") + " : "); // ?? this.m_comboConvertValue = new Combo(compositeKey, SWT.DROP_DOWN | SWT.READ_ONLY); WidgetTestUtil.setTestId(this, "convertvalue", m_comboConvertValue); gridData = new GridData(); gridData.horizontalSpan = 8; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; this.m_comboConvertValue.setLayoutData(gridData); this.m_comboConvertValue.add(ConvertValueMessage.STRING_NO); this.m_comboConvertValue.add(ConvertValueMessage.STRING_DELTA); // ??? this.adjustDialog(); // ? MonitorInfo info = null; if (this.monitorId == null) { // ???? info = new MonitorInfo(); this.setInfoInitialValue(info); } else { // ?? try { MonitorSettingEndpointWrapper wrapper = MonitorSettingEndpointWrapper.getWrapper(managerName); info = wrapper.getMonitor(this.monitorId); } catch (InvalidRole_Exception e) { // ?????? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); return; } catch (Exception e) { // ? m_log.warn("customizeDialog() getMonitor, " + HinemosMessage.replace(e.getMessage()), e); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.hinemos.failure.unexpected") + ", " + HinemosMessage.replace(e.getMessage())); return; } } this.setInputData(info); update(); } /** * ? */ @Override public void update() { // ? super.update(); // ????? if (this.textKeypattern.getEnabled() && "".equals(this.textKeypattern.getText())) { this.textKeypattern.setBackground(RequiredFieldColorConstant.COLOR_REQUIRED); } else { this.textKeypattern.setBackground(RequiredFieldColorConstant.COLOR_UNREQUIRED); } } /** * ????? * * @param monitor * ???? */ @Override protected void setInputData(MonitorInfo monitor) { super.setInputData(monitor); this.inputData = monitor; // ? CustomTrapCheckInfo customtrapInfo = monitor.getCustomTrapCheckInfo(); if (customtrapInfo == null) { this.m_comboConvertValue.setText(ConvertValueMessage.typeToString(ConvertValueConstant.TYPE_NO)); } else { this.textKeypattern.setText(customtrapInfo.getTargetKey()); this.m_comboConvertValue .setText(ConvertValueMessage.typeToString(customtrapInfo.getConvertFlg().intValue())); } m_numericValueInfo.setInputData(monitor); } /** * ?????? * * @return ???? */ @Override protected MonitorInfo createInputData() { // Local Variables CustomTrapCheckInfo customtrapInfo = null; // MAIN super.createInputData(); if (validateResult != null) { return null; } // monitorInfo.setMonitorTypeId(HinemosModuleConstant.MONITOR_CUSTOMTRAP_N); // ? customtrapInfo = new CustomTrapCheckInfo(); customtrapInfo.setMonitorTypeId(HinemosModuleConstant.MONITOR_CUSTOMTRAP_N); customtrapInfo.setConvertFlg(ConvertValueConstant.TYPE_NO); customtrapInfo.setMonitorId(monitorInfo.getMonitorId()); customtrapInfo.setTargetKey(this.textKeypattern.getText()); monitorInfo.setCustomTrapCheckInfo(customtrapInfo); // ?? validateResult = m_numericValueInfo.createInputData(monitorInfo); if (validateResult != null) { return null; } // ?? if (this.m_comboConvertValue.getText() != null && !"".equals((this.m_comboConvertValue.getText()).trim())) { customtrapInfo.setConvertFlg( Integer.valueOf(ConvertValueMessage.stringToType(this.m_comboConvertValue.getText()))); } // ?? validateResult = m_notifyInfo.createInputData(monitorInfo); if (validateResult != null) { if (validateResult.getID() == null) { if (!displayQuestion(validateResult)) { // ID???????? validateResult = null; return null; } } else { return null; // ??? } } return monitorInfo; } /** * ?????<br/> * * @return ????????true, ????false */ @Override protected boolean action() { boolean result = false; MonitorInfo info = this.inputData; String managerName = this.getManagerName(); if (info != null) { String[] args = { info.getMonitorId(), managerName }; MonitorSettingEndpointWrapper wrapper = MonitorSettingEndpointWrapper.getWrapper(managerName); if (!this.updateFlg) { // ???? try { result = wrapper.addMonitor(info); if (result) { // ??????? MessageDialog.openInformation(null, Messages.getString("successful"), Messages.getString("message.monitor.33", args)); } else { // ?????? MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.monitor.34", args)); } } catch (MonitorDuplicate_Exception e) { // ??ID????? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.monitor.53", args)); } catch (Exception e) { String errMessage = ""; if (e instanceof InvalidRole_Exception) { // ????????? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); } else { errMessage = ", " + HinemosMessage.replace(e.getMessage()); } // ?????? MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.monitor.34", args) + errMessage); } } else { // ?? String errMessage = ""; try { result = wrapper.modifyMonitor(info); } catch (InvalidRole_Exception e) { // ????????? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); } catch (Exception e) { errMessage = ", " + HinemosMessage.replace(e.getMessage()); } if (result) { // ??????? MessageDialog.openInformation(null, Messages.getString("successful"), Messages.getString("message.monitor.35", args)); } else { // ?????? MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.monitor.36", args) + errMessage); } } } return result; } }