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

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

Introduction

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

Prototype

public Object[] getCheckedElements() 

Source Link

Document

Returns a list of elements corresponding to checked table items in this viewer.

Usage

From source file:com.google.dart.tools.search.internal.ui.SearchDialog.java

License:Open Source License

private void handleCustomizePressed() {
    List<SearchPageDescriptor> input = SearchPlugin.getDefault().getSearchPageDescriptors();
    input = filterByActivities(input);/* w  w w  .j  ava2 s. c o m*/

    final ArrayList<Image> createdImages = new ArrayList<Image>(input.size());
    ILabelProvider labelProvider = new LabelProvider() {
        @Override
        public Image getImage(Object element) {
            if (element instanceof SearchPageDescriptor) {
                ImageDescriptor imageDesc = ((SearchPageDescriptor) element).getImage();
                if (imageDesc == null) {
                    return null;
                }
                Image image = imageDesc.createImage();
                if (image != null) {
                    createdImages.add(image);
                }
                return image;
            }
            return null;
        }

        @Override
        public String getText(Object element) {
            if (element instanceof SearchPageDescriptor) {
                return LegacyActionTools.removeMnemonics(((SearchPageDescriptor) element).getLabel());
            }
            return null;
        }
    };

    String message = SearchMessages.SearchPageSelectionDialog_message;

    ListSelectionDialog dialog = new ListSelectionDialog(getShell(), input, new ArrayContentProvider(),
            labelProvider, message) {
        @Override
        public void create() {
            super.create();
            final CheckboxTableViewer viewer = getViewer();
            final Button okButton = this.getOkButton();
            viewer.addCheckStateListener(new ICheckStateListener() {
                @Override
                public void checkStateChanged(CheckStateChangedEvent event) {
                    okButton.setEnabled(viewer.getCheckedElements().length > 0);
                }
            });
            SelectionListener listener = new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    okButton.setEnabled(viewer.getCheckedElements().length > 0);
                }
            };
            this.getButton(IDialogConstants.SELECT_ALL_ID).addSelectionListener(listener);
            this.getButton(IDialogConstants.DESELECT_ALL_ID).addSelectionListener(listener);
        }
    };
    dialog.setTitle(SearchMessages.SearchPageSelectionDialog_title);
    dialog.setInitialSelections(
            SearchPlugin.getDefault().getEnabledSearchPageDescriptors(fInitialPageId).toArray());
    if (dialog.open() == Window.OK) {
        SearchPageDescriptor.setEnabled(dialog.getResult());
        Display display = getShell().getDisplay();
        close();
        if (display != null && !display.isDisposed()) {
            display.asyncExec(new Runnable() {
                @Override
                public void run() {
                    new OpenSearchDialogAction().run();
                }
            });
        }
    }
    destroyImages(createdImages);
}

From source file:com.javadude.workingsets.internal.NatureWorkingSetPage.java

License:Open Source License

/**
 * Create the UI for the property page//from ww w  .ja v  a2  s  .  c  o  m
 */
@Override
protected void createFields(Composite parent) {
    if (getWorkingSet() != null) {
        natureId_ = getWorkingSet().getName().substring(8);
    }
    Label label = new Label(parent, SWT.NULL);
    label.setText("Registered Natures:");
    label.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, true));
    int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION
            | SWT.CHECK;
    final CheckboxTableViewer table = CheckboxTableViewer.newCheckList(parent, style);
    List<String> natures = new ArrayList<String>();
    for (IProjectNatureDescriptor nature : ResourcesPlugin.getWorkspace().getNatureDescriptors()) {
        natures.add(nature.getNatureId());
    }
    Collections.sort(natures);
    for (String nature : natures) {
        table.add(nature);
    }
    if (natureId_ != null) {
        String[] split = natureId_.split("[,\\s]");
        for (String nature : split) {
            table.setChecked(nature, true);
        }
    }
    table.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    table.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            natureId_ = null;
            for (Object o : table.getCheckedElements()) {
                if (natureId_ == null) {
                    natureId_ = (String) o;
                } else {
                    natureId_ += ',' + (String) o;
                }
            }
            dialogChanged();
        }
    });
}

From source file:com.nokia.carbide.search.system.internal.ui.SearchDialog.java

License:Open Source License

