Example usage for org.eclipse.jface.dialogs MessageDialog openConfirm

List of usage examples for org.eclipse.jface.dialogs MessageDialog openConfirm

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog openConfirm.

Prototype

public static boolean openConfirm(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a simple confirm (OK/Cancel) dialog.

Usage

From source file:com.clustercontrol.hub.view.action.LogTransferDisableAction.java

License:Open Source License

@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;
    }/*from   w w  w. java 2 s . co m*/

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

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

    StructuredSelection selection = null;
    if (logTransferView.getLogTransferComposite().getTableViewer()
            .getSelection() instanceof StructuredSelection) {
        selection = (StructuredSelection) logTransferView.getLogTransferComposite().getTableViewer()
                .getSelection();
    }

    if (selection == null) {
        return null;
    }

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

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

    StringBuffer idbuf = new StringBuffer();
    int size = 0;
    for (Object obj : sList) {
        List<?> list = (List<?>) obj;
        String transferId = null;
        String managerName = null;
        if (list != null) {
            transferId = (String) list.get(GetTransferTableDefine.TRANSFER_ID);
            managerName = (String) list.get(GetTransferTableDefine.MANAGER_NAME);
            transferIdMap.get(managerName).add(transferId);
            if (size > 0) {
                idbuf.append(", ");
            }
            idbuf.append(transferId);
            size++;
        }
    }

    if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.hub.log.transfer.confirm.action",
                    new Object[] { Messages.getString("hub.log.transfer.id"),
                            Messages.getString("hub.log.transfer.disable.setting"),
                            idbuf.toString() })) == false) {
        return null;
    }

    StringBuffer sucTransferIds = new StringBuffer();
    StringBuffer failTransferIds = new StringBuffer();

    for (Map.Entry<String, List<String>> entry : transferIdMap.entrySet()) {
        String managerName = entry.getKey();
        HubEndpointWrapper wrapper = HubEndpointWrapper.getWrapper(managerName);
        for (String transferId : entry.getValue()) {
            try {
                TransferInfo info = wrapper.getTransferInfo(transferId);
                info.setValidFlg(false);
                try {
                    wrapper.modifyTransferInfo(info);
                    sucTransferIds.append(transferId + "(" + managerName + "), ");
                } catch (InvalidRole_Exception | InvalidUserPass_Exception | InvalidSetting_Exception
                        | LogTransferNotFound_Exception e) {
                    m_log.debug("execute modifyLogTransfer, " + e.getMessage());
                    failTransferIds.append(transferId + ", ");
                }
            } catch (HinemosUnknown_Exception | InvalidRole_Exception | InvalidUserPass_Exception e) {
                m_log.debug("execute getLogTransfer, " + e.getMessage());
                failTransferIds.append(transferId + ", ");
            }
        }
    }

    //?????
    if (sucTransferIds.length() > 0) {
        sucTransferIds.setLength(sucTransferIds.length() - 2);
        MessageDialog.openInformation(null, Messages.getString("successful"),
                Messages.getString("message.hub.log.transfer.action.result",
                        new Object[] { Messages.getString("hub.log.transfer.id"),
                                Messages.getString("hub.log.transfer.disable.setting"),
                                Messages.getString("successful"), sucTransferIds }));
    }
    //????
    if (failTransferIds.length() > 0) {
        failTransferIds.setLength(failTransferIds.length() - 2);
        MessageDialog.openError(null, Messages.getString("failed"),
                Messages.getString("message.hub.log.transfer.action.result",
                        new Object[] { Messages.getString("hub.log.transfer.id"),
                                Messages.getString("hub.log.transfer.disable.setting"),
                                Messages.getString("failed"), failTransferIds }));
    }
    logTransferView.update();
    return null;
}

From source file:com.clustercontrol.hub.view.action.LogTransferEnableAction.java

License:Open Source License

