public void testProjectCreationWithWorkingSets() {
    final IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
    IWorkingSet newSet = manager.createWorkingSet("Testing", new IAdaptable[0]);
    newSet.setId("org.eclipse.jdt.ui.JavaWorkingSetPage");
    manager.addWorkingSet(newSet);
    assertTrue(newSet.getElements().length == 0);

    this.bot.menu("File").menu("New").menu("Project...").click();
    SWTBotShell wizard = this.bot.shell("New Project");
    wizard.activate();
    this.bot.tree().expandNode("Virgo").select("Bundle Project");

    SWTBotButton next = this.bot.button("Next >");
    next.click();
    assertFalse(next.isEnabled());

    this.bot.textWithLabel("Project name:").setText(PROJECT_NAME);
    this.bot.checkBoxInGroup("Working sets").select();
    this.bot.button("Select...").click();
    this.bot.table().getTableItem("Testing").check();
    this.bot.button("OK").click();
    assertTrue(next.isEnabled());
    next.click();

    SWTBotButton finish = this.bot.button("Finish");
    assertTrue(finish.isEnabled());
    finish.click();
    this.bot.waitUntil(shellCloses(wizard));

    IWorkingSet testingSet = manager.getWorkingSet("Testing");
    IAdaptable[] elements = testingSet.getElements();
    assertTrue(elements.length == 1);
    manager.removeWorkingSet(testingSet);
  }
  /**
   * Returns the tool tip text for the given element.
   *
   * @param element the element
   * @return the tooltip for the element
   */
  String getToolTipText(Object element) {
    String result;
    if (!(element instanceof IResource)) {
      result =
          ScriptElementLabels.getDefault()
              .getTextLabel(element, AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS);
    } else {
      IPath path = ((IResource) element).getFullPath();
      if (path.isRoot()) {
        result = getConfigurationElement().getAttribute("name"); // $NON-NLS-1$
      } else {
        result = path.makeRelative().toString();
      }
    }

    if (fWorkingSetFilterActionGroup == null
        || fWorkingSetFilterActionGroup.getWorkingSet() == null) return result;

    IWorkingSet ws = fWorkingSetFilterActionGroup.getWorkingSet();
    String wsstr =
        Messages.format(
            ScriptBrowsingMessages.JavaBrowsingPart_toolTip, new String[] {ws.getLabel()});
    if (result.length() == 0) return wsstr;
    return Messages.format(
        ScriptBrowsingMessages.JavaBrowsingPart_toolTip2, new String[] {result, ws.getLabel()});
  }
Ejemplo n.º 3
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()]));
   }
 }
  /**
   * Creates a map which provides project ids for each working set. If the working set is an
   * AggregateWorkingSet then these are the ids of (simple) working sets. Otherwise these are ids of
   * the contained projects.
   *
   * @return
   */
  private Map<String, Set<String>> getWorkingSetTable() {
    LinkedHashMap<String, Set<String>> table = new LinkedHashMap<String, Set<String>>();

    Map<String, IWorkingSet> workingSetMap = getWorkingSetMap();
    for (String wsId : workingSetMap.keySet()) {
      if (wsId == null) {
        System.err.println("Illegal AggregateWorkingSet: key is null");
        continue;
      }
      IWorkingSet ws = workingSetMap.get(wsId);
      LinkedHashSet<String> ids = new LinkedHashSet<String>();
      if (ws instanceof IAggregateWorkingSet) {
        IWorkingSet[] components = ((IAggregateWorkingSet) ws).getComponents();
        for (IWorkingSet _ws : components) {

          if (_ws == null) {
            System.err.println("Illegal AggregateWorkingSet: null component in " + wsId);
            continue;
          }

          String _wsId = _ws.getName();
          ids.add(_wsId);
        }
      } else {
        IAdaptable[] elements = ws.getElements();
        for (IAdaptable e : elements) {
          String pId = ((IProject) e).getName();
          ids.add(pId);
        }
      }
      table.put(wsId, ids);
    }

    return table;
  }
