private void createTaskTree(Composite parent) {
    PatternFilter filter = new PatternFilter();
    FilteredTree filteredTree =
        new FilteredTree(parent, SWT.CHECK | SWT.BORDER, filter, true) {
          @Override
          protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
            return new ContainerCheckedTreeViewer(parent, style);
          }
        };
    taskSelectionTreeViewer = (CheckboxTreeViewer) filteredTree.getViewer();
    filteredTree.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Add multi column support
    Tree tree = taskSelectionTreeViewer.getTree();
    tree.setHeaderVisible(true);
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("Project/Task");
    TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
    column2.setText("Description");
    column1.pack();
    column2.pack();

    taskSelectionTreeViewer.setLabelProvider(new GradleTaskTreeLabelProvider());
    taskSelectionTreeViewer.setContentProvider(
        new GradleTaskTreeContentProvider(taskSelectionTreeViewer, true));
    taskSelectionTreeViewer.setCheckStateProvider(tasksChecked);
    taskSelectionTreeViewer.addCheckStateListener(tasksChecked);

    if (project != null) {
      setTreeInput(project);
    }
  }
 public void down(List<?> checked, CheckboxTreeViewer tree) {
   if (checked.size() > 0) {
     setElements(reverse(moveUp(reverse(fFields), checked)), tree);
     tree.reveal(checked.get(checked.size() - 1));
   }
   tree.setSelection(new StructuredSelection(checked));
 }
예제 #3
0
  public void testCheckProviderWithFilter() {
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;

    final CheckStateProviderTestsUtil.Filter filter = new CheckStateProviderTestsUtil.Filter();
    ctv.addFilter(filter);

    // First provider
    // Should cause visible items' check state adhere to provider
    final TestCheckStateProvider checkStateProvider = new TestCheckStateProvider(0);
    ctv.setCheckStateProvider(checkStateProvider);
    ctv.expandAll();

    // Check that all states are properly set
    checkAllStates("Testing checkbox state with a sorter", ctv, 0);

    // Check that the provider is only invoked on elements which pass the filter
    for (Iterator i = checkStateProvider.isCheckedInvokedOn.iterator(); i.hasNext(); ) {
      TestElement element = (TestElement) i.next();
      assertTrue(
          "The check provider should not be invoked on elements which did not get through the filter",
          filter.select(ctv, null, element));
    }

    for (Iterator i = checkStateProvider.isGrayedInvokedOn.iterator(); i.hasNext(); ) {
      TestElement element = (TestElement) i.next();
      assertTrue(
          "The check provider should not be invoked on elements which did not get through the filter",
          filter.select(ctv, null, element));
    }
  }
예제 #4
0
 private void findCheckedElements(List checkedResources, Object parent) {
   Object[] children = fTreeContentProvider.getChildren(parent);
   for (int i = 0; i < children.length; i++) {
     if (fTree.getGrayed(children[i])) findCheckedElements(checkedResources, children[i]);
     else if (fTree.getChecked(children[i])) checkedResources.add(children[i]);
   }
 }
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout(1, false));

    treeViewer = new CheckboxTreeViewer(composite, SWT.CHECK | SWT.BORDER);
    treeViewer.setContentProvider(
        new ReferenceTreeContentProvider(DatabasePackage.Literals.TABLE_RESOURCE_DATA__COLUMNS));
    treeViewer.getTree().setHeaderVisible(true);
    treeViewer.getTree().setLinesVisible(true);
    createColumns(treeViewer);

    //		treeViewer.addCheckStateListener(new ICheckStateListener() {
    //			@Override
    //			public void checkStateChanged(CheckStateChangedEvent event) {
    //				Object[] objects = treeViewer.getCheckedElements();
    //				List<TableColumn> columnList = new ArrayList<TableColumn>();
    //				for (Object obj : objects) {
    //					if (obj instanceof TableColumn) {
    //						columnList.add((TableColumn) obj);
    //					}
    //				}
    //				result = columnList.toArray(new TableColumn[0]);
    //			}
    //		});
    treeViewer.setInput(input);
    GridDataFactory.fillDefaults().hint(-1, 300).applyTo(treeViewer.getTree());
    return composite;
  }
