/**
   * Runs the organize manifest operation for projects in the provided selection. Public to allow
   * editors to call this action
   *
   * <p>TODO This could be done better using the ICommandService
   *
   * @param selection selection to run organize manifest operation on
   */
  public void runOrganizeManfestsAction(ISelection selection) {
    if (!PlatformUI.getWorkbench().saveAllEditors(true)) return;

    if (selection instanceof IStructuredSelection) {
      IStructuredSelection ssel = (IStructuredSelection) selection;
      Iterator<?> it = ssel.iterator();
      ArrayList<IProject> projects = new ArrayList<>();
      while (it.hasNext()) {
        Object element = it.next();
        IProject proj = null;
        if (element instanceof IFile) proj = ((IFile) element).getProject();
        else if (element instanceof IProject) proj = (IProject) element;
        else if (element instanceof IJavaProject) {
          proj = ((IJavaProject) element).getProject();
        }
        if (proj != null && PDEProject.getManifest(proj).exists()) projects.add(proj);
      }
      if (projects.size() > 0) {
        OrganizeManifestsProcessor processor = new OrganizeManifestsProcessor(projects);
        PDERefactor refactor = new PDERefactor(processor);
        OrganizeManifestsWizard wizard = new OrganizeManifestsWizard(refactor);
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);

        try {
          op.run(PDEPlugin.getActiveWorkbenchShell(), ""); // $NON-NLS-1$
        } catch (final InterruptedException irex) {
        }
      } else
        MessageDialog.openInformation(
            PDEPlugin.getActiveWorkbenchShell(),
            PDEUIMessages.OrganizeManifestsWizardPage_title,
            PDEUIMessages.OrganizeManifestsWizardPage_errorMsg);
    }
  }
예제 #2
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.ui.forms.events.HyperlinkListener#linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent)
  */
 public void linkActivated(HyperlinkEvent e) {
   String href = (String) e.getHref();
   // try page references
   if (href.equals("dependencies")) // $NON-NLS-1$
   getEditor().setActivePage(DependenciesPage.PAGE_ID);
   else if (href.equals("runtime")) // $NON-NLS-1$
   getEditor().setActivePage(RuntimePage.PAGE_ID);
   else if (href.equals("extensions")) { // $NON-NLS-1$
     if (getEditor().setActivePage(ExtensionsPage.PAGE_ID) == null)
       activateExtensionPages(ExtensionsPage.PAGE_ID);
   } else if (href.equals("ex-points")) { // $NON-NLS-1$
     if (getEditor().setActivePage(ExtensionPointsPage.PAGE_ID) == null)
       activateExtensionPages(ExtensionPointsPage.PAGE_ID);
   } else if (href.equals("build")) { // $NON-NLS-1$
     if (!getPDEEditor().hasInputContext(BuildInputContext.CONTEXT_ID)) {
       if (!MessageDialog.openQuestion(
           PDEPlugin.getActiveWorkbenchShell(),
           PDEUIMessages.OverviewPage_buildTitle,
           PDEUIMessages.OverviewPage_buildQuestion)) return;
       IFile file = PDEProject.getBuildProperties(getPDEEditor().getCommonProject());
       WorkspaceBuildModel model = new WorkspaceBuildModel(file);
       model.save();
       IEditorInput in = new FileEditorInput(file);
       getPDEEditor()
           .getContextManager()
           .putContext(in, new BuildInputContext(getPDEEditor(), in, false));
     }
     getEditor().setActivePage(BuildPage.PAGE_ID);
   } else if (href.equals("export")) { // $NON-NLS-1$
     getExportAction().run();
   } else if (href.equals("action.convert")) { // $NON-NLS-1$
     handleConvert();
   } else if (href.equals("organize")) { // $NON-NLS-1$
     getEditor().doSave(null);
     OrganizeManifestsAction organizeAction = new OrganizeManifestsAction();
     organizeAction.selectionChanged(
         null, new StructuredSelection(getPDEEditor().getCommonProject()));
     organizeAction.run(null);
   } else if (href.equals("externalize")) { // $NON-NLS-1$
     getEditor().doSave(null);
     GetNonExternalizedStringsAction externalizeAction = new GetNonExternalizedStringsAction();
     externalizeAction.selectionChanged(
         null, new StructuredSelection(getPDEEditor().getCommonProject()));
     externalizeAction.run(null);
   } else super.linkActivated(e);
 }