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.infra.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.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import com.clustercontrol.bean.RequiredFieldColorConstant; import com.clustercontrol.bean.SizeConstant; import com.clustercontrol.dialog.ScopeTreeDialog; import com.clustercontrol.repository.FacilityPath; import com.clustercontrol.repository.bean.FacilityConstant; import com.clustercontrol.util.HinemosMessage; import com.clustercontrol.util.Messages; import com.clustercontrol.util.WidgetTestUtil; import com.clustercontrol.ws.infra.InfraManagementInfo; import com.clustercontrol.ws.monitor.MonitorInfo; import com.clustercontrol.ws.repository.FacilityInfo; import com.clustercontrol.ws.repository.FacilityTreeItem; import com.clustercontrol.ClusterControlPlugin; /** * ?<BR> * <dl> * <dt>?</dt> * <dd>? </dd> * <dd>?? </dd> * </dl> * * @version 4.0.0 * @since 5.0.0 */ public class InfraScopeComposite extends Composite { /** */ private Button m_scopeParam = null; /** */ private Button m_scopeFixedValue = null; /** */ private Text m_scope = null; /** ? */ private Button btnRefer = null; /** ????ID */ private String m_facilityId = null; /** ??*/ private boolean m_unregistered = false; /** ID*/ private String m_ownerRoleId = null; /** ??? */ private String m_managerName = null; // /** ??????*/ // private String m_facilityName = null; /** * ??? * <p> * ??????????? * * @param parent ?? * @param style * * @see org.eclipse.swt.SWT * @see #initialize() */ public InfraScopeComposite(Composite parent, int style) { super(parent, style); this.initialize(); } /** * ????? */ private void initialize() { GridLayout layout = new GridLayout(3, false); layout.marginHeight = 0; layout.marginWidth = 0; this.setLayout(layout); // ???? GridData gridData = null; m_scopeParam = new Button(this, SWT.RADIO); WidgetTestUtil.setTestId(this, "m_scopeParam", this.m_scopeParam); this.m_scopeParam.setText(Messages.getString("infra.parameter") + " : "); this.m_scopeParam.setLayoutData(new GridData(100, SizeConstant.SIZE_BUTTON_HEIGHT)); this.m_scopeParam.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { Button check = (Button) e.getSource(); WidgetTestUtil.setTestId(this, null, check); if (check.getSelection()) { m_scopeFixedValue.setSelection(false); btnRefer.setEnabled(false); } update(); } @Override public void widgetDefaultSelected(SelectionEvent e) { } }); // Label scopeJobParamLabel = new Label(this, SWT.LEFT); scopeJobParamLabel.setText("#[FACILITY_ID]"); scopeJobParamLabel.setLayoutData(new GridData(100, SizeConstant.SIZE_LABEL_HEIGHT)); //dummy new Label(this, SWT.LEFT); m_scopeFixedValue = new Button(this, SWT.RADIO); WidgetTestUtil.setTestId(this, "m_scopeFixedValue", this.m_scopeFixedValue); this.m_scopeFixedValue.setText(Messages.getString("fixed.value") + " : "); this.m_scopeFixedValue.setLayoutData(new GridData(100, SizeConstant.SIZE_BUTTON_HEIGHT)); this.m_scopeFixedValue.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { Button check = (Button) e.getSource(); WidgetTestUtil.setTestId(this, null, check); if (check.getSelection()) { m_scopeFixedValue.setSelection(true); btnRefer.setEnabled(true); } update(); } @Override public void widgetDefaultSelected(SelectionEvent e) { } }); this.m_scope = new Text(this, SWT.BORDER | SWT.LEFT | SWT.READ_ONLY); WidgetTestUtil.setTestId(this, "scope", m_scope); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalAlignment = GridData.FILL; this.m_scope.setLayoutData(gridData); this.m_scope.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { update(); } }); // ? btnRefer = new Button(this, SWT.NONE); WidgetTestUtil.setTestId(this, "refer", btnRefer); btnRefer.setText(Messages.getString("refer")); btnRefer.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ScopeTreeDialog dialog = new ScopeTreeDialog(null, m_managerName, m_ownerRoleId, false, m_unregistered); if (dialog.open() == IDialogConstants.OK_ID) { FacilityTreeItem item = dialog.getSelectItem(); FacilityInfo info = item.getData(); if (!info.getFacilityId().equals(InfraScopeComposite.this.m_facilityId)) { InfraScopeComposite.this.m_facilityId = info.getFacilityId(); if (info.getFacilityType() == FacilityConstant.TYPE_NODE) { m_scope.setText(info.getFacilityName()); } else { FacilityPath path = new FacilityPath(ClusterControlPlugin.getDefault().getSeparator()); m_scope.setText(path.getPath(item)); } } } } }); update(); } /** * ? */ @Override public void update() { super.update(); // ????? if (m_scopeFixedValue.getSelection() && "".equals((this.m_scope.getText()).trim())) { this.m_scope.setBackground(RequiredFieldColorConstant.COLOR_REQUIRED); } else { this.m_scope.setBackground(RequiredFieldColorConstant.COLOR_UNREQUIRED); } } /** * ?????????? * * @param info ???? * * @see com.clustercontrol.infra.composite.MonitorBasicComposite#setInputData(MonitorInfo) */ public void setInputData(String managerName, InfraManagementInfo info) { this.m_managerName = managerName; setInputData(info); } public void setInputData(InfraManagementInfo info) { if (info != null) { this.m_ownerRoleId = info.getOwnerRoleId(); this.m_facilityId = info.getFacilityId(); if (m_facilityId == null) { // ?? m_scopeParam.setSelection(true); } else { // ?? m_scopeFixedValue.setSelection(true); this.m_scope.setText(HinemosMessage.replace(info.getScope())); } } else { m_scopeFixedValue.setSelection(true); } // ????? this.update(); } @Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); this.m_scope.setEnabled(enabled); this.btnRefer.setEnabled(enabled); } public String getFacilityId() { if (m_scopeParam.getSelection()) { return null; } return m_facilityId; } public void setOwnerRoleId(String managerName, String ownerRoleId) { this.m_managerName = managerName; setOwnerRoleId(ownerRoleId); } public void setOwnerRoleId(String ownerRoleId) { this.m_ownerRoleId = ownerRoleId; this.m_scope.setText(""); this.m_facilityId = ""; } public String getOwnerRoleId() { return this.m_ownerRoleId; } public String getScope() { return m_scope.getText(); } public void setScopeParam(boolean scopeParam) { this.m_scopeParam.setSelection(scopeParam); } }