@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;
    }/* ww  w .ja v a2 s .com*/

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

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

    StructuredSelection selection = null;
    if (logTransfarView.getLogTransferComposite().getTableViewer()
            .getSelection() instanceof StructuredSelection) {
        selection = (StructuredSelection) logTransfarView.getLogTransferComposite().getTableViewer()
                .getSelection();
    }

    if (selection == null) {
        return null;
    }

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

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

    StringBuffer idbuf = new StringBuffer();
    int size = 0;
    for (Object obj : sList) {
        List<?> list = (List<?>) obj;
        String transferId = null;
        String managerName = null;
        if (list != null) {
            transferId = (String) list.get(GetTransferTableDefine.TRANSFER_ID);
            managerName = (String) list.get(GetTransferTableDefine.MANAGER_NAME);
            transferIdMap.get(managerName).add(transferId);
            if (size > 0) {
                idbuf.append(", ");
            }
            idbuf.append(transferId);
            size++;
        }
    }

    if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.hub.log.transfer.confirm.action",
                    new Object[] { Messages.getString("hub.log.transfer.id"),
                            Messages.getString("hub.log.transfer.enable.setting"),
                            idbuf.toString() })) == false) {
        return null;
    }

    StringBuffer sucTransferIds = new StringBuffer();
    StringBuffer failTransferIds = new StringBuffer();
    for (Map.Entry<String, List<String>> entry : transferIdMap.entrySet()) {
        String managerName = entry.getKey();
        HubEndpointWrapper wrapper = HubEndpointWrapper.getWrapper(managerName);
        for (String transferId : entry.getValue()) {
            try {
                TransferInfo info = wrapper.getTransferInfo(transferId);
                info.setValidFlg(true);
                try {
                    wrapper.modifyTransferInfo(info);
                    sucTransferIds.append(transferId + "(" + managerName + ")" + ", ");
                } catch (InvalidSetting_Exception | HinemosUnknown_Exception | InvalidRole_Exception
                        | InvalidUserPass_Exception | LogTransferNotFound_Exception e) {
                    m_log.debug("execute modifyLogTransfer, " + e.getMessage());
                    failTransferIds.append(transferId + ", ");
                }
            } catch (HinemosUnknown_Exception | InvalidRole_Exception | InvalidUserPass_Exception e) {
                m_log.debug("execute getLogTransfer, " + e.getMessage());
                failTransferIds.append(transferId + ", ");
            }
        }
    }

    //?????
    if (sucTransferIds.length() > 0) {
        sucTransferIds.setLength(sucTransferIds.length() - 2);
        MessageDialog.openInformation(null, Messages.getString("successful"),
                Messages.getString("message.hub.log.transfer.action.result",
                        new Object[] { Messages.getString("hub.log.transfer.id"),
                                Messages.getString("hub.log.transfer.enable.setting"),
                                Messages.getString("successful"), sucTransferIds }));
    }
    //????
    if (failTransferIds.length() > 0) {
        failTransferIds.setLength(failTransferIds.length() - 2);
        MessageDialog.openError(null, Messages.getString("failed"),
                Messages.getString("message.hub.log.transfer.action.result",
                        new Object[] { Messages.getString("hub.log.transfer.id"),
                                Messages.getString("hub.log.transfer.enable.setting"),
                                Messages.getString("failed"), failTransferIds }));
    }

    logTransfarView.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;
    }//from w w  w . j a  v  a 2  s.com

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

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

License:Open Source License

