View | Details | Raw Unified | Return to bug 133277 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTestCase.java (-1 / +1 lines)
Lines 189-195 Link Here
189
	}
189
	}
190
190
191
	protected void assertRefactoringResultAsExpectedIgnoreHashValue(ICompilationUnit[] cus, String[] expected) throws InvocationTargetException, JavaModelException {
191
	protected void assertRefactoringResultAsExpectedIgnoreHashValue(ICompilationUnit[] cus, String[] expected) throws InvocationTargetException, JavaModelException {
192
		RefactoringExecutionStarter.startCleanupRefactoring(cus, false, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
192
		RefactoringExecutionStarter.startCleanupRefactoring(cus, CleanUpRefactoring.createCleanUps(), PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), false, "Clean Up");
193
193
194
		Pattern regex= Pattern.compile("long serialVersionUID = .*L;");
194
		Pattern regex= Pattern.compile("long serialVersionUID = .*L;");
195
195
(-)ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpStressTest.java (-1 / +2 lines)
Lines 35-40 Link Here
35
import org.eclipse.jdt.core.JavaModelException;
35
import org.eclipse.jdt.core.JavaModelException;
36
36
37
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
37
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
38
import org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring;
38
import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter;
39
import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter;
39
40
40
import org.eclipse.jdt.ui.JavaElementLabels;
41
import org.eclipse.jdt.ui.JavaElementLabels;
Lines 5280-5286 Link Here
5280
	
5281
	
5281
		ICompilationUnit[] units= (ICompilationUnit[])cus.toArray(new ICompilationUnit[cus.size()]);	
5282
		ICompilationUnit[] units= (ICompilationUnit[])cus.toArray(new ICompilationUnit[cus.size()]);	
5282
		Shell shell= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
5283
		Shell shell= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
5283
		RefactoringExecutionStarter.startCleanupRefactoring(units, false, shell);
5284
		RefactoringExecutionStarter.startCleanupRefactoring(units, CleanUpRefactoring.createCleanUps(), shell, false, "Clean Up");
5284
		
5285
		
5285
//		generateTable(units);
5286
//		generateTable(units);
5286
		
5287
		
(-)ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringMessages.java (-2 lines)
Lines 98-105 Link Here
98
98
99
	public static String ChangeTypeWizard_with_itself;
99
	public static String ChangeTypeWizard_with_itself;
100
100
101
	public static String CleanUpAction_dialog_title;
102
103
	public static String ConvertAnonymousToNestedAction_Convert_Anonymous;
101
	public static String ConvertAnonymousToNestedAction_Convert_Anonymous;
104
102
105
	public static String ConvertAnonymousToNestedAction_dialog_title;
103
	public static String ConvertAnonymousToNestedAction_dialog_title;
(-)ui refactoring/org/eclipse/jdt/internal/ui/refactoring/refactoringui.properties (-1 lines)
Lines 592-595 Link Here
592
ReplaceInvocationsInputPage_replaceInvocationsBy=&Replace Invocations by:
592
ReplaceInvocationsInputPage_replaceInvocationsBy=&Replace Invocations by:
593
ReplaceInvocationsInputPage_replaceAll=Replace &all invocations
593
ReplaceInvocationsInputPage_replaceAll=Replace &all invocations
594
ReplaceInvocationsAction_unavailable=An unexpected exception occurred. See the error log for more details
594
ReplaceInvocationsAction_unavailable=An unexpected exception occurred. See the error log for more details
595
CleanUpAction_dialog_title=Clean Up
(-)ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.java (-2 / +1 lines)
Lines 109-120 Link Here
109
	public static String CleanUpAction_labelWizard;
109
	public static String CleanUpAction_labelWizard;
110
	public static String CleanUpAction_tooltip;
110
	public static String CleanUpAction_tooltip;
111
	public static String CleanUpAction_description;
111
	public static String CleanUpAction_description;
112
	public static String CleanUpAction_ErrorDialogTitle;
113
	public static String CleanUpAction_MultiStateErrorTitle;
112
	public static String CleanUpAction_MultiStateErrorTitle;
114
	public static String CleanUpAction_UnexpectedErrorMessage;
113
	public static String CleanUpAction_UnexpectedErrorMessage;
115
	public static String CleanUpAction_CUNotOnBuildpathMessage;
114
	public static String CleanUpAction_CUNotOnBuildpathMessage;
116
	public static String CleanUpAction_EmptySelection_description;
115
	public static String CleanUpAction_EmptySelection_description;
117
	public static String CleanUpAction_EmptySelection_title;
116
	public static String CleanUpAction_actionName;
118
	
117
	
119
	public static String AddGetterSetterAction_no_primary_type_title;
118
	public static String AddGetterSetterAction_no_primary_type_title;
120
	public static String AddGetterSetterAction_no_primary_type_message;
119
	public static String AddGetterSetterAction_no_primary_type_message;
(-)ui/org/eclipse/jdt/internal/ui/actions/CleanUpAction.java (-134 / +96 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Alex Blewitt - Bug 133277 Allow Sort Members to be performed on package and project levels
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.actions;
12
package org.eclipse.jdt.internal.ui.actions;
12
13
Lines 19-29 Link Here
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.MultiStatus;
21
import org.eclipse.core.runtime.MultiStatus;
21
import org.eclipse.core.runtime.Status;
22
import org.eclipse.core.runtime.Status;
22
import org.eclipse.core.runtime.preferences.DefaultScope;
23
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
24
import org.eclipse.core.runtime.preferences.InstanceScope;
25
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
26
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
27
23
28
import org.eclipse.jface.dialogs.ErrorDialog;
24
import org.eclipse.jface.dialogs.ErrorDialog;
29
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.jface.dialogs.MessageDialog;
Lines 40-137 Link Here
40
import org.eclipse.jdt.core.IPackageFragmentRoot;
36
import org.eclipse.jdt.core.IPackageFragmentRoot;
41
import org.eclipse.jdt.core.JavaModelException;
37
import org.eclipse.jdt.core.JavaModelException;
42
38
43
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
44
import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter;
45
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
39
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
46
import org.eclipse.jdt.internal.corext.util.Messages;
40
import org.eclipse.jdt.internal.corext.util.Messages;
47
41
48
import org.eclipse.jdt.ui.IWorkingCopyManager;
49
import org.eclipse.jdt.ui.JavaUI;
42
import org.eclipse.jdt.ui.JavaUI;
50
import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
43
import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
51
44
52
import org.eclipse.jdt.internal.ui.JavaPlugin;
45
import org.eclipse.jdt.internal.ui.JavaPlugin;
53
import org.eclipse.jdt.internal.ui.browsing.LogicalPackage;
46
import org.eclipse.jdt.internal.ui.browsing.LogicalPackage;
47
import org.eclipse.jdt.internal.ui.fix.ICleanUp;
54
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
48
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
55
import org.eclipse.jdt.internal.ui.util.ElementValidator;
49
import org.eclipse.jdt.internal.ui.util.ElementValidator;
56
50
57
public class CleanUpAction extends SelectionDispatchAction {
51
public abstract class CleanUpAction extends SelectionDispatchAction {
58
52
59
	private JavaEditor fEditor;
53
	private JavaEditor fEditor;
60
	private IPreferenceChangeListener fPreferenceChangeListener;
61
54
62
	public CleanUpAction(IWorkbenchSite site) {
55
	public CleanUpAction(IWorkbenchSite site) {
63
		super(site); 
56
		super(site);
64
		setToolTipText(ActionMessages.CleanUpAction_tooltip); 
65
		setDescription(ActionMessages.CleanUpAction_description);
66
		
67
		fPreferenceChangeListener= new IPreferenceChangeListener() {
68
			public void preferenceChange(PreferenceChangeEvent event) {
69
				if (event.getKey().equals(CleanUpConstants.SHOW_CLEAN_UP_WIZARD)) {
70
					updateActionLabel();
71
				}
72
			}
73
		};
74
		new InstanceScope().getNode(JavaUI.ID_PLUGIN).addPreferenceChangeListener(fPreferenceChangeListener);
75
76
		updateActionLabel();
77
78
//		PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.ORGANIZE_IMPORTS_ACTION);
79
	}
57
	}
80
	
58
81
	/**
59
	/**
82
	 * Note: This constructor is for internal use only. Clients should not call this constructor.
60
	 * Note: This constructor is for internal use only. Clients should not call
83
	 * @param editor the Java editor
61
	 * this constructor.
62
	 * 
63
	 * @param editor
64
	 *            the Java editor
84
	 */
65
	 */
85
	public CleanUpAction(JavaEditor editor) {
66
	public CleanUpAction(JavaEditor editor) {
86
		this(editor.getEditorSite());
67
		this(editor.getEditorSite());
87
		fEditor= editor;
68
		fEditor= editor;
88
		setEnabled(getCompilationUnit(fEditor) != null);
69
		setEnabled(getCompilationUnit(fEditor) != null);
89
	}
70
	}
90
		
71
91
	/* (non-Javadoc)
72
	/**
92
	 * Method declared on SelectionDispatchAction.
73
	 * @return the name of this action, not <b>null</b>
93
	 */
74
	 */
75
	protected abstract String getActionName();
76
77
	/**
78
	 * @param units
79
	 *            the units to clean up
80
	 * @return the clean ups to be performed or <b>null</b> if none to be
81
	 *         performed
82
	 */
83
	protected abstract ICleanUp[] createCleanUps(ICompilationUnit[] units);
84
85
	/**
86
	 * @param units
87
	 *            to clean up
88
	 * @param cleanUps
89
	 *            clean ups to execute on units
90
	 * 
91
	 * @throws JavaModelException
92
	 * @throws InvocationTargetException
93
	 */
94
	protected abstract void performRefactoring(ICompilationUnit[] units, ICleanUp[] cleanUps) throws JavaModelException, InvocationTargetException;
95
94
	public void run(ITextSelection selection) {
96
	public void run(ITextSelection selection) {
95
		ICompilationUnit cu= getCompilationUnit(fEditor);
97
		ICompilationUnit cu= getCompilationUnit(fEditor);
96
		if (cu != null) {
98
		if (cu != null) {
97
			run(cu);
99
			run(cu);
98
		}
100
		}
99
	}
101
	}
100
	
102
101
	/* (non-Javadoc)
102
	 * Method declared on SelectionDispatchAction.
103
	 */
104
	public void run(IStructuredSelection selection) {
103
	public void run(IStructuredSelection selection) {
105
		ICompilationUnit[] cus= getCompilationUnits(selection);
104
		ICompilationUnit[] cus= getCompilationUnits(selection);
106
		if (cus.length == 0) {
105
		if (cus.length == 0) {
107
			MessageDialog.openInformation(getShell(), ActionMessages.CleanUpAction_EmptySelection_title, ActionMessages.CleanUpAction_EmptySelection_description);
106
			MessageDialog.openInformation(getShell(), getActionName(), ActionMessages.CleanUpAction_EmptySelection_description);
108
		} else if (cus.length == 1) {
107
		} else if (cus.length == 1) {
109
			run(cus[0]);
108
			run(cus[0]);
110
		} else {
109
		} else {
111
			runOnMultiple(cus);
110
			runOnMultiple(cus);
112
		}
111
		}
113
	}
112
	}
114
	
113
115
	/* (non-Javadoc)
116
	 * Method declared on SelectionDispatchAction.
117
	 */
118
	public void selectionChanged(ITextSelection selection) {
114
	public void selectionChanged(ITextSelection selection) {
119
		setEnabled(getCompilationUnit(fEditor) != null);
115
		setEnabled(getCompilationUnit(fEditor) != null);
120
	}
116
	}
121
	
117
122
	/* (non-Javadoc)
123
	 * Method declared on SelectionDispatchAction.
124
	 */
125
	public void selectionChanged(IStructuredSelection selection) {
118
	public void selectionChanged(IStructuredSelection selection) {
126
		setEnabled(isEnabled(selection));
119
		setEnabled(isEnabled(selection));
127
	}
120
	}
128
	
121
129
	private boolean isEnabled(IStructuredSelection selection) {
122
	private boolean isEnabled(IStructuredSelection selection) {
130
		Object[] selected= selection.toArray();
123
		Object[] selected= selection.toArray();
131
		for (int i= 0; i < selected.length; i++) {
124
		for (int i= 0; i < selected.length; i++) {
132
			try {
125
			try {
133
				if (selected[i] instanceof IJavaElement) {
126
				if (selected[i] instanceof IJavaElement) {
134
					IJavaElement elem= (IJavaElement) selected[i];
127
					IJavaElement elem= (IJavaElement)selected[i];
135
					if (elem.exists()) {
128
					if (elem.exists()) {
136
						switch (elem.getElementType()) {
129
						switch (elem.getElementType()) {
137
							case IJavaElement.TYPE:
130
							case IJavaElement.TYPE:
Lines 142-148 Link Here
142
								return true;
135
								return true;
143
							case IJavaElement.PACKAGE_FRAGMENT:
136
							case IJavaElement.PACKAGE_FRAGMENT:
144
							case IJavaElement.PACKAGE_FRAGMENT_ROOT:
137
							case IJavaElement.PACKAGE_FRAGMENT_ROOT:
145
								IPackageFragmentRoot root= (IPackageFragmentRoot) elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
138
								IPackageFragmentRoot root= (IPackageFragmentRoot)elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
146
								return (root.getKind() == IPackageFragmentRoot.K_SOURCE);
139
								return (root.getKind() == IPackageFragmentRoot.K_SOURCE);
147
							case IJavaElement.JAVA_PROJECT:
140
							case IJavaElement.JAVA_PROJECT:
148
								// https://bugs.eclipse.org/bugs/show_bug.cgi?id=65638
141
								// https://bugs.eclipse.org/bugs/show_bug.cgi?id=65638
Lines 160-208 Link Here
160
		}
153
		}
161
		return false;
154
		return false;
162
	}
155
	}
163
	
156
164
	/**
157
	private void run(ICompilationUnit cu) {
165
	 * Note: This method is for internal use only. Clients should not call this method.
166
	 * @param cu The compilation unit to process
167
	 */
168
	public void run(ICompilationUnit cu) {
169
		if (!ElementValidator.check(cu, getShell(), ActionMessages.CleanUpAction_ErrorDialogTitle, fEditor != null)) 
170
			return;
171
		if (!ActionUtil.isEditable(fEditor, getShell(), cu))
158
		if (!ActionUtil.isEditable(fEditor, getShell(), cu))
172
			return;
159
			return;
173
		
160
161
		ICleanUp[] cleanUps= createCleanUps(new ICompilationUnit[] {
162
			cu
163
		});
164
		if (cleanUps == null)
165
			return;
166
167
		if (!ElementValidator.check(cu, getShell(), getActionName(), fEditor != null))
168
			return;
169
174
		try {
170
		try {
175
			RefactoringExecutionStarter.startCleanupRefactoring(new ICompilationUnit[] {cu}, showWizard(), getShell());
171
			performRefactoring(new ICompilationUnit[] {
172
				cu
173
			}, cleanUps);
176
		} catch (InvocationTargetException e) {
174
		} catch (InvocationTargetException e) {
177
			JavaPlugin.log(e);
175
			JavaPlugin.log(e);
178
			if (e.getCause() instanceof CoreException)
176
			if (e.getCause() instanceof CoreException)
179
				showUnexpectedError((CoreException)e.getCause());
177
				showUnexpectedError((CoreException)e.getCause());
180
		} catch (JavaModelException e) {
178
		} catch (JavaModelException e) {
181
			showUnexpectedError(e);
179
			showUnexpectedError(e);
182
        }
180
		}
183
		return;
184
	}
181
	}
185
182
186
	/**
183
	private void runOnMultiple(final ICompilationUnit[] cus) {
187
	 * Perform on multiple compilation units. No editors are opened.
184
		ICleanUp[] cleanUps= createCleanUps(cus);
188
	 * @param cus The compilation units to run on
185
		if (cleanUps == null)
189
	 */
186
			return;
190
	public void runOnMultiple(final ICompilationUnit[] cus) {
187
191
		String message= ActionMessages.CleanUpAction_MultiStateErrorTitle; 
188
		MultiStatus status= new MultiStatus(JavaUI.ID_PLUGIN, IStatus.OK, ActionMessages.CleanUpAction_MultiStateErrorTitle, null);
192
		final MultiStatus status= new MultiStatus(JavaUI.ID_PLUGIN, IStatus.OK, message, null);
193
		
194
		for (int i= 0; i < cus.length; i++) {
189
		for (int i= 0; i < cus.length; i++) {
195
			testOnBuildPath(cus[i], status);
190
			ICompilationUnit cu= cus[i];
191
192
			if (!ActionUtil.isOnBuildPath(cu)) {
193
				String cuLocation= cu.getPath().makeRelative().toString();
194
				String message= Messages.format(ActionMessages.CleanUpAction_CUNotOnBuildpathMessage, cuLocation);
195
				status.add(new Status(IStatus.INFO, JavaUI.ID_PLUGIN, IStatus.ERROR, message, null));
196
			}
196
		}
197
		}
197
		
198
		if (!status.isOK()) {
198
		if (!status.isOK()) {
199
			String title= ActionMessages.CleanUpAction_ErrorDialogTitle; 
199
			ErrorDialog.openError(getShell(), getActionName(), null, status);
200
			ErrorDialog.openError(getShell(), title, null, status);
201
			return;
200
			return;
202
		}
201
		}
203
			
202
204
		try {
203
		try {
205
			RefactoringExecutionStarter.startCleanupRefactoring(cus, showWizard(), getShell());
204
			performRefactoring(cus, cleanUps);
206
		} catch (InvocationTargetException e) {
205
		} catch (InvocationTargetException e) {
207
			JavaPlugin.log(e);
206
			JavaPlugin.log(e);
208
			if (e.getCause() instanceof CoreException)
207
			if (e.getCause() instanceof CoreException)
Lines 210-269 Link Here
210
		} catch (JavaModelException e) {
209
		} catch (JavaModelException e) {
211
			showUnexpectedError(e);
210
			showUnexpectedError(e);
212
		}
211
		}
213
		return;
214
	}
212
	}
215
213
216
	private void showUnexpectedError(CoreException e) {
214
	private void showUnexpectedError(CoreException e) {
217
		String message2= Messages.format(ActionMessages.CleanUpAction_UnexpectedErrorMessage, e.getStatus().getMessage()); 
215
		String message2= Messages.format(ActionMessages.CleanUpAction_UnexpectedErrorMessage, e.getStatus().getMessage());
218
		IStatus status= new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, message2, null);
216
		IStatus status= new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, message2, null);
219
		String title= ActionMessages.CleanUpAction_ErrorDialogTitle; 
217
		ErrorDialog.openError(getShell(), getActionName(), null, status);
220
		ErrorDialog.openError(getShell(), title, null, status);
221
	}
222
	
223
	private boolean testOnBuildPath(ICompilationUnit cu, MultiStatus status) {
224
		IJavaProject project= cu.getJavaProject();
225
		if (!project.isOnClasspath(cu)) {
226
			String cuLocation= cu.getPath().makeRelative().toString();
227
			String message= Messages.format(ActionMessages.CleanUpAction_CUNotOnBuildpathMessage, cuLocation); 
228
			status.add(new Status(IStatus.INFO, JavaUI.ID_PLUGIN, IStatus.ERROR, message, null));
229
			return false;
230
		}
231
		return true;
232
	}
218
	}
233
	
219
234
	private ICompilationUnit[] getCompilationUnits(IStructuredSelection selection) {
220
	private ICompilationUnit[] getCompilationUnits(IStructuredSelection selection) {
235
		HashSet result= new HashSet();
221
		HashSet result= new HashSet();
236
		Object[] selected= selection.toArray();
222
		Object[] selected= selection.toArray();
237
		for (int i= 0; i < selected.length; i++) {
223
		for (int i= 0; i < selected.length; i++) {
238
			try {
224
			try {
239
				if (selected[i] instanceof IJavaElement) {
225
				if (selected[i] instanceof IJavaElement) {
240
					IJavaElement elem= (IJavaElement) selected[i];
226
					IJavaElement elem= (IJavaElement)selected[i];
241
					if (elem.exists()) {
227
					if (elem.exists()) {
242
					
243
						switch (elem.getElementType()) {
228
						switch (elem.getElementType()) {
244
							case IJavaElement.TYPE:
229
							case IJavaElement.TYPE:
245
								if (elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) {
230
								if (elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) {
246
									result.add(elem.getParent());
231
									result.add(elem.getParent());
247
								}
232
								}
248
								break;						
233
								break;
249
							case IJavaElement.COMPILATION_UNIT:
234
							case IJavaElement.COMPILATION_UNIT:
250
								result.add(elem);
235
								result.add(elem);
251
								break;
236
								break;
252
							case IJavaElement.IMPORT_CONTAINER:
237
							case IJavaElement.IMPORT_CONTAINER:
253
								result.add(elem.getParent());
238
								result.add(elem.getParent());
254
								break;							
239
								break;
255
							case IJavaElement.PACKAGE_FRAGMENT:
240
							case IJavaElement.PACKAGE_FRAGMENT:
256
								collectCompilationUnits((IPackageFragment) elem, result);
241
								collectCompilationUnits((IPackageFragment)elem, result);
257
								break;
242
								break;
258
							case IJavaElement.PACKAGE_FRAGMENT_ROOT:
243
							case IJavaElement.PACKAGE_FRAGMENT_ROOT:
259
								collectCompilationUnits((IPackageFragmentRoot) elem, result);
244
								collectCompilationUnits((IPackageFragmentRoot)elem, result);
260
								break;
245
								break;
261
							case IJavaElement.JAVA_PROJECT:
246
							case IJavaElement.JAVA_PROJECT:
262
								IPackageFragmentRoot[] roots= ((IJavaProject) elem).getPackageFragmentRoots();
247
								IPackageFragmentRoot[] roots= ((IJavaProject)elem).getPackageFragmentRoots();
263
								for (int k= 0; k < roots.length; k++) {
248
								for (int k= 0; k < roots.length; k++) {
264
									collectCompilationUnits(roots[k], result);
249
									collectCompilationUnits(roots[k], result);
265
								}
250
								}
266
								break;			
251
								break;
267
						}
252
						}
268
					}
253
					}
269
				} else if (selected[i] instanceof LogicalPackage) {
254
				} else if (selected[i] instanceof LogicalPackage) {
Lines 280-330 Link Here
280
					JavaPlugin.log(e);
265
					JavaPlugin.log(e);
281
			}
266
			}
282
		}
267
		}
283
		return (ICompilationUnit[]) result.toArray(new ICompilationUnit[result.size()]);
268
		return (ICompilationUnit[])result.toArray(new ICompilationUnit[result.size()]);
284
	}
269
	}
285
	
270
286
	private void collectCompilationUnits(IPackageFragment pack, Collection result) throws JavaModelException {
271
	private void collectCompilationUnits(IPackageFragment pack, Collection result) throws JavaModelException {
287
		result.addAll(Arrays.asList(pack.getCompilationUnits()));
272
		result.addAll(Arrays.asList(pack.getCompilationUnits()));
288
	}
273
	}
289
	
274
290
	private void collectCompilationUnits(IPackageFragmentRoot root, Collection result) throws JavaModelException {
275
	private void collectCompilationUnits(IPackageFragmentRoot root, Collection result) throws JavaModelException {
291
		if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
276
		if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
292
			IJavaElement[] children= root.getChildren();
277
			IJavaElement[] children= root.getChildren();
293
			for (int i= 0; i < children.length; i++) {
278
			for (int i= 0; i < children.length; i++) {
294
				collectCompilationUnits((IPackageFragment) children[i], result);
279
				collectCompilationUnits((IPackageFragment)children[i], result);
295
			}
280
			}
296
		}
281
		}
297
	}	
282
	}
298
	
283
299
	private static ICompilationUnit getCompilationUnit(JavaEditor editor) {
284
	private static ICompilationUnit getCompilationUnit(JavaEditor editor) {
300
		IWorkingCopyManager manager= JavaPlugin.getDefault().getWorkingCopyManager();
285
		IJavaElement element= JavaUI.getEditorInputJavaElement(editor.getEditorInput());
301
		ICompilationUnit cu= manager.getWorkingCopy(editor.getEditorInput());
286
		if (!(element instanceof ICompilationUnit))
302
		return cu;
287
			return null;
303
	}
304
305
	private boolean showWizard() {
306
		InstanceScope instanceScope= new InstanceScope();
307
		IEclipsePreferences instanceNode= instanceScope.getNode(JavaUI.ID_PLUGIN);
308
		if (instanceNode.get(CleanUpConstants.SHOW_CLEAN_UP_WIZARD, null) != null)
309
			return instanceNode.getBoolean(CleanUpConstants.SHOW_CLEAN_UP_WIZARD, true);
310
		
311
		DefaultScope defaultScope= new DefaultScope();
312
		IEclipsePreferences defaultNode= defaultScope.getNode(JavaUI.ID_PLUGIN);
313
		return defaultNode.getBoolean(CleanUpConstants.SHOW_CLEAN_UP_WIZARD, true);
314
    }
315
316
	private void updateActionLabel() {
317
	    if (showWizard()) {
318
			setText(ActionMessages.CleanUpAction_labelWizard);
319
		} else {
320
			setText(ActionMessages.CleanUpAction_label);
321
		}
322
    }
323
288
324
	public void dispose() {
289
		return (ICompilationUnit)element;
325
		if (fPreferenceChangeListener != null) {
290
	}
326
			new InstanceScope().getNode(JavaUI.ID_PLUGIN).removePreferenceChangeListener(fPreferenceChangeListener);
291
327
			fPreferenceChangeListener= null;
292
}
328
		}
329
    }
330
}
(-)ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.properties (-3 / +2 lines)
Lines 220-228 Link Here
220
CleanUpAction_labelWizard=Clean &Up...
220
CleanUpAction_labelWizard=Clean &Up...
221
CleanUpAction_tooltip=Solve Problems and Improve Code Style on Selected Resources
221
CleanUpAction_tooltip=Solve Problems and Improve Code Style on Selected Resources
222
CleanUpAction_description=Solve problems and improve code style on selected resources
222
CleanUpAction_description=Solve problems and improve code style on selected resources
223
CleanUpAction_ErrorDialogTitle=Clean Up
223
CleanUpAction_MultiStateErrorTitle=Problems while processing some compilation units. See 'Details' for more information.
224
CleanUpAction_MultiStateErrorTitle=Problems while cleaning up some compilation units. See 'Details' for more information.
224
CleanUpAction_actionName=Clean Up
225
CleanUpAction_EmptySelection_title=Clean Up...
226
CleanUpAction_UnexpectedErrorMessage={0}: Unexpected error. See log for details.
225
CleanUpAction_UnexpectedErrorMessage={0}: Unexpected error. See log for details.
227
CleanUpAction_CUNotOnBuildpathMessage={0}: Compilation unit not on build path. No changes applied.
226
CleanUpAction_CUNotOnBuildpathMessage={0}: Compilation unit not on build path. No changes applied.
228
CleanUpAction_EmptySelection_description=The selection contains no compilation units.
227
CleanUpAction_EmptySelection_description=The selection contains no compilation units.
(-)ui/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties (-1 / +1 lines)
Lines 83-86 Link Here
83
CleanUpSaveParticipantPreferenceConfiguration_edit_button_label=&Edit...
83
CleanUpSaveParticipantPreferenceConfiguration_edit_button_label=&Edit...
84
SortMembersCleanUp_AllMembers_description=Sort all members
84
SortMembersCleanUp_AllMembers_description=Sort all members
85
SortMembersCleanUp_Excluding_description=Sort members excluding fields, enum constants, and initializers
85
SortMembersCleanUp_Excluding_description=Sort members excluding fields, enum constants, and initializers
86
SortMembersCleanUp_RemoveMarkersWarning0=The file ''{0}'' in project ''{1}'' contains markers which may be removed by the Sort Members Clean Up
86
SortMembersCleanUp_RemoveMarkersWarning0=The file ''{0}'' in project ''{1}'' contains markers which may be removed by Sort Members
(-)ui/org/eclipse/jdt/ui/actions/GenerateActionGroup.java (-7 / +8 lines)
Lines 44-53 Link Here
44
44
45
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
45
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
46
import org.eclipse.jdt.internal.ui.actions.AddTaskAction;
46
import org.eclipse.jdt.internal.ui.actions.AddTaskAction;
47
import org.eclipse.jdt.internal.ui.actions.CleanUpAction;
47
import org.eclipse.jdt.internal.ui.actions.AllCleanUpsAction;
48
import org.eclipse.jdt.internal.ui.actions.CopyQualifiedNameAction;
48
import org.eclipse.jdt.internal.ui.actions.CopyQualifiedNameAction;
49
import org.eclipse.jdt.internal.ui.actions.FindBrokenNLSKeysAction;
49
import org.eclipse.jdt.internal.ui.actions.FindBrokenNLSKeysAction;
50
import org.eclipse.jdt.internal.ui.actions.JDTQuickMenuAction;
50
import org.eclipse.jdt.internal.ui.actions.JDTQuickMenuAction;
51
import org.eclipse.jdt.internal.ui.actions.MultiSortMembersAction;
51
import org.eclipse.jdt.internal.ui.javaeditor.AddImportOnSelectionAction;
52
import org.eclipse.jdt.internal.ui.javaeditor.AddImportOnSelectionAction;
52
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
53
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
53
54
Lines 134-144 Link Here
134
	private AddBookmarkAction fAddBookmark;
135
	private AddBookmarkAction fAddBookmark;
135
	private AddTaskAction fAddTaskAction;
136
	private AddTaskAction fAddTaskAction;
136
	private ExternalizeStringsAction fExternalizeStrings;
137
	private ExternalizeStringsAction fExternalizeStrings;
137
	private CleanUpAction fCleanUp;	
138
	private AllCleanUpsAction fCleanUp;	
138
	private FindBrokenNLSKeysAction fFindNLSProblems;
139
	private FindBrokenNLSKeysAction fFindNLSProblems;
139
	
140
	
140
	private OrganizeImportsAction fOrganizeImports;
141
	private OrganizeImportsAction fOrganizeImports;
141
	private SortMembersAction fSortMembers;
142
	private MultiSortMembersAction fSortMembers;
142
	private FormatAllAction fFormatAll;
143
	private FormatAllAction fFormatAll;
143
	private CopyQualifiedNameAction fCopyQualifiedNameAction;
144
	private CopyQualifiedNameAction fCopyQualifiedNameAction;
144
	
145
	
Lines 176-182 Link Here
176
		fOrganizeImports.setActionDefinitionId(IJavaEditorActionDefinitionIds.ORGANIZE_IMPORTS);
177
		fOrganizeImports.setActionDefinitionId(IJavaEditorActionDefinitionIds.ORGANIZE_IMPORTS);
177
		editor.setAction("OrganizeImports", fOrganizeImports); //$NON-NLS-1$
178
		editor.setAction("OrganizeImports", fOrganizeImports); //$NON-NLS-1$
178
179
179
		fSortMembers= new SortMembersAction(editor);
180
		fSortMembers= new MultiSortMembersAction(editor);
180
		fSortMembers.setActionDefinitionId(IJavaEditorActionDefinitionIds.SORT_MEMBERS);
181
		fSortMembers.setActionDefinitionId(IJavaEditorActionDefinitionIds.SORT_MEMBERS);
181
		editor.setAction("SortMembers", fSortMembers); //$NON-NLS-1$
182
		editor.setAction("SortMembers", fSortMembers); //$NON-NLS-1$
182
		
183
		
Lines 213-219 Link Here
213
		fAddJavaDocStub.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_JAVADOC_COMMENT);
214
		fAddJavaDocStub.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_JAVADOC_COMMENT);
214
		editor.setAction("AddJavadocComment", fAddJavaDocStub); //$NON-NLS-1$
215
		editor.setAction("AddJavadocComment", fAddJavaDocStub); //$NON-NLS-1$
215
		
216
		
216
		fCleanUp= new CleanUpAction(editor);
217
		fCleanUp= new AllCleanUpsAction(editor);
217
		fCleanUp.setActionDefinitionId(IJavaEditorActionDefinitionIds.CLEAN_UP);
218
		fCleanUp.setActionDefinitionId(IJavaEditorActionDefinitionIds.CLEAN_UP);
218
		editor.setAction("CleanUp", fCleanUp); //$NON-NLS-1$
219
		editor.setAction("CleanUp", fCleanUp); //$NON-NLS-1$
219
		
220
		
Lines 289-301 Link Here
289
		fOrganizeImports= new OrganizeImportsAction(site);
290
		fOrganizeImports= new OrganizeImportsAction(site);
290
		fOrganizeImports.setActionDefinitionId(IJavaEditorActionDefinitionIds.ORGANIZE_IMPORTS);
291
		fOrganizeImports.setActionDefinitionId(IJavaEditorActionDefinitionIds.ORGANIZE_IMPORTS);
291
		
292
		
292
		fSortMembers= new SortMembersAction(site);
293
		fSortMembers= new MultiSortMembersAction(site);
293
		fSortMembers.setActionDefinitionId(IJavaEditorActionDefinitionIds.SORT_MEMBERS);
294
		fSortMembers.setActionDefinitionId(IJavaEditorActionDefinitionIds.SORT_MEMBERS);
294
		
295
		
295
		fFormatAll= new FormatAllAction(site);
296
		fFormatAll= new FormatAllAction(site);
296
		fFormatAll.setActionDefinitionId(IJavaEditorActionDefinitionIds.FORMAT);
297
		fFormatAll.setActionDefinitionId(IJavaEditorActionDefinitionIds.FORMAT);
297
		
298
		
298
		fCleanUp= new CleanUpAction(site);
299
		fCleanUp= new AllCleanUpsAction(site);
299
		fCleanUp.setActionDefinitionId(IJavaEditorActionDefinitionIds.CLEAN_UP);
300
		fCleanUp.setActionDefinitionId(IJavaEditorActionDefinitionIds.CLEAN_UP);
300
301
301
		
302
		
(-)core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.properties (-2 / +2 lines)
Lines 9-16 Link Here
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
10
###############################################################################
11
CleanUpRefactoring_Refactoring_name=Clean Up
11
CleanUpRefactoring_Refactoring_name=Clean Up
12
CleanUpRefactoring_Initialize_message=Checking Clean Up preconditions for project ''{0}''
12
CleanUpRefactoring_Initialize_message=Checking preconditions for project ''{0}''
13
CleanUpRefactoring_Parser_Startup_message=Cleaning up project {0}
13
CleanUpRefactoring_Parser_Startup_message=Processing project {0}
14
CleanUpRefactoring_clean_up_multi_chang_name=Clean Up
14
CleanUpRefactoring_clean_up_multi_chang_name=Clean Up
15
CleanUpRefactoring_could_not_retrive_profile=Could not retrieve profile for project ''{0}''
15
CleanUpRefactoring_could_not_retrive_profile=Could not retrieve profile for project ''{0}''
16
CleanUpRefactoring_ProcessingCompilationUnit_message=Processing compilation unit {0} of {1} ({2})
16
CleanUpRefactoring_ProcessingCompilationUnit_message=Processing compilation unit {0} of {1} ({2})
(-)core extension/org/eclipse/jdt/internal/corext/fix/CleanUpRefactoring.java (-3 / +7 lines)
Lines 481-492 Link Here
481
	
481
	
482
	private final List/*<ICleanUp>*/fCleanUps;
482
	private final List/*<ICleanUp>*/fCleanUps;
483
	private final Hashtable/*<IJavaProject, List<ICompilationUnit>*/fProjects;
483
	private final Hashtable/*<IJavaProject, List<ICompilationUnit>*/fProjects;
484
	
485
	private Change fChange;
484
	private Change fChange;
486
	
487
	private boolean fLeaveFilesDirty;
485
	private boolean fLeaveFilesDirty;
486
	private final String fName;
488
	
487
	
489
	public CleanUpRefactoring() {
488
	public CleanUpRefactoring() {
489
		this(FixMessages.CleanUpRefactoring_Refactoring_name);
490
	}
491
	
492
	public CleanUpRefactoring(String name) {
493
		fName= name;
490
		fCleanUps= new ArrayList();
494
		fCleanUps= new ArrayList();
491
		fProjects= new Hashtable();
495
		fProjects= new Hashtable();
492
	}
496
	}
Lines 545-551 Link Here
545
	 * @see org.eclipse.ltk.core.refactoring.Refactoring#getName()
549
	 * @see org.eclipse.ltk.core.refactoring.Refactoring#getName()
546
	 */
550
	 */
547
	public String getName() {
551
	public String getName() {
548
		return FixMessages.CleanUpRefactoring_Refactoring_name;
552
		return fName;
549
	}
553
	}
550
	
554
	
551
	/* (non-Javadoc)
555
	/* (non-Javadoc)
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringExecutionStarter.java (-11 / +18 lines)
Lines 25-30 Link Here
25
25
26
import org.eclipse.jface.dialogs.MessageDialog;
26
import org.eclipse.jface.dialogs.MessageDialog;
27
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
27
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
28
import org.eclipse.jface.operation.IRunnableContext;
28
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.jface.viewers.StructuredSelection;
30
import org.eclipse.jface.viewers.StructuredSelection;
30
31
Lines 227-253 Link Here
227
		new RefactoringStarter().activate(refactoring, new ChangeTypeWizard(refactoring), shell, RefactoringMessages.ChangeTypeAction_dialog_title, RefactoringSaveHelper.SAVE_JAVA_ONLY_UPDATES);
228
		new RefactoringStarter().activate(refactoring, new ChangeTypeWizard(refactoring), shell, RefactoringMessages.ChangeTypeAction_dialog_title, RefactoringSaveHelper.SAVE_JAVA_ONLY_UPDATES);
228
	}
229
	}
229
	
230
	
230
	public static void startCleanupRefactoring(ICompilationUnit[] cus, boolean showWizard, Shell shell) throws InvocationTargetException, JavaModelException {
231
	public static void startCleanupRefactoring(ICompilationUnit[] cus, ICleanUp[] cleanUps, Shell shell, boolean showWizard, String actionName) throws InvocationTargetException, JavaModelException {
231
		final CleanUpRefactoring refactoring= new CleanUpRefactoring();
232
		final CleanUpRefactoring refactoring= new CleanUpRefactoring(actionName);
232
		for (int i= 0; i < cus.length; i++) {
233
		for (int i= 0; i < cus.length; i++) {
233
			refactoring.addCompilationUnit(cus[i]);
234
			refactoring.addCompilationUnit(cus[i]);
234
		}
235
		}
235
		
236
		
236
		if (!showWizard) {
237
		if (!showWizard) {
237
			ICleanUp[] cleanUps= CleanUpRefactoring.createCleanUps();
238
			for (int i= 0; i < cleanUps.length; i++) {
238
			for (int i= 0; i < cleanUps.length; i++) {
239
	            refactoring.addCleanUp(cleanUps[i]);
239
				refactoring.addCleanUp(cleanUps[i]);
240
            }
240
			}
241
			
242
			IRunnableContext context;
243
			if (refactoring.getCompilationUnits().length > 1) {
244
				context= new ProgressMonitorDialog(shell);
245
			} else {
246
				context= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
247
			}
241
			
248
			
242
    		RefactoringExecutionHelper helper= new RefactoringExecutionHelper(refactoring, IStatus.ERROR, RefactoringSaveHelper.SAVE_JAVA_ONLY_UPDATES, shell, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
249
			RefactoringExecutionHelper helper= new RefactoringExecutionHelper(refactoring, IStatus.WARNING, RefactoringSaveHelper.SAVE_JAVA_ONLY_UPDATES, shell, context);
243
    		try {
250
			try {
244
    	        helper.perform(true, true);
251
				helper.perform(true, true);
245
            } catch (InterruptedException e) {
252
			} catch (InterruptedException e) {
246
            }
253
			}
247
		} else {
254
		} else {
248
			CleanUpRefactoringWizard refactoringWizard= new CleanUpRefactoringWizard(refactoring, RefactoringWizard.WIZARD_BASED_USER_INTERFACE);
255
			CleanUpRefactoringWizard refactoringWizard= new CleanUpRefactoringWizard(refactoring, RefactoringWizard.WIZARD_BASED_USER_INTERFACE);
249
			RefactoringStarter starter= new RefactoringStarter();
256
			RefactoringStarter starter= new RefactoringStarter();
250
			starter.activate(refactoring, refactoringWizard, shell, RefactoringMessages.CleanUpAction_dialog_title, RefactoringSaveHelper.SAVE_JAVA_ONLY_UPDATES);
257
			starter.activate(refactoring, refactoringWizard, shell, actionName, RefactoringSaveHelper.SAVE_JAVA_ONLY_UPDATES);			
251
		}
258
		}
252
	}
259
	}
253
260
(-)ui/org/eclipse/jdt/internal/ui/actions/AllCleanUpsAction.java (+115 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 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
 *     Alex Blewitt - Bug 133277 Allow Sort Members to be performed on package and project levels
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.actions;
13
14
import java.lang.reflect.InvocationTargetException;
15
16
import org.eclipse.core.runtime.preferences.DefaultScope;
17
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
18
import org.eclipse.core.runtime.preferences.InstanceScope;
19
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
20
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
21
22
import org.eclipse.ui.IWorkbenchSite;
23
24
import org.eclipse.jdt.core.ICompilationUnit;
25
import org.eclipse.jdt.core.JavaModelException;
26
27
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
28
import org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring;
29
import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter;
30
31
import org.eclipse.jdt.ui.JavaUI;
32
33
import org.eclipse.jdt.internal.ui.fix.ICleanUp;
34
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
35
36
public class AllCleanUpsAction extends CleanUpAction {
37
38
	private IPreferenceChangeListener fPreferenceChangeListener;
39
40
	public AllCleanUpsAction(IWorkbenchSite site) {
41
		super(site);
42
		setToolTipText(ActionMessages.CleanUpAction_tooltip);
43
		setDescription(ActionMessages.CleanUpAction_description);
44
		installPreferenceListener();
45
		updateActionLabel();
46
47
		// PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.ORGANIZE_IMPORTS_ACTION);
48
	}
49
50
	public AllCleanUpsAction(JavaEditor editor) {
51
		super(editor);
52
		setToolTipText(ActionMessages.CleanUpAction_tooltip);
53
		setDescription(ActionMessages.CleanUpAction_description);
54
		installPreferenceListener();
55
		updateActionLabel();
56
	}
57
58
	/**
59
	 * {@inheritDoc}
60
	 */
61
	protected ICleanUp[] createCleanUps(ICompilationUnit[] units) {
62
		return CleanUpRefactoring.createCleanUps();
63
	}
64
65
	/**
66
	 * {@inheritDoc}
67
	 */
68
	protected String getActionName() {
69
		return ActionMessages.CleanUpAction_actionName;
70
	}
71
72
	/**
73
	 * {@inheritDoc}
74
	 */
75
	protected void performRefactoring(ICompilationUnit[] cus, ICleanUp[] cleanUps) throws JavaModelException, InvocationTargetException {
76
		RefactoringExecutionStarter.startCleanupRefactoring(cus, cleanUps, getShell(), showWizard(), getActionName());
77
	}
78
79
	private boolean showWizard() {
80
		InstanceScope instanceScope= new InstanceScope();
81
		IEclipsePreferences instanceNode= instanceScope.getNode(JavaUI.ID_PLUGIN);
82
		if (instanceNode.get(CleanUpConstants.SHOW_CLEAN_UP_WIZARD, null) != null)
83
			return instanceNode.getBoolean(CleanUpConstants.SHOW_CLEAN_UP_WIZARD, true);
84
85
		DefaultScope defaultScope= new DefaultScope();
86
		IEclipsePreferences defaultNode= defaultScope.getNode(JavaUI.ID_PLUGIN);
87
		return defaultNode.getBoolean(CleanUpConstants.SHOW_CLEAN_UP_WIZARD, true);
88
	}
89
90
	private void updateActionLabel() {
91
		if (showWizard()) {
92
			setText(ActionMessages.CleanUpAction_labelWizard);
93
		} else {
94
			setText(ActionMessages.CleanUpAction_label);
95
		}
96
	}
97
	
98
	private void installPreferenceListener() {
99
	    fPreferenceChangeListener= new IPreferenceChangeListener() {
100
			public void preferenceChange(PreferenceChangeEvent event) {
101
				if (event.getKey().equals(CleanUpConstants.SHOW_CLEAN_UP_WIZARD)) {
102
					updateActionLabel();
103
				}
104
			}
105
		};
106
		new InstanceScope().getNode(JavaUI.ID_PLUGIN).addPreferenceChangeListener(fPreferenceChangeListener);
107
    }
108
	
109
	public void dispose() {
110
		if (fPreferenceChangeListener != null) {
111
			new InstanceScope().getNode(JavaUI.ID_PLUGIN).removePreferenceChangeListener(fPreferenceChangeListener);
112
			fPreferenceChangeListener= null;
113
		}
114
	}
115
}
(-)ui/org/eclipse/jdt/internal/ui/actions/MultiSortMembersAction.java (+120 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 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
 *     Alex Blewitt - Bug 133277 Allow Sort Members to be performed on package and project levels
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.actions;
13
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.Hashtable;
16
17
import org.eclipse.jface.window.Window;
18
19
import org.eclipse.ui.IWorkbenchSite;
20
import org.eclipse.ui.PlatformUI;
21
22
import org.eclipse.jdt.core.ICompilationUnit;
23
import org.eclipse.jdt.core.IJavaElement;
24
import org.eclipse.jdt.core.IParent;
25
import org.eclipse.jdt.core.JavaModelException;
26
27
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
28
import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter;
29
30
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
31
import org.eclipse.jdt.internal.ui.JavaPlugin;
32
import org.eclipse.jdt.internal.ui.dialogs.SortMembersMessageDialog;
33
import org.eclipse.jdt.internal.ui.fix.ICleanUp;
34
import org.eclipse.jdt.internal.ui.fix.SortMembersCleanUp;
35
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
36
37
public class MultiSortMembersAction extends CleanUpAction {
38
39
	public MultiSortMembersAction(IWorkbenchSite site) {
40
		super(site);
41
		
42
		setText(ActionMessages.SortMembersAction_label); 
43
		setDescription(ActionMessages.SortMembersAction_description); 
44
		setToolTipText(ActionMessages.SortMembersAction_tooltip); 
45
		
46
		PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SORT_MEMBERS_ACTION);
47
	}
48
49
	public MultiSortMembersAction(JavaEditor editor) {
50
		super(editor);
51
		
52
		setText(ActionMessages.SortMembersAction_label); 
53
		setDescription(ActionMessages.SortMembersAction_description); 
54
		setToolTipText(ActionMessages.SortMembersAction_tooltip); 
55
		
56
		PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SORT_MEMBERS_ACTION);
57
	}
58
59
	/**
60
	 * {@inheritDoc}
61
	 */
62
	protected ICleanUp[] createCleanUps(ICompilationUnit[] units) {
63
		try {
64
	        if (!hasMembersToSort(units))
65
	        	return null;
66
        } catch (JavaModelException e) {
67
        	JavaPlugin.log(e);
68
	        return null;
69
        }
70
71
		SortMembersMessageDialog dialog= new SortMembersMessageDialog(getShell());
72
		if (dialog.open() != Window.OK)
73
			return null;
74
75
		Hashtable settings= new Hashtable();
76
		settings.put(CleanUpConstants.SORT_MEMBERS, CleanUpConstants.TRUE);
77
		settings.put(CleanUpConstants.SORT_MEMBERS_ALL, !dialog.isNotSortingFieldsEnabled() ? CleanUpConstants.TRUE : CleanUpConstants.FALSE);
78
79
		return new ICleanUp[] {
80
			new SortMembersCleanUp(settings)
81
		};
82
	}
83
84
	/**
85
	 * {@inheritDoc}
86
	 */
87
	protected String getActionName() {
88
		return ActionMessages.SortMembersAction_dialog_title; 
89
	}
90
91
	private boolean hasMembersToSort(ICompilationUnit[] units) throws JavaModelException {
92
		for (int i= 0; i < units.length; i++) {
93
			if (hasMembersToSort(units[i].getTypes()))
94
				return true;
95
		}
96
97
		return false;
98
	}
99
100
	private boolean hasMembersToSort(IJavaElement[] members) throws JavaModelException {
101
		if (members.length > 1)
102
			return true;
103
104
		if (members.length == 0)
105
			return false;
106
107
		IJavaElement elem= members[0];
108
		if (!(elem instanceof IParent))
109
			return false;
110
111
		return hasMembersToSort(((IParent)elem).getChildren());
112
	}
113
114
	/**
115
	 * {@inheritDoc}
116
	 */
117
	protected void performRefactoring(ICompilationUnit[] units, ICleanUp[] cleanUps) throws JavaModelException, InvocationTargetException {
118
		RefactoringExecutionStarter.startCleanupRefactoring(units, cleanUps, getShell(), false, getActionName());
119
    }
120
}

Return to bug 133277