Example usage for org.eclipse.jface.viewers CheckboxTableViewer setCheckStateProvider

List of usage examples for org.eclipse.jface.viewers CheckboxTableViewer setCheckStateProvider

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers CheckboxTableViewer setCheckStateProvider.

Prototype

public void setCheckStateProvider(ICheckStateProvider checkStateProvider) 

Source Link

Document

Sets the ICheckStateProvider for this CheckboxTreeViewer .

Usage

From source file:org.eclipse.ui.internal.dialogs.cpd.CustomizePerspectiveDialog.java

License:Open Source License

private Composite createActionSetAvailabilityPage(Composite parent) {
    GridData data;/*  w  ww  . j  av a  2  s. c  om*/

    Composite actionSetsComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    actionSetsComposite.setLayout(layout);

    // Select... label
    Label label = new Label(actionSetsComposite, SWT.WRAP);
    label.setText(NLS.bind(WorkbenchMessages.ActionSetSelection_selectActionSetsLabel,
            perspective.getDesc().getLabel()));
    data = new GridData(SWT.FILL, SWT.CENTER, true, false);
    label.setLayoutData(data);

    Label sep = new Label(actionSetsComposite, SWT.HORIZONTAL | SWT.SEPARATOR);
    sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    SashForm sashComposite = new SashForm(actionSetsComposite, SWT.HORIZONTAL);
    data = new GridData(SWT.FILL, SWT.FILL, true, true);
    sashComposite.setLayoutData(data);

    // Action Set List Composite
    Composite actionSetGroup = new Composite(sashComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    actionSetGroup.setLayout(layout);
    actionSetGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    label = new Label(actionSetGroup, SWT.WRAP);
    label.setText(WorkbenchMessages.ActionSetSelection_availableActionSets);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final CheckboxTableViewer actionSetsViewer = CheckboxTableViewer.newCheckList(actionSetGroup,
            SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    actionSetAvailabilityTable = actionSetsViewer;
    actionSetsViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    actionSetsViewer.setContentProvider(new ArrayContentProvider());
    actionSetsViewer.setComparator(new WorkbenchViewerComparator());
    actionSetsViewer.setCheckStateProvider(new ICheckStateProvider() {
        @Override
        public boolean isChecked(Object element) {
            return ((ActionSet) element).isActive();
        }

        @Override
        public boolean isGrayed(Object element) {
            return false;
        }
    });
    actionSetsViewer.setInput(actionSets.toArray());

    Table table = actionSetsViewer.getTable();
    new TableToolTip(table);

    final ActionSet[] selectedActionSet = { null };

    // Filter to show only branches necessary for the selected action set.
    final ViewerFilter setFilter = new ViewerFilter() {
        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (selectedActionSet[0] == null) {
                return false;
            }
            return includeInSetStructure((DisplayItem) element, selectedActionSet[0]);
        }
    };

    // Updates the check state of action sets
    actionSetsViewer.addCheckStateListener(new ICheckStateListener() {
        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            final ActionSet actionSet = (ActionSet) event.getElement();
            if (event.getChecked()) {
                actionSet.setActive(true);
                for (DisplayItem item : actionSet.contributionItems) {
                    item.setCheckState(true);
                }
            } else {
                actionSet.setActive(false);
            }
        }
    });

    // Menu and toolbar composite
    Composite actionGroup = new Composite(sashComposite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = 0;
    actionGroup.setLayout(layout);
    actionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite menubarGroup = new Composite(actionGroup, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    menubarGroup.setLayout(layout);
    menubarGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    label = new Label(menubarGroup, SWT.WRAP);
    label.setText(WorkbenchMessages.ActionSetSelection_menubarActions);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    actionSetMenuViewer = new TreeViewer(menubarGroup);
    actionSetMenuViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    actionSetMenuViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    actionSetMenuViewer.setUseHashlookup(true);
    actionSetMenuViewer.setContentProvider(TreeManager.getTreeContentProvider());
    actionSetMenuViewer.setLabelProvider(new GrayOutUnavailableLabelProvider(null));
    actionSetMenuViewer.addFilter(setFilter);
    actionSetMenuViewer.setInput(menuItems);

    Tree tree = actionSetMenuViewer.getTree();
    new ItemDetailToolTip(this, actionSetMenuViewer, tree, false, true, setFilter);

    Composite toolbarGroup = new Composite(actionGroup, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    toolbarGroup.setLayout(layout);
    toolbarGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    label = new Label(toolbarGroup, SWT.WRAP);
    label.setText(WorkbenchMessages.ActionSetSelection_toolbarActions);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    actionSetToolbarViewer = new TreeViewer(toolbarGroup);
    actionSetToolbarViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    actionSetToolbarViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    actionSetToolbarViewer.setContentProvider(TreeManager.getTreeContentProvider());
    actionSetToolbarViewer.setLabelProvider(new GrayOutUnavailableLabelProvider(null));
    actionSetToolbarViewer.addFilter(setFilter);
    actionSetToolbarViewer.setInput(toolBarItems);

    tree = actionSetToolbarViewer.getTree();
    new ItemDetailToolTip(this, actionSetToolbarViewer, tree, false, true, setFilter);

    // Updates the menu item and toolbar items tree viewers when the
    // selection changes
    actionSetsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            selectedActionSet[0] = (ActionSet) ((IStructuredSelection) event.getSelection()).getFirstElement();
            actionSetMenuViewer.setInput(menuItems);
            actionSetToolbarViewer.setInput(toolBarItems);
        }
    });

    sashComposite.setWeights(new int[] { 30, 70 });

    return actionSetsComposite;
}