예제 #6
0
  /** @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite) */
  public void createControl(Composite parent) {
    Composite composite = createGridLayoutComposite(parent, 1);

    publishConfigRadioButton =
        createRadioButton(composite, PublishingUIResources.publishConfigRadioButton_text, 1, true);

    publishProcessesRadioButton =
        createRadioButton(
            composite, PublishingUIResources.publishProcessesRadioButton_text, 1, false);

    Composite processComposite = createChildGridLayoutComposite(composite, 1);

    processViewer = new CheckboxTreeViewer(processComposite);
    GridData gridData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
    gridData.heightHint = 300;
    processViewer.getTree().setLayoutData(gridData);
    //		processViewer.setContentProvider(new ProcessViewerContentProvider());
    processViewer.setLabelProvider(new ProcessTreeLabelProvider());

    includeBaseProcessesCheckbox =
        createCheckbox(
            processComposite, PublishingUIResources.includeBaseProcessesCheckboxLabel_text);

    initControls();

    addListeners();

    setControl(composite);
  }
예제 #7
0
  public void testSetGrayedElements() {
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;

    TestElement[] children = fRootElement.getChildren();

    List toGray = new ArrayList((children.length + 1) / 2);

    for (int i = 0; i < children.length; i += 2) {
      toGray.add(children[i]);
    }

    ctv.setGrayedElements(toGray.toArray());

    for (int i = 0; i < children.length; i++) {
      if (i % 2 == 0) {
        assertTrue(
            "an element passed through setGrayedElements should be grayed",
            ctv.getGrayed(children[i]));
      } else {
        assertFalse(
            "an element not passed through setGrayedElements should not be grayed",
            ctv.getGrayed(children[i]));
      }
    }
  }
 public void up(List<?> checked, CheckboxTreeViewer tree) {
   if (checked.size() > 0) {
     setElements(moveUp(fFields, checked), tree);
     tree.reveal(checked.get(0));
   }
   tree.setSelection(new StructuredSelection(checked));
 }
예제 #9
0
  public void testCheckProviderLazilyInvoked() {
    // Check that a refresh successfully causes the provider's
    // setChecked and setGrayed methods to be invoked.
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;

    TestMethodsInvokedCheckStateProvider provider = new TestMethodsInvokedCheckStateProvider();

    ctv.setCheckStateProvider(provider);
    ctv.refresh();

    TestElement[] expected = fRootElement.getChildren();

    for (Iterator i = provider.isCheckedInvokedOn.iterator(); i.hasNext(); ) {
      TestElement element = (TestElement) i.next();
      boolean firstLevelElement = false;
      for (int j = 0; j < expected.length && !firstLevelElement; j++) {
        firstLevelElement = element.equals(expected[j]);
      }
      assertTrue(
          "The check provider should only be invoked with visible elements", firstLevelElement);
    }

    for (Iterator i = provider.isGrayedInvokedOn.iterator(); i.hasNext(); ) {
      TestElement element = (TestElement) i.next();
      boolean firstLevelElement = false;
      for (int j = 0; j < expected.length && !firstLevelElement; j++) {
        firstLevelElement = element.equals(expected[j]);
      }
      assertTrue(
          "The check provider should only be invoked with visible elements", firstLevelElement);
    }
  }
예제 #10
0
  private void updateParentState(Object child, boolean baseChildState) {
    if (child == null) return;
    if (child instanceof IAdaptable) {
      IResource resource = (IResource) ((IAdaptable) child).getAdapter(IResource.class);
      if (resource != null && !resource.isAccessible()) return;
    }
    Object parent = fTreeContentProvider.getParent(child);
    if (parent == null) return;

    boolean allSameState = true;
    Object[] children = null;
    children = fTreeContentProvider.getChildren(parent);

    for (int i = children.length - 1; i >= 0; i--) {
      if (fTree.getChecked(children[i]) != baseChildState || fTree.getGrayed(children[i])) {
        allSameState = false;
        break;
      }
    }

    fTree.setGrayed(parent, !allSameState);
    fTree.setChecked(parent, !allSameState || baseChildState);

    updateParentState(parent, baseChildState);
  }
예제 #11
0
 public boolean areChildrenUnchecked(final CheckboxTreeViewer tree) {
   for (final DebugTreeItem i : children) {
     if (tree.getChecked(i) || tree.getGrayed(i)) {
       return false;
     }
   }
   return true;
 }
 /**
  * Iterates through the passed elements which are being realized for the first time and check each
  * one in the tree viewer as appropriate
  *
  * @param elements
  */
 protected void checkNewTreeElements(Object[] elements) {
   for (int i = 0; i < elements.length; ++i) {
     Object currentElement = elements[i];
     boolean checked = fCheckedStateStore.containsKey(currentElement);
     fTreeViewer.setChecked(currentElement, checked);
     fTreeViewer.setGrayed(
         currentElement, checked && !fWhiteCheckedTreeItems.contains(currentElement));
   }
 }
 private void setTreeInput(GradleProject project) {
   if (taskSelectionTreeViewer != null) {
     taskSelectionTreeViewer.setInput(project);
     Tree tree = taskSelectionTreeViewer.getTree();
     for (TreeColumn col : tree.getColumns()) {
       col.pack();
     }
   }
 }
 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();
   }
 }
  /** This method must be called just before this window becomes visible. */
  public void aboutToOpen() {
    determineWhiteCheckedDescendents(fRoot);
    checkNewTreeElements(getTreeChildren(fRoot));
    fCurrentTreeSelection = null;

    // select the first element in the list
    Object[] elements = getTreeChildren(fRoot);
    Object primary = elements.length > 0 ? elements[0] : null;
    if (primary != null) {
      fTreeViewer.setSelection(new StructuredSelection(primary));
    }
    fTreeViewer.getControl().setFocus();
  }
예제 #16
0
  public void testCheckProviderWithSorter() {
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;

    ctv.setSorter(new CheckStateProviderTestsUtil.Sorter());

    // First provider
    // Should cause visible items' check state adhere to provider
    ctv.setCheckStateProvider(new TestCheckStateProvider(0));
    ctv.expandAll();

    // Check that all states are properly set
    checkAllStates("Testing checkbox state with a sorter", ctv, 0);
  }
  public void setPackagePresentation(String command, boolean update) {

    if (command.contains("flat")) {
      patternsTreeViewer.setContentProvider(flatCP);
      patternsTreeViewer.setLabelProvider(flatLP);
    } else {
      patternsTreeViewer.setContentProvider(hierarchicalCP);
      patternsTreeViewer.setLabelProvider(hierarchicalLP);
    }

    if (update) {
      patternsViewerInput.getGeneratedPatternsRoot().updateSelection(patternsTreeViewer);
      patternsViewerInput.getGenericPatternsRoot().updateSelection(patternsTreeViewer);
    }
  }
예제 #18
0
  private void setSubtreeChecked(Object parent, boolean state, boolean checkExpandedState) {
    if (!(parent instanceof IAdaptable)) return;
    IContainer container = (IContainer) ((IAdaptable) parent).getAdapter(IContainer.class);
    if ((!fTree.getExpandedState(parent) && checkExpandedState)
        || (container != null && !container.isAccessible())) return;

    Object[] children = fTreeContentProvider.getChildren(parent);
    for (int i = children.length - 1; i >= 0; i--) {
      Object element = children[i];
      if (state) {
        fTree.setChecked(element, true);
        fTree.setGrayed(element, false);
      } else fTree.setGrayChecked(element, false);
      if (isExpandable(element)) setSubtreeChecked(element, state, true);
    }
  }