Ejemplo n.º 5
0
 private void assertProjectInWorkingSet(String workingSetName, String projectName) {
   IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
   IWorkingSet workingSet = workingSetManager.getWorkingSet(workingSetName);
   IAdaptable[] elements = workingSet.getElements();
   assertEquals("Wrong number of projects in working set", 1, elements.length);
   IProject project = Utils.getAdapter(elements[0], IProject.class);
   assertEquals("Wrong project in working set", projectName, project.getName());
 }
  private static boolean isValidWorkingSet(IWorkingSet workingSet) {
    String id = workingSet.getId();
    if (!IWorkingSetIDs_JAVA.equals(id) && !IWorkingSetIDs_RESOURCE.equals(id)) return false;

    if (workingSet.isAggregateWorkingSet()) return false;

    return true;
  }
  private boolean isValidWorkingSet(IWorkingSet workingSet) {
    String id = workingSet.getId();
    if (!JavaWorkingSetUpdater.ID.equals(id)
        && !"org.eclipse.ui.resourceWorkingSetPage".equals(id)) // $NON-NLS-1$
    return false;

    if (workingSet.isAggregateWorkingSet()) return false;

    return true;
  }
  public Map<String, IWorkingSet> getWorkingSetMap() {
    IWorkingSetManager wsManager = getWorkbench().getWorkingSetManager();

    IWorkingSet[] workingSets = wsManager.getAllWorkingSets();
    HashMap<String, IWorkingSet> wsMap = new HashMap<String, IWorkingSet>();
    for (IWorkingSet ws : workingSets) {
      wsMap.put(ws.getName(), ws);
    }

    return wsMap;
  }
Ejemplo n.º 9
0
 private void collectCompilationUnits(Object element, Collection<IJavaElement> result) {
   try {
     if (element instanceof IJavaElement) {
       IJavaElement elem = (IJavaElement) element;
       if (elem.exists()) {
         switch (elem.getElementType()) {
           case IJavaElement.TYPE:
             if (elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) {
               result.add(elem.getParent());
             }
             break;
           case IJavaElement.COMPILATION_UNIT:
             result.add(elem);
             break;
           case IJavaElement.IMPORT_CONTAINER:
             result.add(elem.getParent());
             break;
           case IJavaElement.PACKAGE_FRAGMENT:
             collectCompilationUnits((IPackageFragment) elem, result);
             break;
           case IJavaElement.PACKAGE_FRAGMENT_ROOT:
             collectCompilationUnits((IPackageFragmentRoot) elem, result);
             break;
           case IJavaElement.JAVA_PROJECT:
             IPackageFragmentRoot[] roots = ((IJavaProject) elem).getPackageFragmentRoots();
             for (int k = 0; k < roots.length; k++) {
               collectCompilationUnits(roots[k], result);
             }
             break;
         }
       }
     } else if (element instanceof LogicalPackage) {
       IPackageFragment[] packageFragments = ((LogicalPackage) element).getFragments();
       for (int k = 0; k < packageFragments.length; k++) {
         IPackageFragment pack = packageFragments[k];
         if (pack.exists()) {
           collectCompilationUnits(pack, result);
         }
       }
     } else if (element instanceof IWorkingSet) {
       IWorkingSet workingSet = (IWorkingSet) element;
       IAdaptable[] elements = workingSet.getElements();
       for (int j = 0; j < elements.length; j++) {
         collectCompilationUnits(elements[j], result);
       }
     }
   } catch (JavaModelException e) {
     if (JavaModelUtil.isExceptionToBeLogged(e)) JavaPlugin.log(e);
   }
 }