From source file:org.eclipse.ui.internal.dialogs.cpd.TreeManager.java

License:Open Source License

/**
 * Sets up this {@link TreeManager} for standard interaction with the
 * provided {@link CheckboxTableViewer}. In particular:
 * <ul>/*from  w  ww.  j  av a 2  s. c  o m*/
 *    <li>Adds a Label Provider for {@link TreeItem}s which provides both
 *       labels and images.</li>
 *    <li>Adds a {@link CheckStateProvider} for {@link TreeItem}s.</li>
 *    <li>Adds an {@link IContentProvider} to build a tree from input
 *       {@link TreeItem}s.</li>
 *    <li>Adds an {@link ICheckStateListener} to the viewer to update the
 *       appropriate {@link TreeItem}s upon a check box state change in the
 *       viewer.</li>
 *    <li>Adds a {@link CheckListener} to the {@link TreeManager} which will
 *       automatically update the viewer on a {@link TreeItem} check state
 *       change.</li>
 * </ul>
 * @param viewer   the viewer to configure with this TreeManager.
 */
public void attachAll(CheckboxTableViewer viewer) {
    viewer.setLabelProvider(getLabelProvider());
    viewer.setCheckStateProvider(getCheckStateProvider());
    viewer.setContentProvider(getTreeContentProvider());
    viewer.addCheckStateListener(getViewerCheckStateListener());
    getCheckListener(viewer);
}

From source file:org.eclipse.ui.internal.dialogs.CustomizePerspectiveDialog.java

License:Open Source License