예제 #19
0
 /*
  * Implements method from IWorkingSetPage
  */
 public void finish() {
   String workingSetName = fWorkingSetName.getText();
   ArrayList elements = new ArrayList(10);
   findCheckedElements(elements, fTree.getInput());
   if (fWorkingSet == null) {
     IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
     fWorkingSet =
         workingSetManager.createWorkingSet(
             workingSetName, (IAdaptable[]) elements.toArray(new IAdaptable[elements.size()]));
   } else {
     // Add inaccessible resources
     IAdaptable[] oldItems = fWorkingSet.getElements();
     ArrayList closedWithChildren = new ArrayList(elements.size());
     for (int i = 0; i < oldItems.length; i++) {
       IResource oldResource = null;
       if (oldItems[i] instanceof IResource) {
         oldResource = (IResource) oldItems[i];
       } else {
         oldResource = (IResource) oldItems[i].getAdapter(IResource.class);
       }
       if (oldResource != null && oldResource.isAccessible() == false) {
         IProject project = oldResource.getProject();
         if (elements.contains(project) || closedWithChildren.contains(project)) {
           elements.add(oldItems[i]);
           elements.remove(project);
           closedWithChildren.add(project);
         }
       }
     }
     fWorkingSet.setName(workingSetName);
     fWorkingSet.setElements((IAdaptable[]) elements.toArray(new IAdaptable[elements.size()]));
   }
 }
예제 #20
0
 private boolean hasCheckedElement() {
   TreeItem[] items = fTree.getTree().getItems();
   for (int i = 0; i < items.length; i++) {
     if (items[i].getChecked()) return true;
   }
   return false;
 }
  /**
   * Sets the checked state of self and all ancestors appropriately
   *
   * @param treeElement
   */
  protected void updateHierarchy(Object treeElement) {

    boolean whiteChecked = determineShouldBeWhiteChecked(treeElement);
    boolean shouldBeAtLeastGray = determineShouldBeAtLeastGrayChecked(treeElement);

    fTreeViewer.setChecked(treeElement, whiteChecked || shouldBeAtLeastGray);
    setWhiteChecked(treeElement, whiteChecked);
    if (whiteChecked) fTreeViewer.setGrayed(treeElement, false);
    else fTreeViewer.setGrayed(treeElement, shouldBeAtLeastGray);

    // proceed up the tree element hierarchy
    Object parent = fTreeContentProvider.getParent(treeElement);
    if (parent != null) {
      updateHierarchy(parent);
    }
  }
