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

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

Introduction

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

Prototype

@Override
    public Object getFirstElement() 

Source Link

Usage

From source file:com.clustercontrol.monitor.view.action.MonitorCopyAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // ???//from  w  w  w. j a v a  2  s  .  co m
    this.viewPart = HandlerUtil.getActivePart(event);
    MonitorListView monitorListView = null;
    try {
        monitorListView = (MonitorListView) this.viewPart.getAdapter(MonitorListView.class);
    } catch (Exception e) {
        m_log.info("execute " + e.getMessage());
        return null;
    }

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

    MonitorListComposite composite = (MonitorListComposite) monitorListView.getListComposite();
    StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection();

    List<?> list = (List<?>) selection.getFirstElement();
    if (list == null || list.size() == 0)
        throw new InternalError("select element is not find");

    String managerName = (String) list.get(GetMonitorListTableDefine.MANAGER_NAME);
    String pluginId = (String) list.get(GetMonitorListTableDefine.MONITOR_TYPE_ID);
    String monitorId = (String) list.get(GetMonitorListTableDefine.MONITOR_ID);
    int monitorType = MonitorTypeMessage
            .stringToType((String) list.get(GetMonitorListTableDefine.MONITOR_TYPE));

    dialogOpen(this.viewPart.getSite().getShell(), managerName, pluginId, monitorId, monitorType);

    // ?
    monitorListView.update();
    return null;
}

From source file:com.clustercontrol.monitor.view.action.MonitorModifyAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // ???/*from  w w w . j  a  va  2  s .co m*/
    this.viewPart = HandlerUtil.getActivePart(event);
    MonitorListView view = null;
    try {
        view = (MonitorListView) this.viewPart.getAdapter(MonitorListView.class);
    } catch (Exception e) {
        m_log.info("execute " + e.getMessage());
        return null;
    }

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

    MonitorListComposite composite = (MonitorListComposite) view.getListComposite();
    StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection();

    List<?> list = (List<?>) selection.getFirstElement();
    if (list == null || list.size() == 0)
        throw new InternalError("select element is not find");

    String managerName = (String) list.get(GetMonitorListTableDefine.MANAGER_NAME);
    String pluginId = (String) list.get(GetMonitorListTableDefine.MONITOR_TYPE_ID);
    String monitorId = (String) list.get(GetMonitorListTableDefine.MONITOR_ID);

    dialogOpen(this.viewPart.getSite().getShell(), managerName, pluginId, monitorId);

    // ?
    view.update();
    return null;
}

From source file:com.clustercontrol.monitor.view.action.StatusModifyMonitorSettingAction.java

License:Open Source License

/**
 * []????????//from w  w w . j  av  a2 s.co  m
 * <p>
 * <ol>
 * <li>[]??????????</li>
 * <li>????????? </li>
 * </ol>
 *
 * @see org.eclipse.core.commands.IHandler#execute
 * @see com.clustercontrol.monitor.view.StatusView
 * @see com.clustercontrol.monitor.view.StatusView#update()
 */
@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);
    ScopeListBaseView view = null;
    try {
        view = (StatusView) this.viewPart.getAdapter(StatusView.class);
    } catch (Exception e) {
        m_log.info("execute " + e.getMessage());
        return null;
    }

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

    StatusListComposite composite = (StatusListComposite) view.getListComposite();
    WidgetTestUtil.setTestId(this, null, composite);
    StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection();

    List<?> list = (ArrayList<?>) selection.getFirstElement();

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

    String managerName = "";
    String pluginId = "";
    String monitorId = "";

    managerName = (String) list.get(GetStatusListTableDefine.MANAGER_NAME);
    pluginId = (String) list.get(GetStatusListTableDefine.PLUGIN_ID);
    if (pluginId == null)
        throw new InternalError("pluginId is null.");

    monitorId = (String) list.get(GetStatusListTableDefine.MONITOR_ID);

    if (monitorId != null) {
        // ???
        MonitorModifyAction mmAction = new MonitorModifyAction();
        // ???????????
        if (mmAction.dialogOpen(composite.getShell(), managerName, pluginId,
                monitorId) == IDialogConstants.OK_ID) {
            composite.update();
        }
    }
    return null;
}

From source file:com.clustercontrol.monitor.view.action.StatusOpenJobHistoryAction.java