private Composite createShortCutsPage(Composite parent) {
    GridData data;//w  ww.  j a  v  a 2  s . co m

    Composite menusComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    menusComposite.setLayout(layout);

    // Select... label
    Label label = new Label(menusComposite, SWT.WRAP);
    label.setText(NLS.bind(WorkbenchMessages.Shortcuts_selectShortcutsLabel, perspective.getDesc().getLabel()));
    data = new GridData(SWT.FILL, SWT.CENTER, true, false);
    label.setLayoutData(data);

    Label sep = new Label(menusComposite, SWT.HORIZONTAL | SWT.SEPARATOR);
    sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    SashForm sashComposite = new SashForm(menusComposite, SWT.HORIZONTAL);
    data = new GridData(SWT.FILL, SWT.FILL, true, true);
    sashComposite.setLayoutData(data);

    // Menus List
    Composite menusGroup = new Composite(sashComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    menusGroup.setLayout(layout);
    menusGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    label = new Label(menusGroup, SWT.WRAP);
    label.setText(WorkbenchMessages.Shortcuts_availableMenus);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    Combo menusCombo = new Combo(menusGroup, SWT.READ_ONLY);
    menusCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    ComboViewer menusViewer = new ComboViewer(menusCombo);
    menusViewer.setContentProvider(TreeManager.getTreeContentProvider());
    menusViewer.setLabelProvider(TreeManager.getLabelProvider());

    // Categories Tree
    label = new Label(menusGroup, SWT.WRAP);
    label.setText(WorkbenchMessages.Shortcuts_availableCategories);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final CheckboxTreeViewer menuCategoriesViewer = new CheckboxTreeViewer(menusGroup);
    menuCategoriesViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    menuCategoriesViewer.setLabelProvider(TreeManager.getLabelProvider());
    menuCategoriesViewer.setContentProvider(TreeManager.getTreeContentProvider());
    menuCategoriesViewer.setComparator(new WorkbenchViewerComparator());
    menuCategoriesViewer.setCheckStateProvider(new CategoryCheckProvider());
    menuCategoriesViewer.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            Category category = (Category) event.getElement();
            category.setItemsState(event.getChecked());
            updateCategoryAndParents(menuCategoriesViewer, category);
        }
    });

    treeManager.addListener(new CheckListener() {
        public void checkChanged(TreeItem changedItem) {
            if (changedItem instanceof Category) {
                menuCategoriesViewer.update(changedItem, null);
            } else if (changedItem instanceof ShortcutItem) {
                ShortcutItem item = (ShortcutItem) changedItem;
                if (item.getCategory() != null) {
                    item.getCategory().update();
                    updateCategoryAndParents(menuCategoriesViewer, item.getCategory());
                }
            }
        }
    });

    // Menu items list
    Composite menuItemsGroup = new Composite(sashComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    menuItemsGroup.setLayout(layout);
    menuItemsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    label = new Label(menuItemsGroup, SWT.WRAP);
    label.setText(WorkbenchMessages.Shortcuts_allShortcuts);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final CheckboxTableViewer menuItemsViewer = CheckboxTableViewer.newCheckList(menuItemsGroup,
            SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    Table menuTable = menuItemsViewer.getTable();
    menuTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    menuItemsViewer.setLabelProvider(new ShortcutLabelProvider());
    menuItemsViewer.setCheckStateProvider(TreeManager.getCheckStateProvider());
    menuItemsViewer.addCheckStateListener(treeManager.getViewerCheckStateListener());
    treeManager.getCheckListener(menuItemsViewer);

    menuItemsViewer.setContentProvider(new TreeManager.TreeItemContentProvider() {
        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof Category)
                return ((Category) parentElement).getContributionItems().toArray();
            return super.getChildren(parentElement);
        }
    });
    menuItemsViewer.setComparator(new WorkbenchViewerComparator());

    // update menuCategoriesViewer, and menuItemsViewer on a change to
    // menusViewer
    menusViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            Category category = (Category) ((IStructuredSelection) event.getSelection()).getFirstElement();
            menuCategoriesViewer.setInput(category);
            menuItemsViewer.setInput(category);
            if (category.getChildren().size() != 0) {
                setSelectionOn(menuCategoriesViewer, category.getChildren().get(0));
            }
        }
    });

    // update menuItemsViewer on a change to menuCategoriesViewer
    menuCategoriesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            Category category = (Category) ((IStructuredSelection) event.getSelection()).getFirstElement();
            menuItemsViewer.setInput(category);
        }
    });

    menuTable.setHeaderVisible(true);
    int[] columnWidths = new int[shortcutMenuColumnWidths.length];
    for (int i = 0; i < shortcutMenuColumnWidths.length; i++) {
        columnWidths[i] = convertHorizontalDLUsToPixels(shortcutMenuColumnWidths[i]);
    }
    for (int i = 0; i < shortcutMenuColumnHeaders.length; i++) {
        TableColumn tc = new TableColumn(menuTable, SWT.NONE, i);
        tc.setResizable(true);
        tc.setText(shortcutMenuColumnHeaders[i]);
        tc.setWidth(columnWidths[i]);
    }
    sashComposite.setWeights(new int[] { 30, 70 });

    menusViewer.setInput(shortcuts);

    if (shortcuts.getChildren().size() > 0) {
        setSelectionOn(menusViewer, shortcuts.getChildren().get(0));
    }

    return menusComposite;
}

