org.eclipse.pde.api.tools.ui_1.0.301.v20110803_r371

ce;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.internal.ui.util.StringMatcher;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange;
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
import org.eclipse.pde.api.tools.internal.ApiDescriptionProcessor;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.pde.api.tools.internal.provisional.IApiBaselineManager;
import org.eclipse.pde.api.tools.internal.util.Util;
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
import org.eclipse.pde.api.tools.ui.internal.IApiToolsHelpContextIds;
import org.eclipse.pde.api.tools.ui.internal.SWTFactory;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.IWorkbenchHelpSystem;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.ui.progress.UIJob;
import org.eclipse.ui.progress.WorkbenchJob;

public class ApiToolingSetupWizardPage
  extends UserInputWizardPage
{
  private static final String SETTINGS_SECTION = "ApiToolingSetupWizardPage";
  private static final String SETTINGS_REMOVECXML = "remove_componentxml";
  
  class UpdateJob
    extends WorkbenchJob
  {
    private String pattern = null;
    
    public UpdateJob()
    {
      super();
      setSystem(true);
    }
    
    public synchronized void setFilter(String pattern)
    {
      this.pattern = pattern;
    }
    
    /* Error */
    public IStatus runInUIThread(IProgressMonitor monitor)
    {
      // Byte code:
      //   0: aload_0
      //   1: getfield 87	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage$UpdateJob:this$0	Lorg/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage;
      //   4: getfield 84	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage:tableviewer	Lorg/eclipse/jface/viewers/CheckboxTableViewer;
      //   7: ifnull +126 -> 133
      //   10: aload_0
      //   11: getfield 87	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage$UpdateJob:this$0	Lorg/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage;
      //   14: getfield 84	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage:tableviewer	Lorg/eclipse/jface/viewers/CheckboxTableViewer;
      //   17: invokevirtual 96	org/eclipse/jface/viewers/CheckboxTableViewer:getTable	()Lorg/eclipse/swt/widgets/Table;
      //   20: iconst_0
      //   21: invokevirtual 99	org/eclipse/swt/widgets/Table:setRedraw	(Z)V
      //   24: aload_0
      //   25: dup
      //   26: astore_2
      //   27: monitorenter
      //   28: aload_0
      //   29: getfield 87	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage$UpdateJob:this$0	Lorg/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage;
      //   32: getfield 85	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage:filter	Lorg/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage$StringFilter;
      //   35: new 37	java/lang/StringBuffer
      //   38: dup
      //   39: aload_0
      //   40: getfield 86	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage$UpdateJob:pattern	Ljava/lang/String;
      //   43: invokestatic 89	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
      //   46: invokespecial 91	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
      //   49: bipush 42
      //   51: invokevirtual 92	java/lang/StringBuffer:append	(C)Ljava/lang/StringBuffer;
      //   54: invokevirtual 90	java/lang/StringBuffer:toString	()Ljava/lang/String;
      //   57: invokevirtual 97	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage$StringFilter:setPattern	(Ljava/lang/String;)V
      //   60: aload_2
      //   61: monitorexit
      //   62: goto +6 -> 68
      //   65: aload_2
      //   66: monitorexit
      //   67: athrow
      //   68: aload_0
      //   69: getfield 87	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage$UpdateJob:this$0	Lorg/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage;
      //   72: getfield 84	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage:tableviewer	Lorg/eclipse/jface/viewers/CheckboxTableViewer;
      //   75: iconst_1
      //   76: invokevirtual 94	org/eclipse/jface/viewers/CheckboxTableViewer:refresh	(Z)V
      //   79: aload_0
      //   80: getfield 87	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage$UpdateJob:this$0	Lorg/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage;
      //   83: getfield 84	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage:tableviewer	Lorg/eclipse/jface/viewers/CheckboxTableViewer;
      //   86: aload_0
      //   87: getfield 87	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage$UpdateJob:this$0	Lorg/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage;
      //   90: getfield 83	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage:checkedset	Ljava/util/HashSet;
      //   93: invokevirtual 93	java/util/HashSet:toArray	()[Ljava/lang/Object;
      //   96: invokevirtual 95	org/eclipse/jface/viewers/CheckboxTableViewer:setCheckedElements	([Ljava/lang/Object;)V
      //   99: goto +20 -> 119
      //   102: astore_3
      //   103: aload_0
      //   104: getfield 87	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage$UpdateJob:this$0	Lorg/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage;
      //   107: getfield 84	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage:tableviewer	Lorg/eclipse/jface/viewers/CheckboxTableViewer;
      //   110: invokevirtual 96	org/eclipse/jface/viewers/CheckboxTableViewer:getTable	()Lorg/eclipse/swt/widgets/Table;
      //   113: iconst_1
      //   114: invokevirtual 99	org/eclipse/swt/widgets/Table:setRedraw	(Z)V
      //   117: aload_3
      //   118: athrow
      //   119: aload_0
      //   120: getfield 87	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage$UpdateJob:this$0	Lorg/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage;
      //   123: getfield 84	org/eclipse/pde/api/tools/ui/internal/wizards/ApiToolingSetupWizardPage:tableviewer	Lorg/eclipse/jface/viewers/CheckboxTableViewer;
      //   126: invokevirtual 96	org/eclipse/jface/viewers/CheckboxTableViewer:getTable	()Lorg/eclipse/swt/widgets/Table;
      //   129: iconst_1
      //   130: invokevirtual 99	org/eclipse/swt/widgets/Table:setRedraw	(Z)V
      //   133: getstatic 82	org/eclipse/core/runtime/Status:OK_STATUS	Lorg/eclipse/core/runtime/IStatus;
      //   136: areturn
      // Line number table:
      //   Java source line #122	-> byte code offset #0
      //   Java source line #124	-> byte code offset #10
      //   Java source line #125	-> byte code offset #24
      //   Java source line #126	-> byte code offset #28
      //   Java source line #125	-> byte code offset #60
      //   Java source line #128	-> byte code offset #68
      //   Java source line #129	-> byte code offset #79
      //   Java source line #131	-> byte code offset #102
      //   Java source line #132	-> byte code offset #103
      //   Java source line #133	-> byte code offset #117
      //   Java source line #132	-> byte code offset #119
      //   Java source line #135	-> byte code offset #133
      // Local variable table:
      //   start	length	slot	name	signature
      //   0	137	0	this	UpdateJob
      //   0	137	1	monitor	IProgressMonitor
      //   102	16	3	localObject1	Object
      // Exception table:
      //   from	to	target	type
      //   28	62	65	finally
      //   65	67	65	finally
      //   10	102	102	finally
    }
  }
  
  static class StringFilter
    extends ViewerFilter
  {
    private String pattern = null;
    StringMatcher matcher = null;
    
    public void setPattern(String pattern)
    {
      this.pattern = pattern;
    }
    
    public boolean select(Viewer viewer, Object parentElement, Object element)
    {
      if (pattern == null) {
        return true;
      }
      if (pattern.trim().length() == 0) {
        return true;
      }
      String name = null;
      if ((element instanceof IResource)) {
        name = ((IResource)element).getName();
      }
      if (name == null) {
        return false;
      }
      matcher = new StringMatcher(pattern, true, false);
      return matcher.match(name, 0, name.length());
    }
  }
  
  CheckboxTableViewer tableviewer = null;
  HashSet checkedset = new HashSet();
  Button removecxml = null;
  UpdateJob updatejob = new UpdateJob();
  StringFilter filter = new StringFilter();
  private Text checkcount = null;
  
  protected ApiToolingSetupWizardPage()
  {
    super(WizardMessages.UpdateJavadocTagsWizardPage_4);
    setTitle(WizardMessages.UpdateJavadocTagsWizardPage_4);
    setMessage(WizardMessages.UpdateJavadocTagsWizardPage_7);
  }
  
  public void createControl(Composite parent)
  {
    Composite comp = SWTFactory.createComposite(parent, 1, 1, 1808);
    setControl(comp);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, IApiToolsHelpContextIds.API_TOOLING_SETUP_WIZARD_PAGE);
    SWTFactory.createWrapLabel(comp, WizardMessages.UpdateJavadocTagsWizardPage_6, 1, 100);
    SWTFactory.createVerticalSpacer(comp, 1);
    SWTFactory.createWrapLabel(comp, WizardMessages.ApiToolingSetupWizardPage_6, 1, 50);
    
    Text text = SWTFactory.createText(comp, 2048, 1);
    text.addModifyListener(new ModifyListener()
    {
      private final Text val$text;
      
      public void modifyText(ModifyEvent e)
      {
        updatejob.setFilter(val$text.getText().trim());
        updatejob.cancel();
        updatejob.schedule();
      }
    });
    text.addKeyListener(new KeyAdapter()
    {
      public void keyPressed(KeyEvent e)
      {
        if ((keyCode == 16777218) && 
          (tableviewer != null)) {
          tableviewer.getTable().setFocus();
        }
      }
    });
    SWTFactory.createWrapLabel(comp, WizardMessages.UpdateJavadocTagsWizardPage_8, 1, 50);
    
    Table table = new Table(comp, 67618);
    GridData gd = new GridData(1808);
    heightHint = 150;
    table.setLayoutData(gd);
    tableviewer = new CheckboxTableViewer(table);
    tableviewer.setLabelProvider(new WorkbenchLabelProvider());
    tableviewer.setContentProvider(new ArrayContentProvider());
    tableviewer.setInput(getInputProjects());
    tableviewer.setComparator(new ViewerComparator());
    tableviewer.addFilter(filter);
    tableviewer.addCheckStateListener(new ICheckStateListener()
    {
      public void checkStateChanged(CheckStateChangedEvent event)
      {
        if (event.getChecked()) {
          checkedset.add(event.getElement());
        } else {
          checkedset.remove(event.getElement());
        }
        setPageComplete(pageValid());
      }
    });
    Composite bcomp = SWTFactory.createComposite(comp, 3, 1, 771, 0, 0);
    Button button = SWTFactory.createPushButton(bcomp, WizardMessages.UpdateJavadocTagsWizardPage_10, null);
    button.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        tableviewer.setAllChecked(true);
        checkedset.addAll(Arrays.asList(tableviewer.getCheckedElements()));
        setPageComplete(pageValid());
      }
    });
    button = SWTFactory.createPushButton(bcomp, WizardMessages.UpdateJavadocTagsWizardPage_11, null);
    button.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        tableviewer.setAllChecked(false);
        TableItem[] items = tableviewer.getTable().getItems();
        for (int i = 0; i < items.length; i++) {
          checkedset.remove(items[i].getData());
        }
        setPageComplete(pageValid());
      }
    });
    checkcount = SWTFactory.createText(bcomp, 8388616, 1, 640);
    checkcount.setBackground(bcomp.getBackground());
    
    Object[] selected = getWorkbenchSelection();
    if (selected.length > 0)
    {
      tableviewer.setCheckedElements(selected);
      checkedset.addAll(Arrays.asList(selected));
    }
    setPageComplete(checkedset.size() > 0);
    
    SWTFactory.createVerticalSpacer(comp, 1);
    removecxml = SWTFactory.createCheckButton(comp, WizardMessages.ApiToolingSetupWizardPage_0, null, true, 1);
    
    IDialogSettings settings = ApiUIPlugin.getDefault().getDialogSettings().getSection("ApiToolingSetupWizardPage");
    if (settings != null) {
      removecxml.setSelection(settings.getBoolean("remove_componentxml"));
    }
  }
  
  public void setPageComplete(boolean complete)
  {
    super.setPageComplete(complete);
    updateCheckStatus(checkedset.size());
  }
  
  private void updateCheckStatus(int count)
  {
    if (checkcount == null) {
      return;
    }
    checkcount.setText(MessageFormat.format(WizardMessages.ApiToolingSetupWizardPage_n_items_checked, new String[] { Integer.toString(count) }));
  }
  
  private IProject[] getInputProjects()
  {
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    ArrayList pjs = new ArrayList();
    for (int i = 0; i < projects.length; i++) {
      try
      {
        IProject project = projects[i];
        if (acceptProject(project)) {
          pjs.add(project);
        }
      }
      catch (CoreException localCoreException) {}
    }
    return (IProject[])pjs.toArray(new IProject[pjs.size()]);
  }
  
  private boolean acceptProject(IProject project)
    throws CoreException
  {
    if (project == null) {
      return false;
    }
    return (project.hasNature("org.eclipse.jdt.core.javanature")) && (project.hasNature("org.eclipse.pde.PluginNature")) && (!project.hasNature("org.eclipse.pde.api.tools.apiAnalysisNature")) && (!Util.isBinaryProject(project));
  }
  
  protected Object[] getWorkbenchSelection()
  {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null)
    {
      IWorkbenchPage page = window.getActivePage();
      if (page != null)
      {
        IWorkbenchPart part = page.getActivePart();
        if (part != null)
        {
          IWorkbenchSite site = part.getSite();
          if (site != null)
          {
            ISelectionProvider provider = site.getSelectionProvider();
            if (provider != null)
            {
              ISelection selection = provider.getSelection();
              if ((selection instanceof IStructuredSelection))
              {
                Object[] jps = ((IStructuredSelection)provider.getSelection()).toArray();
                ArrayList pjs = new ArrayList();
                for (int i = 0; i < jps.length; i++) {
                  if ((jps[i] instanceof IAdaptable))
                  {
                    IAdaptable adapt = (IAdaptable)jps[i];
                    IProject pj = (IProject)adapt.getAdapter(IProject.class);
                    try
                    {
                      if (acceptProject(pj)) {
                        pjs.add(pj);
                      }
                    }
                    catch (CoreException localCoreException) {}
                  }
                }
                return pjs.toArray();
              }
            }
          }
        }
      }
    }
    return new Object[0];
  }
  
  protected boolean pageValid()
  {
    if (checkedset.size() < 1)
    {
      setErrorMessage(WizardMessages.UpdateJavadocTagsWizardPage_12);
      return false;
    }
    setErrorMessage(null);
    return true;
  }
  
  public IWizardPage getNextPage()
  {
    collectChanges();
    IWizardPage page = super.getNextPage();
    if (page != null) {
      page.setDescription(WizardMessages.ApiToolingSetupWizardPage_5);
    }
    return page;
  }
  
  void createTagChanges(CompositeChange projectchange, IJavaProject project, File cxml)
  {
    try
    {
      HashMap map = new HashMap();
      ApiDescriptionProcessor.collectTagUpdates(project, cxml, map);
      IFile file = null;
      TextFileChange change = null;
      MultiTextEdit multiedit = null;
      HashSet alledits = null;
      TextEdit edit = null;
      for (Iterator iter = map.entrySet().iterator(); iter.hasNext();)
      {
        Map.Entry entry = (Map.Entry)iter.next();
        file = (IFile)entry.getKey();
        change = new TextFileChange(MessageFormat.format(WizardMessages.JavadocTagRefactoring_2, new String[] { file.getName() }), file);
        multiedit = new MultiTextEdit();
        change.setEdit(multiedit);
        alledits = (HashSet)entry.getValue();
        if (alledits != null) {
          for (Iterator iter2 = alledits.iterator(); iter2.hasNext();)
          {
            edit = (TextEdit)iter2.next();
            multiedit.addChild(edit);
          }
        }
        if (change != null) {
          projectchange.add(change);
        }
      }
    }
    catch (CoreException e)
    {
      ApiUIPlugin.log(e);
    }
    catch (IOException e)
    {
      ApiUIPlugin.log(e);
    }
  }
  
  private void collectChanges()
  {
    ApiToolingSetupRefactoring refactoring = (ApiToolingSetupRefactoring)getRefactoring();
    IRunnableWithProgress op = new IRunnableWithProgress()
    {
      private final ApiToolingSetupRefactoring val$refactoring;
      
      public void run(IProgressMonitor monitor)
        throws InvocationTargetException, InterruptedException
      {
        Object[] projects = checkedset.toArray(new IProject[checkedset.size()]);
        IProject project = null;
        SubMonitor localmonitor = SubMonitor.convert(monitor);
        localmonitor.beginTask("", projects.length);
        localmonitor.setTaskName(WizardMessages.ApiToolingSetupWizardPage_7);
        val$refactoring.resetRefactoring();
        boolean remove = removecxml.getSelection();
        CompositeChange pchange = null;
        for (int i = 0; i < projects.length; i++)
        {
          project = (IProject)projects[i];
          pchange = new CompositeChange(project.getName());
          val$refactoring.addChange(pchange);
          pchange.add(new ProjectUpdateChange(project));
          localmonitor.subTask(MessageFormat.format(WizardMessages.ApiToolingSetupWizardPage_4, new String[] { project.getName() }));
          IResource cxml = project.findMember("component.xml");
          if (cxml != null)
          {
            createTagChanges(pchange, JavaCore.create(project), new File(cxml.getLocationURI()));
            if (remove) {
              pchange.add(new DeleteResourceChange(cxml.getFullPath(), true));
            }
          }
          Util.updateMonitor(localmonitor, 1);
        }
      }
    };
    try
    {
      getContainer().run(false, false, op);
    }
    catch (InvocationTargetException e)
    {
      ApiUIPlugin.log(e);
    }
    catch (InterruptedException e)
    {
      ApiUIPlugin.log(e);
    }
  }
  
  protected boolean performFinish()
  {
    collectChanges();
    return super.performFinish();
  }
  
  public boolean finish()
  {
    IDialogSettings settings = ApiUIPlugin.getDefault().getDialogSettings().addNewSection("ApiToolingSetupWizardPage");
    settings.put("remove_componentxml", removecxml.getSelection());
    notifyNoDefaultProfile();
    return true;
  }
  
  private void notifyNoDefaultProfile()
  {
    if (ApiPlugin.getDefault().getApiBaselineManager().getDefaultApiBaseline() == null)
    {
      UIJob job = new UIJob("No default API profile detected")
      {
        public IStatus runInUIThread(IProgressMonitor monitor)
        {
          boolean doit = MessageDialog.openQuestion(getShell(), WizardMessages.ApiToolingSetupWizardPage_1, WizardMessages.ApiToolingSetupWizardPage_2 + 
            WizardMessages.ApiToolingSetupWizardPage_3);
          if (doit) {
            SWTFactory.showPreferencePage(getShell(), "org.eclipse.pde.api.tools.ui.apiprofiles.prefpage", null);
          }
          return Status.OK_STATUS;
        }
      };
      job.setSystem(true);
      job.schedule();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.ui.internal.wizards.ApiToolingSetupWizardPage
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.ui.internal.wizards;

import java.util.Comparator;
import org.eclipse.jdt.core.IJavaElement;

class CompareOperation$1
  implements Comparator
{
  public int compare(Object o1, Object o2)
  {
    if (((o1 instanceof IJavaElement)) && ((o2 instanceof IJavaElement)))
    {
      IJavaElement element = (IJavaElement)o1;
      IJavaElement element2 = (IJavaElement)o2;
      return element.getElementType() - element2.getElementType();
    }
    return 0;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.ui.internal.wizards.CompareOperation.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.ui.internal.wizards;

import java.util.Arrays;
import java.util.Comparator;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.api.tools.internal.ApiBaselineManager;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.pde.api.tools.internal.provisional.Factory;
import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations;
import org.eclipse.pde.api.tools.internal.provisional.IApiDescription;
import org.eclipse.pde.api.tools.internal.provisional.ISessionManager;
import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers;
import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiComparator;
import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiScope;
import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiScope;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
import org.eclipse.pde.api.tools.ui.internal.actions.ActionMessages;
import org.eclipse.pde.api.tools.ui.internal.actions.DeltaSession;

public class CompareOperation
  extends Job
{
  private IApiBaseline baseline = null;
  private IStructuredSelection selection = null;
  
  public CompareOperation(IApiBaseline baseline, IStructuredSelection selection)
  {
    super(ActionMessages.CompareWithAction_comparing_apis);
    this.baseline = baseline;
    Assert.isNotNull(this.baseline);
    this.selection = selection;
  }
  
  protected IStatus run(IProgressMonitor monitor)
  {
    monitor.beginTask(ActionMessages.CompareDialogCollectingElementTaskName, -1);
    String baselineName = baseline.getName();
    IApiScope scope = walkStructureSelection(selection, monitor);
    try
    {
      monitor.subTask(ActionMessages.CompareDialogComputeDeltasTaskName);
      try
      {
        IDelta delta = ApiComparator.compare(scope, baseline, 1, false, monitor);
        IStatus localIStatus;
        if (delta == null) {
          return Status.CANCEL_STATUS;
        }
        IDelta delta;
        int size = selection.size();
        String description = NLS.bind(ActionMessages.CompareWithAction_compared_with_against, new Object[] {
          new Integer(size), 
          baselineName, 
          new Integer(delta.getChildren().length) });
        if (size == 1) {
          description = NLS.bind(ActionMessages.CompareWithAction_compared_project_with, new Object[] {
            ((IJavaElement)selection.getFirstElement()).getElementName(), 
            baselineName, 
            new Integer(delta.getChildren().length) });
        }
        ApiPlugin.getDefault().getSessionManager().addSession(new DeltaSession(description, delta, baselineName), true);
        return Status.OK_STATUS;
      }
      catch (CoreException e)
      {
        ApiPlugin.log(e);
      }
      catch (OperationCanceledException localOperationCanceledException) {}
    }
    finally
    {
      monitor.done();
    }
    return Status.CANCEL_STATUS;
  }
  
  public static ApiScope walkStructureSelection(IStructuredSelection structuredSelection, IProgressMonitor monitor)
  {
    Object[] selected = structuredSelection.toArray();
    ApiScope scope = new ApiScope();
    IApiBaseline workspaceBaseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
    if (workspaceBaseline == null) {
      return scope;
    }
    Arrays.sort(selected, new Comparator()
    {
      public int compare(Object o1, Object o2)
      {
        if (((o1 instanceof IJavaElement)) && ((o2 instanceof IJavaElement)))
        {
          IJavaElement element = (IJavaElement)o1;
          IJavaElement element2 = (IJavaElement)o2;
          return element.getElementType() - element2.getElementType();
        }
        return 0;
      }
    });
    int length = selected.length;
    for (int i = 0; i < length; i++)
    {
      Object currentSelection = selected[i];
      if ((currentSelection instanceof IJavaElement))
      {
        IJavaElement element = (IJavaElement)currentSelection;
        IJavaProject javaProject = element.getJavaProject();
        try
        {
          switch (element.getElementType())
          {
          case 5: 
            ICompilationUnit compilationUnit = (ICompilationUnit)element;
            IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
            if (apiComponent != null) {
              addElementFor(compilationUnit, apiComponent, scope);
            }
            break;
          case 4: 
            IPackageFragment fragment = (IPackageFragment)element;
            IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
            IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot)fragment.getAncestor(3);
            boolean isArchive = false;
            if (packageFragmentRoot != null) {
              isArchive = packageFragmentRoot.isArchive();
            }
            if (apiComponent != null) {
              addElementFor(fragment, isArchive, apiComponent, scope);
            }
            break;
          case 3: 
            IPackageFragmentRoot fragmentRoot = (IPackageFragmentRoot)element;
            IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
            if (apiComponent != null) {
              addElementFor(fragmentRoot, apiComponent, scope);
            }
            break;
          case 2: 
            IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
            if (apiComponent != null) {
              scope.addElement(apiComponent);
            }
            break;
          }
        }
        catch (JavaModelException e)
        {
          ApiPlugin.log(e);
        }
        catch (CoreException e)
        {
          ApiPlugin.log(e);
        }
      }
    }
    return scope;
  }
  
  private static void addElementFor(IPackageFragmentRoot fragmentRoot, IApiComponent apiComponent, ApiScope scope)
    throws JavaModelException, CoreException
  {
    boolean isArchive = fragmentRoot.isArchive();
    IJavaElement[] packageFragments = fragmentRoot.getChildren();
    int j = 0;
    for (int max2 = packageFragments.length; j < max2; j++)
    {
      IPackageFragment packageFragment = (IPackageFragment)packageFragments[j];
      addElementFor(packageFragment, isArchive, apiComponent, scope);
    }
  }
  
  private static void addElementFor(IPackageFragment packageFragment, boolean isArchive, IApiComponent apiComponent, ApiScope scope)
    throws JavaModelException, CoreException
  {
    IApiDescription apiDescription = apiComponent.getApiDescription();
    IApiAnnotations annotations = apiDescription.resolveAnnotations(Factory.packageDescriptor(packageFragment.getElementName()));
    if ((annotations == null) || (!VisibilityModifiers.isAPI(annotations.getVisibility()))) {
      return;
    }
    if (isArchive)
    {
      IClassFile[] classFiles = packageFragment.getClassFiles();
      int i = 0;
      for (int max = classFiles.length; i < max; i++) {
        addElementFor(classFiles[i], apiComponent, scope);
      }
    }
    else
    {
      ICompilationUnit[] units = packageFragment.getCompilationUnits();
      int i = 0;
      for (int max = units.length; i < max; i++) {
        addElementFor(units[i], apiComponent, scope);
      }
    }
  }
  
  private static void addElementFor(IClassFile classFile, IApiComponent apiComponent, ApiScope scope)
  {
    try
    {
      IApiTypeRoot typeRoot = apiComponent.findTypeRoot(classFile.getType().getFullyQualifiedName());
      if (typeRoot != null) {
        scope.addElement(typeRoot);
      }
    }
    catch (CoreException e)
    {
      ApiPlugin.log(e);
    }
  }
  
  private static void addElementFor(ICompilationUnit compilationUnit, IApiComponent component, ApiScope scope)
    throws JavaModelException
  {
    IType[] types = compilationUnit.getTypes();
    int i = 0;
    for (int max = types.length; i < max; i++) {
      try
      {
        IApiTypeRoot typeRoot = component.findTypeRoot(types[i].getFullyQualifiedName());
        if (typeRoot != null) {
          scope.addElement(typeRoot);
        }
      }
      catch (CoreException e)
      {
        ApiPlugin.log(e);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.ui.internal.wizards.CompareOperation
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.ui.internal.wizards;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;

public class CompareToBaselineWizard
  extends Wizard
{
  private IStructuredSelection selection = null;
  
  public CompareToBaselineWizard(IStructuredSelection selection, String title)
  {
    this.selection = selection;
    setWindowTitle(title);
  }
  
  public void addPages()
  {
    addPage(new CompareToBaselineWizardPage(selection));
  }
  
  public boolean performFinish()
  {
    return ((CompareToBaselineWizardPage)getStartingPage()).finish();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.ui.internal.wizards.CompareToBaselineWizard
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.ui.internal.wizards;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Combo;

class CompareToBaselineWizardPage$1
  extends SelectionAdapter
{
  final CompareToBaselineWizardPage this$0;
  
  CompareToBaselineWizardPage$1(CompareToBaselineWizardPage paramCompareToBaselineWizardPage)
  {
    this$0 = paramCompareToBaselineWizardPage;
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    Combo combo = (Combo)widget;
    String[] baselineNames = (String[])combo.getData();
    String selectedBaselineName = baselineNames[combo.getSelectionIndex()];
    this$0.baselineName = selectedBaselineName;
    this$0.setPageComplete(this$0.isPageComplete());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.ui.internal.wizards.CompareToBaselineWizardPage.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.ui.internal.wizards;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.pde.api.tools.ui.internal.SWTFactory;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class CompareToBaselineWizardPage$2
  extends SelectionAdapter
{
  final CompareToBaselineWizardPage this$0;
  
  CompareToBaselineWizardPage$2(CompareToBaselineWizardPage paramCompareToBaselineWizardPage)
  {
    this$0 = paramCompareToBaselineWizardPage;
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    IAdaptable element = this$0.getAdaptable();
    if (element == null) {
      return;
    }
    this$0.baselineName = null;
    SWTFactory.showPreferencePage(this$0.getShell(), "org.eclipse.pde.api.tools.ui.apiprofiles.prefpage", element);
    this$0.initialize();
    this$0.setPageComplete(this$0.isPageComplete());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.ui.internal.wizards.CompareToBaselineWizardPage.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.ui.internal.wizards;

import java.util.Arrays;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.api.tools.internal.ApiBaselineManager;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.pde.api.tools.internal.provisional.IApiBaselineManager;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
import org.eclipse.pde.api.tools.ui.internal.IApiToolsHelpContextIds;
import org.eclipse.pde.api.tools.ui.internal.SWTFactory;
import org.eclipse.pde.api.tools.ui.internal.actions.ActionMessages;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.IWorkbenchHelpSystem;

public class CompareToBaselineWizardPage
  extends WizardPage
{
  static final String SETTINGS_SECTION = "org.eclipse.pde.api.tools.ui.api.compare";
  static final String BASELINE_STATE = "org.eclipse.pde.api.tools.ui.api.compare.baseline";
  private IStructuredSelection selection = null;
  private Combo baselinecombo = null;
  String baselineName = null;
  private Link link = null;
  
  protected CompareToBaselineWizardPage(IStructuredSelection selection)
  {
    super(ActionMessages.CompareDialogTitle);
    this.selection = selection;
    setTitle(ActionMessages.CompareToBaselineWizardPage_compare_with_baseline);
    setMessage(ActionMessages.CompareToBaselineWizardPage_compare_with_selected_baseline);
    setImageDescriptor(ApiUIPlugin.getImageDescriptor("IMG_WIZBAN_COMPARE_TO_BASELINE"));
  }
  
  public void createControl(Composite parent)
  {
    Composite comp = SWTFactory.createComposite(parent, 1, 1, 768);
    setControl(comp);
    
    SWTFactory.createLabel(comp, ActionMessages.SelectABaseline, 1);
    baselinecombo = SWTFactory.createCombo(comp, 8390664, 1, 768, null);
    baselinecombo.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        Combo combo = (Combo)widget;
        String[] baselineNames = (String[])combo.getData();
        String selectedBaselineName = baselineNames[combo.getSelectionIndex()];
        baselineName = selectedBaselineName;
        setPageComplete(isPageComplete());
      }
    });
    link = SWTFactory.createLink(comp, ActionMessages.AddNewBaseline, JFaceResources.getDialogFont(), 1, 896);
    link.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        IAdaptable element = getAdaptable();
        if (element == null) {
          return;
        }
        baselineName = null;
        SWTFactory.showPreferencePage(getShell(), "org.eclipse.pde.api.tools.ui.apiprofiles.prefpage", element);
        initialize();
        setPageComplete(isPageComplete());
      }
    });
    link.setToolTipText(ActionMessages.CompareToBaselineWizardPage_open_baseline_pref_page);
    
    initialize();
    getShell().pack();
    PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, IApiToolsHelpContextIds.API_COMPARE_WIZARD_PAGE);
  }
  
  public boolean isPageComplete()
  {
    if ((baselineName == null) || ("".equals(baselineName)))
    {
      setMessage(ActionMessages.CompareToBaselineWizardPage_create_baseline);
      link.forceFocus();
      return false;
    }
    setMessage(ActionMessages.CompareToBaselineWizardPage_compare_with_selected_baseline);
    baselinecombo.setFocus();
    return true;
  }
  
  void initialize()
  {
    IApiBaselineManager apiBaselineManager = ApiPlugin.getDefault().getApiBaselineManager();
    IApiBaseline defaultBaseline = apiBaselineManager.getDefaultApiBaseline();
    String defaultBaselineName = defaultBaseline != null ? defaultBaseline.getName() : null;
    IApiBaseline[] baselines = apiBaselineManager.getApiBaselines();
    int length = baselines.length;
    String[] baselinesItems = new String[length];
    String[] baselinesNames = new String[length];
    for (int i = 0; i < length; i++)
    {
      String currentBaselineName = baselines[i].getName();
      baselinesNames[i] = currentBaselineName;
    }
    Arrays.sort(baselinesNames);
    
    int index = 0;
    for (int i = 0; i < l
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

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-2017. Infinite Loop Ltd