Ejemplo n.º 10
0
 // PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(project, new IWorkingSet[]
 // {workingSet});
 public static void addToWorkingSets(IProject project, List<IWorkingSet> workingSets) {
   if (workingSets != null && workingSets.size() > 0) {
     // IAdaptable[] elements = workingSet.adaptElements(new IAdaptable[] {project});
     // if(elements.length == 1) {
     for (IWorkingSet workingSet : workingSets) {
       if (workingSet != null) {
         IAdaptable[] oldElements = workingSet.getElements();
         IAdaptable[] newElements = new IAdaptable[oldElements.length + 1];
         System.arraycopy(oldElements, 0, newElements, 0, oldElements.length);
         newElements[oldElements.length] = project;
         workingSet.setElements(newElements);
       }
     }
   }
 }
Ejemplo n.º 11
0
 /**
  * Method filterResources filters the given resources using the given working set.
  *
  * @param current
  * @param resources
  * @return ICVSRemoteResource[]
  */
 public ICVSRemoteResource[] filterResources(
     IWorkingSet workingSet, ICVSRemoteResource[] resources) {
   if (workingSet == null) return resources;
   // get the projects associated with the working set
   IAdaptable[] adaptables = workingSet.getElements();
   Set projects = new HashSet();
   for (int i = 0; i < adaptables.length; i++) {
     IAdaptable adaptable = adaptables[i];
     Object adapted = adaptable.getAdapter(IResource.class);
     if (adapted != null) {
       // Can this code be generalized?
       IProject project = ((IResource) adapted).getProject();
       projects.add(project);
     }
   }
   List result = new ArrayList();
   for (int i = 0; i < resources.length; i++) {
     ICVSRemoteResource resource = resources[i];
     for (Iterator iter = projects.iterator(); iter.hasNext(); ) {
       IProject project = (IProject) iter.next();
       if (project.getName().equals(resource.getName())) {
         result.add(resource);
         break;
       }
     }
   }
   return (ICVSRemoteResource[]) result.toArray(new ICVSRemoteResource[result.size()]);
 }
 public void map(IWorkingSet workingSet, IAdaptable root, Pattern pattern) {
   Record r = new Record();
   r.pattern = pattern;
   r.root = root;
   map.put(workingSet.getName(), r);
   saveState();
 }
Ejemplo n.º 13
0
  private void validateInput() {
    String errorMessage = null;
    String infoMessage = null;
    String newText = fWorkingSetName.getText();

    if (newText.equals(newText.trim()) == false)
      errorMessage = WorkingSetMessages.ScriptWorkingSetPage_warning_nameWhitespace;
    if (newText.equals("")) { // $NON-NLS-1$
      if (fFirstCheck) {
        setPageComplete(false);
        fFirstCheck = false;
        return;
      } else errorMessage = WorkingSetMessages.ScriptWorkingSetPage_warning_nameMustNotBeEmpty;
    }

    fFirstCheck = false;

    if (errorMessage == null
        && (fWorkingSet == null || newText.equals(fWorkingSet.getName()) == false)) {
      IWorkingSet[] workingSets = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
      for (int i = 0; i < workingSets.length; i++) {
        if (newText.equals(workingSets[i].getName())) {
          errorMessage = WorkingSetMessages.ScriptWorkingSetPage_warning_workingSetExists;
        }
      }
    }

    if (!hasCheckedElement())
      infoMessage = WorkingSetMessages.ScriptWorkingSetPage_warning_resourceMustBeChecked;

    setMessage(infoMessage, INFORMATION);
    setErrorMessage(errorMessage);
    setPageComplete(errorMessage == null);
  }
  /* (non-Javadoc)
   * @see org.eclipse.ui.dialogs.IWorkingSetPage#finish()
   */
  public void finish() {
    Object[] checked = fTree.getCheckboxTreeViewer().getCheckedElements();
    ArrayList<PersistablePluginObject> list = new ArrayList<PersistablePluginObject>();
    for (int i = 0; i < checked.length; i++) {
      String id = ((IPluginModelBase) checked[i]).getPluginBase().getId();
      if (id != null && id.length() > 0) list.add(new PersistablePluginObject(id));
    }
    PersistablePluginObject[] objects = list.toArray(new PersistablePluginObject[list.size()]);

    String workingSetName = fWorkingSetName.getText().trim();
    if (fWorkingSet == null) {
      IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
      fWorkingSet = workingSetManager.createWorkingSet(workingSetName, objects);
    } else {
      fWorkingSet.setName(workingSetName);
      fWorkingSet.setElements(objects);
    }
  }