From source file:org.eclipse.ui.internal.dialogs.CustomizePerspectiveDialog.java

License:Open Source License

private Composite createActionSetAvailabilityPage(Composite parent) {
    GridData data;//from   w  w  w .  j  av a2 s.  c  o  m

    Composite actionSetsComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    actionSetsComposite.setLayout(layout);

    // Select... label
    Label label = new Label(actionSetsComposite, SWT.WRAP);
    label.setText(NLS.bind(WorkbenchMessages.ActionSetSelection_selectActionSetsLabel,
            perspective.getDesc().getLabel()));
    data = new GridData(SWT.FILL, SWT.CENTER, true, false);
    label.setLayoutData(data);

    Label sep = new Label(actionSetsComposite, SWT.HORIZONTAL | SWT.SEPARATOR);
    sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    SashForm sashComposite = new SashForm(actionSetsComposite, SWT.HORIZONTAL);
    data = new GridData(SWT.FILL, SWT.FILL, true, true);
    sashComposite.setLayoutData(data);

    // Action Set List Composite
    Composite actionSetGroup = new Composite(sashComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    actionSetGroup.setLayout(layout);
    actionSetGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    label = new Label(actionSetGroup, SWT.WRAP);
    label.setText(WorkbenchMessages.ActionSetSelection_availableActionSets);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final CheckboxTableViewer actionSetsViewer = CheckboxTableViewer.newCheckList(actionSetGroup,
            SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    actionSetAvailabilityTable = actionSetsViewer;
    actionSetsViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    actionSetsViewer.setLabelProvider(new LabelProvider());
    actionSetsViewer.setContentProvider(new ArrayContentProvider());
    actionSetsViewer.setComparator(new WorkbenchViewerComparator());
    actionSetsViewer.setCheckStateProvider(new ICheckStateProvider() {
        public boolean isChecked(Object element) {
            return ((ActionSet) element).isActive();
        }

        public boolean isGrayed(Object element) {
            return false;
        }
    });
    actionSetsViewer.setInput(actionSets.toArray());

    Table table = actionSetsViewer.getTable();
    new TableToolTip(table);

    final ActionSet[] selectedActionSet = { null };

    // Filter to show only branches necessary for the selected action set.
    final ViewerFilter setFilter = new ViewerFilter() {
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (selectedActionSet[0] == null)
                return false;
            return includeInSetStructure((DisplayItem) element, selectedActionSet[0]);
        }
    };

    // Updates the check state of action sets
    actionSetsViewer.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            final ActionSet actionSet = (ActionSet) event.getElement();
            if (event.getChecked()) {
                actionSet.setActive(true);
                for (Iterator i = actionSet.contributionItems.iterator(); i.hasNext();) {
                    DisplayItem item = (DisplayItem) i.next();
                    item.setCheckState(true);
                }
            } else {
                actionSet.setActive(false);
            }
        }
    });

    // Menu and toolbar composite
    Composite actionGroup = new Composite(sashComposite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = 0;
    actionGroup.setLayout(layout);
    actionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite menubarGroup = new Composite(actionGroup, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    menubarGroup.setLayout(layout);
    menubarGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    label = new Label(menubarGroup, SWT.WRAP);
    label.setText(WorkbenchMessages.ActionSetSelection_menubarActions);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final TreeViewer actionSetMenuViewer = new TreeViewer(menubarGroup);
    actionSetMenuViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    actionSetMenuViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    actionSetMenuViewer.setUseHashlookup(true);
    actionSetMenuViewer.setContentProvider(TreeManager.getTreeContentProvider());
    actionSetMenuViewer.setLabelProvider(TreeManager.getLabelProvider());
    actionSetMenuViewer.addFilter(setFilter);
    actionSetMenuViewer.setInput(menuItems);

    Tree tree = actionSetMenuViewer.getTree();
    new ItemDetailToolTip(actionSetMenuViewer, tree, false, true, setFilter);

    Composite toolbarGroup = new Composite(actionGroup, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    toolbarGroup.setLayout(layout);
    toolbarGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    label = new Label(toolbarGroup, SWT.WRAP);
    label.setText(WorkbenchMessages.ActionSetSelection_toolbarActions);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final TreeViewer actionSetToolbarViewer = new TreeViewer(toolbarGroup);
    actionSetToolbarViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    actionSetToolbarViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    actionSetToolbarViewer.setContentProvider(TreeManager.getTreeContentProvider());
    actionSetToolbarViewer.setLabelProvider(TreeManager.getLabelProvider());
    actionSetToolbarViewer.addFilter(setFilter);
    actionSetToolbarViewer.setInput(toolBarItems);

    tree = actionSetToolbarViewer.getTree();
    new ItemDetailToolTip(actionSetToolbarViewer, tree, false, true, setFilter);

    // Updates the menu item and toolbar items tree viewers when the
    // selection changes
    actionSetsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            selectedActionSet[0] = (ActionSet) ((IStructuredSelection) event.getSelection()).getFirstElement();
            actionSetMenuViewer.setInput(menuItems);
            actionSetToolbarViewer.setInput(toolBarItems);
        }
    });

    sashComposite.setWeights(new int[] { 30, 70 });

    return actionSetsComposite;
}

