KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > tools > OrganizeManifestsAction


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.wizards.tools;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.resources.IProject;
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.dialogs.MessageDialog;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.jface.wizard.WizardDialog;
23 import org.eclipse.pde.internal.core.ICoreConstants;
24 import org.eclipse.pde.internal.ui.PDEPlugin;
25 import org.eclipse.pde.internal.ui.PDEUIMessages;
26 import org.eclipse.swt.custom.BusyIndicator;
27 import org.eclipse.ui.IWorkbenchWindow;
28 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
29 import org.eclipse.ui.PlatformUI;
30
31 public class OrganizeManifestsAction implements 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 JavaDoc it = ssel.iterator();
53             ArrayList JavaDoc projects = new ArrayList JavaDoc();
54             while (it.hasNext()) {
55                 Object JavaDoc 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 && proj.exists(ICoreConstants.MANIFEST_PATH))
62                     projects.add(proj);
63             }
64             if (projects.size() > 0) {
65                 OrganizeManifestsWizard wizard = new OrganizeManifestsWizard(projects);
66                 final WizardDialog dialog = new WizardDialog(PDEPlugin.getActiveWorkbenchShell(), wizard);
67                 BusyIndicator.showWhile(
68                         PDEPlugin.getActiveWorkbenchShell().getDisplay(),
69                         new Runnable JavaDoc() {
70                     public void run() {
71                         dialog.open();
72                     }
73                 });
74             } else
75                 MessageDialog.openInformation(
76                         PDEPlugin.getActiveWorkbenchShell(),
77                         PDEUIMessages.OrganizeManifestsWizardPage_title,
78                         PDEUIMessages.OrganizeManifestsWizardPage_errorMsg);
79         }
80     }
81
82     public void selectionChanged(IAction action, ISelection selection) {
83         fSelection = selection;
84     }
85
86 }
87
Popular Tags