@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;
    }/*ww w .ja  va2 s  .c o  m*/

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

    InfraManagementView view = (InfraManagementView) viewPart;

    StructuredSelection selection = null;
    if (view.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) {
        selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection();
    }

    StringBuffer strManagementIds = new StringBuffer();
    String tmpManagementId = null;
    Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>();
    if (selection != null) {
        for (Object object : selection.toList()) {
            String managerName = (String) ((ArrayList<?>) object)
                    .get(GetInfraManagementTableDefine.MANAGER_NAME);
            if (map.get(managerName) == null) {
                map.put(managerName, new ArrayList<String>());
            }
        }

        for (Object object : selection.toList()) {
            String managerName = (String) ((ArrayList<?>) object)
                    .get(GetInfraManagementTableDefine.MANAGER_NAME);
            tmpManagementId = (String) ((ArrayList<?>) object).get(GetInfraManagementTableDefine.MANAGEMENT_ID);
            map.get(managerName).add(tmpManagementId);
            strManagementIds.append(tmpManagementId + ", ");

        }
        strManagementIds.setLength(strManagementIds.length() - 2);

        if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
                Messages.getString("message.infra.confirm.action",
                        new Object[] { Messages.getString("infra.management.id"), Messages.getString("delete"),
                                strManagementIds }))) {
            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);
                List<String> managementIds = entry.getValue();
                try {
                    wrapper.deleteInfraManagement(managementIds);
                } catch (InvalidRole_Exception e) {
                    // ???
                    errMsg.put(managerName, Messages.getString("message.accesscontrol.16"));
                } catch (InfraManagementNotFound_Exception | HinemosUnknown_Exception
                        | InvalidUserPass_Exception | NotifyNotFound_Exception e) {
                    m_log.debug("execute() : " + e.getClass() + e.getMessage());
                    String arg = Messages.getString("message.infra.action.result",
                            new Object[] { Messages.getString("infra.management.id"),
                                    Messages.getString("delete"), Messages.getString("failed"),
                                    HinemosMessage.replace(e.getMessage()) });
                    errMsg.put(managerName, arg);
                }
            }

            if (errMsg.isEmpty()) {
                MessageDialog.openInformation(null, Messages.getString("confirmed"),
                        Messages.getString("message.infra.action.result",
                                new Object[] { Messages.getString("infra.management.id"),
                                        Messages.getString("delete"), Messages.getString("successful"),
                                        strManagementIds }));
            } else {
                UIManager.showMessageBox(errMsg, true);
            }
            view.update();
        }
    }
    return null;
}

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

License:Open Source License

@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;
    }/*  w w w .  j av a 2  s  . c  o  m*/

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

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

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

    StructuredSelection selection = null;
    if (infraModuleView.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) {
        selection = (StructuredSelection) infraModuleView.getComposite().getTableViewer().getSelection();
    }

    List<String> moduleIds = new ArrayList<String>();
    StringBuffer strModuleIds = new StringBuffer();
    String tmpModuleId = null;
    if (selection != null) {
        for (Object object : selection.toList()) {
            tmpModuleId = (String) ((ArrayList<?>) object).get(GetInfraModuleTableDefine.MODULE_ID);
            moduleIds.add(tmpModuleId);
            strModuleIds.append(tmpModuleId + ", ");
        }
        strModuleIds.setLength(strModuleIds.length() - 2);
    }

    InfraManagementInfo info = null;
    try {
        InfraEndpointWrapper wrapper = InfraEndpointWrapper
                .getWrapper(infraModuleView.getComposite().getManagerName());
        info = wrapper.getInfraManagement(infraModuleView.getComposite().getManagementId());
    } catch (HinemosUnknown_Exception | InvalidRole_Exception | InvalidUserPass_Exception
            | NotifyNotFound_Exception | InfraManagementNotFound_Exception e) {
        m_log.debug("execute getInfraManagement, " + e.getMessage());
    }

    List<InfraModuleInfo> tmpDeleteList = new ArrayList<InfraModuleInfo>();
    if (info != null && info.getModuleList() != null) {
        for (String moduleId : moduleIds) {
            for (InfraModuleInfo module : info.getModuleList()) {
                if (module.getModuleId().equals(moduleId)) {
                    tmpDeleteList.add(module);
                    break;
                }
            }
        }

        info.getModuleList().removeAll(tmpDeleteList);

        if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
                Messages.getString("message.infra.confirm.action", new Object[] {
                        Messages.getString("infra.module"), Messages.getString("delete"), strModuleIds }))) {
            try {
                InfraEndpointWrapper wrapper = InfraEndpointWrapper
                        .getWrapper(infraModuleView.getComposite().getManagerName());
                wrapper.modifyInfraManagement(info);
                MessageDialog.openInformation(null, Messages.getString("successful"),
                        Messages.getString("message.infra.action.result",
                                new Object[] { Messages.getString("infra.module"),
                                        Messages.getString("delete") + "("
                                                + infraModuleView.getComposite().getManagerName() + ")",
                                        Messages.getString("successful"), strModuleIds }));
            } catch (InvalidRole_Exception e) {
                // ???
                MessageDialog.openError(null, Messages.getString("failed"),
                        Messages.getString("message.accesscontrol.16"));
                return null;
            } catch (HinemosUnknown_Exception | InvalidUserPass_Exception | InvalidSetting_Exception
                    | NotifyDuplicate_Exception | NotifyNotFound_Exception | InfraManagementNotFound_Exception
                    | InfraManagementDuplicate_Exception e) {
                m_log.debug("execute modifyInfraManagement, " + e.getMessage());
                MessageDialog.openError(null, Messages.getString("failed"),
                        Messages.getString("message.infra.action.result",
                                new Object[] { Messages.getString("infra.modlue"), Messages.getString("delete"),
                                        Messages.getString("failed"),
                                        HinemosMessage.replace(e.getMessage()) }));
                return null;
            }

            infraModuleView.update(infraModuleView.getComposite().getManagerName(), info.getManagementId());
        }
    }
    return null;
}

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