License:Open Source License

@Override
/*/* w  ww.  ja  va2s  .c om*/
 * (non-Javadoc)
 *
 * @see org.eclipse.core.commands.IHandler#execute
 */
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;
    }

    IPerspectiveRegistry reg = PlatformUI.getWorkbench().getPerspectiveRegistry();

    PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IPerspectiveDescriptor desc = reg
            .findPerspectiveWithId("com.clustercontrol.jobmanagement.ui.JobHistoryPerspective");
    if (desc == null) {
        return null;
    }

    // ???
    IWorkbenchPart viewPart = HandlerUtil.getActivePart(event);
    ScopeListBaseView statusView = null;
    try {
        statusView = (StatusView) viewPart.getAdapter(StatusView.class);
    } catch (Exception e) {
        m_log.info("execute " + e.getMessage());
        return null;
    }

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

    StatusListComposite composite = (StatusListComposite) statusView.getListComposite();
    StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection();

    List<?> list = (ArrayList<?>) selection.getFirstElement();

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

    JobTreeItem item;

    //IDID?
    String monitorId = (String) list.get(GetStatusListTableDefine.MONITOR_ID);
    String managerName = (String) list.get(GetStatusListTableDefine.MANAGER_NAME);
    try {
        JobEndpointWrapper wrapper = JobEndpointWrapper.getWrapper(managerName);
        item = wrapper.getJobDetailList(monitorId);
    } catch (JobInfoNotFound_Exception e) {
        ClientSession.occupyDialog();
        MessageDialog.openInformation(null, Messages.getString("message"),
                Messages.getString("message.job.122"));
        ClientSession.freeDialog();
        return null;
    } catch (Exception e) {
        m_log.warn("run() getJobDetailList, " + e.getMessage(), e);
        if (ClientSession.isDialogFree()) {
            ClientSession.occupyDialog();
            MessageDialog.openError(null, Messages.getString("failed"),
                    Messages.getString("message.hinemos.failure.unexpected") + ", "
                            + HinemosMessage.replace(e.getMessage()));
            ClientSession.freeDialog();
        }
        return null;
    }

    IWorkbenchPage page = window.getActivePage();

    //??
    page.setPerspective(desc);

    //view?composite?
    JobHistoryView historyView = (JobHistoryView) page.findView(JobHistoryView.ID);
    if (historyView == null)
        throw new InternalError("historyView is null.");

    JobDetailView detailView = (JobDetailView) page.findView(JobDetailView.ID);
    if (detailView == null)
        throw new InternalError("detailView is null.");

    HistoryComposite historyCmp = historyView.getComposite();

    //ID?ID?
    ArrayList<?> objList = (ArrayList<?>) historyCmp.getTableViewer().getInput();
    if (objList == null || objList.size() == 0) {
        return null;
    }

    //ID?ID
    historyCmp.setSessionId(monitorId);
    DetailComposite detailCmp = detailView.getComposite();
    JobTreeItem child = getChild(item);
    String jobId = child.getData().getId();
    String jobunitId = child.getData().getJobunitId();

    //??
    detailCmp.setJobId(jobId);
    detailCmp.setSessionId(monitorId);

    //??
    historyView.update(false);
    detailCmp.setItem(managerName, monitorId, jobunitId, item);
    return null;
}

From source file:com.clustercontrol.monitor.view.MonitorListView.java

License:Open Source License

@Override
public String getSelectedOwnerRoleId() {
    StructuredSelection selection = (StructuredSelection) this.composite.getTableViewer().getSelection();

    List<?> list = (List<?>) selection.getFirstElement();
    String id = null;/*from   w ww. ja  v a 2s  .  c o m*/
    if (list != null) {
        id = (String) list.get(GetMonitorListTableDefine.OWNER_ROLE);
    }
    return id;
}

From source file:com.clustercontrol.notify.composite.NotifyTypeListComposite.java

License:Open Source License

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

    // ??
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    this.setLayout(layout);

    this.notifyTypeList = new ListViewer(this, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER);
    GridData gdata = new GridData(GridData.FILL_BOTH);
    this.notifyTypeList.getList().setLayoutData(gdata);

    this.notifyTypeList.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            selectItem = (Integer) selection.getFirstElement();
        }
    });

}

