public void setVisible(boolean visible) {
   if (visible == true) {
     if (fFilters != null) {
       sourceFileViewer.resetFilters();
       for (Iterator i = fFilters.iterator(); i.hasNext(); )
         sourceFileViewer.addFilter((ViewerFilter) i.next());
     }
     sourceFileViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
   }
   super.setVisible(visible);
 }
 protected void updateCaches(IUElementListRoot newRoot, ProfileChangeOperation op) {
   resolvedOperation = op;
   if (newRoot != null) {
     setDrilldownElements(newRoot, resolvedOperation);
     if (treeViewer != null) {
       if (input != newRoot) treeViewer.setInput(newRoot);
       else treeViewer.refresh();
     }
     input = newRoot;
   }
 }
  public void addSelectedFilesToTargetList() {
    ISelection selection = sourceFileViewer.getSelection();

    if (isValidSourceFileViewerSelection(selection)) {
      java.util.List list = null;
      if (selection instanceof IStructuredSelection) {
        list = ((IStructuredSelection) selection).toList();

        if (list != null) {
          list = ((IStructuredSelection) selection).toList();
          for (Iterator i = list.iterator(); i.hasNext(); ) {
            IResource resource = (IResource) i.next();
            if (resource instanceof IFile) {
              // Check if its in the list. Don't add it if it is.
              String resourceName = resource.getFullPath().toString();
              if (selectedListBox.indexOf(resourceName) == -1) selectedListBox.add(resourceName);
            }
          }
          setFiles(selectedListBox.getItems());
        }

        setAddButtonEnabled(false);

        if (selectedListBox.getItemCount() > 0) {
          removeAllButton.setEnabled(true);
          if (isFileMandatory) setPageComplete(true);
          if (selectedListBox.getSelectionCount() > 0) setRemoveButtonEnabled(true);
          else setRemoveButtonEnabled(false);
        }
      }
    }
  }
  private void createSourceViewer(Composite parent) {
    sourceFileViewer =
        new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER));
    sourceFileViewer.setContentProvider(new WorkbenchContentProvider());
    sourceFileViewer.setLabelProvider(new WorkbenchLabelProvider());
    sourceFileViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          public void selectionChanged(SelectionChangedEvent event) {
            java.util.List list;
            ISelection selection = event.getSelection();
            boolean newFilesSelected = false;

            if (selection instanceof IStructuredSelection) {
              list = ((IStructuredSelection) selection).toList();
              for (Iterator i = list.iterator(); i.hasNext(); ) {
                IResource resource = (IResource) i.next();
                if (resource instanceof IFile) {
                  if (checkIfFileInTarget((IFile) resource) == false) newFilesSelected = true;
                }
              }
              setAddButtonEnabled(newFilesSelected);
            }
          }
        });
    sourceFileViewer.addDoubleClickListener(
        new IDoubleClickListener() {
          public void doubleClick(DoubleClickEvent event) {
            addSelectedFilesToTargetList();
          }
        });

    Control treeWidget = sourceFileViewer.getTree();
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = SIZING_LISTS_WIDTH;
    gd.heightHint = SIZING_LISTS_HEIGHT;
    treeWidget.setLayoutData(gd);
  }
  /*
   * (non-Javadoc)
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  public void createControl(Composite parent) {
    display = parent.getDisplay();
    sashForm = new SashForm(parent, SWT.VERTICAL);
    FillLayout layout = new FillLayout();
    sashForm.setLayout(layout);
    GridData data = new GridData(GridData.FILL_BOTH);
    sashForm.setLayoutData(data);
    initializeDialogUnits(sashForm);

    Composite composite = new Composite(sashForm, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    composite.setLayout(gridLayout);

    treeViewer = createTreeViewer(composite);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = convertHeightInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_HEIGHT);
    data.widthHint = convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_WIDTH);
    Tree tree = treeViewer.getTree();
    tree.setLayoutData(data);
    tree.setHeaderVisible(true);
    activateCopy(tree);
    TreeViewerColumn nameColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
    nameColumn.getColumn().setText(ProvUIMessages.ProvUI_NameColumnTitle);
    nameColumn.getColumn().setWidth(400);
    nameColumn.getColumn().setMoveable(true);
    nameColumn.setLabelProvider(
        new ColumnLabelProvider() {
          public String getText(Object element) {
            IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
            String label = iu.getProperty(IInstallableUnit.PROP_NAME, null);
            if (label == null) label = iu.getId();
            return label;
          }

          public Image getImage(Object element) {
            if (element instanceof ProvElement) return ((ProvElement) element).getImage(element);
            if (ProvUI.getAdapter(element, IInstallableUnit.class) != null)
              return ProvUIImages.getImage(ProvUIImages.IMG_IU);
            return null;
          }

          public String getToolTipText(Object element) {
            if (element instanceof AvailableIUElement
                && ((AvailableIUElement) element).getImageOverlayId(null) == ProvUIImages.IMG_INFO)
              return ProvUIMessages.RemedyElementNotHighestVersion;
            return super.getToolTipText(element);
          }
        });
    TreeViewerColumn versionColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
    versionColumn.getColumn().setText(ProvUIMessages.ProvUI_VersionColumnTitle);
    versionColumn.getColumn().setWidth(200);
    versionColumn.setLabelProvider(
        new ColumnLabelProvider() {
          public String getText(Object element) {
            IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
            if (element instanceof IIUElement) {
              if (((IIUElement) element).shouldShowVersion()) return iu.getVersion().toString();
              return ""; //$NON-NLS-1$
            }
            return iu.getVersion().toString();
          }
        });
    TreeViewerColumn idColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
    idColumn.getColumn().setText(ProvUIMessages.ProvUI_IdColumnTitle);
    idColumn.getColumn().setWidth(200);

    idColumn.setLabelProvider(
        new ColumnLabelProvider() {
          public String getText(Object element) {
            IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
            return iu.getId();
          }
        });

    // Filters and sorters before establishing content, so we don't refresh unnecessarily.
    IUComparator comparator = new IUComparator(IUComparator.IU_NAME);
    comparator.useColumnConfig(getColumnConfig());
    treeViewer.setComparator(comparator);
    treeViewer.setComparer(new ProvElementComparer());
    ColumnViewerToolTipSupport.enableFor(treeViewer);
    contentProvider = new ProvElementContentProvider();
    treeViewer.setContentProvider(contentProvider);
    //		labelProvider = new IUDetailsLabelProvider(null, getColumnConfig(), getShell());
    //		treeViewer.setLabelProvider(labelProvider);

    // Optional area to show the size
    createSizingInfo(composite);

    // The text area shows a description of the selected IU, or error detail if applicable.
    iuDetailsGroup =
        new IUDetailsGroup(
            sashForm,
            treeViewer,
            convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_WIDTH),
            true);

    setControl(sashForm);
    sashForm.setWeights(getSashWeights());
    Dialog.applyDialogFont(sashForm);

    // Controls for filtering/presentation/site selection
    Composite controlsComposite = new Composite(composite, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    gridLayout.numColumns = 2;
    gridLayout.makeColumnsEqualWidth = true;
    gridLayout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    controlsComposite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    controlsComposite.setLayoutData(gd);

    final Runnable runnable =
        new Runnable() {
          public void run() {
            treeViewer.addSelectionChangedListener(
                new ISelectionChangedListener() {
                  public void selectionChanged(SelectionChangedEvent event) {
                    setDetailText(resolvedOperation);
                  }
                });
            setDrilldownElements(input, resolvedOperation);
            treeViewer.setInput(input);
          }
        };

    if (resolvedOperation != null && !resolvedOperation.hasResolved()) {
      try {
        getContainer()
            .run(
                true,
                false,
                new IRunnableWithProgress() {
                  public void run(IProgressMonitor monitor) {
                    resolvedOperation.resolveModal(monitor);
                    display.asyncExec(runnable);
                  }
                });
      } catch (Exception e) {
        StatusManager.getManager()
            .handle(new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, e.getMessage(), e));
      }
    } else {
      runnable.run();
    }
  }
 protected int getColumnWidth(int index) {
   return treeViewer.getTree().getColumn(index).getWidth();
 }
 protected Object[] getSelectedElements() {
   return ((IStructuredSelection) treeViewer.getSelection()).toArray();
 }