License:Open Source License

@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;
    }/* www  .  j  ava 2  s .c o m*/

    // ???
    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) {
        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>());
        }
    }

    StringBuffer idbuf = new StringBuffer();
    int size = 0;
    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);
            if (size > 0) {
                idbuf.append(", ");
            }
            idbuf.append(managementId);
            size++;
        }
    }

    if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.infra.confirm.action",
                    new Object[] { Messages.getString("infra.management.id"),
                            Messages.getString("infra.disable.setting"), idbuf.toString() })) == false) {
        return null;
    }

    StringBuffer sucManagementIds = new StringBuffer();
    StringBuffer failManagementIds = new StringBuffer();

    for (Map.Entry<String, List<String>> entry : managementIdMap.entrySet()) {
        String managerName = entry.getKey();
        InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName);
        for (String managementId : entry.getValue()) {
            try {
                InfraManagementInfo info = wrapper.getInfraManagement(managementId);
                info.setValidFlg(false);
                try {
                    wrapper.modifyInfraManagement(info);
                    sucManagementIds.append(managementId + "(" + managerName + "), ");
                } catch (InvalidSetting_Exception | NotifyDuplicate_Exception | HinemosUnknown_Exception
                        | InvalidRole_Exception | InvalidUserPass_Exception | InfraManagementNotFound_Exception
                        | InfraManagementDuplicate_Exception e) {
                    m_log.debug("execute modifyInfraManagement, " + e.getMessage());
                    failManagementIds.append(managementId + ", ");
                }
            } catch (HinemosUnknown_Exception | InvalidRole_Exception | InvalidUserPass_Exception
                    | NotifyNotFound_Exception | InfraManagementNotFound_Exception e) {
                m_log.debug("execute getInfraManagement, " + e.getMessage());
                failManagementIds.append(managementId + ", ");
            }
        }
    }

    //?????
    if (sucManagementIds.length() > 0) {
        sucManagementIds.setLength(sucManagementIds.length() - 2);
        MessageDialog.openInformation(null, Messages.getString("successful"),
                Messages.getString("message.infra.action.result",
                        new Object[] { Messages.getString("infra.management.id"),
                                Messages.getString("infra.disable.setting"), Messages.getString("successful"),
                                sucManagementIds }));
    }
    //????
    if (failManagementIds.length() > 0) {
        failManagementIds.setLength(failManagementIds.length() - 2);
        MessageDialog.openError(null, Messages.getString("failed"),
                Messages.getString("message.infra.action.result",
                        new Object[] { Messages.getString("infra.management.id"),
                                Messages.getString("infra.disable.setting"), Messages.getString("failed"),
                                failManagementIds }));
    }
    infraManagementView.update();
    return null;
}

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

License:Open Source License

