Example usage for org.eclipse.jface.viewers StructuredSelection toList

List of usage examples for org.eclipse.jface.viewers StructuredSelection toList

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection toList.

Prototype

@Override
    public List toList() 

Source Link

Usage

From source file:com.clustercontrol.hub.view.LogSearchView.java

License:Open Source License

public List<String> getSelectedIdList() {
    StructuredSelection selection = (StructuredSelection) this.logSearchComposite.getTableViewer()
            .getSelection();/*from w  w  w.j  a v a 2  s  .co  m*/

    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;
}

From source file:com.clustercontrol.hub.view.LogSearchView.java

License:Open Source License

public List<String> getSelectedManagerNameList() {
    StructuredSelection selection = (StructuredSelection) this.logSearchComposite.getTableViewer()
            .getSelection();//from  w w  w.  j av  a  2s  . c  om

    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;
}

From source file:com.clustercontrol.hub.view.LogSearchView.java

License:Open Source License

public List<String> getSelectedItem() {
    StructuredSelection selection = (StructuredSelection) this.logSearchComposite.getTableViewer()
            .getSelection();/* w  w  w .  j  a v  a  2  s.c o  m*/

    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;
}

From source file:com.clustercontrol.hub.view.TransferView.java

License:Open Source License

public List<String> getSelectedIdList() {
    StructuredSelection selection = (StructuredSelection) this.transferComposite.getTableViewer()
            .getSelection();/*from w  w  w.j av  a 2  s .c o m*/

    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;
}

From source file:com.clustercontrol.hub.view.TransferView.java

License:Open Source License

public List<String> getSelectedManagerNameList() {
    StructuredSelection selection = (StructuredSelection) this.transferComposite.getTableViewer()
            .getSelection();//from  ww w . j a  va  2  s  .  c om

    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;
}

From source file:com.clustercontrol.hub.view.TransferView.java

License:Open Source License

public Map<String, List<String>> getSelectedItem() {
    StructuredSelection selection = (StructuredSelection) this.transferComposite.getTableViewer()
            .getSelection();//from   w ww .  j ava  2s .c o m

    List<?> list = (List<?>) selection.toList();

    String transferId = null;
    String managerName = null;
    Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>();
    if (list != null) {
        for (Object obj : list) {
            List<?> objList = (List<?>) obj;
            managerName = (String) objList.get(GetTransferTableDefine.MANAGER_NAME);
            if (map.get(managerName) == null) {
                map.put(managerName, new ArrayList<String>());
            }
        }
        for (Object obj : list) {
            List<?> objList = (List<?>) obj;
            transferId = (String) objList.get(GetTransferTableDefine.TRANSFER_ID);
            managerName = (String) objList.get(GetTransferTableDefine.MANAGER_NAME);

            map.get(managerName).add(transferId);
        }
    }
    return map;
}

From source file:com.clustercontrol.infra.util.InfraFileUtil.java

License:Open Source License

public static String getManagerName(StructuredSelection selection) {
    if (selection == null) {
        return null;
    }//  w  w w  .  j a  v  a2  s  .  co m

    @SuppressWarnings("unchecked")
    List<String> itemList = (List<String>) selection.toList().get(0);
    return itemList.get(GetInfraFileManagerTableDefine.MANAGER_NAME);
}

From source file:com.clustercontrol.infra.util.InfraFileUtil.java

License:Open Source License

public static InfraFileInfo getSelectedInfraFileInfo(StructuredSelection selection) {
    if (selection == null) {
        return null;
    }//from w  w w. j  a  v  a  2  s  .c  om

    InfraFileInfo info = new InfraFileInfo();

    @SuppressWarnings("unchecked")
    List<String> itemList = (List<String>) selection.toList().get(0);
    info.setFileId(itemList.get(GetInfraFileManagerTableDefine.FILE_ID));
    info.setFileName(itemList.get(GetInfraFileManagerTableDefine.FILE_NAME));
    info.setOwnerRoleId(itemList.get(GetInfraFileManagerTableDefine.OWNER_ROLE));

    return info;
}

From source file:com.clustercontrol.infra.view.action.CheckInfraManagementAction.java

License:Open Source License

