Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: eae89d3d421d34deec8cfe875b00da1e40056d4d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*******************************************************************************
 * Copyright (c) 2000, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.launchConfigurations;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Shell;

import com.ibm.icu.text.MessageFormat;


public class CompileErrorProjectPromptStatusHandler implements IStatusHandler {

	/* (non-Javadoc)
	 * @see org.eclipse.debug.core.IStatusHandler#handleStatus(org.eclipse.core.runtime.IStatus, java.lang.Object)
	 */
	@Override
	public Object handleStatus(IStatus status, Object source) throws CoreException {
		ILaunchConfiguration config = null;
		List<Object> projects = new ArrayList<>();
		if (source instanceof List) {
			List<?> args = (List<?>) source;
			Iterator<?> iterator = args.iterator();
			while (iterator.hasNext()) {
				Object arg = iterator.next();
				if (arg instanceof ILaunchConfiguration) {
					config = (ILaunchConfiguration) arg;
					if (DebugUITools.isPrivate(config)) {
						return Boolean.TRUE;
					}
				} else if (arg instanceof IProject) {
					projects.add(arg);
				}
			}
		}
		Shell shell = DebugUIPlugin.getShell();
		StringBuffer projectList = new StringBuffer();
		//we need to limit this
		int size = Math.min(20, projects.size());
		for (int i = 0; i < size; i++) {
			if (i > 0) {
				projectList.append(", "); //$NON-NLS-1$
			}
			projectList.append(((IProject)projects.get(i)).getName());
		}
		String projectMessage = null;
		if(projects.size() > 20) {
			projectMessage = MessageFormat.format(LaunchConfigurationsMessages.CompileErrorProjectPromptStatusHandler_0, new Object[]{projectList.toString()});
		} else{
			projectMessage = projectList.toString();
		}
		String title =  LaunchConfigurationsMessages.CompileErrorPromptStatusHandler_0;
		String message = MessageFormat.format(LaunchConfigurationsMessages.CompileErrorPromptStatusHandler_2, new Object[] { projectMessage });
		IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();

		String pref = store.getString(IInternalDebugUIConstants.PREF_CONTINUE_WITH_COMPILE_ERROR);
		if (pref != null) {
			if (pref.equals(MessageDialogWithToggle.ALWAYS)) {
				return Boolean.TRUE;
			}
		}
		MessageDialogWithToggle dialog = new MessageDialogWithToggle(shell,
				title,
				null,
				message,
				MessageDialog.QUESTION,
				new String[] {IDialogConstants.PROCEED_LABEL, IDialogConstants.CANCEL_LABEL},
				0,
				LaunchConfigurationsMessages.CompileErrorProjectPromptStatusHandler_1,
				false);
        int open = dialog.open();
		if (open == IDialogConstants.PROCEED_ID) {
        	if(dialog.getToggleState()) {
        		store.setValue(IInternalDebugUIConstants.PREF_CONTINUE_WITH_COMPILE_ERROR, MessageDialogWithToggle.ALWAYS);
        	}
            return Boolean.TRUE;
        }
        else {
            return Boolean.FALSE;
        }
	}
}

Back to the top