From source file:org.kalypso.contribs.eclipse.ui.dialogs.ListSelectionDialog.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 *//*from   w w  w.  java2 s.c o m*/
@Override
protected Control createDialogArea(final Composite parent) {
    /* Set the title. */
    getShell().setText("Auswahl erforderlich");

    /* Create the main composite. */
    final Composite main = (Composite) super.createDialogArea(parent);
    main.setLayout(new GridLayout(1, false));
    final GridData mainData = new GridData(SWT.FILL, SWT.FILL, true, true);
    mainData.widthHint = 400;
    main.setLayoutData(mainData);

    /* Create a label. */
    final Label descriptionLabel = new Label(main, SWT.WRAP);
    descriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    descriptionLabel.setText("Bitte whlen Sie die gewnschten Elemente aus.");
    if (m_description != null && m_description.length() > 0)
        descriptionLabel.setText(m_description);

    /* Create the list viewer. */
    final CheckboxTableViewer listViewer = CheckboxTableViewer.newCheckList(main, SWT.BORDER);
    listViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    listViewer.getTable().setHeaderVisible(false);
    listViewer.getTable().setLinesVisible(true);
    listViewer.setContentProvider(new ArrayContentProvider());
    listViewer.setInput(m_allElements);
    listViewer.setLabelProvider(new LabelProvider());
    if (m_labelProvider != null)
        listViewer.setLabelProvider(m_labelProvider);

    /* Add a check state provider. */
    listViewer.setCheckStateProvider(new ICheckStateProvider() {
        /**
         * @see org.eclipse.jface.viewers.ICheckStateProvider#isGrayed(java.lang.Object)
         */
        @Override
        public boolean isGrayed(final Object element) {
            return false;
        }

        /**
         * @see org.eclipse.jface.viewers.ICheckStateProvider#isChecked(java.lang.Object)
         */
        @Override
        public boolean isChecked(final Object element) {
            if (m_selectedElements == null || m_selectedElements.length == 0)
                return false;

            final List<T> checkedElements = Arrays.asList(m_selectedElements);
            return checkedElements.contains(element);
        }
    });

    /* Add a listener. */
    listViewer.addCheckStateListener(new ICheckStateListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            /* Store the new selection. */
            final Object[] checkedElements = listViewer.getCheckedElements();

            final Object newInstance = java.lang.reflect.Array.newInstance(m_clazz, checkedElements.length);
            System.arraycopy(checkedElements, 0, newInstance, 0, checkedElements.length);
            m_selectedElements = (T[]) newInstance;

            /* Check if the dialog can be completed. */
            checkDialogComplete();
        }
    });

    return main;
}

From source file:org.kalypso.model.km.internal.ui.kmupdate.KMUpdateWizardPage.java

License:Open Source License

/**
 * This function creates the channel list viewer.
 *
 * @param parent/*from   www  .j av a 2s .co  m*/
 *          The parent composite.
 * @return The channel list viewer.
 */
