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

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

Introduction

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

Prototype

@Override
    public int size() 

Source Link

Usage

From source file:com.clustercontrol.calendar.composite.action.CalendarPatternSelectionChangedListener.java

License:Open Source License

@Override
public void selectionChanged(SelectionChangedEvent event) {
    String id = null;/*from ww w  .ja va2 s .  c o m*/

    StructuredSelection selection = (StructuredSelection) event.getSelection();
    if (selection == null)
        throw new InternalError("selection is null.");

    //ID?
    if (selection.getFirstElement() != null) {
        ArrayList<?> info = (ArrayList<?>) selection.getFirstElement();
        id = (String) info.get(GetCalendarPatternTableDefine.CAL_PATTERN_ID);
        //ID
        m_composite.setCalendarPatternId(id);
    }

    //?
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

    //[]???/???
    IViewPart viewPart = page.findView(CalendarPatternView.ID);
    if (viewPart != null) {
        CalendarPatternView view = (CalendarPatternView) viewPart.getAdapter(CalendarPatternView.class);
        if (view == null) {
            m_log.info("selection changed: view is null");
            return;
        }
        //??/???
        view.setEnabledAction(selection.size(), selection);
    }
}

From source file:com.clustercontrol.calendar.composite.action.CalendarSelectionChangedListener.java

License:Open Source License

@Override
public void selectionChanged(SelectionChangedEvent event) {
    String managerName = null;/*  w  ww. ja  v  a 2  s  . c  om*/
    String calenadarId = null;

    StructuredSelection selection = (StructuredSelection) event.getSelection();
    if (selection == null)
        throw new InternalError("selection is null.");

    //ID?
    if (selection.getFirstElement() != null) {
        ArrayList<?> info = (ArrayList<?>) selection.getFirstElement();
        managerName = (String) info.get(GetCalendarListTableDefine.MANAGER_NAME);
        calenadarId = (String) info.get(GetCalendarListTableDefine.CALENDAR_ID);
        //ID
        m_composite.setCalendarId(calenadarId);
    }

    //?
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

    //[]???/???
    IViewPart viewPart = page.findView(CalendarListView.ID);
    if (viewPart != null) {
        CalendarListView view = (CalendarListView) viewPart.getAdapter(CalendarListView.class);
        if (view == null) {
            m_log.info("selection changed: calendar list view is null");
            return;
        }
        //??/???
        view.setEnabledAction(selection.size(), selection);
    }

    //?
    viewPart = page.findView(CalendarMonthView.ID);
    if (viewPart != null) {
        CalendarMonthView view = (CalendarMonthView) viewPart.getAdapter(CalendarMonthView.class);
        if (view == null) {
            m_log.info("selection changed: calendar month view is null");
            return;
        }
        view.update(managerName, calenadarId);
    }
}

From source file:com.clustercontrol.hub.composite.LogFormatComposite.java

License:Open Source License

/**
 * ??<BR>/*from www .j  a  v  a2 s . c o  m*/
 *
 */