private void handleCustomizePressed() {
    List input = SearchPlugin.getDefault().getSearchPageDescriptors();
    input = filterByActivities(input);//from  w w  w  .j  ava2s  . c  o m

    final ArrayList createdImages = new ArrayList(input.size());
    ILabelProvider labelProvider = new LabelProvider() {
        public String getText(Object element) {
            if (element instanceof SearchPageDescriptor)
                return LegacyActionTools.removeMnemonics(((SearchPageDescriptor) element).getLabel());
            return null;
        }

        public Image getImage(Object element) {
            if (element instanceof SearchPageDescriptor) {
                ImageDescriptor imageDesc = ((SearchPageDescriptor) element).getImage();
                if (imageDesc == null)
                    return null;
                Image image = imageDesc.createImage();
                if (image != null)
                    createdImages.add(image);
                return image;
            }
            return null;
        }
    };

    String message = SearchMessages.SearchPageSelectionDialog_message;

    ListSelectionDialog dialog = new ListSelectionDialog(getShell(), input, new ArrayContentProvider(),
            labelProvider, message) {
        public void create() {
            super.create();
            final CheckboxTableViewer viewer = getViewer();
            final Button okButton = this.getOkButton();
            viewer.addCheckStateListener(new ICheckStateListener() {
                public void checkStateChanged(CheckStateChangedEvent event) {
                    okButton.setEnabled(viewer.getCheckedElements().length > 0);
                }
            });
            SelectionListener listener = new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    okButton.setEnabled(viewer.getCheckedElements().length > 0);
                }
            };
            this.getButton(IDialogConstants.SELECT_ALL_ID).addSelectionListener(listener);
            this.getButton(IDialogConstants.DESELECT_ALL_ID).addSelectionListener(listener);
        }
    };
    dialog.setTitle(SearchMessages.SearchPageSelectionDialog_title);
    dialog.setInitialSelections(
            SearchPlugin.getDefault().getEnabledSearchPageDescriptors(fInitialPageId).toArray());
    if (dialog.open() == Window.OK) {
        SearchPageDescriptor.setEnabled(dialog.getResult());
        Display display = getShell().getDisplay();
        close();
        if (display != null && !display.isDisposed()) {
            display.asyncExec(new Runnable() {
                public void run() {
                    new OpenSearchDialogAction().run();
                }
            });
        }
    }
    destroyImages(createdImages);
}

From source file:com.nokia.s60tools.swmtanalyser.editors.GraphedItemsHelper.java

License:Open Source License

/**
 * The method checks all items in the given viewer and assigns random colors for all checked items.
 * @param tableViewer//w w w .j  a v  a  2  s . com
 */
private void selectAllItems(CheckboxTableViewer tableViewer) {
    tableViewer.setAllChecked(true);

    for (Object obj : tableViewer.getCheckedElements()) {
        if (obj instanceof GraphedItemsInput) {
            GraphedItemsInput graphedItem = (GraphedItemsInput) obj;

            if (graphedItem.getColor() == null)
                graphedItem.setColor(getRandomColor());

            tableViewer.update(obj, null);
        }
    }

}

From source file:com.nokia.s60tools.swmtanalyser.editors.GraphedItemsHelper.java

License:Open Source License

/**
 * This method updates the graph based on the selections made in the given graphed items viewer.
 * @param tableViewer //from  w  w  w.  j  a v  a  2  s  . c o  m
 * @param graphToBeUpdated
 */
private void notifyGraphedItemsSelection(CheckboxTableViewer tableViewer, GraphForAllEvents graphToBeUpdated) {
    Object[] checkedElems = tableViewer.getCheckedElements();

    ArrayList<GraphedItemsInput> selectedItems = new ArrayList<GraphedItemsInput>();

    for (Object obj : checkedElems) {
        GraphedItemsInput graphInput = (GraphedItemsInput) obj;
        selectedItems.add(graphInput);
    }

    graphToBeUpdated.setGraphedItemsInput(selectedItems);
    graphToBeUpdated.constructGraphArea();
}

From source file:com.siteview.mde.internal.ui.parts.WizardCheckboxTablePart.java

License:Open Source License

public Object[] getSelection() {
    CheckboxTableViewer viewer = getTableViewer();
    return viewer.getCheckedElements();
}

