/* (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);
    }
  }
  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());
    }
  }