Ejemplo n.º 15
0
 /*
  * Implements method from IWorkingSetPage
  */
 public void setSelection(IWorkingSet workingSet) {
   Assert.isNotNull(workingSet, "Working set must not be null"); // $NON-NLS-1$
   fWorkingSet = workingSet;
   if (getContainer() != null && getShell() != null && fWorkingSetName != null) {
     fFirstCheck = false;
     fWorkingSetName.setText(fWorkingSet.getName());
     initializeCheckedState();
     validateInput();
   }
 }
Ejemplo n.º 16
0
 public static String[] evaluateEnclosingProject(ISelection selection, IEditorPart activeEditor) {
   // always use the editor if active
   if (activeEditor != null) {
     String name = evaluateEnclosingProject(activeEditor.getEditorInput());
     if (name != null) {
       return new String[] {name};
     }
   } else if (selection instanceof IStructuredSelection) {
     HashSet res = new HashSet();
     for (Iterator iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
       Object curr = iter.next();
       if (curr instanceof IWorkingSet) {
         IWorkingSet workingSet = (IWorkingSet) curr;
         if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) {
           IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
           for (int i = 0; i < projects.length; i++) {
             IProject proj = projects[i];
             if (proj.isOpen()) {
               res.add(proj.getName());
             }
           }
         } else {
           IAdaptable[] elements = workingSet.getElements();
           for (int i = 0; i < elements.length; i++) {
             String name = evaluateEnclosingProject(elements[i]);
             if (name != null) {
               res.add(name);
             }
           }
         }
       } else if (curr instanceof IAdaptable) {
         String name = evaluateEnclosingProject((IAdaptable) curr);
         if (name != null) {
           res.add(name);
         }
       }
     }
     if (!res.isEmpty()) {
       return (String[]) res.toArray(new String[res.size()]);
     }
   }
   return new String[0];
 }
 private void checkElementExistence(IWorkingSet workingSet) {
   List<IAdaptable> elements = new ArrayList<>(Arrays.asList(workingSet.getElements()));
   boolean changed = false;
   for (Iterator<IAdaptable> iter = elements.iterator(); iter.hasNext(); ) {
     IAdaptable element = iter.next();
     boolean remove = false;
     if (element instanceof IJavaElement) {
       IJavaElement jElement = (IJavaElement) element;
       // If we have directly a project then remove it when it
       // doesn't exist anymore. However if we have a sub element
       // under a project only remove the element if the parent
       // project is open. Otherwise we would remove all elements
       // in closed projects.
       if (jElement instanceof IJavaProject) {
         remove = !jElement.exists();
       } else {
         final IJavaProject javaProject = jElement.getJavaProject();
         final boolean isProjectOpen =
             javaProject != null ? javaProject.getProject().isOpen() : true;
         remove = isProjectOpen && !jElement.exists();
       }
     } else if (element instanceof IResource) {
       IResource resource = (IResource) element;
       // See comments above
       if (resource instanceof IProject) {
         remove = !resource.exists();
       } else {
         IProject project = resource.getProject();
         remove = (project != null ? project.isOpen() : true) && !resource.exists();
       }
     }
     if (remove) {
       iter.remove();
       changed = true;
     }
   }
   if (changed) {
     workingSet.setElements(elements.toArray(new IAdaptable[elements.size()]));
   }
 }
