Ejemplo n.º 1
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());
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  @Override
  public void createControl(Composite parent) {
    initializeDialogUnits(parent);

    Composite result = new Composite(parent, SWT.NONE);
    result.setLayout(new GridLayout(1, false));

    new Label(result, SWT.NONE).setText(Messages.ModelReferencesPage_4);

    ModelImportContentProvider contents = new ModelImportContentProvider();
    modelsTree = new CheckboxTreeViewer(result);
    modelsTree.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    modelsTree.setAutoExpandLevel(2);
    modelsTree.setContentProvider(contents);
    modelsTree.setLabelProvider(new TreeNodeLabelProvider());

    new Label(result, SWT.NONE).setText(Messages.ModelReferencesPage_5);
    pathText = new Text(result, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
    pathText.setLayoutData(
        GridDataFactory.fillDefaults()
            .grab(true, false)
            .hint(SWT.DEFAULT, convertHeightInCharsToPixels(3))
            .create());

    if (isImport) {
      stripSashModelContent = new Button(result, SWT.CHECK);
      stripSashModelContent.setText(Messages.ModelReferencesPage_2);
      stripSashModelContent.setToolTipText(Messages.ModelReferencesPage_6);

      stripSashModelContent.addSelectionListener(
          new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
              if (getConfiguration() != null) {
                getConfiguration().setStripSashModelContent(stripSashModelContent.getSelection());
              }
            }
          });
    }

    modelsTree.addSelectionChangedListener(
        new ISelectionChangedListener() {

          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (!sel.isEmpty()) {
              selected(sel.getFirstElement());
            } else {
              selected(null);
            }
          }
        });

    ((ICheckable) modelsTree).addCheckStateListener(contents);
    ((ICheckable) modelsTree)
        .addCheckStateListener(
            new ICheckStateListener() {

              @Override
              public void checkStateChanged(CheckStateChangedEvent event) {
                Display.getCurrent()
                    .asyncExec(
                        new Runnable() {

                          @Override
                          public void run() {
                            validatePage();
                          }
                        });
              }
            });

    setControl(result);

    validatePage();
  }