private CheckboxTableViewer createChannelListViewer(final Composite parent) {
    /* Get the km channels of the NA model. */
    final KMChannelElement[] elements = KMBindingUtils.createKMElements(m_naModel);
    for (final KMChannelElement element : elements) {
        if (ArrayUtils.contains(m_selectedFeatures, element.getKMChannel()))
            element.getKMType().setEnabled(true);
    }

    /* Create a checkbox table viewer. */
    final CheckboxTableViewer channelListViewer = CheckboxTableViewer.newCheckList(parent,
            SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);

    /* Configure it. */
    channelListViewer.setContentProvider(new ArrayContentProvider());
    channelListViewer.setLabelProvider(new KMUpdateLabelProvider());
    channelListViewer.setCheckStateProvider(new KMUpdateCheckstateProvider());
    channelListViewer.setInput(elements);

    /* Add a listener. */
    channelListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            handleChannelListChanged(selection, false);
        }
    });

    channelListViewer.addCheckStateListener(new ICheckStateListener() {
        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            final KMChannelElement element = (KMChannelElement) event.getElement();
            element.getKMType().setEnabled(event.getChecked());
        }
    });

    /* If there are selected features, select the first one. */
    if (m_selectedFeatures.length > 0) {
        /* Select the first selected feature. */
        channelListViewer.setSelection(new StructuredSelection(m_selectedFeatures[0]));
    }

    channelListViewer.update(elements, null);

    return channelListViewer;
}

From source file:org.polarsys.reqcycle.traceability.builder.ui.preferences.TraceabilityBuildersPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    Composite c = new Composite(parent, SWT.None);
    c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    c.setLayout(new GridLayout(1, false));

    Label lblTheCheckedProjects = new Label(c, SWT.NONE);
    lblTheCheckedProjects.setText("The checked projects will be analyzed by ReqCycle traceability engine");

    CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(c, SWT.BORDER);
    Table table = checkboxTableViewer.getTable();
    checkboxTableViewer.setLabelProvider(new WorkbenchLabelProvider());
    checkboxTableViewer.setContentProvider(new BaseWorkbenchContentProvider());
    checkboxTableViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
    checkboxTableViewer.setCheckStateProvider(new ICheckStateProvider() {

        @Override/*from ww w . j  a va  2s .c  o  m*/
        public boolean isGrayed(Object element) {
            return false;
        }

        @Override
        public boolean isChecked(Object element) {
            if (element instanceof IProject) {
                IProject project = (IProject) element;
                return BuilderUtil.isBuilderInstalled(project);
            }
            return false;
        }
    });
    checkboxTableViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return element instanceof IProject && ((IProject) element).isAccessible();
        }
    });
    checkboxTableViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            Object element = event.getElement();
            if (element instanceof IProject) {
                IProject project = (IProject) element;
                if (event.getChecked()) {
                    BuilderUtil.installBuilder(project);
                } else {
                    BuilderUtil.removeBuilder(project);
                }
            }
        }
    });
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    return parent;
}

From source file:org.rulez.magwas.zenta.editor.preferences.ConnectionsPreferencePage.java

License:Open Source License

private CheckboxTableViewer createRelationsTable(Composite parent) {
    final CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 80;//from ww  w .ja v a  2 s . com
    viewer.getTable().setLayoutData(gd);

    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ZentaLabelProvider.INSTANCE.getDefaultName((EClass) element);
        }

        @Override
        public Image getImage(Object element) {
            return ZentaLabelProvider.INSTANCE.getImage(element);
        }
    });

    viewer.setContentProvider(new IStructuredContentProvider() {
        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return ConnectionPreferences.RELATION_KEYMAP.keySet().toArray();
        }
    });

    viewer.setCheckStateProvider(new ICheckStateProvider() {
        @Override
        public boolean isGrayed(Object element) {
            return false;
        }

        @Override
        public boolean isChecked(Object element) {
            int value = (Integer) viewer.getInput();
            return (value & ConnectionPreferences.RELATION_KEYMAP.get(element)) != 0;
        }
    });

    return viewer;
}

From source file:org.talend.camel.designer.ui.editor.dependencies.CheckedCamelDependenciesPanel.java

License:Open Source License

