Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0af157755911b59736b557fe79b1860147118114 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*******************************************************************************
 * Copyright (c) 2009, 2010 Alena Laskavaia 
 * 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:
 *    Alena Laskavaia  - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.dialogs;

import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
import org.eclipse.cdt.codan.core.param.RootProblemPreference;
import org.eclipse.cdt.codan.internal.core.model.CodanProblem;
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
import org.eclipse.cdt.codan.internal.ui.widgets.CustomizeProblemComposite;
import org.eclipse.cdt.codan.internal.ui.widgets.ParametersComposite;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

/**
 * Dialog that allows to customise problems
 * 
 */
public class CustomizeProblemDialog extends TitleAreaDialog {
	private CustomizeProblemComposite comp;
	private IProblem problem;
	private IProblem[] problems;
	private IResource resource;

	/**
	 * @param parentShell
	 * @param selectedProblem
	 * @param iResource
	 */
	public CustomizeProblemDialog(Shell parentShell, IProblem[] selectedProblems, IResource resource) {
		super(parentShell);
		this.problems = selectedProblems;
		this.problem = buildCombined(selectedProblems);
		this.resource = resource;
		setShellStyle(getShellStyle() | SWT.RESIZE);
	}

	/**
	 * @param selectedProblems
	 * @return
	 */
	private IProblem buildCombined(IProblem[] selectedProblems) {
		if (selectedProblems.length == 0)
			return null;
		IProblem one = selectedProblems[0];
		if (selectedProblems.length == 1) {
			return one;
		}
		CodanProblem problem = new CodanProblem("multi", getTitle()); //$NON-NLS-1$
		problem.setMessagePattern(ParametersComposite.NO_CHANGE);
		problem.setPreference(new RootProblemPreference());
		problem.setSeverity(one.getSeverity());
		problem.setEnabled(one.isEnabled());
		if (one.getPreference() instanceof RootProblemPreference) {
			RootProblemPreference onepref = (RootProblemPreference) one.getPreference();
			RootProblemPreference pref = (RootProblemPreference) problem.getPreference();
			pref.addChildDescriptor(onepref.getLaunchModePreference());
			pref.addChildDescriptor(onepref.getScopePreference());
		}
		return problem;
	}

	/**
	 * Stores edit values into problem working copy
	 * 
	 * @param problem
	 *        - problem working copy
	 */
	public void save(IProblemWorkingCopy problem) {
		comp.save(problem);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse
	 * .swt.widgets.Composite)
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		getShell().setText(CodanUIMessages.CustomizeProblemDialog_Title);
		setTitle(getTitle());
		setMessage(CodanUIMessages.CustomizeProblemDialog_Message);
		Composite area = (Composite) super.createDialogArea(parent);
		comp = new CustomizeProblemComposite(area, problem, resource);
		GridData ld = new GridData(GridData.FILL_BOTH);
		ld.minimumHeight = 300;
		comp.setLayoutData(ld);
		return area;
	}

	/**
	 * @return
	 */
	public String getTitle() {
		if (problems.length == 1)
			return problem.getName();
		String b = ""; //$NON-NLS-1$
		for (int i = 0; i < problems.length; i++) {
			IProblem p = problems[i];
			if (i != 0)
				b += ", "; //$NON-NLS-1$
			b += p.getName();
		}
		return b;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
	@Override
	protected void okPressed() {
		for (int i = 0; i < problems.length; i++) {
			IProblemWorkingCopy wc = (IProblemWorkingCopy) problems[i];
			save(wc);
		}
		super.okPressed();
	}
}

Back to the top