예제 #22
0
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout(1, false));

    treeViewer = new CheckboxTreeViewer(composite, SWT.CHECK | SWT.BORDER);
    treeViewer.setContentProvider(
        new ReferenceTreeContentProvider(DatabasePackage.Literals.TABLE_RESOURCE_DATA__INDEXES));
    treeViewer.getTree().setHeaderVisible(true);
    treeViewer.getTree().setLinesVisible(true);
    createColumns(treeViewer);

    treeViewer.setInput(input);
    GridDataFactory.fillDefaults().hint(-1, 300).applyTo(treeViewer.getTree());
    return composite;
  }
  private void updateProjectsList(final String selectedDirectory) {
    if (selectedDirectory == null || selectedDirectory.isEmpty()) {
      candidates = null;
      projectList.refresh(true);
      return;
    }
    final File directory = new File(selectedDirectory);

    try {
      getContainer()
          .run(
              true,
              true,
              new IRunnableWithProgress() {
                @Override
                public void run(IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                  if (directory.isDirectory()) {
                    List<ProjectCandidate> candies =
                        new ArrayList<HybridProjectImportPage.ProjectCandidate>();
                    collectProjectCandidates(candies, directory, monitor);
                    candidates = candies.toArray(new ProjectCandidate[candies.size()]);
                  }
                }
              });
    } catch (InvocationTargetException e) {
      if (e.getTargetException() != null) {
        if (e.getTargetException() instanceof CoreException) {
          StatusManager.handle((CoreException) e.getTargetException());
        } else {
          ErrorDialog.openError(
              getShell(),
              "Error finding projects to import",
              null,
              new Status(
                  IStatus.ERROR,
                  HybridUI.PLUGIN_ID,
                  "Error while searching for projects to import",
                  e.getTargetException()));
        }
      }
    } catch (InterruptedException e) {
      HybridUI.log(IStatus.ERROR, "Error searchig projects to import", e);
    }
    projectList.refresh(true);
  }
 private void setChecked(List<String> tasks) {
   tasksChecked.setChecked(tasks);
   if (taskSelectionTreeViewer != null) {
     taskSelectionTreeViewer.refresh();
   }
   updateOrderedTargets();
   updateLaunchConfigurationDialog();
 }
 protected void forceExistingChecked(CheckStateChangedEvent event) {
   if (fExisting != null) {
     Object elem = event.getElement();
     if (fExisting.contains(elem)) {
       fViewer.setChecked(elem, true);
     }
   }
 }
예제 #26
0
  public void testCheckProviderInvoked() {
    // Check that a refresh successfully causes the provider's
    // setChecked and setGrayed methods to be invoked.
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;

    TestMethodsInvokedCheckStateProvider provider = new TestMethodsInvokedCheckStateProvider();

    ctv.setCheckStateProvider(provider);
    assertTrue(
        "isChecked should be invoked on a refresh", (!provider.isCheckedInvokedOn.isEmpty()));
    assertTrue("isGrayed should be invoked on a refresh", (!provider.isGrayedInvokedOn.isEmpty()));

    provider.reset();
    ctv.refresh();
    assertTrue(
        "isChecked should be invoked on a refresh", (!provider.isCheckedInvokedOn.isEmpty()));
    assertTrue("isGrayed should be invoked on a refresh", (!provider.isGrayedInvokedOn.isEmpty()));
  }
예제 #27
0
  public void testSetNewCheckProvider() {
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;

    // First provider
    // Should cause visible items' check state to adhere to provider
    ctv.setCheckStateProvider(new TestCheckStateProvider(0));
    ctv.expandAll();

    checkAllStates("Testing checkbox state after first refresh", ctv, 0);

    // Put in a new check state provider
    ctv.setCheckStateProvider(new TestCheckStateProvider(1));

    // Check that setting a new check provider caused a refresh,
    // and thus all the items have their new appropriate check
    // states.
    checkAllStates("Testing checkbox state after setting new check provider", ctv, 1);
  }
예제 #28
0
 @Override
 protected void okPressed() {
   List<TableIndex> tableIndexs = new ArrayList<TableIndex>();
   for (Object obj : treeViewer.getCheckedElements()) {
     tableIndexs.add((TableIndex) obj);
   }
   this.result = tableIndexs.toArray(new TableIndex[0]);
   super.okPressed();
 }
 @Override
 protected void okPressed() {
   List<TableColumn> columns = new ArrayList<TableColumn>();
   for (Object obj : treeViewer.getCheckedElements()) {
     columns.add((TableColumn) obj);
   }
   this.result = columns.toArray(new TableColumn[0]);
   super.okPressed();
 }
예제 #30
0
  /** @param listener */
  public TreeViewerBuilder checkStateListener(ICheckStateListener listener) {
    if (!checkable) {
      throw new IllegalStateException(
          "The tree viewer is not a CheckboxTreeViewer!"); //$NON-NLS-1$
    }

    ((CheckboxTreeViewer) viewer).addCheckStateListener(listener);
    return this;
  }