Ejemplo n.º 18
0
 private boolean isEnabled(IStructuredSelection selection) {
   Object[] selected = selection.toArray();
   for (int i = 0; i < selected.length; i++) {
     try {
       if (selected[i] instanceof IJavaElement) {
         IJavaElement elem = (IJavaElement) selected[i];
         if (elem.exists()) {
           switch (elem.getElementType()) {
             case IJavaElement.TYPE:
               return elem.getParent().getElementType()
                   == IJavaElement.COMPILATION_UNIT; // for browsing perspective
             case IJavaElement.COMPILATION_UNIT:
               return true;
             case IJavaElement.IMPORT_CONTAINER:
               return true;
             case IJavaElement.PACKAGE_FRAGMENT:
             case IJavaElement.PACKAGE_FRAGMENT_ROOT:
               IPackageFragmentRoot root =
                   (IPackageFragmentRoot) elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
               return (root.getKind() == IPackageFragmentRoot.K_SOURCE);
             case IJavaElement.JAVA_PROJECT:
               // https://bugs.eclipse.org/bugs/show_bug.cgi?id=65638
               return true;
           }
         }
       } else if (selected[i] instanceof LogicalPackage) {
         return true;
       } else if (selected[i] instanceof IWorkingSet) {
         IWorkingSet workingSet = (IWorkingSet) selected[i];
         return IWorkingSetIDs.JAVA.equals(workingSet.getId());
       }
     } catch (JavaModelException e) {
       if (!e.isDoesNotExist()) {
         JavaPlugin.log(e);
       }
     }
   }
   return false;
 }
  private void initialize() {
    if (fWorkingSet != null) {
      HashSet<String> set = new HashSet<String>();
      IAdaptable[] elements = fWorkingSet.getElements();
      for (int i = 0; i < elements.length; i++) {
        if (elements[i] instanceof PersistablePluginObject)
          set.add(((PersistablePluginObject) elements[i]).getPluginID());
      }

      IPluginModelBase[] bases = PluginRegistry.getAllModels();
      for (int i = 0; i < bases.length; i++) {

        String id = bases[i].getPluginBase().getId();
        if (id == null) continue;
        if (set.contains(id)) {
          fTree.getCheckboxTreeViewer().setChecked(bases[i], true);
          set.remove(id);
        }
        if (set.isEmpty()) break;
      }
      fWorkingSetName.setText(fWorkingSet.getName());
    }
  }
 private void checkElementExistence(IWorkingSet workingSet) {
   List elements = new ArrayList(Arrays.asList(workingSet.getElements()));
   boolean changed = false;
   for (Iterator iter = elements.iterator(); iter.hasNext(); ) {
     IAdaptable element = (IAdaptable) iter.next();
     boolean remove = false;
     if (element instanceof IProject) {
       IProject project = (IProject) element;
       remove = !project.exists();
     } else if (element instanceof IResource) {
       IResource resource = (IResource) element;
       IProject project = resource.getProject();
       remove = (project != null ? project.isOpen() : true) && !resource.exists();
     }
     if (remove) {
       iter.remove();
       changed = true;
     }
   }
   if (changed) {
     workingSet.setElements((IAdaptable[]) elements.toArray(new IAdaptable[elements.size()]));
   }
 }