From source file:com.clustercontrol.notify.mail.view.action.MailTemplateCopyAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // ???//from   ww w .j av a 2s  .  co  m
    this.viewPart = HandlerUtil.getActivePart(event);

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

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

    MailTemplateListComposite composite = (MailTemplateListComposite) view.getListComposite();
    WidgetTestUtil.setTestId(this, null, composite);
    WidgetTestUtil.setTestId(this, null, composite);

    StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection();

    List<?> list = (List<?>) selection.getFirstElement();
    String managerName = null;
    String mailTemplateId = null;
    if (list != null && list.size() > 0) {
        managerName = (String) list.get(GetMailTemplateListTableDefine.MANAGER_NAME);
        mailTemplateId = (String) list.get(GetMailTemplateListTableDefine.MAIL_TEMPLATE_ID);
    }

    Table table = composite.getTableViewer().getTable();
    WidgetTestUtil.setTestId(this, null, table);

    // ???????
    if (mailTemplateId != null) {
        MailTemplateCreateDialog dialog = new MailTemplateCreateDialog(view.getListComposite().getShell(),
                managerName, mailTemplateId, PropertyDefineConstant.MODE_ADD);
        if (dialog.open() == IDialogConstants.OK_ID) {
            int selectIndex = table.getSelectionIndex();
            composite.update();
            table.setSelection(selectIndex);
        }
    } else {
        MessageDialog.openWarning(null, Messages.getString("warning"),
                Messages.getString("message.notify.mail.8"));
    }
    return null;
}

From source file:com.clustercontrol.notify.mail.view.action.MailTemplateModifyAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // ???//  w  ww  . ja v  a  2 s .c o m
    this.viewPart = HandlerUtil.getActivePart(event);
    MailTemplateListView view = null;
    try {
        view = (MailTemplateListView) this.viewPart.getAdapter(MailTemplateListView.class);
    } catch (Exception e) {
        m_log.info("execute " + e.getMessage());
        return null;
    }

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

    MailTemplateListComposite composite = (MailTemplateListComposite) view.getListComposite();
    WidgetTestUtil.setTestId(this, null, composite);
    StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection();

    List<?> list = (List<?>) selection.getFirstElement();
    String managerName = null;
    String mailTemplateId = null;
    if (list != null && list.size() > 0) {
        managerName = (String) list.get(GetMailTemplateListTableDefine.MANAGER_NAME);
        mailTemplateId = (String) list.get(GetMailTemplateListTableDefine.MAIL_TEMPLATE_ID);
    }

    Table table = composite.getTableViewer().getTable();
    WidgetTestUtil.setTestId(this, null, table);

    // ???????
    if (mailTemplateId != null) {
        MailTemplateCreateDialog dialog = new MailTemplateCreateDialog(view.getListComposite().getShell(),
                managerName, mailTemplateId, PropertyDefineConstant.MODE_MODIFY);
        if (dialog.open() == IDialogConstants.OK_ID) {
            int selectIndex = table.getSelectionIndex();
            composite.update();
            table.setSelection(selectIndex);
        }
    } else {
        MessageDialog.openWarning(null, Messages.getString("warning"),
                Messages.getString("message.notify.mail.8"));
    }
    return null;
}

From source file:com.clustercontrol.notify.mail.view.MailTemplateListView.java

License:Open Source License

public String getSelectedId() {
    StructuredSelection selection = (StructuredSelection) this.composite.getTableViewer().getSelection();

    List<?> list = (List<?>) selection.getFirstElement();
    String id = null;/*from  w  w w. j a  v a  2 s.  c o  m*/
    if (list != null) {
        id = (String) list.get(GetMailTemplateListTableDefine.MAIL_TEMPLATE_ID);
    }
    return id;
}

From source file:com.clustercontrol.notify.mail.view.MailTemplateListView.java

License:Open Source License

@Override
public String getSelectedOwnerRoleId() {
    StructuredSelection selection = (StructuredSelection) this.composite.getTableViewer().getSelection();

    List<?> list = (List<?>) selection.getFirstElement();
    String id = null;//from   w ww . j ava2  s  . co  m
    if (list != null) {
        id = (String) list.get(GetMailTemplateListTableDefine.OWNER_ROLE);
    }
    return id;
}