private void initialize() {
    GridLayout layout = new GridLayout(1, true);
    this.setLayout(layout);
    layout.marginHeight = 0;
    layout.marginWidth = 0;

    //?
    logFormatListTable = new Table(this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
    WidgetTestUtil.setTestId(this, null, logFormatListTable);
    logFormatListTable.setHeaderVisible(true);
    logFormatListTable.setLinesVisible(true);

    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalSpan = 1;
    logFormatListTable.setLayoutData(gridData);

    m_labelCount = new Label(this, SWT.RIGHT);
    WidgetTestUtil.setTestId(this, "count", m_labelCount);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    m_labelCount.setLayoutData(gridData);

    m_viewer = new CommonTableViewer(logFormatListTable);

    m_viewer.createTableColumn(GetLogFormatTableDefine.get(), GetLogFormatTableDefine.SORT_COLUMN_INDEX1,
            GetLogFormatTableDefine.SORT_COLUMN_INDEX2, GetLogFormatTableDefine.SORT_ORDER);

    for (int i = 0; i < logFormatListTable.getColumnCount(); i++) {
        logFormatListTable.getColumn(i).setMoveable(true);
    }
    m_viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        /**
         * ??????<BR>
         * ?????????<BR>
         * ??????????
         * 
         * @param event ?
         * 
         * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
         */
        @Override
        public void selectionChanged(SelectionChangedEvent event) {

            String id = null;

            //[]??
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

            IViewPart viewPart = page.findView(LogFormatView.ID);

            //??
            StructuredSelection selection = (StructuredSelection) event.getSelection();

            if (viewPart != null && selection != null) {
                if (selection.getFirstElement() != null) {
                    ArrayList<?> info = (ArrayList<?>) selection.getFirstElement();
                    id = (String) info.get(GetLogFormatTableDefine.FORMAT_ID);
                    //?ID
                    LogFormatComposite.this.setFormatId(id);
                }
                LogFormatView view = (LogFormatView) viewPart.getAdapter(LogFormatView.class);
                if (view == null) {
                    m_log.info("selection changed: view is null");
                    return;
                }
                //???/???
                view.setEnabledAction(selection.size(), event.getSelection());
            }
        }
    });
    // ?
    m_viewer.addDoubleClickListener(new IDoubleClickListener() {
        /**
         * 
         * @param event
         */
        @Override
        public void doubleClick(DoubleClickEvent event) {
            String managerName = "";
            String formatId = "";

            if (((StructuredSelection) event.getSelection()).getFirstElement() != null) {
                ArrayList<?> info = (ArrayList<?>) ((StructuredSelection) event.getSelection())
                        .getFirstElement();

                managerName = (String) info.get(GetLogFormatTableDefine.MANAGER_NAME);
                formatId = (String) info.get(GetLogFormatTableDefine.FORMAT_ID);
            }

            if (formatId != null) {
                // ???
                LogFormatDialog dialog = new LogFormatDialog(LogFormatComposite.this.getShell(), managerName,
                        formatId, PropertyDefineConstant.MODE_MODIFY);

                // ???????????
                if (dialog.open() == IDialogConstants.OK_ID) {
                    LogFormatComposite.this.update();
                }
            }
        }
    });
}

From source file:com.clustercontrol.hub.composite.TransferComposite.java

License:Open Source License

/**
 * ??<BR>// ww  w.  jav  a  2 s  .  c o  m
 *
 */
private void initialize() {
    GridLayout layout = new GridLayout(1, true);
    this.setLayout(layout);
    layout.marginHeight = 0;
    layout.marginWidth = 0;

    //??[?]?
    m_transferListTable = new Table(this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
    WidgetTestUtil.setTestId(this, null, m_transferListTable);
    m_transferListTable.setHeaderVisible(true);
    m_transferListTable.setLinesVisible(true);

    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalSpan = 1;
    m_transferListTable.setLayoutData(gridData);

    m_labelCount = new Label(this, SWT.RIGHT);
    WidgetTestUtil.setTestId(this, "count", m_labelCount);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    m_labelCount.setLayoutData(gridData);

    m_viewer = new CommonTableViewer(m_transferListTable);

    m_viewer.createTableColumn(GetTransferTableDefine.get(), GetTransferTableDefine.SORT_COLUMN_INDEX1,
            GetTransferTableDefine.SORT_COLUMN_INDEX2, GetTransferTableDefine.SORT_ORDER);

    for (int i = 0; i < m_transferListTable.getColumnCount(); i++) {
        m_transferListTable.getColumn(i).setMoveable(true);
    }
    m_viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        /**
         * ??????<BR>
         * ???????<BR>
         * ??????????
         * 
         * @param event ?
         * 
         * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
         */
        @Override
        public void selectionChanged(SelectionChangedEvent event) {

            String id = null;

            //??[?]??
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

            IViewPart viewPart = page.findView(TransferView.ID);

            //??
            StructuredSelection selection = (StructuredSelection) event.getSelection();

            if (viewPart != null && selection != null) {
                if (selection.getFirstElement() != null) {
                    ArrayList<?> info = (ArrayList<?>) selection.getFirstElement();
                    id = (String) info.get(GetTransferTableDefine.TRANSFER_ID);
                    //ID
                    TransferComposite.this.setTransferId(id);
                }
                TransferView view = (TransferView) viewPart.getAdapter(TransferView.class);
                //???/???
                view.setEnabledAction(selection.size(), event.getSelection());
            }
        }
    });
    // ?
    m_viewer.addDoubleClickListener(new IDoubleClickListener() {
        /**
         * 
         * @param event
         */
        @Override
        public void doubleClick(DoubleClickEvent event) {
            String managerName = "";
            String exportId = "";

            if (((StructuredSelection) event.getSelection()).getFirstElement() != null) {
                ArrayList<?> info = (ArrayList<?>) ((StructuredSelection) event.getSelection())
                        .getFirstElement();

                managerName = (String) info.get(GetTransferTableDefine.MANAGER_NAME);
                exportId = (String) info.get(GetTransferTableDefine.TRANSFER_ID);
            }

            if (exportId != null) {
                // ???
                TransferInfoDialog dialog = new TransferInfoDialog(TransferComposite.this.getShell(),
                        managerName, exportId, PropertyDefineConstant.MODE_MODIFY);

                // ???????????
                if (dialog.open() == IDialogConstants.OK_ID) {
                    TransferComposite.this.update();
                }
            }
        }
    });
}

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