Ejemplo n.º 21
0
 private FileTextSearchScope getSelectedResourcesScope() {
   HashSet<Object> resources = new HashSet<Object>();
   ISelection sel = getContainer().getSelection();
   if (sel instanceof IStructuredSelection && !sel.isEmpty()) {
     Iterator<?> iter = ((IStructuredSelection) sel).iterator();
     while (iter.hasNext()) {
       Object curr = iter.next();
       if (curr instanceof IWorkingSet) {
         IWorkingSet workingSet = (IWorkingSet) curr;
         if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) {
           return FileTextSearchScope.newWorkspaceScope(getExtensions(), fSearchDerived);
         }
         IAdaptable[] elements = workingSet.getElements();
         for (int i = 0; i < elements.length; i++) {
           IResource resource = (IResource) elements[i].getAdapter(IResource.class);
           if (resource != null && resource.isAccessible()) {
             resources.add(resource);
           }
         }
       } else if (curr instanceof LineElement) {
         IResource resource = ((LineElement) curr).getParent();
         if (resource != null && resource.isAccessible()) {
           resources.add(resource);
         }
       } else if (curr instanceof IAdaptable) {
         IResource resource = (IResource) ((IAdaptable) curr).getAdapter(IResource.class);
         if (resource != null && resource.isAccessible()) {
           resources.add(resource);
         }
       }
     }
   } else if (getContainer().getActiveEditorInput() != null) {
     resources.add(getContainer().getActiveEditorInput().getAdapter(IFile.class));
   }
   IResource[] arr = resources.toArray(new IResource[resources.size()]);
   return FileTextSearchScope.newSearchScope(arr, getExtensions(), fSearchDerived);
 }
Ejemplo n.º 22
0
  private boolean hasCProjects(IWorkingSet workingSet) {
    boolean result = false;

    if (workingSet != null) {
      IAdaptable[] members = workingSet.getElements();

      for (IAdaptable next : members) {
        IProject project = next.getAdapter(IProject.class);

        if ((project != null) && CoreModel.hasCNature(project)) {
          result = true;
          break;
        }
      }
    }

    return result;
  }
  /**
   * Returns all resources within the working set.
   *
   * @param workingSet the working set
   * @return the array of resources from the given working set
   */
  private static IResource[] getResourcesInWorkingSet(final IWorkingSet workingSet) {

    if (workingSet == null) {
      return new IResource[0];
    }

    final IAdaptable[] elements = workingSet.getElements();
    final List<IResource> result = new ArrayList<IResource>(elements.length);

    for (final IAdaptable element : elements) {
      final IResource next = (IResource) element.getAdapter(IResource.class);

      if (next != null) {
        result.add(next);
      }
    }

    return (IResource[]) result.toArray(new IResource[result.size()]);
  }
