org.eclipse.jface.viewers.CheckboxTreeViewer Java Examples

The following examples show how to use org.eclipse.jface.viewers.CheckboxTreeViewer. 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: DirectoryTreeContentProvider.java    From eclipse with Apache License 2.0 8 votes vote down vote up
private static void setChecked(final CheckboxTreeViewer tv, Object element) {
  // When user checks a checkbox in the tree, check all its children and mark parent as greyed
  // When a user uncheck a checkbox, mark the subtree as unchecked and ungrayed and if unique
  // sibling parent as grayed.
  DirectoryTreeContentProvider provider = (DirectoryTreeContentProvider) tv.getContentProvider();

  boolean isChecked = tv.getChecked(element);
  if (tv.getGrayed(element)) {
    isChecked = !isChecked;
  }
  tv.setChecked(element, isChecked);
  tv.setGrayed(element, false);
  if (isChecked) {
    tv.setSubtreeChecked(element, true);
  } else {
    tv.setSubtreeChecked(element, false);
  }
  setGrayed(tv, provider.getParent(element));
}
 
Example #2
Source File: FieldToContractInputMappingViewerCheckStateManagerTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_regeneratedAttributes_whenReselectParent() {
    final FieldToContractInputMappingViewerCheckStateManager checkedStateManager = new FieldToContractInputMappingViewerCheckStateManager();
    final FieldToContractInputMapping rootMapping = new RelationFieldToContractInputMapping(
            Mockito.mock(RelationField.class));
    final SimpleFieldToContractInputMapping childMapping1 = new SimpleFieldToContractInputMapping(
            Mockito.mock(SimpleField.class));
    final SimpleFieldToContractInputMapping childMapping2 = new SimpleFieldToContractInputMapping(
            Mockito.mock(SimpleField.class));
    rootMapping.addChild(childMapping1);
    rootMapping.addChild(childMapping2);
    final CheckboxTreeViewer viewer = aCheckBoxTreeViewer(Lists.newArrayList(rootMapping));
    checkedStateManager.checkStateChanged(new CheckStateChangedEvent(viewer, rootMapping, false));
    assertThat(rootMapping.isGenerated()).isFalse();
    assertThat(childMapping1.isGenerated()).isFalse();
    assertThat(childMapping2.isGenerated()).isFalse();
    checkedStateManager.checkStateChanged(new CheckStateChangedEvent(viewer, rootMapping, true));
    assertThat(rootMapping.isGenerated()).isTrue();
    assertThat(childMapping1.isGenerated()).isTrue();
    assertThat(childMapping2.isGenerated()).isTrue();
}
 
Example #3
Source File: TraceTypePreferencePageViewer.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create the filter area
 *
 * @param parent
 *            The parent composite
 * @return The filter area composite
 */
public Composite createFilterArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, true));
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    CheckboxTreeViewer treeViewer = createTreeViewer(composite);
    Control buttonComposite = createSelectionButtons(composite);
    GridData data = new GridData(GridData.FILL_BOTH);
    Tree treeWidget = treeViewer.getTree();
    treeWidget.setLayoutData(data);
    treeWidget.setFont(parent.getFont());
    if (fIsEmpty) {
        treeWidget.setEnabled(false);
        buttonComposite.setEnabled(false);
    }
    return composite;
}
 
Example #4
Source File: DirectoryTreeContentProvider.java    From eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the list of path selected in <code>tv</code>. It returns the list of checked path
 * without the children of the checked path. Each path is returned as a string giving the relative
 * path from the root of the tree.
 */
static ImmutableList<String> getSelectPathsRelativeToRoot(CheckboxTreeViewer tv) {
  DirectoryTreeContentProvider provider = (DirectoryTreeContentProvider) tv.getContentProvider();
  String root = provider.root.getAbsolutePath();
  ImmutableList.Builder<String> builder = ImmutableList.builder();
  for (Object element : tv.getCheckedElements()) {
    if (!tv.getGrayed(element)) {
      Object parent = provider.getParent(element);
      if (parent == null || tv.getGrayed(parent)) {
        // Only add this element if its parent is not selected (so it's the root).
        String path = ((File) element).getAbsolutePath();
        // Strip root from path
        if (path.startsWith(root)) {
          path = path.substring(root.length());
          if (path.startsWith("/")) {
            path = path.substring(1);
          }
          builder.add(path);
        }
      }
    }
  }
  return builder.build();
}
 
