org.eclipse.equinox.p2.ui.importexport_1.0.1.v20120913-155635

on:    0.7.1
 */
package org.eclipse.equinox.internal.p2.importexport.internal.wizard;

import java.util.Comparator;
import org.eclipse.equinox.internal.p2.ui.ProvUI;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;

class AbstractPage$TreeViewerComparator
  extends ViewerComparator
{
  private int sortColumn = 0;
  private int lastSortColumn = 0;
  private boolean ascending = false;
  private boolean lastAscending = false;
  final AbstractPage this$0;
  
  AbstractPage$TreeViewerComparator(AbstractPage paramAbstractPage) {}
  
  public int compare(Viewer viewer1, Object e1, Object e2)
  {
    Class tmp4_1 = AbstractPage.class$1;
    if (tmp4_1 == null)
    {
      tmp4_1;
      try
      {
        tmpTernaryOp = (AbstractPage.class$1 = Class.forName("org.eclipse.equinox.p2.metadata.IInstallableUnit"));
      }
      catch (ClassNotFoundException localClassNotFoundException1)
      {
        throw new NoClassDefFoundError(localClassNotFoundException1.getMessage());
      }
    }
    IInstallableUnit iu1 = (IInstallableUnit)ProvUI.getAdapter(e1, tmp4_1); Class 
      tmp45_42 = AbstractPage.class$1;
    if (tmp45_42 == null)
    {
      tmp45_42;
      try
      {
        tmpTernaryOp = (AbstractPage.class$1 = Class.forName("org.eclipse.equinox.p2.metadata.IInstallableUnit"));
      }
      catch (ClassNotFoundException localClassNotFoundException2)
      {
        throw new NoClassDefFoundError(localClassNotFoundException2.getMessage());
      }
    }
    IInstallableUnit iu2 = (IInstallableUnit)ProvUI.getAdapter(e2, tmp45_42);
    if ((iu1 != null) && (iu2 != null))
    {
      if ((viewer1 instanceof TreeViewer))
      {
        TreeViewer treeViewer = (TreeViewer)viewer1;
        IBaseLabelProvider baseLabel = treeViewer.getLabelProvider();
        if ((baseLabel instanceof ITableLabelProvider))
        {
          ITableLabelProvider tableProvider = (ITableLabelProvider)baseLabel;
          String e1p = tableProvider.getColumnText(e1, getSortColumn());
          String e2p = tableProvider.getColumnText(e2, getSortColumn());
          
          int result = getComparator().compare(e1p, e2p);
          if (result == 0)
          {
            e1p = tableProvider.getColumnText(e1, lastSortColumn);
            e2p = tableProvider.getColumnText(e2, lastSortColumn);
            
            int result2 = getComparator().compare(e1p, e2p);
            return lastAscending ? result2 : -1 * result2;
          }
          return isAscending() ? result : -1 * result;
        }
      }
      return 0;
    }
    return super.compare(viewer1, e1, e2);
  }
  
  public int getSortColumn()
  {
    return sortColumn;
  }
  
  public void setSortColumn(int sortColumn)
  {
    if (this.sortColumn != sortColumn)
    {
      lastSortColumn = this.sortColumn;
      lastAscending = ascending;
      this.sortColumn = sortColumn;
    }
  }
  
  public boolean isAscending()
  {
    return ascending;
  }
  
  public void setAscending(boolean ascending)
  {
    this.ascending = ascending;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.importexport.internal.wizard.AbstractPage.TreeViewerComparator
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.importexport.internal.wizard;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.equinox.internal.p2.importexport.P2ImportExport;
import org.eclipse.equinox.internal.p2.importexport.internal.Messages;
import org.eclipse.equinox.internal.p2.ui.ProvUI;
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
import org.eclipse.equinox.internal.p2.ui.dialogs.AvailableIUPatternFilter;
import org.eclipse.equinox.internal.p2.ui.model.InstalledIUElement;
import org.eclipse.equinox.internal.p2.ui.viewers.IUColumnConfig;
import org.eclipse.equinox.internal.p2.ui.viewers.IUDetailsLabelProvider;
import org.eclipse.equinox.internal.p2.ui.viewers.ProvElementComparer;
import org.eclipse.equinox.internal.p2.ui.viewers.ProvElementContentProvider;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ICheckStateProvider;
import org.eclipse.jface.viewers.IElementComparer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
import org.eclipse.ui.progress.WorkbenchJob;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;

public abstract class AbstractPage
  extends WizardPage
  implements Listener
{
  protected String currentMessage;
  protected Button destinationBrowseButton;
  protected Combo destinationNameField;
  protected P2ImportExport importexportService = null;
  protected CheckboxTreeViewer viewer = null;
  protected Exception finishException;
  protected static IProfileRegistry profileRegistry = null;
  static IProvisioningAgent agent = null;
  private static final String STORE_DESTINATION_NAMES_ID = "P2ImportExportPage.STORE_DESTINATION_NAMES_ID";
  protected static final int COMBO_HISTORY_LENGTH = 5;
  static Class class$1;
  
  final class ImportExportFilteredTree
    extends FilteredTree
  {
    ArrayList<Object> checkState = new ArrayList();
    
    ImportExportFilteredTree(Composite parent, int treeStyle, PatternFilter filter, boolean useNewLook)
    {
      super(treeStyle, filter, useNewLook);
    }
    
    protected TreeViewer doCreateTreeViewer(Composite composite, int style)
    {
      return new CheckboxTreeViewer(composite, style);
    }
    
    protected WorkbenchJob doCreateRefreshJob()
    {
      WorkbenchJob job = super.doCreateRefreshJob();
      job.addJobChangeListener(new JobChangeAdapter()
      {
        public void aboutToRun(IJobChangeEvent event)
        {
          Display.getDefault().syncExec(new Runnable()
          {
            public void run()
            {
              Object[] checked = viewer.getCheckedElements();
              if (checkState == null) {
                checkState = new ArrayList(checked.length);
              }
              for (int i = 0; i < checked.length; i++) {
                if ((!viewer.getGrayed(checked[i])) && 
                  (!checkState.contains(checked[i]))) {
                  checkState.add(checked[i]);
                }
              }
            }
          });
        }
        
        public void done(IJobChangeEvent event)
        {
          if (event.getResult().isOK()) {
            Display.getDefault().asyncExec(new Runnable()
            {
              public void run()
              {
                if ((viewer == null) || (viewer.getTree().isDisposed())) {
                  return;
                }
                if (checkState == null) {
                  return;
                }
                viewer.setCheckedElements(new Object[0]);
                viewer.setGrayedElements(new Object[0]);
                
                Iterator<Object> iter = checkState.iterator();
                while (iter.hasNext()) {
                  viewer.setChecked(iter.next(), true);
                }
                updatePageCompletion();
              }
            });
          }
        }
      });
      return job;
    }
  }
  
  class TreeViewerComparator
    extends ViewerComparator
  {
    private int sortColumn = 0;
    private int lastSortColumn = 0;
    private boolean ascending = false;
    private boolean lastAscending = false;
    
    TreeViewerComparator() {}
    
    public int compare(Viewer viewer1, Object e1, Object e2)
    {
      Class tmp4_1 = AbstractPage.class$1;
      if (tmp4_1 == null)
      {
        tmp4_1;
        try
        {
          tmpTernaryOp = (AbstractPage.class$1 = Class.forName("org.eclipse.equinox.p2.metadata.IInstallableUnit"));
        }
        catch (ClassNotFoundException localClassNotFoundException1)
        {
          throw new NoClassDefFoundError(localClassNotFoundException1.getMessage());
        }
      }
      IInstallableUnit iu1 = (IInstallableUnit)ProvUI.getAdapter(e1, tmp4_1); Class 
        tmp45_42 = AbstractPage.class$1;
      if (tmp45_42 == null)
      {
        tmp45_42;
        try
        {
          tmpTernaryOp = (AbstractPage.class$1 = Class.forName("org.eclipse.equinox.p2.metadata.IInstallableUnit"));
        }
        catch (ClassNotFoundException localClassNotFoundException2)
        {
          throw new NoClassDefFoundError(localClassNotFoundException2.getMessage());
        }
      }
      IInstallableUnit iu2 = (IInstallableUnit)ProvUI.getAdapter(e2, tmp45_42);
      if ((iu1 != null) && (iu2 != null))
      {
        if ((viewer1 instanceof TreeViewer))
        {
          TreeViewer treeViewer = (TreeViewer)viewer1;
          IBaseLabelProvider baseLabel = treeViewer.getLabelProvider();
          if ((baseLabel instanceof ITableLabelProvider))
          {
            ITableLabelProvider tableProvider = (ITableLabelProvider)baseLabel;
            String e1p = tableProvider.getColumnText(e1, getSortColumn());
            String e2p = tableProvider.getColumnText(e2, getSortColumn());
            
            int result = getComparator().compare(e1p, e2p);
            if (result == 0)
            {
              e1p = tableProvider.getColumnText(e1, lastSortColumn);
              e2p = tableProvider.getColumnText(e2, lastSortColumn);
              
              int result2 = getComparator().compare(e1p, e2p);
              return lastAscending ? result2 : -1 * result2;
            }
            return isAscending() ? result : -1 * result;
          }
        }
        return 0;
      }
      return super.compare(viewer1, e1, e2);
    }
    
    public int getSortColumn()
    {
      return sortColumn;
    }
    
    public void setSortColumn(int sortColumn)
    {
      if (this.sortColumn != sortColumn)
      {
        lastSortColumn = this.sortColumn;
        lastAscending = ascending;
        this.sortColumn = sortColumn;
      }
    }
    
    public boolean isAscending()
    {
      return ascending;
    }
    
    public void setAscending(boolean ascending)
    {
      this.ascending = ascending;
    }
  }
  
  static
  {
    BundleContext context = Platform.getBundle("org.eclipse.equinox.p2.ui.importexport").getBundleContext();
    ServiceTracker<IProvisioningAgent, IProvisioningAgent> tracker = new ServiceTracker(context, IProvisioningAgent.class, null);
    tracker.open();
    agent = (IProvisioningAgent)tracker.getService();
    tracker.close();
    if (agent != null) {
      profileRegistry = (IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
    }
  }
  
  public AbstractPage(String pageName)
  {
    super(pageName);
  }
  
  public AbstractPage(String pageName, String title, ImageDescriptor titleImage)
  {
    super(pageName, title, titleImage);
  }
  
  protected IProfile getSelfProfile()
  {
    if (profileRegistry != null)
    {
      String selfID = System.getProperty("eclipse.p2.profile");
      if (selfID == null) {
        selfID = "_SELF_";
      }
      return profileRegistry.getProfile(selfID);
    }
    return null;
  }
  
  private void createColumns(TreeViewer treeViewer)
  {
    String[] titles = { Messages.Column_Name, Messages.Column_Version, Messages.Column_Id };
    for (int i = 0; i < titles.length; i++)
    {
      TreeViewerColumn column = new TreeViewerColumn(treeViewer, 0);
      column.getColumn().setText(titles[i]);
      column.getColumn().setResizable(true);
      column.getColumn().setMoveable(true);
      if (Messages.Column_Name.equals(titles[i])) {
        updateTableSorting(i);
      }
      final int columnIndex = i;
      column.getColumn().addSelectionListener(new SelectionAdapter()
      {
        public void widgetSelected(SelectionEvent e)
        {
          updateTableSorting(columnIndex);
        }
      });
    }
  }
  
  protected void updateTableSorting(int columnIndex)
  {
    TreeViewerComparator comparator = (TreeViewerComparator)viewer.getComparator();
    if (columnIndex == comparator.getSortColumn()) {
      comparator.setAscending(!comparator.isAscending());
    }
    comparator.setSortColumn(columnIndex);
    viewer.getTree().setSortColumn(viewer.getTree().getColumn(columnIndex));
    viewer.getTree().setSortDirection(comparator.isAscending() ? 128 : 1024);
    viewer.refresh(false);
  }
  
  protected abstract void createContents(Composite paramComposite);
  
  public void createControl(Composite parent)
  {
    initializeDialogUnits(parent);
    initializeService();
    Composite composite = new Composite(parent, 0);
    GridLayout layout = new GridLayout(1, true);
    horizontalSpacing = 0;
    verticalSpacing = 5;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(272));
    
    createContents(composite);
    if ((!validDestination()) || (!validateOptionsGroup())) {
      setPageComplete(false);
    }
    setControl(composite);
    giveFocusToDestination();
    Dialog.applyDialogFont(composite);
  }
  
  protected void createDestinationGroup(Composite parent)
  {
    Composite composite = new Composite(parent, 2048);
    GridLayout layout = new GridLayout();
    numColumns = 3;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(4, 4, true, false));
    
    Label label = new Label(composite, 0);
    label.setText(getDestinationLabel());
    
    destinationNameField = new Combo(composite, 2052);
    restoreWidgetValues();
    GridData data = new GridData(768);
    destinationNameField.setLayoutData(data);
    destinationNameField.addListener(24, this);
    destinationNameField.addListener(13, this);
    destinationNameField.addListener(15, new Listener()
    {
      public void handleEvent(Event event)
      {
        destinationNameField.clearSelection();
      }
    });
    destinationBrowseButton = new Button(composite, 8);
    destinationBrowseButton.setText(Messages.Page_BUTTON_BROWSER);
    destinationBrowseButton.addListener(13, this);
    destinationBrowseButton.setLayoutData(new GridData(256));
  }
  
  protected IUColumnConfig[] getColumnConfig()
  {
    return new IUColumnConfig[] { new IUColumnConfig(ProvUIMessages.ProvUI_NameColumnTitle, 1, 60), new IUColumnConfig(ProvUIMessages.ProvUI_VersionColumnTitle, 2, 20), new IUColumnConfig(ProvUIMessages.ProvUI_IdColumnTitle, 0, 40) };
  }
  
  protected void createInstallationTable(final Composite parent)
  {
    Group group = new Group(parent, 0);
    GridData griddata = new GridData(4, 4, true, true);
    verticalSpan = (horizontalSpan = 0);
    group.setLayoutData(griddata);
    group.setLayout(new GridLayout(1, false));
    PatternFilter filter = getPatternFilter();
    filter.setIncludeLeadingWildcard(true);
    final ImportExportFilteredTree filteredTree = new ImportExportFilteredTree(group, 68354, filter, true);
    viewer = ((CheckboxTreeViewer)filteredTree.getViewer());
    final Tree tree = viewer.getTree();
    tree.setHeaderVisible(true);
    tree.setLinesVisible(false);
    viewer.setComparator(new TreeViewerComparator());
    viewer.setComparer(new ProvElementComparer());
    createColumns(viewer);
    final ITreeContentProvider contentProvider = getContentProvider();
    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(getLabelProvider());
    viewer.addCheckStateListener(new ICheckStateListener()
    {
      public void checkStateChanged(CheckStateChangedEvent event)
      {
        if ((!event.getChecked()) && (filteredTreecheckState != null))
        {
          ArrayList<Object> toRemove = new ArrayList(1);
          Object[] children;
          if (contentProvider.hasChildren(event.getElement()))
          {
            Set<Object> unchecked = new HashSet();
            children = contentProvider.getChildren(event.getElement());
            for (int i = 0; i < children.length; i++) {
              unchecked.add(children[i]);
            }
            Iterator<Object> iter = filteredTreecheckState.iterator();
            while (iter.hasNext())
            {
              Object current = iter.next();
              if ((current != null) && (unchecked.contains(current))) {
                toRemove.add(current);
              }
            }
          }
          else
          {
            for (children = filteredTreecheckState.iterator(); children.hasNext();)
            {
              Object element = children.next();
              if (viewer.getComparer().equals(element, event.getElement())) {
                toRemove.add(element);
              }
            }
          }
          filteredTreecheckState.removeAll(toRemove);
        }
      }
    });
    parent.addControlListener(new ControlAdapter()
    {
      private final int[] columnRate = { 6, 2, 2 };
      
      public void controlResized(ControlEvent e)
      {
        Rectangle area = parent.getClientArea();
        Point size = tree.computeSize(-1, -1);
        ScrollBar vBar = tree.getVerticalBar();
        int width = width - treecomputeTrim0000width - getSizex;
        if (y > height + tree.getHeaderHeight())
        {
          Point vBarSize = vBar.getSize();
          width -= x;
        }
        Point oldSize = tree.getSize();
        TreeColumn[] columns = tree.getColumns();
        int hasUsed = 0;int i = 0;
        if (x > width)
        {
          for (; i < columns.length - 1; i++)
          {
            columns[i].setWidth(width * columnRate[i] / 10);
            hasUsed += columns[i].getWidth();
          }
          columns[(columns.length - 1)].setWidth(width - hasUsed);
          tree.setSize(width, height);
        }
        else
        {
          tree.setSize(width, height);
          for (; i < columns.length - 1; i++)
          {
            columns[i].setWidth(width * columnRate[i] / 10);
            hasUsed += columns[i].getWidth();
          }
          columns[(columns.length - 1)].setWidth(width - hasUsed);
        }
      }
    });
    ICheckStateProvider provider = getViewerDefaultState();
    if (provider != null) {
      viewer.setCheckStateProvider(provider);
    } else {
      viewer.addSelectionChangedListener(new ISelectionChangedListener()
      {
        public void selectionChanged(SelectionChangedEvent event)
        {
          updatePageCompletion();
        }
      });
    }
    viewer.getControl().setLayoutData(new GridData(4, 4, true, true));
    viewer.getControl().setSize(300, 200);
    viewer.setInput(getInput());
    Composite buttons = new Composite(group, 0);
    buttons.setLayoutData(new GridData(4, 4, true, false));
    buttons.setLayout(new RowLayout(256));
    Button selectAll = new Button(buttons, 8);
    selectAll.setText(Messages.AbstractPage_ButtonSelectAll);
    selectAll.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        TreeItem[] arrayOfTreeItem;
        int j = (arrayOfTreeItem = viewer.getTree().getItems()).length;
        for (int i = 0; i < j; i++)
        {
          TreeItem item = arrayOfTreeItem[i];
          if (!item.getChecked())
          {
            item.setChecked(true);
            Event event = new Event();
            widget = item.getParent();
            detail = 32;
            item = item;
            type = 13;
            viewer.getTree().notifyListeners(13, event);
          }
        }
        updatePageCompletion();
      }
    });
    Button deselectAll = new Button(buttons, 8);
    deselectAll.setText(Messages.AbstractPage_ButtonDeselectAll);
    deselectAll.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        TreeItem[] arrayOfTreeItem;
        int j = (arrayOfTreeItem = viewer.getTree().getItems()).length;
        for (int i = 0; i < j; i++)
        {
          TreeItem item = arrayOfTreeItem[i];
          viewer.setSubtreeChecked(item.getData(), false);
        }
        updatePageCompletion();
      }
    });
  }
  
  protected PatternFilter getPatternFilter()
  {
    return new AvailableIUPatternFilter(getColumnConfig());
  }
  
  protected ICheckStateProvider getViewerDefaultState()
  {
    return null;
  }
  
  protected ITableLabelProvider getLabelProvider()
  {
    return new IUDetailsLabelProvider(null, getColumnConfig(), null);
  }
  
  protected ITreeContentProvider getContentProvider()
  {
    ProvElementContentProvider provider = new ProvElementContentProvider()
    {
      public boolean hasChildren(Object element)
      {
        if ((element instanceof InstalledIUElement)) {
          return false;
        }
        return super.hasChildren(element);
      }
      
      public Object[] getChildren(Object parent)
      {
        if ((parent instanceof InstalledIUElement)) {
          return new Object[0];
        }
        return super.getChildren(parent);
      }
    };
    return provider;
  }
  
  protected boolean determinePageCompletion()
  {
    currentMessage = null;
    
    boolean complete = (validateDestinationGroup()) && (validateOptionsGroup());
    if (complete) {
      setErrorMessage(null);
    } else {
      setErrorMessage(currentMessage);
    }
    return complete;
  }
  
  protected abstract void doFinish()
    throws Exception;
  
  protected int getBrowseDialogStyle()
  {
    return 4096;
  }
  
  protected abstract String getDestinationLabel();
  
  protected String getDestinationValue()
  {
    return destinationNameField.getText().trim();
  }
  
  protected abstract String getDialogTitle();
  
  protected abstract Object getInput();
  
  protected abstract String getInvalidDestinationMessage();
  
  protected String getNoOptionsMessage()
  {
    return Messages.PAGE_NOINSTALLTION_ERROR;
  }
  
  protected abstract void giveFocusToDestination();
  
  protected void handleDestinationBrowseButtonPressed()
  {
    FileDialog dialog = new FileDialog(getContainer().getShell(), getBrowseDialogStyle() | 0x10000000);
    dialog.setText(getDialogTitle());
    dialog.setFilterPath(getDestinationValue());
    dialog.setFilterExtensions(new String[] { Messages.EXTENSION_p2F, Messages.EXTENSION_ALL });
    dialog.setFilterNames(new String[] { Messages.EXTENSION_p2F_NAME, Messages.EXTENSION_ALL_NAME });
    String selectedFileName = dialog.open();
    if (selectedFileName != null)
    {
      if (!selectedFileName.endsWith(Messages.EXTENSION_p2F.substring(1))) {
        selectedFileName = selectedFileName + Messages.EXTENSION_p2F.substring(1);
      }
      setDestinationValue(selectedFileName);
    }
  }
  
  public void handleEvent(Event event)
  {
    Widget source = widget;
    if (source == destinationBrowseButton) {
      handleDestinationBrowseButtonPressed();
    } else {
      handleDestinationChanged(getDestinationValue());
    }
    updatePageCompletion();
  }
  
  protected void handleDestinationChanged(String newDestination) {}
  
  protected void initializeService()
  {
    ServiceTracker<P2ImportExport, P2ImportExport> tracker = new ServiceTracker(Platform.getBundle("org.eclipse.equinox.p2.ui.importexport").getBundleContext(), P2ImportExport.class.getName(), null);
    tracker.open();
    importexportService = ((P2ImportExport)tracker.getService());
    tracker.close();
  }
  
  protected void setDestinationValue(String selectedFileName)
  {
    destinationNameField.setText(selectedFileName);
  }
  
  protected void updatePageCompletion()
  {
    boolean pageComplete = determinePageCompletion();
    setPageComplete(pageComplete);
    if (pageComplete)
    {
      if ((this instanceof AbstractImportPage)) {
        saveWidgetValues();
      }
      setMessage(null);
    }
  }
  
  protected boolean validateDestinationGroup()
  {
    if (!validDestination())
    {
      currentMessage = getInvalidDestinationMessage();
      return false;
    }
    return true;
  }
  
  protected boolean validateOptionsGroup()
  {
    if ((viewer == null) || (viewer.getCheckedElements().length > 0)) {
      return true;
    }
    currentMessage = getNoOptionsMessage();
    return false;
  }
  
  protected boolean validDestination()
  {
    if (destinationNameField == null) {
      return true;
    }
    File file = new File(getDestinationValue());
    return (file.getPath().length() > 0) && (!file.isDirectory());
  }
  
  protected void saveWidgetValues()
  {
    IDialogSettings settings = getDialogSettings();
    if (settings != null)
    {
      String[] directoryNames = settings.getArray("P2ImportExportPage.STORE_DESTINATION_NAMES_ID");
      if (directoryNames == null) {
        directoryNames = new String[0];
      }
      directoryNames = addToHistory(directoryNames, getDestinationValue());
      settings.put("P2ImportExportPage.STORE_DESTINATION_NAMES_ID", directoryNames);
    }
  }
  
  protected String[] addToHistory(String[] history, String newEntry)
  {
    List<String> l = new ArrayList(Arrays.asList(history));
    addToHistory(l, newEntry);
    String[] r = new String[l.size()];
    l.toArray(r);
    return r;
  }
  
  protected void addToHistory(List<String> history, String newEntry)
  {
    history.remove(newEntry);
    history.add(0, newEntry);
    if (history.size() > 5) {
      history.remove(5);
    }
  }
  
  protected void restoreWidgetValues()
  {
    IDialogSettings settings = getDialogSettings();
    if (settings != null)
    {
      String[] directoryNames = settings.getArray("P2ImportExportPage.STORE_DESTINATION_NAMES_ID");
      if (directoryNames != null)
      {
        setDestinationValue(directoryNames[0]);
        for (int i = 0; i < directoryNames.length; i++) {
          addDestinationItem(directoryNames[i]);
        }
        setDestinationValue("");
      }
    }
  }
  
  protected void addDestinationItem(String value)
  {
    destinationNameField.add(value);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.importexport.internal.wizard.AbstractPage
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.importexport.internal.wizard;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.MessageBox;

public abstract class AbstractWizard
  extends Wizard
{
  protected AbstractPage mainPage = null;
  
  public boolean performFinish()
  {
    try
    {
      mainPage.doFinish();
    }
    catch (InterruptedException localInterruptedException)
    {
      return false;
    }
    catch (Exception e)
    {
      Platform.getLog(Platform.getBundle("org.eclipse.equinox.p2.ui.importexport")).log(new Status(4, "org.eclipse.equinox.p2.ui.importexport", e.getMessage(), e));
      MessageBox messageBox = new MessageBox(getShell(), 1);
      messageBox.setMessage(e.getMessage() == null ? "Unknown error" : e.getMessage());
      messageBox.open();
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.importexport.internal.wizard.AbstractWizard
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.importexport.internal.wizard;

import org.eclipse.equinox.internal.p2.importexport.internal.Messages;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

class ExportPage$1$1
  implements Runnable
{
  final ExportPage.1 this$1;
  
  ExportPage$1$1(ExportPage.1 param1, StringBuilder paramStringBuilder) {}
  
  public void run()
  {
    String title = Messages.ExportPage_Title;
    this$1.tryAgain = StyledErrorDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, val$sb.toString());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.importexport.internal.wizard.ExportPage.1.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.importexport.internal.wizard;

import java.io.OutputStream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.equinox.internal.p2.importexport.P2ImportExport;
import org.eclipse.equinox.internal.p2.importexport.internal.Messages;
import org.eclipse.equinox.internal.p2.ui.ProvUI;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

class ExportPage$1
  implements IRunnableWithProgress
{
  ExportPage$1(ExportPage paramExportPage, Object[] paramArrayOfObject, OutputStream paramOutputStream) {}
  
  public void run(IProgressMonitor monitor)
    throws InterruptedException
  {
    try
    {
      IInstallableUnit[] units = new IInstallableUnit[val$checked.length];
      for (int i = 0; i < units.length; i++)
      {
        Class tmp25_22 = ExportPage.class$0;
        if (tmp25_22 == null)
        {
          tmp25_22;
          try
          {
            tmpTernaryOp = (ExportPage.class$0 = Class.forName("org.eclipse.equinox.p2.metadata.IInstallableUnit"));
          }
          catch (ClassNotFoundException localClassNotFoundException)
          {
            throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
          }
        }
        units[i] = ((IInstallableUnit)ProvUI.getAdapter(val$checked[i], tmp25_22));
      }
      IStatus status = this$0.importexportService.exportP2F(val$out, units, monitor);
      if (status.isMultiStatus())
      {
        final StringBuilder sb = new StringBuilder();
        IStatus[] arrayOfIStatus1;
        int j = (arrayOfIStatus1 = status.getChildren()).length;
        for (int i = 0; i < j; i++)
        {
          IStatus child = arrayOfIStatus1[i];
          if (child.isMultiStatus())
          {
            IStatus[] arrayOfIStatus2;
            int m = (arrayOfIStatus2 = child.getChildren()).length;
            for (int k = 0; k < m; k++)
            {
              IStatus grandchild = arrayOfIStatus2[k];
              sb.append("<li>").append(grandchild.getMessage()).append("</li>");
            }
          }
          else if (child.isOK())
          {
            sb.insert(0, Messages.ExportPage_SuccessWithProblems);
          }
          else
          {
            sb.insert(0, Messages.ExportPage_Fail);
            sb.append(status.getMessage());
          }
        }
        sb.append(Messages.ExportPage_FixSuggestion);
        sb.append(Messages.ExportPage_TryAgainQuestion);
        Runnable runnable = new Runnable()
        {
          public void run()
          {
            String title = Messages.ExportPage_Title;
            tryAgain = StyledErrorDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, sb.toString());
          }
        };
        Display.getDefault().syncExec(runnable);
        if (tryAgain) {
          throw new OperationCanceledException("User chosed try again.");
        }
      }
    }
    catch (OperationCanceledException e)
    {
      throw new InterruptedException(e.getMessage());
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  boolean tryAgain = false;
  final ExportPage this$0;
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.importexport.internal.wizard.ExportPage.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.importexport.internal.wizard;

import java.io.OutputStream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.equinox.internal.p2.importexport.P2ImportExport;
import org.eclipse.equinox.internal.p2.importexport.internal.Messages;
import org.eclipse.equinox.internal.p2.ui.ProvUI;
import org.eclipse.equinox.internal.p2.ui.model.ProfileElement;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

public class ExportPage
  extends AbstractPage
{
  static Class class$0;
  
  public ExportPage(String pageName)
  {
    super(pageName);
    setTitle(Messages.ExportPage_Title);
    setDescription(Messages.ExportPage_Description);
  }
  
  protected void createContents(Composite composite)
  {
    Label label = new Label(composite, 0);
    label.setLayoutData(new GridData(4, 2, true, false));
    if (getSelfProfile() == null)
    {
      label.setText(Messages.ExportPage_ERROR_CONFIG);
    }
    else
    {
      label.setText(Messages.ExportPage_Label);
      
      createInstallationTable(composite);
      createDestinationGroup(composite);
    }
  }
  
  /* Error */
  public void doFinish()
    throws Exception
  {
    // Byte code:
    //   0: aload_0
    //   1: aconst_null
    //   2: putfield 158	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage:finishException	Ljava/lang/Exception;
    //   5: aload_0
    //   6: getfield 159	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage:viewer	Lorg/eclipse/jface/viewers/CheckboxTreeViewer;
    //   9: ifnonnull +4 -> 13
    //   12: return
    //   13: aload_0
    //   14: invokevirtual 168	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage:saveWidgetValues	()V
    //   17: aload_0
    //   18: getfield 159	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage:viewer	Lorg/eclipse/jface/viewers/CheckboxTreeViewer;
    //   21: invokevirtual 177	org/eclipse/jface/viewers/CheckboxTreeViewer:getCheckedElements	()[Ljava/lang/Object;
    //   24: astore_1
    //   25: aconst_null
    //   26: astore_2
    //   27: new 73	java/io/File
    //   30: dup
    //   31: aload_0
    //   32: getfield 160	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage:destinationNameField	Lorg/eclipse/swt/widgets/Combo;
    //   35: invokevirtual 180	org/eclipse/swt/widgets/Combo:getText	()Ljava/lang/String;
    //   38: invokespecial 164	java/io/File:<init>	(Ljava/lang/String;)V
    //   41: astore_3
    //   42: aload_3
    //   43: invokevirtual 163	java/io/File:exists	()Z
    //   46: ifne +8 -> 54
    //   49: aload_3
    //   50: invokevirtual 162	java/io/File:createNewFile	()Z
    //   53: pop
    //   54: new 72	java/io/BufferedOutputStream
    //   57: dup
    //   58: new 74	java/io/FileOutputStream
    //   61: dup
    //   62: aload_3
    //   63: invokespecial 165	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   66: invokespecial 161	java/io/BufferedOutputStream:<init>	(Ljava/io/OutputStream;)V
    //   69: astore_2
    //   70: aload_2
    //   71: astore 4
    //   73: aload_0
    //   74: invokevirtual 172	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage:getContainer	()Lorg/eclipse/jface/wizard/IWizardContainer;
    //   77: iconst_1
    //   78: iconst_1
    //   79: new 81	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage$1
    //   82: dup
    //   83: aload_0
    //   84: aload_1
    //   85: aload 4
    //   87: invokespecial 175	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage$1:<init>	(Lorg/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage;[Ljava/lang/Object;Ljava/io/OutputStream;)V
    //   90: invokeinterface 186 4 0
    //   95: goto +32 -> 127
    //   98: astore 5
    //   100: aload_2
    //   101: ifnull +11 -> 112
    //   104: aload_2
    //   105: invokevirtual 166	java/io/OutputStream:close	()V
    //   108: goto +4 -> 112
    //   111: pop
    //   112: aload_0
    //   113: getfield 158	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage:finishException	Ljava/lang/Exception;
    //   116: ifnull +8 -> 124
    //   119: aload_0
    //   120: getfield 158	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage:finishException	Ljava/lang/Exception;
    //   123: athrow
    //   124: aload 5
    //   126: athrow
    //   127: aload_2
    //   128: ifnull +11 -> 139
    //   131: aload_2
    //   132: invokevirtual 166	java/io/OutputStream:close	()V
    //   135: goto +4 -> 139
    //   138: pop
    //   139: aload_0
    //   140: getfield 158	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage:finishException	Ljava/lang/Exception;
    //   143: ifnull +8 -> 151
    //   146: aload_0
    //   147: getfield 158	org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage:finishException	Ljava/lang/Exception;
    //   150: athrow
    //   151: return
    // Line number table:
    //   Java source line #49	-> byte code offset #0
    //   Java source line #50	-> byte code offset #5
    //   Java source line #51	-> byte code offset #12
    //   Java source line #53	-> byte code offset #13
    //   Java source line #54	-> byte code offs
1 2 3 4 5 6

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd