Java Code Examples for org.eclipse.jface.viewers.CheckboxTableViewer#setCheckStateProvider()

The following examples show how to use org.eclipse.jface.viewers.CheckboxTableViewer#setCheckStateProvider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PathsProvider.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected PathsProvider(TableViewer viewer, FindbugsPropertyPage propertyPage) {
    this.propertyPage = propertyPage;
    this.paths = new ArrayList<>();
    this.viewer = viewer;
    if (viewer instanceof CheckboxTableViewer) {
        CheckboxTableViewer tv = (CheckboxTableViewer) viewer;
        tv.setCheckStateProvider(this);
        tv.addCheckStateListener(new ICheckStateListener() {
            @Override
            public void checkStateChanged(CheckStateChangedEvent event) {
                boolean checked = event.getChecked();
                IPathElement element = (IPathElement) event.getElement();
                element.setEnabled(checked);
                handleContendChanged();
            }
        });
    }
    this.control = viewer.getTable();
    listeners = new ListenerList();
    viewer.setContentProvider(this);
}
 
Example 2
Source File: CheckedCamelDependenciesPanel.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
@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
        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;
}
 
Example 3
Source File: MOOSETreePropertySection.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Adds the default and additional columns to the provided
 * <code>TableViewer</code>. This should only be invoked on
 * CheckboxTableViewers.
 */
@Override
protected void addTableViewerColumns(TableViewer tableViewer) {
	if (tableViewer != null) {
		TableColumn column;
		ICellContentProvider contentProvider;

		// // ---- Create the placeholder CheckBox column. ---- //
		checkColumn = new TableViewerColumn(tableViewer, SWT.LEFT);
		column = checkColumn.getColumn();
		column.setText("Enabled");
		column.setToolTipText("If checked, the parameter will be written "
				+ "to the input file.\n" + "If unchecked, the parameter "
				+ "will be commented out in the input file.");
		column.setResizable(true);

		// Create the check state manager. It also functions as the cell
		// content provider for the first column.
		TableCheckStateManager checkStateManager = new TableCheckStateManager(
				tableViewer) {
			@Override
			public boolean setValue(Object element, Object value) {
				boolean changed = super.setValue(element, value);
				// If the value changed, mark the associated ICEFormEditor
				// as dirty.
				if (changed && getFormEditor() != null) {
					getFormEditor().setDirty(true);
				}
				return changed;
			}
		};

		// Create a MOOSECheckStateProvider which sets the FormEditor as
		// dirty when the checkbox's value is changed.
		contentProvider = checkStateManager;

		// Add a blank label provider. Nothing should appear in the first
		// column except for the checkboxes.
		checkColumn.setLabelProvider(
				new CellColumnLabelProvider(contentProvider));

		// Set the content provider and listener for the CheckBox column
		CheckboxTableViewer checkedTableViewer = (CheckboxTableViewer) tableViewer;
		checkedTableViewer.setCheckStateProvider(checkStateManager);
		checkedTableViewer.addCheckStateListener(checkStateManager);

		// Create the default columns.
		super.addTableViewerColumns(tableViewer);

		// ---- Create the description/comments column. ---- //
		descriptionColumn = new TableViewerColumn(tableViewer, SWT.LEFT);
		column = descriptionColumn.getColumn();
		column.setText("Comments");
		column.setToolTipText("Comments about the property. These are "
				+ "stored as comments in the input file.");
		column.setResizable(true);
		// Create an ICellContentProvider for a column that shows the
		// descriptions of Entries. Then hook it up as a label provider and
		// for editing support.
		contentProvider = new DescriptionCellContentProvider() {
			@Override
			public boolean setValue(Object element, Object value) {
				boolean changed = super.setValue(element, value);
				// If the value changed, mark the associated ICEFormEditor
				// as dirty.
				if (changed && getFormEditor() != null) {
					getFormEditor().setDirty(true);
				}
				return changed;
			}
		};
		descriptionColumn.setLabelProvider(
				new CellColumnLabelProvider(contentProvider));
		descriptionColumn.setEditingSupport(
				new TextCellEditingSupport(tableViewer, contentProvider));
		// ------------------------------------------------- //
	}

	return;
}