@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;
    }//from  w  w  w.  j ava2  s.  co  m

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

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

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

    StructuredSelection selection = null;
    if (infraModuleView.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) {
        selection = (StructuredSelection) infraModuleView.getComposite().getTableViewer().getSelection();
    }

    StringBuffer strModuleIds = new StringBuffer();
    List<String> moduleIds = new ArrayList<>();

    if (selection != null) {

        for (Object object : selection.toList()) {
            String tmpModuleId = (String) ((ArrayList<?>) object).get(GetInfraModuleTableDefine.MODULE_ID);
            moduleIds.add(tmpModuleId);
            strModuleIds.append(tmpModuleId + ", ");
        }
        strModuleIds.setLength(strModuleIds.length() - 2);
    }

    String managerName = infraModuleView.getComposite().getManagerName();
    if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.infra.confirm.action",
                    new Object[] { Messages.getString("infra.module.id"),
                            Messages.getString("infra.disable.setting"), strModuleIds })) == false) {
        return null;
    }

    InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName);
    try {
        InfraManagementInfo info = wrapper.getInfraManagement(infraModuleView.getComposite().getManagementId());
        for (String moduleId : moduleIds) {
            for (InfraModuleInfo module : info.getModuleList()) {
                if (module.getModuleId().equals(moduleId)) {
                    module.setValidFlg(false);
                    break;
                }
            }
        }

        try {
            wrapper.modifyInfraManagement(info);
        } catch (InvalidRole_Exception e) {
            // ???
            MessageDialog.openError(null, Messages.getString("failed"),
                    Messages.getString("message.accesscontrol.16"));
            return null;
        } catch (InvalidSetting_Exception | NotifyDuplicate_Exception | HinemosUnknown_Exception
                | InvalidUserPass_Exception | InfraManagementNotFound_Exception
                | InfraManagementDuplicate_Exception e) {
            m_log.debug("execute modifyInfraManagement, " + e.getMessage());
            MessageDialog.openError(null, Messages.getString("failed"),
                    Messages.getString("message.infra.action.result",
                            new Object[] { Messages.getString("infra.module.id"),
                                    Messages.getString("infra.disable.setting"), Messages.getString("failed"),
                                    strModuleIds }));
            return null;
        }
    } catch (InvalidRole_Exception e) {
        MessageDialog.openError(null, Messages.getString("failed"),
                Messages.getString("message.accesscontrol.16"));
    } catch (HinemosUnknown_Exception | InvalidUserPass_Exception | NotifyNotFound_Exception
            | InfraManagementNotFound_Exception e) {
        m_log.debug("execute getInfraManagement, " + e.getMessage());
        MessageDialog.openError(null, Messages.getString("failed"), HinemosMessage.replace(e.getMessage()));

    }

    MessageDialog.openInformation(null, Messages.getString("successful"),
            Messages.getString("message.infra.action.result",
                    new Object[] { Messages.getString("infra.module.id"),
                            Messages.getString("infra.disable.setting") + "(" + managerName + ")",
                            Messages.getString("successful"), strModuleIds }));
    infraModuleView.update(infraModuleView.getComposite().getManagerName(),
            infraModuleView.getComposite().getManagementId());
    return null;
}

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

License:Open Source License

@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;
    }/*ww w.  jav  a 2s .  c om*/

    // ???
    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) {
        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>());
        }
    }

    StringBuffer idbuf = new StringBuffer();
    int size = 0;
    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);
            if (size > 0) {
                idbuf.append(", ");
            }
            idbuf.append(managementId);
            size++;
        }
    }

    if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.infra.confirm.action",
                    new Object[] { Messages.getString("infra.management.id"),
                            Messages.getString("infra.enable.setting"), idbuf.toString() })) == false) {
        return null;
    }

    StringBuffer sucManagementIds = new StringBuffer();
    StringBuffer failManagementIds = new StringBuffer();
    for (Map.Entry<String, List<String>> entry : managementIdMap.entrySet()) {
        String managerName = entry.getKey();
        InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName);
        for (String managementId : entry.getValue()) {
            try {
                InfraManagementInfo info = wrapper.getInfraManagement(managementId);
                info.setValidFlg(true);
                try {
                    wrapper.modifyInfraManagement(info);
                    sucManagementIds.append(managementId + "(" + managerName + ")" + ", ");
                } catch (InvalidSetting_Exception | NotifyDuplicate_Exception | HinemosUnknown_Exception
                        | InvalidRole_Exception | InvalidUserPass_Exception | InfraManagementNotFound_Exception
                        | InfraManagementDuplicate_Exception e) {
                    m_log.debug("execute modifyInfraManagement, " + e.getMessage());
                    failManagementIds.append(managementId + ", ");
                }
            } catch (HinemosUnknown_Exception | InvalidRole_Exception | InvalidUserPass_Exception
                    | NotifyNotFound_Exception | InfraManagementNotFound_Exception e) {
                m_log.debug("execute getInfraManagement, " + e.getMessage());
                failManagementIds.append(managementId + ", ");
            }
        }
    }

    //?????
    if (sucManagementIds.length() > 0) {
        sucManagementIds.setLength(sucManagementIds.length() - 2);
        MessageDialog.openInformation(null, Messages.getString("successful"),
                Messages.getString("message.infra.action.result",
                        new Object[] { Messages.getString("infra.management.id"),
                                Messages.getString("infra.enable.setting"), Messages.getString("successful"),
                                sucManagementIds }));
    }
    //????
    if (failManagementIds.length() > 0) {
        failManagementIds.setLength(failManagementIds.length() - 2);
        MessageDialog.openError(null, Messages.getString("failed"),
                Messages.getString("message.infra.action.result",
                        new Object[] { Messages.getString("infra.management.id"),
                                Messages.getString("infra.enable.setting"), Messages.getString("failed"),
                                failManagementIds }));
    }

    infraManagementView.update();
    return null;
}

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

