Пример #1
0
    @Override
    public void checkStateChanged(CheckStateChangedEvent event) {
      ITreeNode node = (ITreeNode) event.getElement();
      IModelTransferNode model = node.getElement();

      // apply the check state to the model
      if (event.getChecked()) {
        config.addModelToTransfer(model.getPrimaryResourceURI());
      } else {
        config.removeModelToTransfer(model);
      }

      // propagate the check state to other occurrences of the same model
      for (ITreeNode next : nodes.get(model)) {
        event.getCheckable().setChecked(next, event.getChecked());
      }
    }
Пример #2
0
  private void initializeCheckedNodes() {
    final Collection<IModelTransferNode> initialSet = importConfig.getModelsToTransfer();
    final ITreeContentProvider contents = (ITreeContentProvider) modelsTree.getContentProvider();
    final ICheckable checkable = (ICheckable) modelsTree;

    final Set<IModelTransferNode> visited = Sets.newHashSet();
    final Queue<Object> queue =
        new java.util.ArrayDeque<Object>(Arrays.asList(contents.getElements(importConfig)));

    for (Object next = queue.poll(); next != null; next = queue.poll()) {
      ITreeNode parent = (ITreeNode) next;

      // we must check a parent if the user initially selected it on opening the wizard
      // or we are importing and it is a dependent of a checked node,
      // or we are exporting and it is a dependency of a checked node,
      // or it is a model sub-unit (required dependency) of a checked node
      boolean mustCheck = initialSet.contains(parent.getElement());
      if (mustCheck) {
        checkable.setChecked(next, true);
      }

      if (visited.add(parent.getElement())) {
        // recurse into the children
        for (Object child : contents.getChildren(next)) {
          ITreeNode treeNode = (ITreeNode) child;
          queue.add(treeNode);

          // we must check a node if either the user initially selected it on opening the wizard,
          // or we are importing and it is a dependent of a checked node,
          // or we are exporting and it is a dependency of a checked node,
          // or it is a model sub-unit (required dependency) of a checked node
          mustCheck =
              initialSet.contains(treeNode.getElement()) //
                  || (isImport ? treeNode.isDependent() : treeNode.isDependency()) //
                  || (checkable.getChecked(parent)
                      && parent.getElement().isModelSubUnit(treeNode.getElement()));

          if (mustCheck) {
            checkable.setChecked(child, true);
            importConfig.addModelToTransfer(treeNode.getElement().getPrimaryResourceURI());
          }
        }
      }
    }
  }