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.preference; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.FieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IntegerFieldEditor; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.IWorkbenchWindow; import com.clustercontrol.ClusterControlPlugin; import com.clustercontrol.bean.DataRangeConstant; import com.clustercontrol.monitor.view.EventView; import com.clustercontrol.monitor.view.ScopeView; import com.clustercontrol.monitor.view.StatusView; import com.clustercontrol.util.Messages; import com.clustercontrol.util.WidgetTestUtil; /** * ??<BR> * * @version 2.1.1 * @since 1.0.0 */ public class MonitorPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { /** []? */ public static final String P_SCOPE_UPDATE_FLG = "scopeUpdateFlg"; /** []? */ public static final String P_SCOPE_UPDATE_CYCLE = "scopeUpdateCycle"; /** []? */ public static final String P_STATUS_UPDATE_FLG = "statusUpdateFlg"; /** []? */ public static final String P_STATUS_UPDATE_CYCLE = "stateUpdateCycle"; /** []?? */ public static final String P_STATUS_NEW_STATE_FLG = "statusNewStateFlg"; /** []? */ public static final String P_EVENT_UPDATE_FLG = "eventUpdateFlg"; /** []? */ public static final String P_EVENT_UPDATE_CYCLE = "eventUpdateCycle"; /** []? */ public static final String P_EVENT_MESSAGE_FLG = "eventMessageFlg"; /** []? */ public static final String P_EVENT_MAX = "eventMaxMessages"; /** []?? */ public static final String P_EVENT_NEW_EVENT_FLG = "eventNewEventFlg"; /** SNMPTRAP[?]?trap_value_info? */ public static final String P_MAX_TRAP_OID = "maxTrapOid"; private static final String MSG_ENABLE = Messages.getString("autoupdate.enable"); private static final String MSG_CYCLE = Messages.getString("autoupdate.cycle") + " : "; private static final String MSG_MESSAGE = Messages.getString("over.limit.message"); private static final String MSG_MAX_EVENTS = Messages.getString("number.of.display.events") + " : "; private static final String MSG_MAX_TRAP_OIDS = Messages.getString("number.of.display.trap.oids") + " : "; private static final String MSG_NEW_STATUS_MESSAGE = Messages.getString("new.status.message"); private static final String MSG_NEW_EVENT_MESSAGE = Messages.getString("new.event.message"); public MonitorPreferencePage() { super(GRID); } /** * ? * * @param workbench ? */ @Override public void init(IWorkbench workbench) { setPreferenceStore(ClusterControlPlugin.getDefault().getPreferenceStore()); } /** * ???? */ @Override public void createFieldEditors() { Composite parent = this.getFieldEditorParent(); GridData gridData = null; // Group scopeGroup = new Group(parent, SWT.SHADOW_NONE); WidgetTestUtil.setTestId(this, "scope", scopeGroup); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 10; gridData.verticalSpan = 10; scopeGroup.setLayoutData(gridData); scopeGroup.setText(Messages.getString("view.monitor.scope")); // this.addField(new BooleanFieldEditor(P_SCOPE_UPDATE_FLG, MSG_ENABLE, scopeGroup)); // IntegerFieldEditor scopeCycle = new IntegerFieldEditor(P_SCOPE_UPDATE_CYCLE, MSG_CYCLE, scopeGroup); scopeCycle.setValidRange(1, DataRangeConstant.SMALLINT_HIGH); String[] args = { Integer.toString(1), Integer.toString(DataRangeConstant.SMALLINT_HIGH) }; scopeCycle.setErrorMessage(Messages.getString("message.hinemos.8", args)); this.addField(scopeCycle); // Group statusGroup = new Group(parent, SWT.SHADOW_NONE); WidgetTestUtil.setTestId(this, "status", statusGroup); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 10; gridData.verticalSpan = 10; statusGroup.setLayoutData(gridData); statusGroup.setText(Messages.getString("view.monitor.status")); // this.addField(new BooleanFieldEditor(P_STATUS_UPDATE_FLG, MSG_ENABLE, statusGroup)); // IntegerFieldEditor statusCycle = new IntegerFieldEditor(P_STATUS_UPDATE_CYCLE, MSG_CYCLE, statusGroup); statusCycle.setValidRange(1, DataRangeConstant.SMALLINT_HIGH); statusCycle.setErrorMessage(Messages.getString("message.hinemos.8", args)); this.addField(statusCycle); // ?? this.addField(new BooleanFieldEditor(P_STATUS_NEW_STATE_FLG, MSG_NEW_STATUS_MESSAGE, statusGroup)); // ??????? this.addField(new DummyFieldEditor(statusGroup)); // Group eventGroup = new Group(parent, SWT.SHADOW_NONE); WidgetTestUtil.setTestId(this, "event", eventGroup); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 10; gridData.verticalSpan = 10; eventGroup.setLayoutData(gridData); eventGroup.setText(Messages.getString("view.monitor.event")); // this.addField(new BooleanFieldEditor(P_EVENT_UPDATE_FLG, MSG_ENABLE, eventGroup)); // IntegerFieldEditor eventCycle = new IntegerFieldEditor(P_EVENT_UPDATE_CYCLE, MSG_CYCLE, eventGroup); eventCycle.setValidRange(1, DataRangeConstant.SMALLINT_HIGH); eventCycle.setErrorMessage(Messages.getString("message.hinemos.8", args)); this.addField(eventCycle); // ?? this.addField(new BooleanFieldEditor(P_EVENT_NEW_EVENT_FLG, MSG_NEW_EVENT_MESSAGE, eventGroup)); // this.addField(new BooleanFieldEditor(P_EVENT_MESSAGE_FLG, MSG_MESSAGE, eventGroup)); // IntegerFieldEditor eventMax = new IntegerFieldEditor(P_EVENT_MAX, MSG_MAX_EVENTS, eventGroup); eventMax.setValidRange(1, DataRangeConstant.MONITOR_EVENT_MAX); String[] argsEvent = { Integer.toString(1), Integer.toString(DataRangeConstant.MONITOR_EVENT_MAX) }; eventMax.setErrorMessage(Messages.getString("message.hinemos.8", argsEvent)); this.addField(eventMax); // SNMPTRAP Group trapGroup = new Group(parent, SWT.SHADOW_NONE); WidgetTestUtil.setTestId(this, "trap", trapGroup); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 10; gridData.verticalSpan = 10; trapGroup.setLayoutData(gridData); trapGroup.setText(Messages.getString("view.monitor.trap")); // TrapValueInfo IntegerFieldEditor maxTrapOid = new IntegerFieldEditor(P_MAX_TRAP_OID, MSG_MAX_TRAP_OIDS, trapGroup); maxTrapOid.setValidRange(1, DataRangeConstant.MONITOR_TRAP_OID_MAX); String[] argsTrap = { Integer.toString(1), Integer.toString(DataRangeConstant.MONITOR_TRAP_OID_MAX) }; maxTrapOid.setErrorMessage(Messages.getString("message.hinemos.8", argsTrap)); this.addField(maxTrapOid); } /** * ??????? * * @see org.eclipse.jface.preference.IPreferencePage#performOk() */ @Override public boolean performOk() { boolean result = super.performOk(); this.applySetting(); return result; } /** * ????? */ private void applySetting() { IPreferenceStore store = this.getPreferenceStore(); // ????? IWorkbench workbench = ClusterControlPlugin.getDefault().getWorkbench(); IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); int windowCount = windows.length; for (int i = 0; i < windowCount; i++) { IWorkbenchPage[] pages = windows[i].getPages(); int pageCount = pages.length; for (int j = 0; j < pageCount; j++) { ScopeView scopeView = (ScopeView) pages[j].findView(ScopeView.ID); if (scopeView != null) { int cycle = store.getInt(P_SCOPE_UPDATE_CYCLE); scopeView.setInterval(cycle); if (store.getBoolean(P_SCOPE_UPDATE_FLG)) { scopeView.startAutoReload(); } else { scopeView.stopAutoReload(); } } StatusView statusView = (StatusView) pages[j].findView(StatusView.ID); if (statusView != null) { int cycle = store.getInt(P_STATUS_UPDATE_CYCLE); statusView.setInterval(cycle); if (store.getBoolean(P_STATUS_UPDATE_FLG)) { statusView.startAutoReload(); } else { statusView.stopAutoReload(); } } EventView eventView = (EventView) pages[j].findView(EventView.ID); if (eventView != null) { int cycle = store.getInt(P_EVENT_UPDATE_CYCLE); eventView.setInterval(cycle); if (store.getBoolean(P_EVENT_UPDATE_FLG)) { eventView.startAutoReload(); } else { eventView.stopAutoReload(); } } } } } /** * ????<BR> * */ static class DummyFieldEditor extends FieldEditor { private DummyFieldEditor(Composite parent) { super("Dummy", "", parent); } @Override protected void adjustForNumColumns(int numColumns) { // } @Override protected void doFillIntoGrid(Composite parent, int numColumns) { // } @Override protected void doLoad() { // } @Override protected void doLoadDefault() { // } @Override protected void doStore() { // } @Override public int getNumberOfControls() { // ????2?? return 2; } } }