Example #5
Source File: TriStateFilteredCheckboxTree.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void checkSubtree(Object element, boolean state) {
    CheckboxTreeViewer checkboxTreeViewer = getCheckboxTreeViewer();
    if (checkboxTreeViewer.testFindItem(element) != null) {
        if (state) {
            fCheckedObjects.add(element);
        } else {
            fCheckedObjects.remove(element);
        }
    }
    boolean expanded = checkboxTreeViewer.getExpandedState(element);
    /* make sure element is expanded so that testFindItem will find the children */
    checkboxTreeViewer.setExpandedState(element, true);
    for (Object o : ((ITreeContentProvider) checkboxTreeViewer.getContentProvider()).getChildren(element)) {
        checkSubtree(o, state);
    }
    checkboxTreeViewer.setExpandedState(element, expanded);
    maintainAllCheckIntegrity();
}
 
Example #6
Source File: DirectoryTreeContentProvider.java    From eclipse with Apache License 2.0 6 votes vote down vote up
private static void setGrayed(CheckboxTreeViewer tv, Object element) {
  if (element == null) {
    return;
  }
  DirectoryTreeContentProvider provider = (DirectoryTreeContentProvider) tv.getContentProvider();
  boolean checked = tv.getChecked(element);
  boolean grayed = false;
  for (Object object : provider.getChildren(element)) {
    grayed = grayed || tv.getGrayed(object) || tv.getChecked(object);
    checked = checked && tv.getChecked(object) && !tv.getGrayed(element);
  }
  if (checked) {
    tv.setChecked(element, true);
    tv.setGrayed(element, false);
  } else if (grayed) {
    tv.setGrayChecked(element, true);
  } else {
    tv.setChecked(element, false);
    tv.setGrayed(element, false);
  }
  setGrayed(tv, provider.getParent(element));
}
 
Example #7
Source File: TimeGraphFilterDialog.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    Label messageLabel = createMessageArea(composite);
    CheckboxTreeViewer treeViewer = createTreeViewer(composite);
    Control buttonComposite = createSelectionButtons(composite);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = convertWidthInCharsToPixels(fWidth);
    data.heightHint = convertHeightInCharsToPixels(fHeight);
    Tree treeWidget = treeViewer.getTree();
    treeWidget.setLayoutData(data);
    treeWidget.setFont(parent.getFont());
    if (fIsEmpty) {
        messageLabel.setEnabled(false);
        treeWidget.setEnabled(false);
        buttonComposite.setEnabled(false);
    }
    return composite;
}
 
Example #8
Source File: TimeGraphFilterDialog.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates the tree viewer.
 *
 * @param parent
 *            the parent composite
 * @return the tree viewer
 */
protected CheckboxTreeViewer createTreeViewer(Composite parent) {
    PatternFilter filter = new TreePatternFilter();
    filter.setIncludeLeadingWildcard(true);
    fTree = new FilteredCheckboxTree(parent, SWT.BORDER | SWT.MULTI, filter, true, false);

    Tree tree = fTree.getViewer().getTree();
    tree.setHeaderVisible(true);
    for (String columnName : fColumnNames) {
        TreeColumn column = new TreeColumn(tree, SWT.LEFT);
        column.setText(columnName);
    }

    fTree.getViewer().setContentProvider(fContentProvider);
    fTree.getViewer().setLabelProvider(fLabelProvider);
    fTree.addCheckStateListener(new CheckStateListener());
    fTree.getViewer().setComparator(fComparator);
    if (fFilters != null) {
        for (int i = 0; i != fFilters.size(); i++) {
            fTree.getViewer().addFilter(fFilters.get(i));
        }
    }
    fTree.getViewer().setInput(fInput);
    return (CheckboxTreeViewer) fTree.getViewer();
}
 
Example #9
Source File: ImportTracePackageWizardPage.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void updateWithFilePathSelection() {
    if (!isFilePathValid()) {
        setErrorMessage(Messages.ImportTracePackageWizardPage_ErrorFileNotFound);
        getElementViewer().setInput(null);
        return;
    }
    setErrorMessage(null);

    getContainer().getShell().getDisplay().asyncExec(() -> {
        CheckboxTreeViewer elementViewer = getElementViewer();
        Object elementViewerInput = createElementViewerInput();
        elementViewer.setInput(elementViewerInput);
        if (elementViewerInput != null) {
            elementViewer.expandToLevel(2);
            setAllChecked(elementViewer, false, true);
            fValidatedFilePath = getFilePathValue();
        }

        updatePageCompletion();
    });
}
 
Example #10
Source File: AbstractSelectTreeViewer.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param parent
 *            Parent composite
 * @param checkboxTree
 *            <code>TriStateFilteredTree</code> wrapping a
 *            <code>CheckboxTreeViewer</code>
 * @param legendColumnIndex
 *            index of the legend column (-1 if none)
 */
private AbstractSelectTreeViewer(Composite parent, TriStateFilteredCheckboxTree checkboxTree,
        int legendIndex, String id) {
    super(parent, checkboxTree.getViewer());

    TreeViewer treeViewer = checkboxTree.getViewer();
    treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    treeViewer.setComparator(COMPARATOR);
    if (treeViewer instanceof CheckboxTreeViewer) {
        ((CheckboxTreeViewer) treeViewer).addCheckStateListener(new CheckStateChangedListener());
    }
    treeViewer.addSelectionChangedListener(new TreeViewerSelectionListener());
    checkboxTree.getFilterControl().addModifyListener(e -> saveViewContext());
    fCheckboxTree = checkboxTree;
    fLegendIndex = legendIndex;
    fId = id;
    fLogCategory = fId + LOG_CATEGORY_SUFFIX;
    setLabelProvider(new DataProviderTreeLabelProvider());
    fInstanceId = INSTANCE_ID_SEQUENCE.incrementAndGet();
}
 
Example #11
Source File: AbstractSelectTreeViewer2.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param parent
 *            Parent composite
 * @param checkboxTree
 *            <code>TriStateFilteredTree</code> wrapping a
 *            <code>CheckboxTreeViewer</code>
 * @param legendColumnIndex
 *            index of the legend column (-1 if none)
 */
private AbstractSelectTreeViewer2(Composite parent, TriStateFilteredCheckboxTree checkboxTree,
        int legendIndex, String id) {
    super(parent, checkboxTree.getViewer());

    TreeViewer treeViewer = checkboxTree.getViewer();
    treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    treeViewer.setComparator(COMPARATOR);
    if (treeViewer instanceof CheckboxTreeViewer) {
        ((CheckboxTreeViewer) treeViewer).addCheckStateListener(new CheckStateChangedListener());
    }
    treeViewer.addSelectionChangedListener(new TreeViewerSelectionListener());
    checkboxTree.getFilterControl().addModifyListener(e -> saveViewContext());
    fCheckboxTree = checkboxTree;
    fLegendIndex = legendIndex;
    fId = id;
    fLogCategory = fId + LOG_CATEGORY_SUFFIX;
    fInstanceId = INSTANCE_ID_SEQUENCE.incrementAndGet();
    setLabelProvider(new DataProviderTreeLabelProvider());
}
 
Example #12
Source File: FieldToContractInputMappingViewerCheckStateManagerTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_not_deselectParent_IfNoChildIsSelected() {
    final FieldToContractInputMappingViewerCheckStateManager checkedStateManager = new FieldToContractInputMappingViewerCheckStateManager();

    final FieldToContractInputMapping rootMapping = new RelationFieldToContractInputMapping(
            Mockito.mock(RelationField.class));
    final SimpleFieldToContractInputMapping childMapping1 = new SimpleFieldToContractInputMapping(
            Mockito.mock(SimpleField.class));
    final SimpleFieldToContractInputMapping childMapping2 = new SimpleFieldToContractInputMapping(
            Mockito.mock(SimpleField.class));
    rootMapping.addChild(childMapping1);
    rootMapping.addChild(childMapping2);
    final CheckboxTreeViewer viewer = aCheckBoxTreeViewer(Lists.newArrayList(rootMapping));
    checkedStateManager.checkStateChanged(new CheckStateChangedEvent(viewer, childMapping2, true));
    checkedStateManager.checkStateChanged(new CheckStateChangedEvent(viewer, childMapping1, false));

    assertThat(viewer.getChecked(rootMapping)).isTrue();
}
 