/**
 * ?????????????/*from  ww  w .j a  v  a  2  s .co m*/
 *
 * @param view ?
 *
 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
 */

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    this.window = HandlerUtil.getActiveWorkbenchWindow(event);
    // In case this action has been disposed
    if (null == this.window || !isEnabled()) {
        return null;
    }

    // ???
    this.viewPart = HandlerUtil.getActivePart(event);
    if (!(viewPart instanceof InfraManagementView)) {
        return null;
    }

    InfraManagementView infraManagementView = null;
    try {
        infraManagementView = (InfraManagementView) viewPart.getAdapter(InfraManagementView.class);
    } catch (Exception e) {
        m_log.info("execute " + e.getMessage());
        return null;
    }

    if (infraManagementView == null) {
        m_log.info("execute: view is null");
        return null;
    }

    StructuredSelection selection = null;
    if (!(infraManagementView.getComposite().getTableViewer().getSelection() instanceof StructuredSelection)) {
        return null;
    }
    selection = (StructuredSelection) infraManagementView.getComposite().getTableViewer().getSelection();
    if (selection == null) {
        return null;
    }

    List<?> sList = (List<?>) selection.toList();
    Map<String, List<String>> managementIdMap = new ConcurrentHashMap<String, List<String>>();

    for (Object obj : sList) {
        List<?> list = (List<?>) obj;
        String managerName = null;
        if (list == null) {
            continue;
        }
        managerName = (String) list.get(GetInfraManagementTableDefine.MANAGER_NAME);
        if (managementIdMap.get(managerName) == null) {
            managementIdMap.put(managerName, new ArrayList<String>());
        }
    }

    for (Object obj : sList) {
        List<?> list = (List<?>) obj;
        String managementId = null;
        String managerName = null;
        if (list != null) {
            managementId = (String) list.get(GetInfraManagementTableDefine.MANAGEMENT_ID);
            managerName = (String) list.get(GetInfraManagementTableDefine.MANAGER_NAME);
            managementIdMap.get(managerName).add(managementId);
        }
    }

    Map<String, List<InfraManagementInfo>> managementMap = new ConcurrentHashMap<String, List<InfraManagementInfo>>();
    Map<String, String> errorMsgs = new ConcurrentHashMap<>();
    StringBuffer idbuf = new StringBuffer();
    int size = 0;
    for (Map.Entry<String, List<String>> entry : managementIdMap.entrySet()) {
        String managerName = entry.getKey();
        if (managementMap.get(managerName) == null) {
            managementMap.put(managerName, new ArrayList<InfraManagementInfo>());
        }
        for (String managementId : entry.getValue()) {
            try {
                InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName);
                InfraManagementInfo management = wrapper.getInfraManagement(managementId);
                managementMap.get(managerName).add(management);
                if (size > 0) {
                    idbuf.append(", ");
                }
                idbuf.append(managementId);

            } catch (InvalidRole_Exception e) {
                // ???
                errorMsgs.put(managerName, Messages.getString("message.accesscontrol.16"));
            } catch (HinemosUnknown_Exception | InvalidUserPass_Exception | NotifyNotFound_Exception
                    | InfraManagementNotFound_Exception e) {
                m_log.error("execute() : " + e.getClass().getName() + ", " + e.getMessage());
                Object[] arg = new Object[] { Messages.getString("infra.module.id"),
                        Messages.getString("infra.module.check"), Messages.getString("failed"),
                        HinemosMessage.replace(e.getMessage()) };
                errorMsgs.put(managerName, Messages.getString("message.infra.action.result", arg));
            }
            size++;
        }
    }

    //
    if (0 < errorMsgs.size()) {
        UIManager.showMessageBox(errorMsgs, true);
        return null;
    }

    boolean allRun = false;
    RunDialog dialog = new RunDialog(null,
            Messages.getString("message.infra.confirm.action",
                    new Object[] { Messages.getString("infra.management.id"),
                            Messages.getString("infra.module.check"), idbuf.toString() }));
    if (dialog.open() == IDialogConstants.CANCEL_ID) {
        return null;
    }
    allRun = dialog.isAllRun();

    errorMsgs = new ConcurrentHashMap<>();
    for (Map.Entry<String, List<InfraManagementInfo>> entry : managementMap.entrySet()) {
        String managerName = entry.getKey();
        for (InfraManagementInfo management : entry.getValue()) {
            List<AccessInfo> accessInfoList = AccessUtil.getAccessInfoList(viewPart.getSite().getShell(),
                    management.getFacilityId(), management.getOwnerRoleId(), managerName,
                    infraManagementView.isUseNodeProp());
            // ?????????null?????
            // ???????
            if (accessInfoList == null) {
                continue;
            }
            List<String> moduleIdList = new ArrayList<String>();
            for (InfraModuleInfo info : management.getModuleList()) {
                moduleIdList.add(info.getModuleId());
            }
            String managementId = management.getManagementId();

            try {
                InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName);
                String sessionId = wrapper.createSession(managementId, moduleIdList, accessInfoList);

                while (true) {
                    ModuleResult moduleResult = wrapper.checkInfraModule(sessionId, !allRun);
                    if (!allRun && !ModuleUtil.displayResult(moduleResult.getModuleId(), moduleResult)) {
                        break;
                    }
                    if (!moduleResult.isHasNext()) {
                        break;
                    }
                }
                wrapper.deleteSession(sessionId);
                MessageDialog.openInformation(null, Messages.getString("message"),
                        Messages.getString("message.infra.management.check.end"));
            } catch (InvalidRole_Exception e) {
                // ???
                errorMsgs.put(managerName, Messages.getString("message.accesscontrol.16"));
                continue;
            } catch (HinemosUnknown_Exception | InvalidUserPass_Exception | InfraManagementNotFound_Exception
                    | InfraModuleNotFound_Exception | SessionNotFound_Exception | FacilityNotFound_Exception
                    | InvalidSetting_Exception e) {
                m_log.error("execute() :  " + e.getClass().getName() + ", " + e.getMessage());
                Object[] arg = new Object[] { Messages.getString("infra.module.id"),
                        Messages.getString("infra.module.check"), Messages.getString("failed"),
                        HinemosMessage.replace(e.getMessage()) };
                errorMsgs.put(managerName, Messages.getString("message.infra.action.result", arg));
                continue;
            } catch (Exception e) {
                m_log.error("execute() :  " + e.getClass().getName() + ", " + e.getMessage());
                Object[] arg = new Object[] { Messages.getString("infra.module.id"),
                        Messages.getString("infra.module.check"), Messages.getString("failed"),
                        HinemosMessage.replace(e.getMessage()) };
                errorMsgs.put(managerName, Messages.getString("message.infra.action.result", arg));
                continue;
            }
        }
    }

    //
    if (0 < errorMsgs.size()) {
        UIManager.showMessageBox(errorMsgs, true);
    }

    infraManagementView.update();
    return null;
}

