KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > CompileErrorProjectPromptStatusHandler


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.debug.internal.ui.launchConfigurations;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.resources.IProject;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.debug.core.ILaunchConfiguration;
21 import org.eclipse.debug.core.IStatusHandler;
22 import org.eclipse.debug.internal.ui.DebugUIPlugin;
23 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
24 import org.eclipse.debug.ui.DebugUITools;
25 import org.eclipse.jface.dialogs.IDialogConstants;
26 import org.eclipse.jface.dialogs.MessageDialog;
27 import org.eclipse.jface.dialogs.MessageDialogWithToggle;
28 import org.eclipse.jface.preference.IPreferenceStore;
29 import org.eclipse.swt.widgets.Shell;
30
31 import com.ibm.icu.text.MessageFormat;
32
33
34 public class CompileErrorProjectPromptStatusHandler implements IStatusHandler {
35
36     /* (non-Javadoc)
37      * @see org.eclipse.debug.core.IStatusHandler#handleStatus(org.eclipse.core.runtime.IStatus, java.lang.Object)
38      */

39     public Object JavaDoc handleStatus(IStatus status, Object JavaDoc source) throws CoreException {
40         ILaunchConfiguration config = null;
41         List JavaDoc projects = new ArrayList JavaDoc();
42         
43         if (source instanceof List JavaDoc) {
44             List JavaDoc args = (List JavaDoc) source;
45             Iterator JavaDoc iterator = args.iterator();
46             while (iterator.hasNext()) {
47                 Object JavaDoc arg = iterator.next();
48                 if (arg instanceof ILaunchConfiguration) {
49                     config = (ILaunchConfiguration) arg;
50                     if (DebugUITools.isPrivate(config)) {
51                         return Boolean.TRUE;
52                     }
53                 } else if (arg instanceof IProject) {
54                     projects.add(arg);
55                 }
56             }
57         }
58         Shell shell = DebugUIPlugin.getShell();
59         StringBuffer JavaDoc projectList = new StringBuffer JavaDoc();
60         //we need to limit this
61
int size = Math.min(20, projects.size());
62         for (int i = 0; i < size; i++) {
63             if (i > 0) {
64                 projectList.append(", "); //$NON-NLS-1$
65
}
66             projectList.append(((IProject)projects.get(i)).getName());
67         }
68         String JavaDoc projectMessage = null;
69         if(projects.size() > 20) {
70             projectMessage = MessageFormat.format(LaunchConfigurationsMessages.CompileErrorProjectPromptStatusHandler_0, new Object JavaDoc[]{projectList.toString()});
71         } else{
72             projectMessage = projectList.toString();
73         }
74         String JavaDoc title = LaunchConfigurationsMessages.CompileErrorPromptStatusHandler_0;
75         String JavaDoc message = MessageFormat.format(LaunchConfigurationsMessages.CompileErrorPromptStatusHandler_2, new String JavaDoc[]{projectMessage});
76         IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
77         
78         String JavaDoc pref = store.getString(IInternalDebugUIConstants.PREF_CONTINUE_WITH_COMPILE_ERROR);
79         if (pref != null) {
80             if (pref.equals(MessageDialogWithToggle.ALWAYS)) {
81                 return Boolean.TRUE;
82             }
83         }
84         MessageDialogWithToggle dialog = new MessageDialogWithToggle(shell,
85                 title,
86                 null,
87                 message,
88                 MessageDialog.QUESTION,
89                 new String JavaDoc[] {IDialogConstants.PROCEED_LABEL, IDialogConstants.CANCEL_LABEL},
90                 0,
91                 LaunchConfigurationsMessages.CompileErrorProjectPromptStatusHandler_1,
92                 false);
93         int open = dialog.open();
94         if (open == IDialogConstants.PROCEED_ID) {
95             if(dialog.getToggleState()) {
96                 store.setValue(IInternalDebugUIConstants.PREF_CONTINUE_WITH_COMPILE_ERROR, MessageDialogWithToggle.ALWAYS);
97             }
98             return Boolean.TRUE;
99         }
100         else {
101             return Boolean.FALSE;
102         }
103     }
104 }
105
Popular Tags