From source file:com.siteview.mde.internal.ui.parts.WizardCheckboxTablePart.java

License:Open Source License

public void setSelection(Object[] selected) {
    CheckboxTableViewer viewer = getTableViewer();
    viewer.setCheckedElements(selected);
    updateCounter(viewer.getCheckedElements().length);
}

From source file:com.siteview.mde.internal.ui.parts.WizardCheckboxTablePart.java

License:Open Source License

protected void handleSelect(boolean select) {
    CheckboxTableViewer viewer = getTableViewer();
    if (viewer.getTable().getSelection().length > 0) {
        TableItem[] selected = viewer.getTable().getSelection();
        for (int i = 0; i < selected.length; i++) {
            TableItem item = selected[i];
            item.setChecked(select);/*from  ww  w.ja  v  a  2  s  .c  om*/
        }
        updateCounter(viewer.getCheckedElements().length);
    }
}

From source file:fr.inria.soctrace.tools.framesoc.exporter.BackupFiles.java

License:Open Source License

/**
 * Creates the main window's contents//  www .j a  va 2 s  .  co m
 * 
 * @param parent
 *            the main window
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    // Create the source directory panel and its controls
    final Text sourceDir = createFilePanelHelper(composite, "Source Dir:");

    // Create the CheckboxTableViewer to display the files in the source dir
    final CheckboxTableViewer ctv = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
    ctv.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    ctv.setContentProvider(new BackupFilesContentProvider());
    ctv.setLabelProvider(new BackupFilesLabelProvider());

    // Create the destination directory panel and its controls
    final Text destDir = createFilePanelHelper(composite, "Dest Dir:");

    // Create the Copy button
    Button copy = new Button(composite, SWT.PUSH);
    copy.setText("Copy");

    // Create the status field
    status = new Label(composite, SWT.NONE);
    status.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // When the source directory changes, change the input for the viewer
    sourceDir.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            ctv.setInput(((Text) event.widget).getText());
        }
    });

    // When copy is pressed, copy the files
    copy.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Get the checked elements
            Object[] files = ctv.getCheckedElements();
            if (files.length > 0) {
                // Some files are checked; make sure we have a valid
                // destination
                File dest = new File(destDir.getText());
                if (dest.isDirectory()) {
                    // Go through each file
                    for (int i = 0, n = files.length; i < n; i++) {
                        copyFile((File) files[i], dest);
                    }
                } else
                    showMessage("You must select a valid destination directory");
            } else
                showMessage("You must select some files to copy");
        }
    });

    return composite;
}

From source file:gov.redhawk.ide.sdr.ui.export.DeployableScaExportWizardPage.java

License:Open Source License

@Override
public void createControl(final Composite parent) {
    this.model = ((DeployableScaExportWizard) getWizard()).getModel();

    final DataBindingContext dbc = new DataBindingContext();
    WizardPageSupport.create(this, dbc);

    setTitle("Deployable SCA");
    setMessage("Export the selected projects into a form suitable for deploying into a OSSIE SDR root");

    final Composite client = new Composite(parent, SWT.NULL);
    client.setLayout(new GridLayout(1, false));

    final Composite projectSelectionGroup = new Composite(client, SWT.NULL);
    projectSelectionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    projectSelectionGroup.setLayout(new GridLayout(2, false));

    final Label availScaProjects = new Label(projectSelectionGroup, SWT.NONE);
    availScaProjects.setText("Available SCA Projects:");
    availScaProjects.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));

    final CheckboxTableViewer availableProjectsViewer = new CheckboxTableViewer(
            new Table(projectSelectionGroup, SWT.CHECK | SWT.READ_ONLY | SWT.BORDER));
    availableProjectsViewer.setContentProvider(new ArrayContentProvider());
    availableProjectsViewer.setLabelProvider(new LabelProvider() {

        @Override//  w w w  . j a v a2s .c o  m
        public String getText(final Object element) {
            return ((IProject) element).getName();
        }

    });
    final IProject[] scaProjects = getScaProjects();
    availableProjectsViewer.setInput(scaProjects);
    availableProjectsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    final Composite buttonBox = new Composite(projectSelectionGroup, SWT.NULL);
    buttonBox.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
    buttonBox.setLayout(new GridLayout(1, false));

    final Label selectedProjects = new Label(projectSelectionGroup, SWT.NONE);
    selectedProjects.setText(this.model.projectsToExport.size() + " of " + scaProjects.length + " selected.");
    selectedProjects.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
    availableProjectsViewer.addCheckStateListener(new ICheckStateListener() {
        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            selectedProjects.setText(availableProjectsViewer.getCheckedElements().length + " of "
                    + scaProjects.length + " selected.");
        }
    });

    final Button selectAll = new Button(buttonBox, SWT.PUSH);
    selectAll.setText("Select All");
    selectAll.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    selectAll.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            availableProjectsViewer.setAllChecked(true);
            DeployableScaExportWizardPage.this.model.projectsToExport.clear();
            DeployableScaExportWizardPage.this.model.projectsToExport.addAll(Arrays.asList(scaProjects));
            selectedProjects.setText(availableProjectsViewer.getCheckedElements().length + " of "
                    + scaProjects.length + " selected.");
        }

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            // PASS
        }
    });

    final Button selectNone = new Button(buttonBox, SWT.PUSH);
    selectNone.setText("Deselect All");
    selectNone.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    selectNone.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            availableProjectsViewer.setAllChecked(false);
            DeployableScaExportWizardPage.this.model.projectsToExport.clear();
            selectedProjects.setText(availableProjectsViewer.getCheckedElements().length + " of "
                    + scaProjects.length + " selected.");
        }

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            // PASS
        }
    });

    final TabFolder exportCustomization = new TabFolder(client, SWT.TOP);
    exportCustomization.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));

    final Composite destinationComposite = new Composite(exportCustomization, SWT.NONE);
    destinationComposite.setLayout(new GridLayout(2, false));

    final Button directoryRadio = new Button(destinationComposite, SWT.RADIO);
    directoryRadio.setText("Directory:");
    directoryRadio.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
    directoryRadio.setSelection(true);

    final Text directoryText = new Text(destinationComposite, SWT.BORDER);
    directoryText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    directoryText.setEnabled(true);

    final Button directoryBrowse = new Button(destinationComposite, SWT.PUSH);
    directoryBrowse.setText("Browse...");
    directoryBrowse.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    directoryBrowse.setEnabled(true);
    directoryBrowse.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final DirectoryDialog fd = new DirectoryDialog(
                    PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.OPEN);
            fd.setText("Destination Directory");
            fd.setFilterPath(null);
            final String selected = fd.open();
            if (selected != null) {
                directoryText.setText(selected);
                dbc.updateModels();
            }
        }

    });

    directoryRadio.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final boolean selected = directoryRadio.getSelection();
            directoryText.setEnabled(selected);
            directoryBrowse.setEnabled(selected);
        }

    });

    final Button archiveRadio = new Button(destinationComposite, SWT.RADIO);
    archiveRadio.setText("Archive file:");
    archiveRadio.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
    archiveRadio.setSelection(false);

    final Text archiveText = new Text(destinationComposite, SWT.BORDER);
    archiveText.setText("");
    archiveText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    archiveText.setEnabled(false);

    final Button archiveBrowse = new Button(destinationComposite, SWT.PUSH);
    archiveBrowse.setText("Browse...");
    archiveBrowse.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    archiveBrowse.setEnabled(false);
    archiveBrowse.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final FileDialog fd = new FileDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
                    SWT.SAVE);
            fd.setText("Destination Archive");
            fd.setFilterPath(null);
            final String[] filterExt = { "*.zip" };
            fd.setFilterExtensions(filterExt);
            final String selected = fd.open();
            if (selected != null) {
                IPath zippath = new Path(selected);
                if (zippath.getFileExtension() == null) {
                    zippath = zippath.addFileExtension("zip");
                }
                archiveText.setText(zippath.toString());
                dbc.updateModels();
            }
        }

    });

    archiveRadio.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final boolean selected = archiveRadio.getSelection();
            archiveText.setEnabled(selected);
            archiveBrowse.setEnabled(selected);
        }

    });

    final TabItem destinationtab = new TabItem(exportCustomization, SWT.NONE);
    destinationtab.setText("Destination");
    destinationtab.setControl(destinationComposite);

    setControl(client);

    bind(dbc, availableProjectsViewer, directoryRadio, directoryText, archiveRadio, archiveText);
}