01: /*
02: * uDig - User Friendly Desktop Internet GIS client
03: * http://udig.refractions.net
04: * (C) 2004, Refractions Research Inc.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package net.refractions.udig.project.ui.internal.actions;
18:
19: import java.util.Iterator;
20:
21: import net.refractions.udig.project.IProject;
22: import net.refractions.udig.project.IProjectElement;
23: import net.refractions.udig.project.ui.ApplicationGIS;
24: import net.refractions.udig.project.ui.internal.ProjectExplorer;
25: import net.refractions.udig.project.ui.internal.UDIGEditorInputDescriptor;
26:
27: import org.eclipse.jface.action.IAction;
28: import org.eclipse.jface.viewers.ISelection;
29: import org.eclipse.jface.viewers.IStructuredSelection;
30: import org.eclipse.jface.viewers.StructuredSelection;
31: import org.eclipse.ui.IEditorPart;
32: import org.eclipse.ui.IWorkbenchPage;
33: import org.eclipse.ui.IWorkbenchWindow;
34: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
35: import org.eclipse.ui.PlatformUI;
36:
37: /**
38: * Closes the selected projects
39: *
40: * @author jeichar
41: * @since 0.6.0
42: */
43: public class CloseProject implements IWorkbenchWindowActionDelegate {
44: private IStructuredSelection selection;
45:
46: /**
47: * @see org.eclipse.ui.actions.ActionDelegate#run(org.eclipse.jface.action.IAction)
48: */
49: public void run(IAction action) {
50: for (Iterator iter = selection.iterator(); iter.hasNext();) {
51: IProject project = (IProject) iter.next();
52: for (IProjectElement element : project.getElements()) {
53: for (UDIGEditorInputDescriptor desc : ApplicationGIS
54: .getEditorInputs(element.getClass())) {
55: IWorkbenchPage page = PlatformUI.getWorkbench()
56: .getActiveWorkbenchWindow().getActivePage();
57: IEditorPart editor = page.findEditor(desc
58: .createInput(element));
59: if (editor != null)
60: page.closeEditor(editor, false);
61: }
62: }
63: ProjectExplorer explorer = ProjectExplorer
64: .getProjectExplorer();
65: explorer.collapseToLevel(project, 1);
66: }
67: }
68:
69: /**
70: * @see org.eclipse.ui.actions.ActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
71: * org.eclipse.jface.viewers.ISelection)
72: */
73: public void selectionChanged(IAction action, ISelection selection) {
74: if (selection instanceof IStructuredSelection)
75: this .selection = (IStructuredSelection) selection;
76: else
77: this .selection = new StructuredSelection();
78: }
79:
80: /**
81: * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
82: */
83: public void dispose() {
84: }
85:
86: /**
87: * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
88: */
89: public void init(IWorkbenchWindow window) {
90: }
91: }
|