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.monitor.run.composite; import java.util.ArrayList; import java.util.List; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; import org.eclipse.ui.PlatformUI; import com.clustercontrol.bean.PriorityConstant; import com.clustercontrol.bean.TableColumnInfo; import com.clustercontrol.dialog.ValidateResult; import com.clustercontrol.monitor.run.action.GetStringFilterTableDefine; import com.clustercontrol.monitor.run.dialog.StringValueInfoCreateDialog; import com.clustercontrol.util.WidgetTestUtil; import com.clustercontrol.viewer.CommonTableViewer; import com.clustercontrol.ws.monitor.MonitorInfo; import com.clustercontrol.ws.monitor.MonitorStringValueInfo; /** * ??<BR> * * @version 3.0.0 * @since 2.1.0 */ public class StringValueListComposite extends Composite { /** */ private CommonTableViewer m_tableViewer = null; /** */ private ArrayList<TableColumnInfo> m_tableDefine = null; /** */ private ArrayList<MonitorStringValueInfo> m_stringValueInfoList = null; /** * ??? * <p> * ?????????? * * @param parent ?? * @param style * * @see org.eclipse.swt.SWT * @see org.eclipse.swt.widgets.Composite#Composite(Composite parent, int style) * @see #initialize() */ public StringValueListComposite(Composite parent, int style) { super(parent, style); this.initialize(); } /** * ??? * <p> * ?????????? * * @param parent ?? * @param style * @param tableDefine ?{@link com.clustercontrol.bean.TableColumnInfo}? * * @see org.eclipse.swt.SWT * @see org.eclipse.swt.widgets.Composite#Composite(Composite parent, int style) * @see com.clustercontrol.bean.TableColumnInfo#TableColumnInfo(java.lang.String, int, int, int) * @see com.clustercontrol.monitor.run.action.GetStringFilterTableDefine * @see #initialize() */ public StringValueListComposite(Composite parent, int style, ArrayList<TableColumnInfo> tableDefine) { super(parent, style); this.m_tableDefine = tableDefine; this.initialize(); } /** * ????? */ private void initialize() { GridLayout layout = new GridLayout(1, true); this.setLayout(layout); layout.marginHeight = 0; layout.marginWidth = 0; Table table = new Table(this, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); WidgetTestUtil.setTestId(this, null, table); table.setHeaderVisible(true); table.setLinesVisible(true); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; table.setLayoutData(gridData); // ?? this.m_tableViewer = new CommonTableViewer(table); this.m_tableViewer.createTableColumn(m_tableDefine, GetStringFilterTableDefine.ORDER_NO, GetStringFilterTableDefine.SORT_ORDER); this.m_tableViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { MonitorStringValueInfo info = getFilterItem(); if (info != null) { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); StringValueInfoCreateDialog dialog = new StringValueInfoCreateDialog(shell, info); if (dialog.open() == IDialogConstants.OK_ID) { Table table = getTableViewer().getTable(); WidgetTestUtil.setTestId(this, null, table); int selectIndex = table.getSelectionIndex(); m_stringValueInfoList.set(selectIndex, dialog.getInputData()); update(); table.setSelection(selectIndex); } } } }); } /** * ???????? * * @return */ public CommonTableViewer getTableViewer() { return this.m_tableViewer; } /** * ???????? * <p> * ?????????<code>null</code>??? * * @return ? */ public MonitorStringValueInfo getFilterItem() { StructuredSelection selection = (StructuredSelection) this.m_tableViewer.getSelection(); if (selection == null) { return null; } else { ArrayList<?> list = (ArrayList<?>) selection.getFirstElement(); return (MonitorStringValueInfo) m_stringValueInfoList.get((Integer) list.get(0) - 1); } } /** * ?????????? * * @param info ???? */ public void setInputData(MonitorInfo info) { if (info != null) { // m_stringValueInfoList = new ArrayList<MonitorStringValueInfo>(info.getStringValueInfo()); // update(); } } /** * ????<BR> * ??????? * * @see com.clustercontrol.monitor.run.util.StringValueInfoManager#get() * @see com.clustercontrol.monitor.run.viewer.StringValueListTableViewer */ @Override public void update() { // ArrayList<Object> listAll = new ArrayList<Object>(); int i = 1; for (MonitorStringValueInfo info : m_stringValueInfoList) { ArrayList<Object> list = new ArrayList<Object>(); // ? list.add(i); // ? list.add(info.isProcessType()); // ?? if (!info.isProcessType()) { // ??????? list.add(PriorityConstant.TYPE_NONE); } else { list.add(info.getPriority()); } // ?? list.add(info.getPattern()); // list.add(info.getDescription()); // / list.add(info.isValidFlg()); listAll.add(list); ++i; } m_tableViewer.setInput(listAll); } /** * ???????? * <p> * ???????????? * ????????<code>null</code>??? * * @param monitorInfo ? * @return ? * * @see #setValidateResult(String, String) */ public ValidateResult createInputData(MonitorInfo monitorInfo) { if (m_stringValueInfoList != null && m_stringValueInfoList.size() > 0) { String MonitorId = monitorInfo.getMonitorId(); for (int index = 0; index < m_stringValueInfoList.size(); index++) { MonitorStringValueInfo info = m_stringValueInfoList.get(index); info.setMonitorId(MonitorId); } List<MonitorStringValueInfo> monitorStringValueInfoList = monitorInfo.getStringValueInfo(); monitorStringValueInfoList.clear(); monitorStringValueInfoList.addAll(m_stringValueInfoList); } return null; } /* (? Javadoc) * @see org.eclipse.swt.widgets.Control#setEnabled(boolean) */ @Override public void setEnabled(boolean enabled) { this.m_tableViewer.getTable().setEnabled(enabled); } /** * ????? * * @param id ID * @param message * @return ?? */ protected ValidateResult setValidateResult(String id, String message) { ValidateResult validateResult = new ValidateResult(); validateResult.setValid(false); validateResult.setID(id); validateResult.setMessage(message); return validateResult; } /** * ????? * */ public Integer getSelection() { StructuredSelection selection = (StructuredSelection) m_tableViewer.getSelection(); if (selection.getFirstElement() instanceof ArrayList) { ArrayList<?> list = (ArrayList<?>) selection.getFirstElement(); if (list.get(0) instanceof Integer) { return (Integer) list.get(0); } } return null; } public void setSelection() { Table calDetailListSetSelectionTable = m_tableViewer.getTable(); WidgetTestUtil.setTestId(this, null, calDetailListSetSelectionTable); int selectIndex = calDetailListSetSelectionTable.getSelectionIndex(); update(); calDetailListSetSelectionTable.setSelection(selectIndex); } /** * ????????? * * @param identifier */ private void selectItem(Integer order) { Table stringValueListSelectItemTable = m_tableViewer.getTable(); WidgetTestUtil.setTestId(this, null, stringValueListSelectItemTable); TableItem[] items = stringValueListSelectItemTable.getItems(); if (items == null || order == null) { return; } stringValueListSelectItemTable.select(order); return; } /** * ??? */ public void up() { //????? Integer order = getSelection(); //??1?????-1? --order; if (order > 0) { MonitorStringValueInfo a = m_stringValueInfoList.get(order); MonitorStringValueInfo b = m_stringValueInfoList.get(order - 1); m_stringValueInfoList.set(order, b); m_stringValueInfoList.set(order - 1, a); } update(); //?????? selectItem(order - 1); } /** * ??? */ public void down() { //????? Integer order = getSelection(); //??1?????-1? --order; if (order < m_stringValueInfoList.size() - 1) { MonitorStringValueInfo a = m_stringValueInfoList.get(order); MonitorStringValueInfo b = m_stringValueInfoList.get(order + 1); m_stringValueInfoList.set(order, b); m_stringValueInfoList.set(order + 1, a); } update(); //?????? selectItem(order + 1); } public ArrayList<MonitorStringValueInfo> getMonitorStringValueInfoList() { return m_stringValueInfoList; } }