Example #13
Source File: FieldToContractInputMappingViewerCheckStateManagerTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_deselectParent_IfNoChildIsSelected() {
    final FieldToContractInputMappingViewerCheckStateManager checkedStateManager = new FieldToContractInputMappingViewerCheckStateManager();

    final FieldToContractInputMapping rootMapping = new RelationFieldToContractInputMapping(
            Mockito.mock(RelationField.class));
    final SimpleFieldToContractInputMapping childMapping = new SimpleFieldToContractInputMapping(
            Mockito.mock(SimpleField.class));
    rootMapping.addChild(childMapping);
    final CheckboxTreeViewer viewer = aCheckBoxTreeViewer(Lists.newArrayList(rootMapping));

    checkedStateManager.checkStateChanged(new CheckStateChangedEvent(viewer, childMapping, false));

    assertThat(viewer.getChecked(rootMapping)).isFalse();
    assertThat(rootMapping.isGenerated()).isFalse();
}
 
Example #14
Source File: FieldToContractInputMappingViewerCheckStateManagerTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_selectParentIfChildIsSelected() {
    final FieldToContractInputMappingViewerCheckStateManager checkedStateManager = new FieldToContractInputMappingViewerCheckStateManager();

    final FieldToContractInputMapping rootMapping = new RelationFieldToContractInputMapping(
            Mockito.mock(RelationField.class));
    final SimpleFieldToContractInputMapping childMapping = new SimpleFieldToContractInputMapping(
            Mockito.mock(SimpleField.class));
    rootMapping.addChild(childMapping);
    final CheckboxTreeViewer viewer = aCheckBoxTreeViewer(Lists.newArrayList(rootMapping));

    checkedStateManager.checkStateChanged(new CheckStateChangedEvent(viewer, childMapping, true));

    assertThat(viewer.getChecked(rootMapping)).isTrue();
    assertThat(rootMapping.isGenerated()).isTrue();
}
 
Example #15
Source File: CheckNodeTreeView.java    From depan with Apache License 2.0 6 votes vote down vote up
@Override
protected CheckboxTreeViewer createTreeViewer(Composite parent) {
  int style = SWT.VIRTUAL | SWT.FULL_SELECTION | SWT.BORDER
      | SWT.H_SCROLL | SWT.V_SCROLL;
  CheckboxTreeViewer result = new CheckboxTreeViewer(parent, style);
  result.setLabelProvider(new WorkbenchLabelProvider());
  result.setContentProvider(new BaseWorkbenchContentProvider());
  result.setComparator(new NodeWrapperTreeSorter());

  result.addCheckStateListener(new ICheckStateListener() {
    @Override
    public void checkStateChanged(CheckStateChangedEvent event) {
      if (recursiveTreeSelect) {
        tree.setSubtreeChecked(event.getElement(), event.getChecked());
      }
    }
  });

  tree = result;
  return result;
}
 
Example #16
Source File: MultipleFolderSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates the tree viewer.
 *
 * @param parent the parent composite
 * @return the tree viewer
 */
protected CheckboxTreeViewer createTreeViewer(Composite parent) {
	fViewer = new CheckboxTreeViewer(parent, SWT.BORDER);

	fViewer.setContentProvider(fContentProvider);
	fViewer.setLabelProvider(fLabelProvider);
	fViewer.addCheckStateListener(new ICheckStateListener() {
		public void checkStateChanged(CheckStateChangedEvent event) {
			updateOKStatus();
		}
	});

	fViewer.setComparator(new ResourceComparator(ResourceComparator.NAME));
	if (fFilters != null) {
		for (int i = 0; i != fFilters.size(); i++)
			fViewer.addFilter(fFilters.get(i));
	}

	fViewer.setInput(fInput);

	return fViewer;
}
 
Example #17
Source File: ResourceSelectionTree.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void updateParentState(IResource child, boolean baseChildState) {
	if (mode == MODE_FLAT || child == null || child.getParent() == null || resourceList.contains(child.getParent())) {
		return;
	}
	CheckboxTreeViewer checkboxTreeViewer = (CheckboxTreeViewer)treeViewer;
	if (child == null) return;
	Object parent = resourceSelectionContentProvider.getParent(child);
	if (parent == null) return;
	boolean allSameState = true;
	Object[] children = null;
	children = resourceSelectionContentProvider.getChildren(parent);
	for (int i = children.length - 1; i >= 0; i--) {
		if (checkboxTreeViewer.getChecked(children[i]) != baseChildState || checkboxTreeViewer.getGrayed(children[i])) {
		   allSameState = false;
	       break;
		}
	}
	checkboxTreeViewer.setGrayed(parent, !allSameState);
	checkboxTreeViewer.setChecked(parent, !allSameState || baseChildState);
	updateParentState((IResource)parent, baseChildState);
}
 
Example #18
Source File: SourceActionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void create() {
	super.create();

	// select the first checked element, or if none are checked, the first element
	CheckboxTreeViewer treeViewer= getTreeViewer();
	TreeItem[] items= treeViewer.getTree().getItems();
	if (items.length > 0) {
		Object revealedElement= items[0];

		for (int i= 0; i < items.length; i++) {
			if (items[i].getChecked()) {
				revealedElement= items[i].getData();
				break;
			}
		}
		treeViewer.setSelection(new StructuredSelection(revealedElement));
		treeViewer.reveal(revealedElement);
	}
}
 
Example #19
Source File: CheckboxTreeAndListGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 *	Creates this group's tree viewer.
 * @param parent parent composite
 * @param width the width
 * @param height the height
 */
protected void createTreeViewer(Composite parent, int width, int height) {
	Tree tree= new Tree(parent, SWT.CHECK | SWT.BORDER);
	GridData data= new GridData(GridData.FILL_BOTH);
	data.widthHint= width;
	data.heightHint= height;
	tree.setLayoutData(data);

	fTreeViewer= new CheckboxTreeViewer(tree);
	fTreeViewer.setUseHashlookup(true);
	fTreeViewer.setContentProvider(fTreeContentProvider);
	fTreeViewer.setLabelProvider(fTreeLabelProvider);
	fTreeViewer.addTreeListener(this);
	fTreeViewer.addCheckStateListener(this);
	fTreeViewer.addSelectionChangedListener(this);
}
 
Example #20
Source File: PackageFilterEditor.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
  Composite composite = (Composite) super.createDialogArea(parent);
  Label messageLabel = createMessageArea(composite);
  CheckboxTreeViewer treeViewer = createTreeViewer(composite);

  GridData data = new GridData(GridData.FILL_BOTH);
  data.widthHint = convertWidthInCharsToPixels(mWidth);
  data.heightHint = convertHeightInCharsToPixels(mHeight);
  Tree treeWidget = treeViewer.getTree();
  treeWidget.setLayoutData(data);
  treeWidget.setFont(parent.getFont());
  if (mIsEmpty) {
    messageLabel.setEnabled(false);
    treeWidget.setEnabled(false);
  }
  return composite;
}
 
Example #21
Source File: OverrideMethodDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected CheckboxTreeViewer createTreeViewer(Composite composite) {
	initializeDialogUnits(composite);
	ViewerPane pane= new ViewerPane(composite, SWT.BORDER | SWT.FLAT);
	pane.setText(JavaUIMessages.OverrideMethodDialog_dialog_description);
	CheckboxTreeViewer treeViewer= super.createTreeViewer(pane);
	pane.setContent(treeViewer.getControl());
	GridLayout paneLayout= new GridLayout();
	paneLayout.marginHeight= 0;
	paneLayout.marginWidth= 0;
	paneLayout.numColumns= 1;
	pane.setLayout(paneLayout);
	GridData gd= new GridData(GridData.FILL_BOTH);
	gd.widthHint= convertWidthInCharsToPixels(55);
	gd.heightHint= convertHeightInCharsToPixels(15);
	pane.setLayoutData(gd);
	ToolBarManager manager= pane.getToolBarManager();
	manager.add(new OverrideFlatTreeAction()); // create after tree is created
	manager.update(true);
	treeViewer.getTree().setFocus();
	return treeViewer;
}
 
Example #22
Source File: GenerateToStringDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void move(Object element, CheckboxTreeViewer tree, int direction) {
	Object[] array= getContainingArray(element);
	int position= getElementPosition(element, array);
	Object temp= array[position];
	array[position]= array[position + direction];
	array[position + direction]= temp;
	tree.setSelection(new StructuredSelection(element));
	tree.refresh();
}
 
Example #23
Source File: RepositoryImportWizard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void createControl(Composite parent) {
	Composite container = UI.formComposite(parent);
	setControl(container);
	viewer = new CheckboxTreeViewer(container, SWT.BORDER);
	viewer.setLabelProvider(new Label());
	viewer.setContentProvider(new ContentProvider());
	viewer.setUseHashlookup(true);
	viewer.addCheckStateListener(new SelectionState(this));
	UI.gridData(viewer.getTree(), true, true);
}
 
Example #24
Source File: FieldToContractInputMappingViewerCheckStateManagerTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_manage_persistence_id_fields_generated() {

    BusinessObject rootBo = mock(BusinessObject.class);

    RelationField root = RelationFieldBuilder.aCompositionField("root", rootBo);
    SimpleField nameField = SimpleFieldBuilder.aStringField("name").build();
    SimpleField persistenceIdField = SimpleFieldBuilder.aStringField("persistenceId_string").build();

    RelationFieldToContractInputMapping rootMapping = new RelationFieldToContractInputMapping(root);
    SimpleFieldToContractInputMapping rootNameMapping = new SimpleFieldToContractInputMapping(nameField);
    SimpleFieldToContractInputMapping rootPersistenceIdMapping = new SimpleFieldToContractInputMapping(
            persistenceIdField);
    rootMapping.addChild(rootNameMapping);
    rootMapping.addChild(rootPersistenceIdMapping);

    CheckboxTreeViewer viewer = aCheckBoxTreeViewer(Lists.newArrayList(rootMapping));
    FieldToContractInputMappingViewerCheckStateManager checkedStateManager = new FieldToContractInputMappingViewerCheckStateManager();

    checkedStateManager.checkStateChanged(new CheckStateChangedEvent(viewer, rootMapping, false));
    assertThat(viewer.getCheckedElements()).isEmpty();
    assertThat(Arrays.asList(rootMapping, rootNameMapping, rootPersistenceIdMapping))
            .allMatch(mapping -> !mapping.isGenerated());

    checkedStateManager.checkStateChanged(new CheckStateChangedEvent(viewer, rootMapping, true));
    assertThat(viewer.getChecked(rootMapping)).isTrue();
    assertThat(checkedStateManager.isGrayed(rootMapping)).isFalse();
    assertThat(viewer.getChecked(rootNameMapping)).isTrue();
    assertThat(Arrays.asList(rootMapping, rootNameMapping, rootPersistenceIdMapping))
            .allMatch(FieldToContractInputMapping::isGenerated);

    checkedStateManager.checkStateChanged(new CheckStateChangedEvent(viewer, rootNameMapping, false));
    assertThat(viewer.getChecked(rootMapping)).isTrue();
    assertThat(checkedStateManager.isGrayed(rootMapping)).isTrue();
    assertThat(rootMapping.isGenerated()).isTrue();
    assertThat(rootNameMapping.isGenerated()).isFalse();
    assertThat(rootPersistenceIdMapping.isGenerated()).isTrue();
}
 
Example #25
Source File: ModelSelectionPage.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void createViewer(Composite composite) {
	viewer = new CheckboxTreeViewer(composite, SWT.VIRTUAL | SWT.MULTI
			| SWT.BORDER);
	viewer.setUseHashlookup(true);
	viewer.getTree().setLayoutData(
			new GridData(SWT.FILL, SWT.FILL, true, true));
	viewer.setContentProvider(new NavigationContentProvider());
	viewer.setLabelProvider(new NavigationLabelProvider(false));
	viewer.setComparator(new NavigationComparator());
	viewer.addFilter(new ModelTypeFilter(types));
	viewer.addCheckStateListener(new ModelSelectionState(this, viewer));
	registerInputHandler(composite);
	ColumnViewerToolTipSupport.enableFor(viewer);
}
 
Example #26
Source File: MultipleFolderSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void newFolderButtonPressed() {
	Object createdFolder= createFolder(fSelectedContainer);
	if (createdFolder != null) {
		CheckboxTreeViewer treeViewer= fViewer;
		treeViewer.refresh(fSelectedContainer);
		treeViewer.reveal(createdFolder);
		treeViewer.setChecked(createdFolder, true);
		treeViewer.setSelection(new StructuredSelection(createdFolder));
		updateOKStatus();
	}
}
 
Example #27
Source File: LevelViewDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void createLevelViewer( Composite parent )
{
	levelViewer = new CheckboxTreeViewer( parent, SWT.SINGLE | SWT.BORDER );

	GridData gd = new GridData( GridData.FILL_BOTH );
	gd.widthHint = 340;
	gd.heightHint = 250;
	levelViewer.getTree( ).setLayoutData( gd );

	levelViewer.setContentProvider( new CubeContentProvider( ) );
	levelViewer.setLabelProvider( new CubeLabelProvider( ) );
	levelViewer.addCheckStateListener( new ICheckStateListener( ) {

		public void checkStateChanged( CheckStateChangedEvent event )
		{

			LevelHandle item = (LevelHandle) event.getElement( );
			if ( event.getChecked( ) )
			{
				if ( !showLevels.contains( item ) )
					showLevels.add( item );
			}
			else
			{
				if ( showLevels.contains( item ) )
					showLevels.remove( item );
			}

			checkOKButtonStatus( );
		}

	} );
}
 
Example #28
Source File: MOOSETreeCompositeView.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Overrides the default viewer to add an additional feature: When a parent
 * node is unchecked, all of its child nodes are unchecked.
 */
@Override
protected TreeViewer createViewer(Composite parent) {
	TreeViewer treeViewer = null;

	if (parent != null) {
		// Initialize the TreeViewer. Note: We create a CheckboxTreeViewer!
		final CheckboxTreeViewer checkboxTreeViewer = new CheckboxTreeViewer(
				parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL
						| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
		treeViewer = checkboxTreeViewer;

		// Set and configure the content and label providers
		treeViewer.setContentProvider(new TreeCompositeContentProvider(
				this, parentMap));
		treeViewer.setLabelProvider(new TreeCompositeLabelProvider());

		// Add a provider to tell the viewer when elements should be
		// checked. This is NOT default behavior.
		MOOSETreeCheckStateManager checkManager;
		checkManager = new MOOSETreeCheckStateManager();
		checkboxTreeViewer.setCheckStateProvider(checkManager);
		checkboxTreeViewer.addCheckStateListener(checkManager);
	}

	return treeViewer;
}
 
Example #29
Source File: ModelCheckBoxTree.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
public void drawOn(Composite comp, FormToolkit tk) {
	tree = new CheckboxTreeViewer(comp,
			SWT.VIRTUAL | SWT.MULTI | SWT.BORDER);
	tree.setUseHashlookup(true);
	tree.setContentProvider(new NavigationContentProvider());
	tree.setLabelProvider(new NavigationLabelProvider(false));
	tree.setComparator(new NavigationComparator());
	tree.addFilter(new ModelTypeFilter(types));
	tree.addCheckStateListener(this);
	ColumnViewerToolTipSupport.enableFor(tree);
	if (tk != null) {
		tk.adapt(tree.getTree());
	}

	// compute a height hint
	GridData data = UI.gridData(tree.getTree(), true, true);
	data.minimumHeight = 120;
	Point p = comp.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	data.heightHint = p.y < 120 ? 120 : p.y;

	if (types == null || types.length == 0)
		return;
	if (types.length == 1) {
		tree.setInput(Navigator.findElement(types[0]));
	} else {
		List<INavigationElement<?>> elems = Arrays.stream(types)
				.map(type -> Navigator.findElement(type))
				.filter(elem -> !elem.getChildren().isEmpty())
				.collect(Collectors.toList());
		tree.setInput(elems);
	}
	tree.expandToLevel(2);
}
 
Example #30
Source File: CommitDiffViewer.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void setChecked(CheckboxTreeViewer viewer, DiffNode node, boolean value, boolean selectChildren) {
	DiffResult result = node.getContent();
	if (node.isModelTypeNode() || !result.local.tracked || result.noAction()) {
		viewer.setChecked(node, false);
	} else if (value) {
		selected.add(node);
	} else if (lockNewElements && result.local.type == DiffType.NEW) {
		viewer.setChecked(node, true);
	} else {
		selected.remove(node);
	}
}