Ejemplo n.º 24
0
  /*
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  public void createControl(Composite parent) {
    initializeDialogUnits(parent);

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    setControl(composite);

    Label label = new Label(composite, SWT.WRAP);
    label.setText(WorkingSetMessages.ScriptWorkingSetPage_workingSet_name);
    GridData gd =
        new GridData(
            GridData.GRAB_HORIZONTAL
                | GridData.HORIZONTAL_ALIGN_FILL
                | GridData.VERTICAL_ALIGN_CENTER);
    label.setLayoutData(gd);

    fWorkingSetName = new Text(composite, SWT.SINGLE | SWT.BORDER);
    fWorkingSetName.setLayoutData(
        new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    fWorkingSetName.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            validateInput();
          }
        });
    fWorkingSetName.setFocus();

    label = new Label(composite, SWT.WRAP);
    label.setText(WorkingSetMessages.ScriptWorkingSetPage_workingSet_content);
    gd =
        new GridData(
            GridData.GRAB_HORIZONTAL
                | GridData.HORIZONTAL_ALIGN_FILL
                | GridData.VERTICAL_ALIGN_CENTER);
    label.setLayoutData(gd);

    fTree = new CheckboxTreeViewer(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL);
    gd.heightHint = convertHeightInCharsToPixels(15);
    fTree.getControl().setLayoutData(gd);

    fTreeContentProvider = new ScriptWorkingSetPageContentProvider();
    fTree.setContentProvider(fTreeContentProvider);

    AppearanceAwareLabelProvider fScriptElementLabelProvider =
        new AppearanceAwareLabelProvider(
            AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | ScriptElementLabels.P_COMPRESSED,
            AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS
                | ScriptElementImageProvider.SMALL_ICONS,
            DLTKUIPlugin.getDefault().getPreferenceStore());

    fTree.setLabelProvider(new DecoratingModelLabelProvider(fScriptElementLabelProvider));
    fTree.setSorter(new ModelElementSorter());
    if (DLTKCore.DEBUG) {
      System.err.println("Add empty inner package filter support here..."); // $NON-NLS-1$
    }
    // fTree.addFilter(new EmptyInnerPackageFilter());
    fTree.setUseHashlookup(true);

    fTree.setInput(DLTKCore.create(ResourcesPlugin.getWorkspace().getRoot()));

    fTree.addCheckStateListener(
        new ICheckStateListener() {
          public void checkStateChanged(CheckStateChangedEvent event) {
            handleCheckStateChange(event);
          }
        });

    fTree.addTreeListener(
        new ITreeViewerListener() {
          public void treeCollapsed(TreeExpansionEvent event) {}

          public void treeExpanded(TreeExpansionEvent event) {
            final Object element = event.getElement();
            if (fTree.getGrayed(element) == false)
              BusyIndicator.showWhile(
                  getShell().getDisplay(),
                  new Runnable() {
                    public void run() {
                      setSubtreeChecked(element, fTree.getChecked(element), false);
                    }
                  });
          }
        });

    // Add select / deselect all buttons for bug 46669
    Composite buttonComposite = new Composite(composite, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    buttonComposite.setLayout(layout);
    buttonComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    Button selectAllButton = new Button(buttonComposite, SWT.PUSH);
    selectAllButton.setText(WorkingSetMessages.ScriptWorkingSetPage_selectAll_label);
    selectAllButton.setToolTipText(WorkingSetMessages.ScriptWorkingSetPage_selectAll_toolTip);
    selectAllButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent selectionEvent) {
            fTree.setCheckedElements(fTreeContentProvider.getElements(fTree.getInput()));
            validateInput();
          }
        });
    selectAllButton.setLayoutData(new GridData());
    SWTUtil.setButtonDimensionHint(selectAllButton);

    Button deselectAllButton = new Button(buttonComposite, SWT.PUSH);
    deselectAllButton.setText(WorkingSetMessages.ScriptWorkingSetPage_deselectAll_label);
    deselectAllButton.setToolTipText(WorkingSetMessages.ScriptWorkingSetPage_deselectAll_toolTip);
    deselectAllButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent selectionEvent) {
            fTree.setCheckedElements(new Object[0]);
            validateInput();
          }
        });
    deselectAllButton.setLayoutData(new GridData());
    SWTUtil.setButtonDimensionHint(deselectAllButton);

    if (fWorkingSet != null) fWorkingSetName.setText(fWorkingSet.getName());
    initializeCheckedState();
    validateInput();

    Dialog.applyDialogFont(composite);
    // Set help for the page
    if (DLTKCore.DEBUG) {
      System.err.println("Add help support here..."); // $NON-NLS-1$
    }
    // ScriptUIHelp.setHelp(fTree, IScriptHelpContextIds.Script_WORKING_SET_PAGE);
  }
 public IAdaptable getRoot(IWorkingSet workingSet) {
   Record record = (Record) map.get(workingSet.getName());
   if (record == null) return null;
   return record.root;
 }
 public Pattern getPattern(IWorkingSet workingSet) {
   Record record = (Record) map.get(workingSet.getName());
   if (record == null) return null;
   return record.pattern;
 }
 /** Process the changes to this delta and update the working set if necessary. */
 public void process() {
   if (fChanged) {
     fWorkingSet.setElements((IAdaptable[]) fElements.toArray(new IAdaptable[fElements.size()]));
   }
 }
 /**
  * Create a new instance of this class.
  *
  * @param workingSet the working set to track.
  */
 public WorkingSetDelta(IWorkingSet workingSet) {
   fWorkingSet = workingSet;
   fElements = new ArrayList(Arrays.asList(workingSet.getElements()));
 }