License:Open Source License

@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;
    }/* ww  w. j a  va  2  s  .  c om*/

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

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

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

    StructuredSelection selection = null;
    if (infraModuleView.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) {
        selection = (StructuredSelection) infraModuleView.getComposite().getTableViewer().getSelection();
    }

    StringBuffer strModuleIds = new StringBuffer();
    List<String> moduleIds = new ArrayList<>();

    if (selection != null) {

        for (Object object : selection.toList()) {
            String tmpModuleId = (String) ((ArrayList<?>) object).get(GetInfraModuleTableDefine.MODULE_ID);
            moduleIds.add(tmpModuleId);
            strModuleIds.append(tmpModuleId + ", ");
        }
        strModuleIds.setLength(strModuleIds.length() - 2);
    }

    String managerName = infraModuleView.getComposite().getManagementId();

    if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.infra.confirm.action",
                    new Object[] { Messages.getString("infra.module.id"),
                            Messages.getString("infra.enable.setting"), strModuleIds })) == false) {
        return null;
    }

    InfraEndpointWrapper wrapper = InfraEndpointWrapper
            .getWrapper(infraModuleView.getComposite().getManagerName());

    try {
        InfraManagementInfo info = wrapper.getInfraManagement(managerName);
        for (String moduleId : moduleIds) {
            for (InfraModuleInfo module : info.getModuleList()) {
                if (module.getModuleId().equals(moduleId)) {
                    module.setValidFlg(true);
                    break;
                }
            }
        }

        try {
            wrapper.modifyInfraManagement(info);
        } catch (InvalidRole_Exception e) {
            // ???
            MessageDialog.openError(null, Messages.getString("failed"),
                    Messages.getString("message.accesscontrol.16"));
            return null;
        } catch (InvalidSetting_Exception | NotifyDuplicate_Exception | HinemosUnknown_Exception
                | InvalidUserPass_Exception | InfraManagementNotFound_Exception
                | InfraManagementDuplicate_Exception e) {
            m_log.debug("execute modifyInfraManagement, " + e.getMessage());
            MessageDialog.openError(null, Messages.getString("failed"),
                    Messages.getString("message.infra.action.result",
                            new Object[] { Messages.getString("infra.module.id"),
                                    Messages.getString("infra.enable.setting"), Messages.getString("failed"),
                                    strModuleIds }));
            return null;
        }
    } catch (HinemosUnknown_Exception | InvalidRole_Exception | InvalidUserPass_Exception
            | NotifyNotFound_Exception | InfraManagementNotFound_Exception e) {
        m_log.debug("execute getInfraManagement, " + e.getMessage());
    }

    MessageDialog.openInformation(null, Messages.getString("successful"),
            Messages.getString("message.infra.action.result",
                    new Object[] { Messages.getString("infra.module.id"),
                            Messages.getString("infra.enable.setting") + "(" + managerName + ")",
                            Messages.getString("successful"), strModuleIds }));
    infraModuleView.update(infraModuleView.getComposite().getManagerName(),
            infraModuleView.getComposite().getManagementId());

    return null;
}

From source file:com.clustercontrol.jobmanagement.composite.JobCommandParameterComposite.java

License:Open Source License

/**
 * ????/* w w w  .  j  a v a 2 s .  c o  m*/
 */