License:Open Source License

@Override
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
    boolean enable = false;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    // page may not start at state restoring
    if (null != window) {
        IWorkbenchPage page = window.getActivePage();
        if (null != page) {
            IWorkbenchPart part = page.getActivePart();

            if (part instanceof TransferView) {
                TransferView view = (TransferView) part.getAdapter(TransferView.class);
                // Enable button when 1 item is selected
                StructuredSelection selection = null;
                if (view.getLogTransferComposite().getTableViewer()
                        .getSelection() instanceof StructuredSelection) {
                    selection = (StructuredSelection) view.getLogTransferComposite().getTableViewer()
                            .getSelection();
                }/*from   w w  w  .j a  v a 2s.com*/
                if (selection != null && selection.size() > 0) {
                    enable = true;
                }
            }
            this.setBaseEnabled(enable);
        } else {
            this.setBaseEnabled(false);
        }
    }
}

From source file:com.clustercontrol.infra.composite.action.InfraManagementSelectionChangedListener.java

License:Open Source License

/**
 * ??????<BR>/*from   www.  java 2 s  .c o m*/
 * [?]???????????
 * []???
 * <P>
 * <ol>
 * <li>????????ID?ID????</li>
 * <li>ID?ID[?]??????</li>
 * <li>[]???</li>
 * </ol>
 *
 * @param event ?
 *
 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
 */
@Override
public void selectionChanged(SelectionChangedEvent event) {
    //[?]??
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

    //??
    StructuredSelection selection = (StructuredSelection) event.getSelection();

    //[?]?
    IViewPart viewPart = page.findView(InfraManagementView.ID);
    //?
    if (viewPart != null && selection != null) {
        InfraManagementView view = (InfraManagementView) viewPart.getAdapter(InfraManagementView.class);
        if (view == null) {
            m_log.info("selection changed: infra management view is null");
        } else {
            //[?]???/???
            view.setEnabledAction(selection.size(), selection);
        }
    }

    //[]?
    viewPart = page.findView(InfraModuleView.ID);
    if (viewPart != null && selection != null) {
        InfraModuleView view = (InfraModuleView) viewPart.getAdapter(InfraModuleView.class);
        if (view == null) {
            m_log.info("execute: infra module view is null");
            return;
        }
        if (selection.size() == 1) {
            ArrayList<?> info = (ArrayList<?>) selection.getFirstElement();

            //
            view.update((String) info.get(GetInfraManagementTableDefine.MANAGER_NAME),
                    (String) info.get(GetInfraManagementTableDefine.MANAGEMENT_ID));
        } else {
            //??
            view.update(null, null);
        }
        view.setEnabledAction();
    }
}

From source file:com.clustercontrol.infra.composite.FileReplaceSettingComposite.java

License:Open Source License

/**
 * ????/*from   w  w w  .ja  v  a2s . co m*/
 */