@Override
protected TableViewer createTableViewer() {
    final CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList(this,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    viewer.setCheckStateProvider(checkStateProvider);
    viewer.addCheckStateListener(new ICheckStateListener() {
        @Override//from  w  w  w. j a v  a  2  s  .co m
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (((ManifestItem) event.getElement()).isBuiltIn()) {
                viewer.setChecked(event.getElement(), !event.getChecked());
            } else {
                ((ManifestItem) event.getElement()).setOptional(!event.getChecked());
                fireDependenciesChangedListener();
            }
        }
    });
    return viewer;
}

From source file:x10dt.core.builder.migration.ProjectMigrationDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite area = (Composite) super.createDialogArea(parent);
    GridLayout topLayout = new GridLayout(1, false);
    area.setLayout(topLayout);//from  w ww .  j  a va 2 s .c o m

    Text descriptionText = new Text(area, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
    descriptionText.setText(Messages.ProjectMigrationDialog_explanationText);
    descriptionText.setBackground(parent.getBackground());
    descriptionText.setLayoutData(new GridData(340, 45));

    Label topLabel = new Label(area, SWT.NONE);
    topLabel.setText(Messages.ProjectMigrationDialog_projectListLabel);

    Composite tableButtons = new Composite(area, SWT.NONE);
    tableButtons.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    final CheckboxTableViewer cbTableViewer = CheckboxTableViewer.newCheckList(tableButtons,
            SWT.BORDER | SWT.V_SCROLL);

    cbTableViewer.setContentProvider(new IStructuredContentProvider() {
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public void dispose() {
        }

        public Object[] getElements(Object inputElement) {
            return fBrokenProjects.toArray();
        }
    });
    cbTableViewer.setLabelProvider(new ITableLabelProvider() {
        public void addListener(ILabelProviderListener listener) {
        }

        public void removeListener(ILabelProviderListener listener) {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void dispose() {
        }

        public String getColumnText(Object element, int columnIndex) {
            return ((IProject) element).getName();
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }
    });
    cbTableViewer.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            IProject p = (IProject) event.getElement();
            if (event.getChecked()) {
                fMigrateProjects.add(p);
            } else {
                fMigrateProjects.remove(p);
            }
        }
    });
    cbTableViewer.setCheckStateProvider(new ICheckStateProvider() {
        public boolean isGrayed(Object element) {
            return false;
        }

        public boolean isChecked(Object element) {
            return fMigrateProjects.contains(element);
        }
    });
    cbTableViewer.setInput(new Object()); // a dummy input just to trigger the initial update

    Composite selectButtons = new Composite(tableButtons, SWT.NONE);
    GridLayout selectButtonsLayout = new GridLayout(1, true);
    selectButtons.setLayout(selectButtonsLayout);

    Button selectAllButton = new Button(selectButtons, SWT.PUSH);
    selectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    selectAllButton.setText(Messages.ProjectMigrationDialog_selectAllButtonTitle);
    selectAllButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            fMigrateProjects.addAll(fBrokenProjects);
            cbTableViewer.refresh();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    Button deselectAllButton = new Button(selectButtons, SWT.PUSH);
    deselectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    deselectAllButton.setText(Messages.ProjectMigrationDialog_deselectAllButtonTitle);
    deselectAllButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            fMigrateProjects.clear();
            cbTableViewer.refresh();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    GridLayout tableButtonsLayout = new GridLayout(2, false);
    GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
    gridData.heightHint = 100; // if you don't set this, the vertical scrollbar will never appear!
    cbTableViewer.getTable().setLayoutData(gridData);

    selectButtons.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    tableButtons.setLayout(tableButtonsLayout);

    final Button dontAskAgainCB = new Button(area, SWT.CHECK);

    dontAskAgainCB.setText(Messages.ProjectMigrationDialog_dontAskCheckboxTitle);

    Text dontAskExplanationText = new Text(area, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
    dontAskExplanationText.setBackground(parent.getBackground());
    dontAskExplanationText.setLayoutData(new GridData(340, 65));
    dontAskExplanationText.setText(Messages.ProjectMigrationDialog_dontAskExplanationText1
            + Messages.ProjectMigrationDialog_dontAskExplanationText2
            + Messages.ProjectMigrationDialog_dontAskExplanationText3);

    dontAskAgainCB.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            fDontAskAgain = dontAskAgainCB.getSelection();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    return area;
}