From source file:com.clustercontrol.infra.view.action.DeleteInfraFileAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    InfraFileManagerView view = getView(event);
    if (view == null) {
        m_log.info("execute: view is null");
        return null;
    }/*  w w  w  .jav  a2 s  .c  om*/

    List<String> fileIdList = getSelectedInfraFileIdList(view);
    if (fileIdList.isEmpty()) {
        return null;
    }

    StructuredSelection selection = null;
    if (view.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) {
        selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection();
    }
    if (selection == null || selection.isEmpty()) {
        return null;
    }
    Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>();
    for (Object object : selection.toList()) {
        String managerName = (String) ((ArrayList<?>) object).get(GetInfraFileManagerTableDefine.MANAGER_NAME);
        if (map.get(managerName) == null) {
            map.put(managerName, new ArrayList<String>());
        }
    }

    StringBuffer strFileIds = new StringBuffer();
    String tmpFileId = null;
    for (Object object : selection.toList()) {
        String managerName = (String) ((ArrayList<?>) object).get(GetInfraFileManagerTableDefine.MANAGER_NAME);
        tmpFileId = (String) ((ArrayList<?>) object).get(GetInfraFileManagerTableDefine.FILE_ID);
        map.get(managerName).add(tmpFileId);
        if (strFileIds.length() == 0) {
            strFileIds.append(tmpFileId);
        } else {
            strFileIds.append(", " + tmpFileId);
        }
    }

    if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.infra.confirm.action",
                    new Object[] { Messages.getString("file"), Messages.getString("delete"), strFileIds }))) {

        Map<String, String> errMsg = new ConcurrentHashMap<String, String>();
        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
            String managerName = entry.getKey();
            InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName);
            try {
                wrapper.deleteInfraFileList(entry.getValue());
            } catch (Exception e) {
                m_log.error(e);
                errMsg.put(managerName, HinemosMessage.replace(e.getMessage()));
            }
        }

        if (errMsg.isEmpty()) {
            String action = Messages.getString("delete");
            InfraFileUtil.showSuccessDialog(action, strFileIds.toString());
        } else {
            UIManager.showMessageBox(errMsg, true);
        }
        // ?
        view.update();
    }

    return null;
}