mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
added support of specifing launch mode per problem
This commit is contained in:
parent
569c4f47ea
commit
57547df8f4
16 changed files with 563 additions and 35 deletions
|
@ -150,7 +150,7 @@ public abstract class AbstractChecker implements IChecker {
|
|||
}
|
||||
|
||||
/**
|
||||
* Defines if checker should be run as user type in C editor. Override this
|
||||
* Defines if checker should be run as user type in editor. Override this
|
||||
* method is checker is too heavy for that (runs too long)
|
||||
*/
|
||||
public boolean runInEditor() {
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
/**
|
||||
* CheckerLaunchMode - how checker can be run
|
||||
* <p>
|
||||
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
|
||||
* part of a work in progress. There is no guarantee that this API will
|
||||
* work or that it will remain the same.
|
||||
* </p>
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public enum CheckerLaunchMode {
|
||||
/**
|
||||
* use parent settings
|
||||
*/
|
||||
USE_PARENT,
|
||||
/**
|
||||
* checker run when full build is running
|
||||
*/
|
||||
RUN_ON_FULL_BUILD,
|
||||
/**
|
||||
* checker run when incremental build is running
|
||||
*/
|
||||
RUN_ON_INC_BUILD,
|
||||
/**
|
||||
* checker run in editor as you type
|
||||
*/
|
||||
RUN_AS_YOU_TYPE,
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009,2010 QNX Software Systems
|
||||
* 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:
|
||||
* QNX Software Systems (Alena Laskavaia) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.param;
|
||||
|
||||
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
|
||||
|
||||
/**
|
||||
* Problem preference for launch type of the checker
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class LaunchTypeProblemPreference extends MapProblemPreference {
|
||||
/**
|
||||
* Propery key
|
||||
*/
|
||||
public static final String KEY = "launchModes"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
public LaunchTypeProblemPreference() {
|
||||
CheckerLaunchMode[] values = CheckerLaunchMode.values();
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
CheckerLaunchMode checkerLaunchMode = values[i];
|
||||
addChildDescriptor(new BasicProblemPreference(
|
||||
checkerLaunchMode.name(), checkerLaunchMode.name(),
|
||||
PreferenceType.TYPE_BOOLEAN));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if property is set to use parent mode
|
||||
*/
|
||||
public boolean isUsingParent() {
|
||||
return isRunningInMode(CheckerLaunchMode.USE_PARENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mode
|
||||
* @return true if this mode enabled for this preference
|
||||
*/
|
||||
public boolean isRunningInMode(CheckerLaunchMode mode) {
|
||||
Object value = getChildValue(mode.name());
|
||||
if (value instanceof Boolean) {
|
||||
return (Boolean) value;
|
||||
}
|
||||
if (mode == CheckerLaunchMode.USE_PARENT && value == null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mode
|
||||
* @param value
|
||||
*/
|
||||
public void setRunningMode(CheckerLaunchMode mode, boolean value) {
|
||||
setChildValue(mode.name(), value);
|
||||
}
|
||||
}
|
|
@ -173,6 +173,10 @@ public class MapProblemPreference extends AbstractProblemPreference implements
|
|||
throw new IllegalArgumentException(
|
||||
String.valueOf((char) token));
|
||||
IProblemPreference desc = getChildDescriptor(key);
|
||||
if (desc == null && LaunchTypeProblemPreference.KEY.equals(key)) {
|
||||
desc = new LaunchTypeProblemPreference();
|
||||
addChildDescriptor(desc);
|
||||
}
|
||||
if (desc != null && desc instanceof AbstractProblemPreference) {
|
||||
((AbstractProblemPreference) desc).importValue(tokenizer);
|
||||
setChildValue(key, desc.getValue());
|
||||
|
@ -253,8 +257,9 @@ public class MapProblemPreference extends AbstractProblemPreference implements
|
|||
if (value2 instanceof IProblemPreference) {
|
||||
hash.put(key, (IProblemPreference) value2);
|
||||
} else {
|
||||
setChildValue(key, value2);
|
||||
IProblemPreference pref = hash2.get(key);
|
||||
addChildDescriptor(pref);
|
||||
//setChildValue(key, value2);
|
||||
pref.setValue(value2);
|
||||
hash.put(key, pref);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import java.util.Iterator;
|
|||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
||||
import org.eclipse.cdt.codan.core.model.AbstractCheckerWithProblemPreferences;
|
||||
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
|
||||
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
||||
import org.eclipse.cdt.codan.core.model.IChecker;
|
||||
import org.eclipse.cdt.codan.core.model.ICheckerWithPreferences;
|
||||
|
@ -25,6 +27,9 @@ import org.eclipse.cdt.codan.core.model.IProblem;
|
|||
import org.eclipse.cdt.codan.core.model.IProblemCategory;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
||||
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.param.LaunchTypeProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
|
||||
import org.eclipse.cdt.codan.internal.core.model.CodanProblem;
|
||||
import org.eclipse.cdt.codan.internal.core.model.CodanProblemCategory;
|
||||
import org.eclipse.cdt.codan.internal.core.model.ProblemProfile;
|
||||
|
@ -433,6 +438,46 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if checker need to run in specific launch mode
|
||||
*
|
||||
* @param checker
|
||||
* @param resource
|
||||
* @param mode
|
||||
* @return
|
||||
*/
|
||||
public boolean isCheckerEnabledForLaunchMode(IChecker checker,
|
||||
IResource resource, CheckerLaunchMode mode) {
|
||||
IProblemProfile resourceProfile = getResourceProfile(resource);
|
||||
Collection<IProblem> refProblems = getRefProblems(checker);
|
||||
boolean enabled = false;
|
||||
for (Iterator<IProblem> iterator = refProblems.iterator(); iterator
|
||||
.hasNext();) {
|
||||
IProblem p = iterator.next();
|
||||
// we need to check problem enablement in particular profile
|
||||
IProblem problem = resourceProfile.findProblem(p.getId());
|
||||
if (problem == null)
|
||||
throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$
|
||||
if (checker instanceof AbstractCheckerWithProblemPreferences) {
|
||||
MapProblemPreference map = (MapProblemPreference) problem
|
||||
.getPreference();
|
||||
IProblemPreference pref1 = map
|
||||
.getChildDescriptor(LaunchTypeProblemPreference.KEY);
|
||||
LaunchTypeProblemPreference pref = (LaunchTypeProblemPreference) pref1;
|
||||
if (pref == null
|
||||
|| pref.isRunningInMode(CheckerLaunchMode.USE_PARENT)) {
|
||||
enabled = true;
|
||||
break;
|
||||
}
|
||||
if (pref.isRunningInMode(mode)) {
|
||||
enabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.util.Map;
|
|||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.cdt.codan.core.Messages;
|
||||
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
|
||||
import org.eclipse.cdt.codan.core.model.IChecker;
|
||||
import org.eclipse.cdt.codan.core.model.ICodanBuilder;
|
||||
import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker;
|
||||
|
@ -91,17 +92,19 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
|
|||
}
|
||||
|
||||
public void processResource(IResource resource, IProgressMonitor monitor) {
|
||||
processResource(resource, monitor, null, false, true);
|
||||
processResource(resource, monitor, null,
|
||||
CheckerLaunchMode.RUN_ON_FULL_BUILD);
|
||||
}
|
||||
|
||||
public void processResourceDelta(IResource resource,
|
||||
IProgressMonitor monitor) {
|
||||
processResource(resource, monitor, null, false, false);
|
||||
processResource(resource, monitor, null,
|
||||
CheckerLaunchMode.RUN_ON_INC_BUILD);
|
||||
}
|
||||
|
||||
protected void processResource(IResource resource,
|
||||
IProgressMonitor monitor, Object model, boolean inEditor,
|
||||
boolean recursive) {
|
||||
IProgressMonitor monitor, Object model,
|
||||
CheckerLaunchMode checkerLaunchMode) {
|
||||
CheckersRegistry chegistry = CheckersRegistry.getInstance();
|
||||
int checkers = chegistry.getCheckersSize();
|
||||
int memsize = 0;
|
||||
|
@ -122,14 +125,16 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
|
|||
try {
|
||||
if (monitor.isCanceled())
|
||||
return;
|
||||
if (checker.enabledInContext(resource)) {
|
||||
if (checker.enabledInContext(resource)
|
||||
&& chegistry.isCheckerEnabledForLaunchMode(checker,
|
||||
resource, checkerLaunchMode)) {
|
||||
synchronized (checker) {
|
||||
try {
|
||||
checker.before(resource);
|
||||
if (chegistry.isCheckerEnabled(checker,
|
||||
resource)) {
|
||||
//long time = System.currentTimeMillis();
|
||||
if (inEditor) {
|
||||
if (checkerLaunchMode == CheckerLaunchMode.RUN_AS_YOU_TYPE) {
|
||||
if (checker.runInEditor()
|
||||
&& checker instanceof IRunnableInEditorChecker) {
|
||||
((IRunnableInEditorChecker) checker)
|
||||
|
@ -155,7 +160,8 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
|
|||
CodanCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
if (resource instanceof IContainer && recursive) {
|
||||
if (resource instanceof IContainer
|
||||
&& (checkerLaunchMode == CheckerLaunchMode.RUN_ON_FULL_BUILD)) {
|
||||
try {
|
||||
IResource[] members = ((IContainer) resource).members();
|
||||
for (int i = 0; i < members.length; i++) {
|
||||
|
@ -174,6 +180,15 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param checker
|
||||
* @return
|
||||
*/
|
||||
private boolean isEnabledForLaunchMode(IChecker checker) {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void fullBuild(final IProgressMonitor monitor)
|
||||
throws CoreException {
|
||||
processResource(getProject(), monitor);
|
||||
|
@ -196,6 +211,7 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
|
|||
IProgressMonitor monitor) {
|
||||
if (model == null)
|
||||
return;
|
||||
processResource(resource, monitor, model, true, false);
|
||||
processResource(resource, monitor, model,
|
||||
CheckerLaunchMode.RUN_AS_YOU_TYPE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,7 +144,11 @@ public class CodanPreferencesLoader {
|
|||
String exported = storePreferences.get(prefKey, null);
|
||||
if (exported != null) {
|
||||
//System.err.println(prefKey + " import " + exported);
|
||||
prob.getPreference().importValue(exported);
|
||||
try {
|
||||
prob.getPreference().importValue(exported);
|
||||
} catch (IllegalArgumentException e) {
|
||||
CodanCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ public class CodanUIMessages extends NLS {
|
|||
public static String OverlayPage_Use_Project_Settings;
|
||||
public static String OverlayPage_Configure_Workspace_Settings;
|
||||
public static String PropertyStore_Cannot_write_resource_property;
|
||||
public static String CustomizeProblemComposite_LaunchingTab;
|
||||
public static String CustomizeProblemComposite_TabParameters;
|
||||
public static String CustomizeProblemComposite_TabScope;
|
||||
public static String CustomizeProblemDialog_Message;
|
||||
|
|
|
@ -18,6 +18,7 @@ CodanPreferencePage_Info=Info
|
|||
CodanPreferencePage_MessageLabel=Message:
|
||||
CodanPreferencePage_NoInfo=Not defined
|
||||
CodanPreferencePage_Parameters=Parameters:
|
||||
CustomizeProblemComposite_LaunchingTab=Launching
|
||||
CustomizeProblemComposite_TabParameters=Preferences
|
||||
CustomizeProblemComposite_TabScope=Scope
|
||||
CustomizeProblemDialog_Message=Edit problem preferences, scope and launch options
|
||||
|
|
|
@ -42,9 +42,11 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
|||
@Override
|
||||
protected void createFieldEditors() {
|
||||
addField(new BooleanFieldEditor(PreferenceConstants.P_RUN_ON_BUILD,
|
||||
CodanUIMessages.BuildPropertyPage_RunWithBuild, getFieldEditorParent()));
|
||||
CodanUIMessages.BuildPropertyPage_RunWithBuild,
|
||||
getFieldEditorParent()));
|
||||
addField(new BooleanFieldEditor(PreferenceConstants.P_RUN_IN_EDITOR,
|
||||
CodanUIMessages.BuildPropertyPage_RunAsYouType, getFieldEditorParent()));
|
||||
CodanUIMessages.BuildPropertyPage_RunAsYouType,
|
||||
getFieldEditorParent()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,8 +101,4 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
|||
setPreferenceStore(scoped);
|
||||
}
|
||||
}
|
||||
|
||||
protected String getPageId() {
|
||||
return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage"; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
|
|
@ -283,6 +283,8 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
|||
*
|
||||
*/
|
||||
protected void openCustomizeDialog() {
|
||||
if (selectedProblem == null)
|
||||
return;
|
||||
CustomizeProblemDialog d = new CustomizeProblemDialog(getShell(),
|
||||
selectedProblem, (IResource) getElement());
|
||||
d.open();
|
||||
|
|
|
@ -66,7 +66,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
* Constructor
|
||||
*
|
||||
* @param style
|
||||
* - layout style
|
||||
* - layout style
|
||||
*/
|
||||
public FieldEditorOverlayPage(int style) {
|
||||
super(style);
|
||||
|
@ -76,9 +76,9 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
* Constructor
|
||||
*
|
||||
* @param title
|
||||
* - title string
|
||||
* - title string
|
||||
* @param style
|
||||
* - layout style
|
||||
* - layout style
|
||||
*/
|
||||
public FieldEditorOverlayPage(String title, int style) {
|
||||
super(title, style);
|
||||
|
@ -88,11 +88,11 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
* Constructor
|
||||
*
|
||||
* @param title
|
||||
* - title string
|
||||
* - title string
|
||||
* @param image
|
||||
* - title image
|
||||
* - title image
|
||||
* @param style
|
||||
* - layout style
|
||||
* - layout style
|
||||
*/
|
||||
public FieldEditorOverlayPage(String title, ImageDescriptor image, int style) {
|
||||
super(title, image, style);
|
||||
|
@ -144,6 +144,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
*
|
||||
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#addField(org.eclipse.jface.preference.FieldEditor)
|
||||
*/
|
||||
@Override
|
||||
protected void addField(FieldEditor editor) {
|
||||
editors.add(editor);
|
||||
super.addField(editor);
|
||||
|
@ -156,6 +157,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#createControl()
|
||||
*/
|
||||
@Override
|
||||
public void createControl(Composite parent) {
|
||||
// Special treatment for property pages
|
||||
if (isPropertyPage()) {
|
||||
|
@ -185,6 +187,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
|
||||
*/
|
||||
@Override
|
||||
protected Control createContents(Composite parent) {
|
||||
if (isPropertyPage())
|
||||
createSelectionGroup(parent);
|
||||
|
@ -196,7 +199,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
* push button.
|
||||
*
|
||||
* @param parent
|
||||
* - the parent composite
|
||||
* - the parent composite
|
||||
*/
|
||||
private void createSelectionGroup(Composite parent) {
|
||||
Composite comp = new Composite(parent, SWT.NONE);
|
||||
|
@ -213,8 +216,10 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
useProjectSettingsButton = createRadioButton(radioGroup,
|
||||
CodanUIMessages.OverlayPage_Use_Project_Settings);
|
||||
configureButton = new Button(comp, SWT.PUSH);
|
||||
configureButton.setText(CodanUIMessages.OverlayPage_Use_Workspace_Settings);
|
||||
configureButton
|
||||
.setText(CodanUIMessages.OverlayPage_Configure_Workspace_Settings);
|
||||
configureButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
configureWorkspaceSettings();
|
||||
}
|
||||
|
@ -238,15 +243,16 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
* Convenience method creating a radio button
|
||||
*
|
||||
* @param parent
|
||||
* - the parent composite
|
||||
* - the parent composite
|
||||
* @param label
|
||||
* - the button label
|
||||
* - the button label
|
||||
* @return - the new button
|
||||
*/
|
||||
private Button createRadioButton(Composite parent, String label) {
|
||||
final Button button = new Button(parent, SWT.RADIO);
|
||||
button.setText(label);
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
configureButton
|
||||
.setEnabled(button == useWorkspaceSettingsButton);
|
||||
|
@ -262,6 +268,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#getPreferenceStore()
|
||||
*/
|
||||
@Override
|
||||
public IPreferenceStore getPreferenceStore() {
|
||||
if (isPropertyPage())
|
||||
return overlayStore;
|
||||
|
@ -282,7 +289,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
* may override.
|
||||
*
|
||||
* @param enabled
|
||||
* - true if enabled
|
||||
* - true if enabled
|
||||
*/
|
||||
protected void updateFieldEditors(boolean enabled) {
|
||||
Composite parent = getFieldEditorParent();
|
||||
|
@ -300,6 +307,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
*
|
||||
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
||||
*/
|
||||
@Override
|
||||
public boolean performOk() {
|
||||
boolean result = super.performOk();
|
||||
if (result && isPropertyPage()) {
|
||||
|
@ -316,6 +324,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
|
||||
*/
|
||||
@Override
|
||||
protected void performDefaults() {
|
||||
if (isPropertyPage()) {
|
||||
useWorkspaceSettingsButton.setSelection(true);
|
||||
|
@ -350,9 +359,9 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
|
|||
* Show a single preference pages
|
||||
*
|
||||
* @param id
|
||||
* - the preference page identification
|
||||
* - the preference page identification
|
||||
* @param page
|
||||
* - the preference page
|
||||
* - the preference page
|
||||
*/
|
||||
protected void showPreferencePage(String id, IPreferencePage page) {
|
||||
final IPreferenceNode targetNode = new PreferenceNode(id, page);
|
||||
|
|
|
@ -0,0 +1,201 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Alena Laskavaia 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:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
|
||||
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
||||
import org.eclipse.jface.preference.BooleanFieldEditor;
|
||||
import org.eclipse.jface.preference.FieldEditor;
|
||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||
import org.eclipse.jface.preference.PreferenceStore;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
|
||||
public class LaunchModesPropertyPage extends FieldEditorPreferencePage {
|
||||
private Button useParentSettingsButton;
|
||||
private Button useLocalSettingsButton;
|
||||
private Button configureButton;
|
||||
private ArrayList<FieldEditor> editors;
|
||||
private Group useLocalGroup;
|
||||
|
||||
/**
|
||||
* @param prefStore
|
||||
*
|
||||
*/
|
||||
public LaunchModesPropertyPage(PreferenceStore prefStore) {
|
||||
super(GRID);
|
||||
setPreferenceStore(prefStore);
|
||||
editors = new ArrayList<FieldEditor>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noDefaultAndApplyButton() {
|
||||
super.noDefaultAndApplyButton();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors
|
||||
* ()
|
||||
*/
|
||||
@Override
|
||||
protected void createFieldEditors() {
|
||||
createSelectionGroup(getFieldEditorParent());
|
||||
addField(new BooleanFieldEditor(
|
||||
CheckerLaunchMode.RUN_ON_FULL_BUILD.name(),
|
||||
"Run on full build", useLocalGroup));
|
||||
addField(new BooleanFieldEditor(
|
||||
CheckerLaunchMode.RUN_ON_INC_BUILD.name(),
|
||||
"Run on incremental build", useLocalGroup));
|
||||
addField(new BooleanFieldEditor(
|
||||
CheckerLaunchMode.RUN_AS_YOU_TYPE.name(),
|
||||
"Run as you type", useLocalGroup));
|
||||
updateFieldEditors();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.jface.preference.FieldEditorPreferencePage#addField(org.eclipse
|
||||
* .jface.preference.FieldEditor)
|
||||
*/
|
||||
@Override
|
||||
protected void addField(FieldEditor editor) {
|
||||
editors.add(editor);
|
||||
super.addField(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes a selection group with two choice buttons and one
|
||||
* push button.
|
||||
*
|
||||
* @param parent
|
||||
* - the parent composite
|
||||
*/
|
||||
private void createSelectionGroup(Composite parent) {
|
||||
Composite comp = new Composite(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout(2, false);
|
||||
layout.marginHeight = 0;
|
||||
layout.marginWidth = 0;
|
||||
comp.setLayout(layout);
|
||||
comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
Composite radioGroup = new Composite(comp, SWT.NONE);
|
||||
radioGroup.setLayout(new GridLayout(2, false));
|
||||
radioGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
useParentSettingsButton = createRadioButton(radioGroup,
|
||||
CodanUIMessages.OverlayPage_Use_Project_Settings);
|
||||
configureButton = new Button(radioGroup, SWT.PUSH);
|
||||
configureButton.setText("Configure...");
|
||||
configureButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
configureProjectSettings();
|
||||
}
|
||||
});
|
||||
useLocalSettingsButton = createRadioButton(radioGroup,
|
||||
"Use checker specific settings");
|
||||
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalSpan = 2;
|
||||
useLocalSettingsButton.setLayoutData(gd);
|
||||
// Set workspace/project radio buttons
|
||||
try {
|
||||
Boolean useParent = getPreferenceStore().getBoolean(
|
||||
CheckerLaunchMode.USE_PARENT.name());
|
||||
if (useParent) {
|
||||
useParentSettingsButton.setSelection(true);
|
||||
} else {
|
||||
useLocalSettingsButton.setSelection(true);
|
||||
configureButton.setEnabled(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
useParentSettingsButton.setSelection(true);
|
||||
}
|
||||
useLocalGroup = new Group(radioGroup, SWT.NONE);
|
||||
GridLayout layout2 = new GridLayout(2, false);
|
||||
useLocalGroup.setLayout(layout2);
|
||||
GridData gd2 = new GridData(GridData.FILL_BOTH);
|
||||
gd2.horizontalSpan = 2;
|
||||
useLocalGroup.setLayoutData(gd2);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void configureProjectSettings() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method creating a radio button
|
||||
*
|
||||
* @param parent
|
||||
* - the parent composite
|
||||
* @param label
|
||||
* - the button label
|
||||
* @return - the new button
|
||||
*/
|
||||
private Button createRadioButton(Composite parent, String label) {
|
||||
final Button button = new Button(parent, SWT.RADIO);
|
||||
button.setText(label);
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
boolean useParent = button == useParentSettingsButton;
|
||||
configureButton.setEnabled(useParent);
|
||||
getPreferenceStore().setValue(
|
||||
CheckerLaunchMode.USE_PARENT
|
||||
.name(), useParent);
|
||||
updateFieldEditors();
|
||||
}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
private void updateFieldEditors() {
|
||||
// We iterate through all field editors
|
||||
boolean enabled = useLocalSettingsButton.getSelection();
|
||||
updateFieldEditors(enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables the field editors and buttons of this page Subclasses
|
||||
* may override.
|
||||
*
|
||||
* @param enabled
|
||||
* - true if enabled
|
||||
*/
|
||||
protected void updateFieldEditors(boolean enabled) {
|
||||
Composite parent = useLocalGroup;
|
||||
Iterator it = editors.iterator();
|
||||
while (it.hasNext()) {
|
||||
FieldEditor editor = (FieldEditor) it.next();
|
||||
editor.setEnabled(enabled, parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performOk() {
|
||||
boolean result = super.performOk();
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ public class CustomizeProblemComposite extends Composite {
|
|||
private ParametersComposite problemsComposite;
|
||||
private FileScopeComposite scopeComposite;
|
||||
private IResource resource;
|
||||
private LaunchingTabComposite launchingComposite;
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
|
@ -49,11 +50,13 @@ public class CustomizeProblemComposite extends Composite {
|
|||
// createMainTab(tabFolder);
|
||||
createParamtersTab(tabFolder);
|
||||
createScopeTab(tabFolder);
|
||||
createLaunchingTab(tabFolder);
|
||||
}
|
||||
|
||||
public void save(IProblemWorkingCopy problem) {
|
||||
problemsComposite.save(problem);
|
||||
scopeComposite.save(problem);
|
||||
launchingComposite.save(problem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,4 +86,15 @@ public class CustomizeProblemComposite extends Composite {
|
|||
scopeComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING,
|
||||
true, false));
|
||||
}
|
||||
|
||||
private void createLaunchingTab(TabFolder tabFolder) {
|
||||
TabItem tabItem1 = new TabItem(tabFolder, SWT.NULL);
|
||||
tabItem1.setText(CodanUIMessages.CustomizeProblemComposite_LaunchingTab);
|
||||
Composite comp = new Composite(tabFolder, SWT.NONE);
|
||||
tabItem1.setControl(comp);
|
||||
comp.setLayout(new GridLayout());
|
||||
launchingComposite = new LaunchingTabComposite(comp, problem, resource);
|
||||
launchingComposite.setLayoutData(new GridData(SWT.BEGINNING,
|
||||
SWT.BEGINNING, true, false));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
/*******************************************************************************
|
||||
* 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.widgets;
|
||||
|
||||
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
||||
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.param.LaunchTypeProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
|
||||
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
||||
import org.eclipse.cdt.codan.internal.ui.preferences.LaunchModesPropertyPage;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferenceStore;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
/**
|
||||
* Composite to show problem launchPref
|
||||
*
|
||||
*/
|
||||
public class LaunchingTabComposite extends Composite {
|
||||
private LaunchModesPropertyPage page;
|
||||
private IProblem problem;
|
||||
private PreferenceStore prefStore;
|
||||
private LaunchTypeProblemPreference launchPref;
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
* @param problem
|
||||
* @param resource
|
||||
* @param style
|
||||
*/
|
||||
public LaunchingTabComposite(Composite parent, final IProblem problem,
|
||||
IResource resource) {
|
||||
super(parent, SWT.NONE);
|
||||
if (problem == null)
|
||||
throw new NullPointerException();
|
||||
this.setLayout(new GridLayout(2, false));
|
||||
this.problem = problem;
|
||||
this.prefStore = new PreferenceStore();
|
||||
IProblemPreference info = problem.getPreference();
|
||||
if (info == null || (!(info instanceof MapProblemPreference))) {
|
||||
Label label = new Label(this, 0);
|
||||
label.setText(CodanUIMessages.ParametersComposite_None);
|
||||
return;
|
||||
}
|
||||
LaunchTypeProblemPreference launchModes = (LaunchTypeProblemPreference) ((MapProblemPreference) info)
|
||||
.getChildDescriptor(LaunchTypeProblemPreference.KEY);
|
||||
if (launchModes == null) {
|
||||
launchPref = new LaunchTypeProblemPreference();
|
||||
} else {
|
||||
launchPref = (LaunchTypeProblemPreference) launchModes.clone();
|
||||
}
|
||||
initPrefStore();
|
||||
page = new LaunchModesPropertyPage(prefStore);
|
||||
page.noDefaultAndApplyButton();
|
||||
page.createControl(parent);
|
||||
page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
}
|
||||
|
||||
public void save(@SuppressWarnings("unused") IProblemWorkingCopy problem) {
|
||||
if (page != null)
|
||||
page.performOk();
|
||||
savePrefStore();
|
||||
}
|
||||
|
||||
private void savePrefStore() {
|
||||
if (launchPref == null)
|
||||
return;
|
||||
saveToPref(launchPref, page.getPreferenceStore());
|
||||
MapProblemPreference parentMap = (MapProblemPreference) problem
|
||||
.getPreference();
|
||||
parentMap.addChildDescriptor(launchPref);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param launchPref2
|
||||
* @param preferenceStore
|
||||
*/
|
||||
private void saveToPref(LaunchTypeProblemPreference launchPref,
|
||||
IPreferenceStore preferenceStore) {
|
||||
CheckerLaunchMode[] values = CheckerLaunchMode.values();
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
CheckerLaunchMode checkerLaunchMode = values[i];
|
||||
if (!preferenceStore.isDefault(checkerLaunchMode.name())) {
|
||||
launchPref.setRunningMode(checkerLaunchMode,
|
||||
preferenceStore.getBoolean(checkerLaunchMode.name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initPrefStore() {
|
||||
if (launchPref == null)
|
||||
return;
|
||||
prefStore.setDefault(
|
||||
CheckerLaunchMode.USE_PARENT.name(), true);
|
||||
CheckerLaunchMode[] values = CheckerLaunchMode.values();
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
CheckerLaunchMode checkerLaunchMode = values[i];
|
||||
prefStore.setValue(checkerLaunchMode.name(),
|
||||
launchPref.isRunningInMode(checkerLaunchMode));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the problem
|
||||
*/
|
||||
public IProblem getProblem() {
|
||||
return problem;
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
|||
import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.param.IProblemPreferenceCompositeDescriptor;
|
||||
import org.eclipse.cdt.codan.core.param.LaunchTypeProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.param.ListProblemPreference;
|
||||
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
||||
import org.eclipse.jface.dialogs.InputDialog;
|
||||
|
@ -66,7 +67,8 @@ public class ParametersComposite extends Composite {
|
|||
noDefaultAndApplyButton();
|
||||
((GridLayout) getFieldEditorParent().getLayout()).numColumns = 2;
|
||||
addField(new BooleanFieldEditor(PREF_ENABLED,
|
||||
CodanUIMessages.ParametersComposite_IsEnabled, getFieldEditorParent()));
|
||||
CodanUIMessages.ParametersComposite_IsEnabled,
|
||||
getFieldEditorParent()));
|
||||
String[][] entries = {
|
||||
{ CodanSeverity.Error.toString(),
|
||||
CodanSeverity.Error.toString() }, //
|
||||
|
@ -75,9 +77,11 @@ public class ParametersComposite extends Composite {
|
|||
{ CodanSeverity.Info.toString(),
|
||||
CodanSeverity.Info.toString() }, //
|
||||
};
|
||||
addField(new ComboFieldEditor(PREF_SEVERITY, CodanUIMessages.ParametersComposite_Severity,
|
||||
entries, getFieldEditorParent()));
|
||||
addField(new StringFieldEditor(PREF_MESSAGE, CodanUIMessages.ParametersComposite_MessagePattern,
|
||||
addField(new ComboFieldEditor(PREF_SEVERITY,
|
||||
CodanUIMessages.ParametersComposite_Severity, entries,
|
||||
getFieldEditorParent()));
|
||||
addField(new StringFieldEditor(PREF_MESSAGE,
|
||||
CodanUIMessages.ParametersComposite_MessagePattern,
|
||||
getFieldEditorParent()));
|
||||
IProblemPreference pref = problem.getPreference();
|
||||
createFieldEditorsForParameters(pref);
|
||||
|
@ -97,6 +101,8 @@ public class ParametersComposite extends Composite {
|
|||
return;
|
||||
if (info.getKey() == FileScopeProblemPreference.KEY)
|
||||
return; // skip the scope
|
||||
if (info.getKey() == LaunchTypeProblemPreference.KEY)
|
||||
return; // skip the launch
|
||||
switch (info.getType()) {
|
||||
case TYPE_STRING: {
|
||||
StringFieldEditor fe = new StringFieldEditor(
|
||||
|
@ -256,7 +262,7 @@ public class ParametersComposite extends Composite {
|
|||
}
|
||||
|
||||
private void initPrefStore(IProblemPreference desc) {
|
||||
if (desc == null)
|
||||
if (desc == null || desc.getValue() == null)
|
||||
return;
|
||||
String key = desc.getQualifiedKey();
|
||||
switch (desc.getType()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue