01: /*******************************************************************************
02: * Copyright (c) 2005, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.tools;
11:
12: import java.util.ArrayList;
13: import java.util.Iterator;
14:
15: import org.eclipse.core.resources.IFile;
16: import org.eclipse.core.resources.IProject;
17: import org.eclipse.jface.action.IAction;
18: import org.eclipse.jface.dialogs.MessageDialog;
19: import org.eclipse.jface.viewers.ISelection;
20: import org.eclipse.jface.viewers.IStructuredSelection;
21: import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
22: import org.eclipse.pde.internal.core.ICoreConstants;
23: import org.eclipse.pde.internal.ui.PDEPlugin;
24: import org.eclipse.pde.internal.ui.PDEUIMessages;
25: import org.eclipse.pde.internal.ui.refactoring.PDERefactor;
26: import org.eclipse.ui.IWorkbenchWindow;
27: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
28: import org.eclipse.ui.PlatformUI;
29:
30: public class OrganizeManifestsAction implements
31: IWorkbenchWindowActionDelegate {
32:
33: private ISelection fSelection;
34:
35: public OrganizeManifestsAction() {
36: super ();
37: }
38:
39: public void dispose() {
40: }
41:
42: public void init(IWorkbenchWindow window) {
43: }
44:
45: public void run(IAction action) {
46:
47: if (!PlatformUI.getWorkbench().saveAllEditors(true))
48: return;
49:
50: if (fSelection instanceof IStructuredSelection) {
51: IStructuredSelection ssel = (IStructuredSelection) fSelection;
52: Iterator it = ssel.iterator();
53: ArrayList projects = new ArrayList();
54: while (it.hasNext()) {
55: Object element = it.next();
56: IProject proj = null;
57: if (element instanceof IFile)
58: proj = ((IFile) element).getProject();
59: else if (element instanceof IProject)
60: proj = (IProject) element;
61: if (proj != null
62: && proj.exists(ICoreConstants.MANIFEST_PATH))
63: projects.add(proj);
64: }
65: if (projects.size() > 0) {
66: OrganizeManifestsProcessor processor = new OrganizeManifestsProcessor(
67: projects);
68: PDERefactor refactor = new PDERefactor(processor);
69: OrganizeManifestsWizard wizard = new OrganizeManifestsWizard(
70: refactor);
71: RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(
72: wizard);
73:
74: try {
75: op.run(PDEPlugin.getActiveWorkbenchShell(), ""); //$NON-NLS-1$
76: } catch (final InterruptedException irex) {
77: }
78: } else
79: MessageDialog
80: .openInformation(
81: PDEPlugin.getActiveWorkbenchShell(),
82: PDEUIMessages.OrganizeManifestsWizardPage_title,
83: PDEUIMessages.OrganizeManifestsWizardPage_errorMsg);
84: }
85: }
86:
87: public void selectionChanged(IAction action, ISelection selection) {
88: fSelection = selection;
89: }
90:
91: }
|