mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 13:55:39 +02:00
added general problem attributes in customize page
This commit is contained in:
parent
844b2fa4bd
commit
97b109e9ba
3 changed files with 120 additions and 4 deletions
|
@ -191,4 +191,32 @@
|
||||||
super="org.eclipse.ui.workbench.texteditor.info">
|
super="org.eclipse.ui.workbench.texteditor.info">
|
||||||
</type>
|
</type>
|
||||||
</extension>
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.popupMenus">
|
||||||
|
<objectContribution
|
||||||
|
adaptable="true"
|
||||||
|
id="org.eclipse.cdt.codan.ui.CodanProblemActions"
|
||||||
|
objectClass="org.eclipse.core.resources.IMarker">
|
||||||
|
<action
|
||||||
|
class="org.eclipse.cdt.codan.internal.ui.actions.OpenProblemPreferences"
|
||||||
|
id="org.eclipse.cdt.codan.ui.OpenProblemProperties"
|
||||||
|
label="Customize Problem..."
|
||||||
|
menubarPath="additions"/>
|
||||||
|
|
||||||
|
<filter name="type"
|
||||||
|
value="org.eclipse.cdt.codan.core.codanProblem"/>
|
||||||
|
<!-- user: menubarPath="org.eclipse.cdt.codan.ui.configureMenu/configureProblemSep" -->
|
||||||
|
<!-- <menu
|
||||||
|
id="org.eclipse.cdt.codan.ui.configureMenu"
|
||||||
|
label="Configure Problem"
|
||||||
|
path="additions">
|
||||||
|
<separator
|
||||||
|
name="configureProblemSep">
|
||||||
|
</separator>
|
||||||
|
|
||||||
|
</menu>
|
||||||
|
-->
|
||||||
|
|
||||||
|
</objectContribution>
|
||||||
|
</extension>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package org.eclipse.cdt.codan.internal.ui.actions;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
||||||
|
import org.eclipse.cdt.codan.internal.core.model.CodanProblem;
|
||||||
|
import org.eclipse.cdt.codan.internal.core.model.CodanProblemMarker;
|
||||||
|
import org.eclipse.cdt.codan.internal.ui.dialogs.CustomizeProblemDialog;
|
||||||
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.jface.action.IAction;
|
||||||
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.ui.IObjectActionDelegate;
|
||||||
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
|
|
||||||
|
public class OpenProblemPreferences implements IObjectActionDelegate {
|
||||||
|
private ISelection selection;
|
||||||
|
private IWorkbenchPart targetPart;
|
||||||
|
|
||||||
|
public OpenProblemPreferences() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(IAction action) {
|
||||||
|
if (selection instanceof IStructuredSelection) {
|
||||||
|
Object firstElement = ((IStructuredSelection) selection)
|
||||||
|
.getFirstElement(); // TODO support multiple
|
||||||
|
if (firstElement instanceof IMarker) {
|
||||||
|
IMarker marker = (IMarker) firstElement;
|
||||||
|
String id = CodanProblemMarker.getProblemId(marker);
|
||||||
|
if (id == null)
|
||||||
|
return;
|
||||||
|
IResource resource = marker.getResource();
|
||||||
|
IProblemProfile profile = CodanProblemMarker
|
||||||
|
.getProfile(resource);
|
||||||
|
CodanProblem problem = ((CodanProblem) profile.findProblem(id));
|
||||||
|
new CustomizeProblemDialog(targetPart.getSite().getShell(),
|
||||||
|
problem, resource).open();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectionChanged(IAction action, ISelection selection) {
|
||||||
|
this.selection = selection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||||
|
this.targetPart = targetPart;
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.codan.internal.ui.widgets;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
||||||
import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference;
|
import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference;
|
||||||
|
@ -21,6 +22,7 @@ import org.eclipse.cdt.codan.core.param.ListProblemPreference;
|
||||||
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
||||||
import org.eclipse.jface.dialogs.InputDialog;
|
import org.eclipse.jface.dialogs.InputDialog;
|
||||||
import org.eclipse.jface.preference.BooleanFieldEditor;
|
import org.eclipse.jface.preference.BooleanFieldEditor;
|
||||||
|
import org.eclipse.jface.preference.ComboFieldEditor;
|
||||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||||
import org.eclipse.jface.preference.FileFieldEditor;
|
import org.eclipse.jface.preference.FileFieldEditor;
|
||||||
import org.eclipse.jface.preference.ListEditor;
|
import org.eclipse.jface.preference.ListEditor;
|
||||||
|
@ -31,6 +33,7 @@ import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.Control;
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,6 +41,9 @@ import org.eclipse.swt.widgets.Label;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ParametersComposite extends Composite {
|
public class ParametersComposite extends Composite {
|
||||||
|
private static final String PREF_ENABLED = "enabled"; //$NON-NLS-1$
|
||||||
|
private static final String PREF_SEVERITY = "severity"; //$NON-NLS-1$
|
||||||
|
private static final String PREF_MESSAGE = "message"; //$NON-NLS-1$
|
||||||
private FieldEditorPreferencePage page;
|
private FieldEditorPreferencePage page;
|
||||||
private IProblem problem;
|
private IProblem problem;
|
||||||
private PreferenceStore prefStore;
|
private PreferenceStore prefStore;
|
||||||
|
@ -54,14 +60,34 @@ public class ParametersComposite extends Composite {
|
||||||
this.setLayout(new GridLayout(2, false));
|
this.setLayout(new GridLayout(2, false));
|
||||||
this.problem = problem;
|
this.problem = problem;
|
||||||
this.prefStore = new PreferenceStore();
|
this.prefStore = new PreferenceStore();
|
||||||
page = new FieldEditorPreferencePage() {
|
page = new FieldEditorPreferencePage(FieldEditorPreferencePage.GRID) {
|
||||||
@Override
|
@Override
|
||||||
protected void createFieldEditors() {
|
protected void createFieldEditors() {
|
||||||
noDefaultAndApplyButton();
|
noDefaultAndApplyButton();
|
||||||
|
((GridLayout) getFieldEditorParent().getLayout()).numColumns = 2;
|
||||||
|
addField(new BooleanFieldEditor(PREF_ENABLED,
|
||||||
|
"This problem is enabled", getFieldEditorParent()));
|
||||||
|
String[][] entries = {
|
||||||
|
{ CodanSeverity.Error.toString(),
|
||||||
|
CodanSeverity.Error.toString() }, //
|
||||||
|
{ CodanSeverity.Warning.toString(),
|
||||||
|
CodanSeverity.Warning.toString() }, //
|
||||||
|
{ CodanSeverity.Info.toString(),
|
||||||
|
CodanSeverity.Info.toString() }, //
|
||||||
|
};
|
||||||
|
addField(new ComboFieldEditor(PREF_SEVERITY, "Severity",
|
||||||
|
entries, getFieldEditorParent()));
|
||||||
|
addField(new StringFieldEditor(PREF_MESSAGE, "Message Pattern",
|
||||||
|
getFieldEditorParent()));
|
||||||
IProblemPreference pref = problem.getPreference();
|
IProblemPreference pref = problem.getPreference();
|
||||||
createFieldEditorsForParameters(pref);
|
createFieldEditorsForParameters(pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Control createContents(Composite parent) {
|
||||||
|
return super.createContents(parent);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param info
|
* @param info
|
||||||
*/
|
*/
|
||||||
|
@ -161,6 +187,16 @@ public class ParametersComposite extends Composite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
load(problem);
|
||||||
|
page.setPreferenceStore(prefStore);
|
||||||
|
page.createControl(parent);
|
||||||
|
page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param problem
|
||||||
|
*/
|
||||||
|
public void load(final IProblem problem) {
|
||||||
IProblemPreference info = problem.getPreference();
|
IProblemPreference info = problem.getPreference();
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
Label label = new Label(this, 0);
|
Label label = new Label(this, 0);
|
||||||
|
@ -168,14 +204,18 @@ public class ParametersComposite extends Composite {
|
||||||
} else {
|
} else {
|
||||||
initPrefStore(info);
|
initPrefStore(info);
|
||||||
}
|
}
|
||||||
page.setPreferenceStore(prefStore);
|
prefStore.setValue(PREF_ENABLED, problem.isEnabled());
|
||||||
page.createControl(parent);
|
prefStore.setValue(PREF_SEVERITY, problem.getSeverity().toString());
|
||||||
page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
|
prefStore.setValue(PREF_MESSAGE, problem.getMessagePattern());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(IProblemWorkingCopy problem) {
|
public void save(IProblemWorkingCopy problem) {
|
||||||
page.performOk();
|
page.performOk();
|
||||||
savePrefStore(problem.getPreference());
|
savePrefStore(problem.getPreference());
|
||||||
|
problem.setEnabled(prefStore.getBoolean(PREF_ENABLED));
|
||||||
|
problem.setSeverity(CodanSeverity.valueOf(prefStore
|
||||||
|
.getString(PREF_SEVERITY)));
|
||||||
|
problem.setMessagePattern(prefStore.getString(PREF_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void savePrefStore(IProblemPreference desc) {
|
private void savePrefStore(IProblemPreference desc) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue