Java tutorial
/* Copyright (C) 2016 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.hub.view; import java.util.ArrayList; import java.util.List; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.ICommandService; import com.clustercontrol.accesscontrol.util.ObjectBean; import com.clustercontrol.bean.HinemosModuleConstant; import com.clustercontrol.hub.action.GetLogSearchResultTableDefine; import com.clustercontrol.hub.action.GetTransferTableDefine; import com.clustercontrol.hub.composite.LogSearchComposite; import com.clustercontrol.util.Messages; import com.clustercontrol.util.WidgetTestUtil; import com.clustercontrol.view.CommonViewPart; import com.clustercontrol.view.ObjectPrivilegeTargetListView; /** * ??[]<BR> * */ public class LogSearchView extends CommonViewPart implements ObjectPrivilegeTargetListView { public static final String ID = LogSearchView.class.getName(); public static final String SECONDARYID_SEPARATOR = ",node="; private LogSearchComposite logSearchComposite = null; /** * Number of selected items */ private int selectedNum; /** * <BR><B>?????</B></BR> * ??[]?? * LogSearchView.createSearchView????? */ @Deprecated public LogSearchView() { super(); } /** * ???? * <BR><B>??????????</B></BR> * secondaryId????@ID ??? * @param page * @param manager * @param facilityid * @return * @throws PartInitException * * FIXME * ?????????????? * ?? -^\@[;:],./\=~|`{+*}<>?_!"#$%&'() * ? ?????? * ?????????????????? * ??",node="?? */ public static LogSearchView createSearchView(IWorkbenchPage page, String manager, String facilityid) throws PartInitException { //ID???????????? String managerRep = manager.replaceAll(":", "@"); //????ID???ID?? String secondaryId = managerRep + SECONDARYID_SEPARATOR + facilityid; return (LogSearchView) page.showView(LogSearchView.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE); } /** * ViewPart????<BR> * * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ @Override public void createPartControl(Composite parent) { logSearchComposite = new LogSearchComposite(parent, SWT.NONE); WidgetTestUtil.setTestId(this, null, logSearchComposite); /* * ??[]??FacilityID?? */ if (this.getViewSite().getSecondaryId() != null) { String title = this.getViewSite().getSecondaryId(); //getSecondaryId??????ID?????????????? String[] spltStr = title.split(SECONDARYID_SEPARATOR); String manager = spltStr[0]; String facilityId = spltStr[1]; // this.setPartName(Messages.getString("view.hub.search", new Object[] { manager, facilityId })); logSearchComposite.setManager(manager); logSearchComposite.setFacilityId(facilityId); logSearchComposite.updateMonitorCombo(); } //?? //TODO createContextMenu(); // this.update(); } /** * ??[]<BR> */ @Override public void update() { logSearchComposite.update(); } public LogSearchComposite getLogTransferComposite() { return logSearchComposite; } public List<String> getSelectedIdList() { StructuredSelection selection = (StructuredSelection) this.logSearchComposite.getTableViewer() .getSelection(); List<?> list = (List<?>) selection.toList(); String id = null; List<String> idList = new ArrayList<String>(); if (list != null) { for (Object obj : list) { @SuppressWarnings("unchecked") List<String> objList = (List<String>) obj; id = objList.get(GetTransferTableDefine.TRANSFER_ID); idList.add(id); } } return idList; } public List<String> getSelectedManagerNameList() { StructuredSelection selection = (StructuredSelection) this.logSearchComposite.getTableViewer() .getSelection(); List<?> list = (List<?>) selection.toList(); String managerName = null; List<String> managerList = new ArrayList<String>(); if (list != null) { for (Object obj : list) { @SuppressWarnings("unchecked") List<String> objList = (List<String>) obj; managerName = objList.get(GetTransferTableDefine.MANAGER_NAME); managerList.add(managerName); } } return managerList; } @Override public List<ObjectBean> getSelectedObjectBeans() { StructuredSelection selection = (StructuredSelection) this.logSearchComposite.getTableViewer() .getSelection(); Object[] objs = selection.toArray(); String managerName = null; String objectType = HinemosModuleConstant.HUB_TRANSFER; String objectId = null; List<ObjectBean> objectBeans = new ArrayList<ObjectBean>(); for (Object obj : objs) { managerName = (String) ((List<?>) obj).get(GetTransferTableDefine.MANAGER_NAME); objectId = (String) ((List<?>) obj).get(GetTransferTableDefine.TRANSFER_ID); ObjectBean objectBean = new ObjectBean(managerName, objectType, objectId); objectBeans.add(objectBean); } return objectBeans; } @Override public String getSelectedOwnerRoleId() { StructuredSelection selection = (StructuredSelection) this.logSearchComposite.getTableViewer() .getSelection(); List<?> list = (List<?>) selection.getFirstElement(); String id = null; if (list != null) { id = (String) list.get(GetTransferTableDefine.OWNER_ROLE); } return id; } /** * Get the number of selected items * @return */ public int getSelectedNum() { return this.selectedNum; } @Override protected String getViewName() { return this.getClass().getName(); } public List<String> getSelectedItem() { StructuredSelection selection = (StructuredSelection) this.logSearchComposite.getTableViewer() .getSelection(); List<?> list = (List<?>) selection.toList(); String orgMsg = null; List<String> orgMsgList = new ArrayList<String>(); if (list != null) { for (Object obj : list) { List<?> objList = (List<?>) obj; orgMsg = (String) objList.get(GetLogSearchResultTableDefine.ORG_MESSAGE); orgMsgList.add(orgMsg); } } return orgMsgList; } /** * ??/??? * * @param num ? * @param selection ????? */ public void setEnabledAction(int num, ISelection selection) { this.selectedNum = num; //??/?? ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); if (null != service) { // 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); } } }