private void initialize() {
    // ????
    GridData gridData = null;

    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 12;
    this.setLayout(layout);

    Table table = new Table(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE);
    gridData = new GridData();
    gridData.horizontalSpan = 12;
    gridData.horizontalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.heightHint = 100;
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    table.setLayoutData(gridData);

    // 
    Label label = new Label(this, SWT.NONE);
    gridData = new GridData();
    gridData.horizontalSpan = 6;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    label.setLayoutData(gridData);

    m_createCondition = new Button(this, SWT.NONE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = true;
    m_createCondition.setText(Messages.getString("add"));
    m_createCondition.setLayoutData(gridData);
    m_createCondition.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            ReplaceTextDialog dialog = new ReplaceTextDialog(m_shell);
            if (dialog.open() == IDialogConstants.OK_ID) {
                List<?> info = dialog.getInputData();
                List<Object> list = (ArrayList<Object>) m_viewer.getInput();
                if (list == null) {
                    list = new ArrayList<Object>();
                }
                list.add(info);
                m_viewer.setInput(list);
            }
        }
    });

    //?
    m_modifyCondition = new Button(this, SWT.NONE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = true;
    WidgetTestUtil.setTestId(this, "modifycondition", m_modifyCondition);
    m_modifyCondition.setText(Messages.getString("modify"));
    m_modifyCondition.setLayoutData(gridData);
    m_modifyCondition.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection selection = (StructuredSelection) m_viewer.getSelection();
            if (selection != null && selection.size() > 0) {
                m_selectItem = (List<Object>) selection.getFirstElement();
            } else {
                m_selectItem = null;
            }

            if (m_selectItem != null) {
                ReplaceTextDialog dialog = new ReplaceTextDialog(m_shell, m_selectItem);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    List<?> info = dialog.getInputData();
                    List<Object> list = (ArrayList<Object>) m_viewer.getInput();
                    list.remove(m_selectItem);
                    list.add(info);
                    m_selectItem = null;
                    m_viewer.setInput(list);
                }
            } else {

            }
        }
    });

    //?
    m_deleteCondition = new Button(this, SWT.NONE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = true;
    m_deleteCondition.setText(Messages.getString("delete"));
    m_deleteCondition.setLayoutData(gridData);
    m_deleteCondition.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection selection = (StructuredSelection) m_viewer.getSelection();
            if (selection != null && selection.size() > 0) {
                m_selectItem = (List<Object>) selection.getFirstElement();
            } else {
                m_selectItem = null;
            }
            if (m_selectItem != null) {
                List<Object> list = (ArrayList<Object>) m_viewer.getInput();
                boolean b = list.remove(m_selectItem);
                m_log.debug("remove " + b);
                m_selectItem = null;
                m_viewer.setInput(list);
            } else {
                m_log.debug("m_selectItem is null.");
            }
        }
    });

    m_viewer = new CommonTableViewer(table);
    m_viewer.createTableColumn(GetInfraFileReplaceSettingTableDefine.get(),
            GetInfraFileReplaceSettingTableDefine.SORT_COLUMN_INDEX,
            GetInfraFileReplaceSettingTableDefine.SORT_ORDER);

}

From source file:com.clustercontrol.infra.composite.InfraFileManagerComposite.java

License:Open Source License

@Override
public void selectionChanged(SelectionChangedEvent event) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

    StructuredSelection selection = (StructuredSelection) event.getSelection();
    IViewPart viewPart = page.findView(InfraFileManagerView.ID);
    if (viewPart != null && selection != null) {
        InfraFileManagerView view = (InfraFileManagerView) viewPart.getAdapter(InfraFileManagerView.class);
        if (view == null) {
            m_log.info("selection changed: view is null");
            return;
        }/*from w w  w.  j a v a  2s .  c o m*/
        view.setEnabledAction(selection.size(), selection);
    }
}

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

License:Open Source License

@Override
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
    boolean enable = false;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    // page may not start at state restoring
    if (null != window) {
        IWorkbenchPage page = window.getActivePage();
        if (null != page) {
            IWorkbenchPart part = page.getActivePart();

            if (part instanceof InfraModuleView) {
                InfraModuleView view = (InfraModuleView) part.getAdapter(InfraModuleView.class);
                if (view == null) {
                    m_log.info("execute: infra module view is null");
                    return;
                }/*from   w  w  w . j  ava  2s.  co m*/
                if (view.getComposite().getManagementId() != null) {
                    enable = true;
                }
            } else if (part instanceof InfraManagementView) {
                InfraManagementView view = (InfraManagementView) part.getAdapter(InfraManagementView.class);
                if (view == null) {
                    m_log.info("execute: infra management view is null");
                    return;
                }
                StructuredSelection selection = (StructuredSelection) view.getComposite().getTableViewer()
                        .getSelection();
                if (selection.size() == 1) {
                    enable = true;
                }
            }
            this.setBaseEnabled(enable);
        }
    }
}

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

License:Open Source License

@Override
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
    boolean enable = false;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    // page may not start at state restoring
    if (null != window) {
        IWorkbenchPage page = window.getActivePage();
        if (null != page) {
            IWorkbenchPart part = page.getActivePart();

            if (part instanceof InfraManagementView) {
                InfraManagementView view = (InfraManagementView) part.getAdapter(InfraManagementView.class);
                if (view == null) {
                    m_log.info("execute: view is null");
                    return;
                }//from   w  ww  .ja va 2s  .  co m
                // Enable button when 1 item is selected
                StructuredSelection selection = null;
                if (view.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) {
                    selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection();
                }
                if (selection != null && selection.size() > 0) {
                    enable = true;
                }
            }
            this.setBaseEnabled(enable);
        } else {
            this.setBaseEnabled(false);
        }
    }
}