private void initialize() {

    this.setLayout(JobDialogUtil.getParentLayout());

    // 
    Table table = new Table(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
    WidgetTestUtil.setTestId(this, "table", table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    table.setLayoutData(new RowData(430, 75));

    // Composite
    Composite buttonComposite = new Composite(this, SWT.NONE);
    buttonComposite.setLayout(new RowLayout());

    // dummy
    new Label(buttonComposite, SWT.NONE).setLayoutData(new RowData(190, SizeConstant.SIZE_LABEL_HEIGHT));

    // 
    this.m_btnAdd = new Button(buttonComposite, SWT.NONE);
    WidgetTestUtil.setTestId(this, "m_btnAdd", this.m_btnAdd);
    this.m_btnAdd.setText(Messages.getString("add"));
    this.m_btnAdd.setLayoutData(new RowData(80, SizeConstant.SIZE_BUTTON_HEIGHT));
    this.m_btnAdd.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            JobCommandParameterDialog dialog = new JobCommandParameterDialog(m_shell);
            if (dialog.open() == IDialogConstants.OK_ID) {
                if (isParameterDuplicate(dialog.getInputData().getParamId())) {
                    // ????
                    MessageDialog.openWarning(null, Messages.getString("warning"),
                            Messages.getString("message.job.134"));
                } else {
                    m_jobCommandParamMap.put(dialog.getInputData().getParamId(), dialog.getInputData());
                    reflectParamInfo();
                }
            }
        }
    });

    // 
    this.m_btnModify = new Button(buttonComposite, SWT.NONE);
    WidgetTestUtil.setTestId(this, "m_btnModify", this.m_btnModify);
    this.m_btnModify.setText(Messages.getString("modify"));
    this.m_btnModify.setLayoutData(new RowData(80, SizeConstant.SIZE_BUTTON_HEIGHT));
    this.m_btnModify.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int order = m_viewer.getTable().getSelectionIndex();
            if (order >= 0) {
                String paramId = (String) ((ArrayList<?>) m_viewer.getTable().getSelection()[0].getData())
                        .get(0);
                JobCommandParameterDialog dialog = new JobCommandParameterDialog(m_shell,
                        m_jobCommandParamMap.get(paramId));
                if (dialog.open() == IDialogConstants.OK_ID) {
                    m_jobCommandParamMap.put(paramId, (JobCommandParam) dialog.getInputData());
                    reflectParamInfo();
                }
            } else {
                MessageDialog.openWarning(null, Messages.getString("warning"),
                        Messages.getString("message.job.129"));
            }
        }
    });

    // 
    this.m_btnDelete = new Button(buttonComposite, SWT.NONE);
    WidgetTestUtil.setTestId(this, "m_btnDelete", this.m_btnDelete);
    this.m_btnDelete.setText(Messages.getString("delete"));
    this.m_btnDelete.setLayoutData(new RowData(80, SizeConstant.SIZE_BUTTON_HEIGHT));
    this.m_btnDelete.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int order = m_viewer.getTable().getSelectionIndex();
            if (order >= 0) {
                String paramId = (String) ((ArrayList<?>) m_viewer.getTable().getSelection()[0].getData())
                        .get(0);
                if (paramId == null) {
                    paramId = "";
                }

                String[] args = { paramId };
                if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
                        Messages.getString("message.job.130", args))) {
                    m_jobCommandParamMap.remove(paramId);
                    reflectParamInfo();
                }
            } else {
                MessageDialog.openWarning(null, Messages.getString("warning"),
                        Messages.getString("message.job.129"));
            }
        }
    });

    this.m_viewer = new CommonTableViewer(table);
    this.m_viewer.createTableColumn(GetCommandParameterTableDefine.get(),
            GetCommandParameterTableDefine.SORT_COLUMN_INDEX, GetCommandParameterTableDefine.SORT_ORDER);
    this.m_viewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (m_btnAdd.isEnabled()) {
                int order = m_viewer.getTable().getSelectionIndex();
                if (order >= 0) {
                    String paramId = (String) ((ArrayList<?>) m_viewer.getTable().getSelection()[0].getData())
                            .get(0);
                    JobCommandParameterDialog dialog = new JobCommandParameterDialog(m_shell,
                            m_jobCommandParamMap.get(paramId));
                    if (dialog.open() == IDialogConstants.OK_ID) {
                        m_jobCommandParamMap.put(paramId, dialog.getInputData());
                        reflectParamInfo();
                    }
                } else {
                    MessageDialog.openWarning(null, Messages.getString("warning"),
                            Messages.getString("message.job.129"));
                }
            }
        }
    });
}