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 java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; 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.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import com.clustercontrol.bean.SizeConstant; import com.clustercontrol.dialog.ValidateResult; import com.clustercontrol.jobmanagement.action.GetParameterTableDefine; import com.clustercontrol.jobmanagement.bean.JobParamTypeConstant; import com.clustercontrol.jobmanagement.composite.action.ParameterSelectionChangedListener; import com.clustercontrol.jobmanagement.dialog.ParameterDialog; import com.clustercontrol.jobmanagement.util.JobDialogUtil; import com.clustercontrol.util.Messages; import com.clustercontrol.util.WidgetTestUtil; import com.clustercontrol.viewer.CommonTableViewer; import com.clustercontrol.ws.jobmanagement.JobParameterInfo; /** * ???? * * @version 2.1.0 * @since 2.1.0 */ public class ParameterComposite extends Composite { /** */ private CommonTableViewer m_viewer = null; /** */ private Button m_createCondition = null; /** */ private Button m_modifyCondition = null; /** */ private Button m_deleteCondition = null; /** ? */ private List<JobParameterInfo> m_paramList = null; /** */ private Shell m_shell = null; /** ? */ private List<?> m_selectItem = new ArrayList<Object>(); /** ?(???) */ private boolean initFlag; /** * * * @param parent ?? * @param style * * @see org.eclipse.swt.SWT * @see org.eclipse.swt.widgets.Composite#Composite(Composite parent, int style) * @see #initialize() */ public ParameterComposite(Composite parent, int style, boolean initFlag) { super(parent, style); initialize(); m_shell = this.getShell(); this.initFlag = initFlag; } /** * ???? */ private void initialize() { this.setLayout(JobDialogUtil.getParentLayout()); // Label tableTitle = new Label(this, SWT.NONE); tableTitle.setText(Messages.getString("list")); // Table table = new Table(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI); WidgetTestUtil.setTestId(this, "table", table); table.setHeaderVisible(true); table.setLinesVisible(true); table.setLayoutData(new RowData(430, 235)); // Composite Composite buttonComposite = new Composite(this, SWT.NONE); buttonComposite.setLayout(new RowLayout()); // dummy new Label(buttonComposite, SWT.NONE).setLayoutData(new RowData(190, SizeConstant.SIZE_LABEL_HEIGHT)); // this.m_createCondition = new Button(buttonComposite, SWT.NONE); WidgetTestUtil.setTestId(this, "m_createCondition", this.m_createCondition); this.m_createCondition.setText(Messages.getString("add")); this.m_createCondition.setLayoutData(new RowData(80, SizeConstant.SIZE_BUTTON_HEIGHT)); this.m_createCondition.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ParameterDialog dialog = new ParameterDialog(m_shell); if (dialog.open() == IDialogConstants.OK_ID) { ArrayList<?> info = dialog.getInputData(); @SuppressWarnings("unchecked") ArrayList<Object> list = (ArrayList<Object>) m_viewer.getInput(); if (list == null) { list = new ArrayList<Object>(); } else { // Check if parameter name already exists for (Object one : list) { @SuppressWarnings("unchecked") String name = (String) ((ArrayList<Object>) one).get(0); if (name.equals(info.get(0))) { MessageDialog.openError(null, Messages.getString("message.hinemos.1"), Messages.getString("message.hinemos.10", new Object[] { Messages.getString("job.parameter"), name })); return; } } } // Finally, add it list.add(info); m_viewer.setInput(list); } } }); // this.m_modifyCondition = new Button(buttonComposite, SWT.NONE); WidgetTestUtil.setTestId(this, "m_modifyCondition", this.m_modifyCondition); this.m_modifyCondition.setText(Messages.getString("modify")); this.m_modifyCondition.setLayoutData(new RowData(80, SizeConstant.SIZE_BUTTON_HEIGHT)); this.m_modifyCondition.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (m_selectItem != null) { ParameterDialog dialog = new ParameterDialog(m_shell); @SuppressWarnings("unchecked") ArrayList<Object> objList = m_selectItem.isEmpty() ? null : (ArrayList<Object>) m_selectItem.get(0); if (objList != null) { dialog.setInputData(objList); if (dialog.open() == IDialogConstants.OK_ID) { ArrayList<?> info = dialog.getInputData(); @SuppressWarnings("unchecked") ArrayList<Object> list = (ArrayList<Object>) m_viewer.getInput(); list.remove(objList); list.add(info); m_selectItem = null; m_viewer.setInput(list); } } } } }); // this.m_deleteCondition = new Button(buttonComposite, SWT.NONE); WidgetTestUtil.setTestId(this, "m_deleteCondition", this.m_deleteCondition); this.m_deleteCondition.setText(Messages.getString("delete")); this.m_deleteCondition.setLayoutData(new RowData(80, SizeConstant.SIZE_BUTTON_HEIGHT)); this.m_deleteCondition.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (m_selectItem != null) { ArrayList<?> list = (ArrayList<?>) m_viewer.getInput(); for (Object obj : m_selectItem) { if (obj instanceof ArrayList) { @SuppressWarnings("unchecked") ArrayList<Object> objList = (ArrayList<Object>) obj; list.remove(objList); m_selectItem = new ArrayList<Object>(); m_viewer.setInput(list); } } } } }); this.m_viewer = new CommonTableViewer(table); this.m_viewer.createTableColumn(GetParameterTableDefine.get(), GetParameterTableDefine.SORT_COLUMN_INDEX, GetParameterTableDefine.SORT_ORDER); this.m_viewer.addSelectionChangedListener(new ParameterSelectionChangedListener(this)); } /** * ??????? * * @see com.clustercontrol.jobmanagement.bean.JobParameterInfo * @param callJobHystory */ public void reflectParamInfo(boolean callJobHystory) { if (!initFlag) { // ArrayList<ArrayList<?>> tableData = new ArrayList<ArrayList<?>>(); for (int i = 0; i < m_paramList.size(); i++) { JobParameterInfo info = m_paramList.get(i); if (info.getType() == JobParamTypeConstant.TYPE_USER || callJobHystory) { ArrayList<Object> tableLineData = new ArrayList<Object>(); tableLineData.add(info.getParamId()); tableLineData.add(info.getType()); tableLineData.add(info.getValue()); tableLineData.add(info.getDescription()); tableData.add(tableLineData); } } m_viewer.setInput(tableData); } } /** * ??? * * @param paramList ? */ public void setParamInfo(List<JobParameterInfo> paramList) { m_paramList = paramList; } /** * ??? * * @return ? */ public List<JobParameterInfo> getParamInfo() { return m_paramList; } /** * ???????? * * @return ?? * * @see com.clustercontrol.jobmanagement.bean.JobParameterInfo */ public ValidateResult createParamInfo() { //??? m_paramList = new ArrayList<JobParameterInfo>(); //? ArrayList<?> tableData = (ArrayList<?>) m_viewer.getInput(); HashMap<String, Object> map = new HashMap<String, Object>(); if (tableData != null) { for (int i = 0; i < tableData.size(); i++) { ArrayList<?> tableLineData = (ArrayList<?>) tableData.get(i); JobParameterInfo info = new JobParameterInfo(); Integer type = (Integer) tableLineData.get(GetParameterTableDefine.TYPE); info.setType(type); if (info.getType() == JobParamTypeConstant.TYPE_USER) { info.setParamId((String) tableLineData.get(GetParameterTableDefine.PARAM_ID)); info.setValue((String) tableLineData.get(GetParameterTableDefine.VALUE)); info.setDescription((String) tableLineData.get(GetParameterTableDefine.DESCRIPTION)); } //?? Integer checkValue = (Integer) map.get(info.getParamId()); if (checkValue == null) { m_paramList.add(info); map.put(info.getParamId(), 0); } } } return null; } /** * ???? * * @return ? */ public List<?> getSelectItem() { return m_selectItem; } /** * ???? * * @param selectItem ? */ public void setSelectItem(List<?> selectItem) { m_selectItem = selectItem; } /** * ?????? */ @Override public void setEnabled(boolean enabled) { m_modifyCondition.setEnabled(enabled); m_createCondition.setEnabled(enabled); m_deleteCondition.setEnabled(enabled); } }