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.view; import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.ISelection; 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.Menu; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.ICommandService; import com.clustercontrol.ClusterControlPlugin; import com.clustercontrol.bean.Property; import com.clustercontrol.monitor.bean.ConfirmConstant; import com.clustercontrol.monitor.composite.EventListComposite; import com.clustercontrol.monitor.composite.action.EventListSelectionChangedListener; import com.clustercontrol.monitor.preference.MonitorPreferencePage; import com.clustercontrol.monitor.view.action.EventCollectGraphOffAction; import com.clustercontrol.monitor.view.action.EventCollectGraphOnAction; import com.clustercontrol.monitor.view.action.EventConfirmAction; import com.clustercontrol.monitor.view.action.EventDetailAction; import com.clustercontrol.monitor.view.action.EventModifyMonitorSettingAction; import com.clustercontrol.monitor.view.action.EventOpenJobHistoryAction; import com.clustercontrol.monitor.view.action.EventUnconfirmAction; import com.clustercontrol.repository.FacilityPath; import com.clustercontrol.repository.bean.FacilityConstant; import com.clustercontrol.repository.util.ScopePropertyUtil; import com.clustercontrol.util.EndpointManager; import com.clustercontrol.util.Messages; import com.clustercontrol.util.WidgetTestUtil; import com.clustercontrol.view.ScopeListBaseView; import com.clustercontrol.ws.repository.FacilityInfo; import com.clustercontrol.ws.repository.FacilityTreeItem; /** * []<BR> * * @version 5.0.0 * @since 1.0.0 */ public class EventView extends ScopeListBaseView { private static Log m_log = LogFactory.getLog(EventView.class); /** []ID */ public static final String ID = EventView.class.getName(); /** ? */ private EventListComposite tableComposite = null; /** ? */ private Property condition = null; /** ?/?? */ private int confirmType = ConfirmConstant.TYPE_UNCONFIRMED; /** ID */ private String pluginId; protected String getViewName() { return this.getClass().getName(); } /** * ???? * <p> * <ol> * <li>????</li> * <li>??????</li> * <li>???</li> * <li>??[]??????????</li> * <li>??[]??????????</li> * <li>???</li> * </ol> * * @param parent ?? * @return ? * * @see com.clustercontrol.monitor.composite.EventListComposite#EventListComposite(Composite, int) * @see #createContextMenu() * @see #update() */ @Override protected Composite createListContents(Composite parent) { GridLayout layout = new GridLayout(1, true); parent.setLayout(layout); layout.marginHeight = 0; layout.marginWidth = 0; this.tableComposite = new EventListComposite(parent, SWT.NONE); WidgetTestUtil.setTestId(this, null, tableComposite); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; this.tableComposite.setLayoutData(gridData); //?? createContextMenu(); // ?? IPreferenceStore store = ClusterControlPlugin.getDefault().getPreferenceStore(); this.setInterval(store.getInt(MonitorPreferencePage.P_EVENT_UPDATE_CYCLE)); if (store.getBoolean(MonitorPreferencePage.P_EVENT_UPDATE_FLG)) { this.startAutoReload(); } // ? this.tableComposite.getTableViewer().addSelectionChangedListener(new EventListSelectionChangedListener()); return this.tableComposite; } /** * ?????????? * * @param item * * @see #update() */ @Override protected void doSelectTreeItem(FacilityTreeItem item) { this.update(false); } /** * ????? */ private void createContextMenu() { MenuManager menuManager = new MenuManager(); menuManager.setRemoveAllWhenShown(true); Menu menu = menuManager.createContextMenu(tableComposite.getTable()); WidgetTestUtil.setTestId(this, null, menu); tableComposite.getTable().setMenu(menu); getSite().registerContextMenu(menuManager, this.tableComposite.getTableViewer()); } /** * ???<BR> * <p> * <ol> * <li>?????????</li> * <li>?ID????</li> * <li>ID????? * ??<code>null</code>???????????</li> * </ol> * * @see com.clustercontrol.composite.FacilityTreeComposite#getSelectItem() * @see com.clustercontrol.bean.FacilityInfo#getFacilityId() * @see com.clustercontrol.monitor.composite.EventListComposite#update(String) * @see com.clustercontrol.monitor.composite.EventListComposite#update(String, Property) */ @Override public void update(boolean refreshFlag) { @SuppressWarnings("unchecked") List<FacilityTreeItem> itemList = (List<FacilityTreeItem>) getScopeTreeComposite().getSelectionList(); FacilityTreeItem top = (FacilityTreeItem) getScopeTreeComposite().getTree().getItem(0).getData(); // ????????????????? if (itemList == null || itemList.size() == 0) { itemList = new ArrayList<FacilityTreeItem>(); itemList.add(top); } int type = 0; String label = null; // Select root if nothing selected tableComposite.resetDisp(); for (FacilityTreeItem item : itemList) { List<String> managerList = new ArrayList<String>(); String facilityId = null; if (item == null && 0 < getScopeTreeComposite().getTree().getItemCount()) { item = top; } if (item != null) { FacilityInfo itemData = item.getData(); if (itemData.getFacilityType() == FacilityConstant.TYPE_COMPOSITE) { type = FacilityConstant.TYPE_COMPOSITE; managerList = EndpointManager.getActiveManagerNameList(); } else if (itemData.getFacilityType() == FacilityConstant.TYPE_MANAGER) { String managerName = itemData.getFacilityId(); type = FacilityConstant.TYPE_MANAGER; managerList.add(managerName); } else { type = FacilityConstant.TYPE_SCOPE; facilityId = item.getData().getFacilityId(); FacilityTreeItem manager = ScopePropertyUtil.getManager(item); String managerName = manager.getData().getFacilityId(); managerList.add(managerName); } } m_log.debug("update " + facilityId); if (this.condition == null) { // ????????? if (label == null) { label = Messages.getString("scope") + ": "; } if (facilityId != null) { FacilityPath path = new FacilityPath(ClusterControlPlugin.getDefault().getSeparator()); label += path.getPath(item) + " "; } if (type == FacilityConstant.TYPE_COMPOSITE) { //???? tableComposite.setDisp(null, null, managerList); } else if (type == FacilityConstant.TYPE_MANAGER) { //????? tableComposite.setDisp(null, null, managerList); } else { //?? tableComposite.setDisp(facilityId, null, managerList); } } else { if (label == null) { label = Messages.getString("filtered.list") + ": "; } if (facilityId != null) { FacilityPath path = new FacilityPath(ClusterControlPlugin.getDefault().getSeparator()); label += path.getPath(item) + " "; } tableComposite.setDisp(facilityId, this.condition, managerList); } } tableComposite.updateDisp(refreshFlag); m_log.debug("update() : label=" + label + ", " + tableComposite.getLabel()); if (label == null) { setPathLabel(""); } else { setPathLabel(label + ", " + tableComposite.getLabel()); } } /** * ???? * <p>?<code>update</code>??????????? * * @param condition ? */ public void setCondition(Property condition) { this.condition = condition; } /** * ?????? */ @Override public void dispose() { super.dispose(); this.setCondition(null); } public void initButton() { setEnabledAction(ConfirmConstant.TYPE_ALL, null, null); } public int getConfirmType() { return this.confirmType; } public String getPluginId() { return this.pluginId; } /** * ??/??? * * @param confirmType ?/?? * @param pluginId ID * @param selection ????? * * @see com.clustercontrol.bean.FacilityConstant */ public void setEnabledAction(int confirmType, String pluginId, ISelection selection) { this.confirmType = confirmType; this.pluginId = pluginId; //??/?? ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); if (null != service) { service.refreshElements(EventConfirmAction.ID, null); service.refreshElements(EventUnconfirmAction.ID, null); service.refreshElements(EventDetailAction.ID, null); service.refreshElements(EventModifyMonitorSettingAction.ID, null); service.refreshElements(EventOpenJobHistoryAction.ID, null); service.refreshElements(EventCollectGraphOnAction.ID, null); service.refreshElements(EventCollectGraphOffAction.ID, null); // Update ToolBar after elements refreshed // WARN : Both ToolBarManager must be updated after updateActionBars(), otherwise icon won't change. getViewSite().getActionBars().updateActionBars(); getViewSite().getActionBars().getToolBarManager().update(false); } } }