From 8ebbd32496cb2cdb7f7cd431602146e64f85bd93 Mon Sep 17 00:00:00 2001
From: Alena Laskavaia
Date: Thu, 16 Apr 2009 01:46:57 +0000
Subject: [PATCH] - updated property store to initialize from core
---
.../cdt/codan/core/CodanCorePlugin.java | 6 +
.../cdt/codan/core}/PreferenceConstants.java | 3 +-
.../core/builder/CodanPreferencesLoader.java | 145 ++++++++
.../core/model/AbstractIndexAstChecker.java | 7 +-
.../cdt/codan/core/model/CheckersRegisry.java | 96 +++--
.../cdt/codan/core/model/CodanProblem.java | 10 +
.../core/model/CodanProblemCategory.java | 57 ++-
.../cdt/codan/core/model/ErrorReporter.java | 4 +-
.../cdt/codan/core/model/IProblem.java | 3 +-
.../codan/core/model/IProblemCategory.java | 14 +-
.../cdt/codan/core/model/IProblemElement.java | 19 +
.../codan/core/model/IProblemsProfile.java | 23 ++
.../cdt/codan/core/model/ProblemsProfile.java | 101 ++++++
.../ui/preferences/BuildPropertyPage.java | 17 +-
.../ui/preferences/CheckedTreeEditor.java | 110 +-----
.../ui/preferences/CodanPreferencePage.java | 7 +-
.../preferences/FieldEditorOverlayPage.java | 172 +++++----
.../internal/ui/preferences/OverlayPage.java | 334 ------------------
.../ui/preferences/PreferenceInitializer.java | 1 +
.../ui/preferences/ProblemsTreeEditor.java | 134 +++++--
.../ui/preferences/PropertyStore.java | 234 ------------
.../cdt/codan/ui/actions/RunCodeAnalysis.java | 11 +-
22 files changed, 684 insertions(+), 824 deletions(-)
rename codan/{org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences => org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core}/PreferenceConstants.java (88%)
create mode 100644 codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanPreferencesLoader.java
create mode 100644 codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemElement.java
create mode 100644 codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemsProfile.java
create mode 100644 codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemsProfile.java
delete mode 100644 codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/OverlayPage.java
delete mode 100644 codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PropertyStore.java
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java
index 1810762e144..00b554abd86 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java
@@ -3,6 +3,8 @@ package org.eclipse.cdt.codan.core;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.framework.BundleContext;
/**
@@ -20,6 +22,10 @@ public class CodanCorePlugin extends Plugin {
public CodanCorePlugin() {
}
+ public IEclipsePreferences getStorePreferences() {
+ return new InstanceScope().getNode(PLUGIN_ID);
+ }
+
/*
* (non-Javadoc)
*
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceConstants.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java
similarity index 88%
rename from codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceConstants.java
rename to codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java
index fc685504842..a309ae3751a 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceConstants.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java
@@ -8,11 +8,12 @@
* Contributors:
* Alena Laskavaia - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.codan.internal.ui.preferences;
+package org.eclipse.cdt.codan.core;
/**
* Constant definitions for plug-in preferences
*/
public class PreferenceConstants {
public static final String P_RUN_ON_BUILD = "booleanPreference";
+ public static final String P_PROBLEMS = "problems";
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanPreferencesLoader.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanPreferencesLoader.java
new file mode 100644
index 00000000000..7419498d433
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanPreferencesLoader.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.core.builder;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.cdt.codan.core.model.CodanProblem;
+import org.eclipse.cdt.codan.core.model.CodanSeverity;
+import org.eclipse.cdt.codan.core.model.IProblem;
+import org.eclipse.cdt.codan.core.model.IProblemsProfile;
+
+/**
+ * @author Alena
+ *
+ */
+public class CodanPreferencesLoader {
+ private static String LIST_SEP = ",";
+ private IProblemsProfile baseModel;
+
+ /**
+ * @param workspaceProfile
+ */
+ public CodanPreferencesLoader(IProblemsProfile profile) {
+ setInput(profile);
+ }
+
+ /**
+ *
+ */
+ public CodanPreferencesLoader() {
+ }
+
+ public void setInput(Object model) {
+ baseModel = (IProblemsProfile) model;
+ }
+
+ /**
+ * Stored as element=true|false,...
+ *
+ * @param stringList
+ * @return
+ */
+ public Object modelFromString(String stringList) {
+ String[] arr = stringList.split(LIST_SEP);
+ for (int i = 0; i < arr.length; i++) {
+ String elem = arr[i];
+ String[] pair = elem.split("=", 2);
+ if (pair.length == 0)
+ continue;
+ String id = pair[0];
+ IProblem p = problemFromString(id);
+ if (p == null) {
+ System.err.println("cannot find '" + id + "'");
+ continue;
+ }
+ if (pair.length == 1) {
+ ((CodanProblem) p).setEnabled(true);
+ } else {
+ String check = pair[1];
+ Boolean c = Boolean.valueOf(check);
+ ((CodanProblem) p).setEnabled(c);
+ }
+ }
+ return baseModel;
+ }
+
+ protected String problemToString(Object element) {
+ IProblem p = ((IProblem) element);
+ return p.getId() + ":" + p.getSeverity();
+ }
+
+ protected IProblem problemFromString(String string) {
+ String[] pair = string.split(":");
+ if (pair.length == 0)
+ return null;
+ String id = pair[0];
+ String arg = "";
+ if (pair.length > 1) {
+ arg = pair[1];
+ }
+ CodanSeverity sev;
+ try {
+ sev = CodanSeverity.valueOf(arg);
+ } catch (RuntimeException e) {
+ sev = CodanSeverity.Warning;
+ }
+ IProblem prob = baseModel.findProblem(id);
+ if (prob instanceof CodanProblem) {
+ ((CodanProblem) prob).setSeverity(sev);
+ }
+ return prob;
+ }
+
+ /**
+ * Combines the given list of items into a single string. This method is the
+ * converse of parseString
.
+ *
+ * Subclasses may implement this method.
+ *
+ *
+ * @return the combined string
+ * @see #parseString
+ */
+ public String modelToString(Object model) {
+ StringBuffer buf = new StringBuffer();
+ Map
*/
-public class CheckedTreeEditor extends FieldEditor implements
+public abstract class CheckedTreeEditor extends FieldEditor implements
ICheckStateListener {
/**
* The list widget; null
if none (before creation or after
@@ -49,7 +45,6 @@ public class CheckedTreeEditor extends FieldEditor implements
private CheckboxTreeViewer treeViewer;
private Composite listParent;
private boolean isValid;
- private static String LIST_SEP = ",";
private boolean emptySelectionAllowed = false;
/**
@@ -121,10 +116,16 @@ public class CheckedTreeEditor extends FieldEditor implements
protected void doLoad() {
if (getTreeControl() != null) {
String s = getPreferenceStore().getString(getPreferenceName());
- setTreeData(parseString(s));
+ getViewer().setInput(modelFromString(s));
}
}
+ /**
+ * @param s
+ * @return
+ */
+ protected abstract Object modelFromString(String s);
+
Control getTreeControl() {
if (treeViewer == null)
return null;
@@ -135,23 +136,6 @@ public class CheckedTreeEditor extends FieldEditor implements
return treeViewer;
}
- /**
- * @param map
- */
- private void setTreeData(Map checked) {
- for (Iterator iter = checked.keySet().iterator(); iter.hasNext();) {
- Object element = iter.next();
- if (element != null) {
- Boolean state = checked.get(element);
- treeViewer.setChecked(element, state);
- checkStateChanged(new CheckStateChangedEvent(treeViewer,
- element, state));
- }
- }
- }
-
-
-
/**
* @Override
* @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
@@ -206,7 +190,7 @@ public class CheckedTreeEditor extends FieldEditor implements
treeViewer.refresh();
String s = getPreferenceStore().getDefaultString(
getPreferenceName());
- setTreeData(parseString(s));
+ getViewer().setInput(modelFromString(s));
}
}
@@ -214,7 +198,7 @@ public class CheckedTreeEditor extends FieldEditor implements
* (non-Javadoc) Method declared on FieldEditor.
*/
protected void doStore() {
- String s = unparseTree();
+ String s = modelToString(getViewer().getInput());
if (s != null) {
getPreferenceStore().setValue(getPreferenceName(), s);
}
@@ -266,35 +250,6 @@ public class CheckedTreeEditor extends FieldEditor implements
return treeViewer.getControl().getShell();
}
- /**
- * Stored as element=true|false,...
- *
- * @param stringList
- * @return
- */
- public Map parseString(String stringList) {
- Map data = new HashMap();
- String[] arr = stringList.split(LIST_SEP);
- for (int i = 0; i < arr.length; i++) {
- String elem = arr[i];
- String[] pair = elem.split("=", 2);
- if (pair.length == 0)
- continue;
- String id = pair[0];
- if (pair.length == 1) {
- data.put(parseObject(id), true);
- continue;
- }
- String check = pair[1];
- data.put(parseObject(id), Boolean.valueOf(check));
- }
- return data;
- }
-
- protected Object parseObject(String string) {
- return string;
- }
-
/*
* (non-Javadoc) Method declared on FieldEditor.
*/
@@ -320,49 +275,9 @@ public class CheckedTreeEditor extends FieldEditor implements
*
*
* @return the combined string
- * @see #parseString
+ * @see #stringToModel
*/
- protected String unparseTree() {
- StringBuffer buf = new StringBuffer();
- Map map = fillElementsFromUi(treeViewer.getInput(),
- new HashMap());
- for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
- Object element = iterator.next();
- buf.append(unparseElement(element));
- buf.append('=');
- buf.append(map.get(element));
- if (iterator.hasNext())
- buf.append(LIST_SEP);
- }
- return buf.toString();
- }
-
- /**
- * @param element
- * @return
- */
- protected String unparseElement(Object element) {
- return element.toString();
- }
-
- /**
- * @param root
- */
- public Map fillElementsFromUi(Object root,
- Map checked) {
-
- Object[] children = getContentProvider().getChildren(root);
- if (children.length == 0) {
- checked.put(root, treeViewer.getChecked(root));
- } else {
- for (int i = 0; i < children.length; i++) {
- Object object = children[i];
- fillElementsFromUi(object, checked);
- }
- }
-
- return checked;
- }
+ protected abstract String modelToString(Object model);
protected void createControl(Composite parent) {
GridLayout ly = (GridLayout) parent.getLayout();
@@ -406,7 +321,6 @@ public class CheckedTreeEditor extends FieldEditor implements
return true;
}
-
public final boolean isEmptySelectionAllowed() {
return emptySelectionAllowed;
}
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java
index 0649f26700e..1bcfe36f0ab 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java
@@ -11,6 +11,8 @@
package org.eclipse.cdt.codan.internal.ui.preferences;
import org.eclipse.cdt.codan.core.CodanCorePlugin;
+import org.eclipse.cdt.codan.core.model.CheckersRegisry;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
@@ -46,7 +48,10 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
*/
public void createFieldEditors() {
CheckedTreeEditor checkedTreeEditor = new ProblemsTreeEditor(
- getFieldEditorParent());
+ getFieldEditorParent(), isPropertyPage() ? CheckersRegisry
+ .getInstance().getResourceProfile(
+ (IResource) getElement()) : CheckersRegisry
+ .getInstance().getWorkspaceProfile());
addField(checkedTreeEditor);
}
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java
index 441f1b5f9e2..dee50942ffb 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java
@@ -14,10 +14,15 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.cdt.codan.core.CodanCorePlugin;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceNode;
@@ -37,43 +42,39 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbenchPropertyPage;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
/**
* @author Berthold Daum
*/
-public abstract class FieldEditorOverlayPage
- extends FieldEditorPreferencePage
- implements IWorkbenchPropertyPage {
-
- /*** Name of resource property for the selection of workbench or project settings ***/
+public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
+ implements IWorkbenchPropertyPage {
+ /***
+ * Name of resource property for the selection of workbench or project
+ * settings
+ ***/
public static final String USEPROJECTSETTINGS = "useProjectSettings"; //$NON-NLS-1$
-
private static final String FALSE = "false"; //$NON-NLS-1$
private static final String TRUE = "true"; //$NON-NLS-1$
-
// Stores all created field editors
private List editors = new ArrayList();
-
// Stores owning element of properties
private IAdaptable element;
-
// Additional buttons for property pages
- private Button useWorkspaceSettingsButton,
- useProjectSettingsButton,
- configureButton;
-
+ private Button useWorkspaceSettingsButton, useProjectSettingsButton,
+ configureButton;
// Overlay preference store for property pages
private IPreferenceStore overlayStore;
-
// The image descriptor of this pages title image
private ImageDescriptor image;
-
// Cache for page id
private String pageId;
/**
* Constructor
- * @param style - layout style
+ *
+ * @param style
+ * - layout style
*/
public FieldEditorOverlayPage(int style) {
super(style);
@@ -81,8 +82,11 @@ public abstract class FieldEditorOverlayPage
/**
* Constructor
- * @param title - title string
- * @param style - layout style
+ *
+ * @param title
+ * - title string
+ * @param style
+ * - layout style
*/
public FieldEditorOverlayPage(String title, int style) {
super(title, style);
@@ -90,28 +94,30 @@ public abstract class FieldEditorOverlayPage
/**
* Constructor
- * @param title - title string
- * @param image - title image
- * @param style - layout style
+ *
+ * @param title
+ * - title string
+ * @param image
+ * - title image
+ * @param style
+ * - layout style
*/
- public FieldEditorOverlayPage(
- String title,
- ImageDescriptor image,
- int style) {
+ public FieldEditorOverlayPage(String title, ImageDescriptor image, int style) {
super(title, image, style);
this.image = image;
}
/**
* Returns the id of the current preference page as defined in plugin.xml
- * Subclasses must implement.
+ * Subclasses must implement.
*
* @return - the qualifier
*/
protected abstract String getPageId();
/**
- * Receives the object that owns the properties shown in this property page.
+ * Receives the object that owns the properties shown in this property page.
+ *
* @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
*/
public void setElement(IAdaptable element) {
@@ -120,6 +126,7 @@ public abstract class FieldEditorOverlayPage
/**
* Delivers the object that owns the properties shown in this property page.
+ *
* @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
*/
public IAdaptable getElement() {
@@ -128,15 +135,16 @@ public abstract class FieldEditorOverlayPage
/**
* Returns true if this instance represents a property page
+ *
* @return - true for property pages, false for preference pages
*/
public boolean isPropertyPage() {
return getElement() != null;
}
- /**
- * We override the addField method. This allows us to store each field editor added by subclasses
- * in a list for later processing.
+ /**
+ * We override the addField method. This allows us to store each field
+ * editor added by subclasses in a list for later processing.
*
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#addField(org.eclipse.jface.preference.FieldEditor)
*/
@@ -146,9 +154,9 @@ public abstract class FieldEditorOverlayPage
}
/**
- * We override the createControl method.
- * In case of property pages we create a new PropertyStore as local preference store.
- * After all control have been create, we enable/disable these controls.
+ * We override the createControl method. In case of property pages we create
+ * a new PropertyStore as local preference store. After all control have
+ * been create, we enable/disable these controls.
*
* @see org.eclipse.jface.preference.PreferencePage#createControl()
*/
@@ -158,11 +166,12 @@ public abstract class FieldEditorOverlayPage
// Cache the page id
pageId = getPageId();
// Create an overlay preference store and fill it with properties
- overlayStore =
- new PropertyStore(
- (IResource) getElement(),
- super.getPreferenceStore(),
- pageId);
+ ProjectScope ps = new ProjectScope((IProject) getElement());
+ ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps,
+ CodanCorePlugin.PLUGIN_ID);
+ scoped.setSearchContexts(new IScopeContext[] { ps,
+ new InstanceScope() });
+ overlayStore = scoped;
// Set overlay store as current preference store
}
super.createControl(parent);
@@ -171,9 +180,9 @@ public abstract class FieldEditorOverlayPage
updateFieldEditors();
}
- /**
- * We override the createContents method.
- * In case of property pages we insert two radio buttons at the top of the page.
+ /**
+ * We override the createContents method. In case of property pages we
+ * insert two radio buttons at the top of the page.
*
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@@ -184,8 +193,11 @@ public abstract class FieldEditorOverlayPage
}
/**
- * Creates and initializes a selection group with two choice buttons and one push button.
- * @param parent - the parent composite
+ * 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);
@@ -197,10 +209,13 @@ public abstract class FieldEditorOverlayPage
Composite radioGroup = new Composite(comp, SWT.NONE);
radioGroup.setLayout(new GridLayout());
radioGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- useWorkspaceSettingsButton = createRadioButton(radioGroup, Messages.getString("OverlayPage.Use_Workspace_Settings")); //$NON-NLS-1$
- useProjectSettingsButton = createRadioButton(radioGroup, Messages.getString("OverlayPage.Use_Project_Settings")); //$NON-NLS-1$
+ useWorkspaceSettingsButton = createRadioButton(radioGroup, Messages
+ .getString("OverlayPage.Use_Workspace_Settings")); //$NON-NLS-1$
+ useProjectSettingsButton = createRadioButton(radioGroup, Messages
+ .getString("OverlayPage.Use_Project_Settings")); //$NON-NLS-1$
configureButton = new Button(comp, SWT.PUSH);
- configureButton.setText(Messages.getString("OverlayPage.Configure_Workspace_Settings")); //$NON-NLS-1$
+ configureButton.setText(Messages
+ .getString("OverlayPage.Configure_Workspace_Settings")); //$NON-NLS-1$
configureButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
configureWorkspaceSettings();
@@ -208,9 +223,9 @@ public abstract class FieldEditorOverlayPage
});
// Set workspace/project radio buttons
try {
- String use =
- ((IResource) getElement()).getPersistentProperty(
- new QualifiedName(pageId, USEPROJECTSETTINGS));
+ String use = ((IResource) getElement())
+ .getPersistentProperty(new QualifiedName(pageId,
+ USEPROJECTSETTINGS));
if (TRUE.equals(use)) {
useProjectSettingsButton.setSelection(true);
configureButton.setEnabled(false);
@@ -223,8 +238,11 @@ public abstract class FieldEditorOverlayPage
/**
* Convenience method creating a radio button
- * @param parent - the parent composite
- * @param label - the button label
+ *
+ * @param parent
+ * - the parent composite
+ * @param label
+ * - the button label
* @return - the new button
*/
private Button createRadioButton(Composite parent, String label) {
@@ -232,8 +250,8 @@ public abstract class FieldEditorOverlayPage
button.setText(label);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
- configureButton.setEnabled(
- button == useWorkspaceSettingsButton);
+ configureButton
+ .setEnabled(button == useWorkspaceSettingsButton);
updateFieldEditors();
}
});
@@ -241,8 +259,9 @@ public abstract class FieldEditorOverlayPage
}
/**
- * Returns in case of property pages the overlay store,
- * in case of preference pages the standard preference store
+ * Returns in case of property pages the overlay store, in case of
+ * preference pages the standard preference store
+ *
* @see org.eclipse.jface.preference.PreferencePage#getPreferenceStore()
*/
public IPreferenceStore getPreferenceStore() {
@@ -255,15 +274,17 @@ public abstract class FieldEditorOverlayPage
* Enables or disables the field editors and buttons of this page
*/
private void updateFieldEditors() {
- // We iterate through all field editors
+ // We iterate through all field editors
boolean enabled = useProjectSettingsButton.getSelection();
updateFieldEditors(enabled);
}
/**
- * Enables or disables the field editors and buttons of this page
- * Subclasses may override.
- * @param enabled - true if 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 = getFieldEditorParent();
@@ -274,10 +295,10 @@ public abstract class FieldEditorOverlayPage
}
}
- /**
- * We override the performOk method. In case of property pages we copy the values in the
- * overlay store into the property values of the selected project.
- * We also save the state of the radio buttons.
+ /**
+ * We override the performOk method. In case of property pages we copy the
+ * values in the overlay store into the property values of the selected
+ * project. We also save the state of the radio buttons.
*
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
*/
@@ -287,11 +308,10 @@ public abstract class FieldEditorOverlayPage
// Save state of radiobuttons in project properties
IResource resource = (IResource) getElement();
try {
- String value =
- (useProjectSettingsButton.getSelection()) ? TRUE : FALSE;
- resource.setPersistentProperty(
- new QualifiedName(pageId, USEPROJECTSETTINGS),
- value);
+ String value = (useProjectSettingsButton.getSelection()) ? TRUE
+ : FALSE;
+ resource.setPersistentProperty(new QualifiedName(pageId,
+ USEPROJECTSETTINGS), value);
} catch (CoreException e) {
}
}
@@ -320,8 +340,8 @@ public abstract class FieldEditorOverlayPage
protected void configureWorkspaceSettings() {
try {
// create a new instance of the current class
- IPreferencePage page =
- (IPreferencePage) this.getClass().newInstance();
+ IPreferencePage page = (IPreferencePage) this.getClass()
+ .newInstance();
page.setTitle(getTitle());
page.setImageDescriptor(image);
// and show it
@@ -335,15 +355,18 @@ public abstract class FieldEditorOverlayPage
/**
* Show a single preference pages
- * @param id - the preference page identification
- * @param page - the preference page
+ *
+ * @param id
+ * - the preference page identification
+ * @param page
+ * - the preference page
*/
protected void showPreferencePage(String id, IPreferencePage page) {
final IPreferenceNode targetNode = new PreferenceNode(id, page);
PreferenceManager manager = new PreferenceManager();
manager.addToRoot(targetNode);
- final PreferenceDialog dialog =
- new PreferenceDialog(getControl().getShell(), manager);
+ final PreferenceDialog dialog = new PreferenceDialog(getControl()
+ .getShell(), manager);
BusyIndicator.showWhile(getControl().getDisplay(), new Runnable() {
public void run() {
dialog.create();
@@ -352,5 +375,4 @@ public abstract class FieldEditorOverlayPage
}
});
}
-
}
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/OverlayPage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/OverlayPage.java
deleted file mode 100644
index ddcac1652fb..00000000000
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/OverlayPage.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003 Berthold Daum.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * Berthold Daum
- *******************************************************************************/
-package org.eclipse.cdt.codan.internal.ui.preferences;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.jface.preference.IPreferenceNode;
-import org.eclipse.jface.preference.IPreferencePage;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceDialog;
-import org.eclipse.jface.preference.PreferenceManager;
-import org.eclipse.jface.preference.PreferenceNode;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.swt.custom.CTabFolder;
-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.Control;
-import org.eclipse.swt.widgets.TabFolder;
-import org.eclipse.ui.dialogs.PropertyPage;
-import org.eclipse.ui.part.PageBook;
-
-/**
- * @author Berthold Daum
- */
-public abstract class OverlayPage extends PropertyPage {
-
- /*** Name of resource property for the selection of workbench or project settings ***/
- public static final String USEPROJECTSETTINGS = "useProjectSettings"; //$NON-NLS-1$
-
- private static final String FALSE = "false"; //$NON-NLS-1$
- private static final String TRUE = "true"; //$NON-NLS-1$
-
- // Additional buttons for property pages
- private Button useWorkspaceSettingsButton,
- useProjectSettingsButton,
- configureButton;
-
- // Overlay preference store for property pages
- private PropertyStore overlayStore;
-
- // The image descriptor of this pages title image
- private ImageDescriptor image;
-
- // Cache for page id
- private String pageId;
-
- // Container for subclass controls
- private Composite contents;
-
- /**
- * Constructor
- */
- public OverlayPage() {
- super();
- }
-
- /**
- * Constructor
- * @param title - title string
- */
- public OverlayPage(String title) {
- super();
- setTitle(title);
- }
-
- /**
- * Constructor
- * @param title - title string
- * @param image - title image
- */
- public OverlayPage(String title, ImageDescriptor image) {
- super();
- setTitle(title);
- setImageDescriptor(image);
- this.image = image;
- }
-
- /**
- * Returns the id of the current preference page as defined in plugin.xml
- * Subclasses must implement.
- *
- * @return - the qualifier
- */
- protected abstract String getPageId();
-
- /**
- * Returns true if this instance represents a property page
- * @return - true for property pages, false for preference pages
- */
- public boolean isPropertyPage() {
- return getElement() != null;
- }
-
- /**
- * We need to implement createContents method. In case of property pages we insert two radio buttons
- * and a push button at the top of the page. Below this group we create a new composite for the contents
- * created by subclasses.
- *
- * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
- */
- protected Control createContents(Composite parent) {
- if (isPropertyPage())
- createSelectionGroup(parent);
- contents = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- contents.setLayout(layout);
- contents.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- return contents;
- }
-
- /**
- * 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());
- radioGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- useWorkspaceSettingsButton = createRadioButton(radioGroup, Messages.getString("OverlayPage.Use_Workspace_Settings")); //$NON-NLS-1$
- useProjectSettingsButton = createRadioButton(radioGroup, Messages.getString("OverlayPage.Use_Project_Settings")); //$NON-NLS-1$
- configureButton = new Button(comp, SWT.PUSH);
- configureButton.setText(Messages.getString("OverlayPage.Configure_Workspace_Settings")); //$NON-NLS-1$
- configureButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- configureWorkspaceSettings();
- }
- });
- // Set workspace/project radio buttons
- try {
- String use =
- ((IResource) getElement()).getPersistentProperty(
- new QualifiedName(pageId, USEPROJECTSETTINGS));
- if (TRUE.equals(use)) {
- useProjectSettingsButton.setSelection(true);
- configureButton.setEnabled(false);
- } else
- useWorkspaceSettingsButton.setSelection(true);
- } catch (CoreException e) {
- useWorkspaceSettingsButton.setSelection(true);
- }
- }
-
- /**
- * 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() {
- public void widgetSelected(SelectionEvent e) {
- configureButton.setEnabled(
- button == useWorkspaceSettingsButton);
- setControlsEnabled();
- }
- });
- return button;
- }
-
- /**
- * In case of property pages we create a new PropertyStore as local overlay store.
- * After all controls have been create, we enable/disable these controls
- *
- * @see org.eclipse.jface.preference.PreferencePage#createControl()
- */
- public void createControl(Composite parent) {
- // Special treatment for property pages
- if (isPropertyPage()) {
- // Cache the page id
- pageId = getPageId();
- // Create an overlay preference store and fill it with properties
- overlayStore =
- new PropertyStore(
- (IResource) getElement(),
- super.getPreferenceStore(),
- pageId);
- // Set overlay store as current preference store
- }
- super.createControl(parent);
- // Update enablement of all subclass controls
- if (isPropertyPage())
- setControlsEnabled();
- }
-
- /*
- * Returns in case of property pages the overlay store - otherwise the standard preference store
- * @see org.eclipse.jface.preference.PreferencePage#getPreferenceStore()
- */
- public IPreferenceStore getPreferenceStore() {
- if (isPropertyPage())
- return overlayStore;
- return super.getPreferenceStore();
- }
-
- /**
- * Enables or disables the controls of this page
- */
- private void setControlsEnabled() {
- boolean enabled = useProjectSettingsButton.getSelection();
- setControlsEnabled(enabled);
- }
-
- /**
- * Enables or disables the controls of this page
- * Subclasses may override.
- *
- * @param enabled - true if controls shall be enabled
- */
- protected void setControlsEnabled(boolean enabled) {
- setControlsEnabled(contents, enabled);
- }
-
- /**
- * Enables or disables a tree of controls starting at the specified root.
- * We spare tabbed notebooks and pagebooks to allow for user navigation.
- *
- * @param root - the root composite
- * @param enabled - true if controls shall be enabled
- */
- private void setControlsEnabled(Composite root, boolean enabled) {
- Control[] children = root.getChildren();
- for (int i = 0; i < children.length; i++) {
- Control child = children[i];
- if (!(child instanceof CTabFolder) && !(child instanceof TabFolder) && !(child instanceof PageBook))
- child.setEnabled(enabled);
- if (child instanceof Composite)
- setControlsEnabled((Composite) child, enabled);
- }
- }
-
- /**
- * We override the performOk method. In case of property pages
- * we save the state of the radio buttons.
- *
- * @see org.eclipse.jface.preference.IPreferencePage#performOk()
- */
- public boolean performOk() {
- boolean result = super.performOk();
- if (result && isPropertyPage()) {
- // Save state of radiobuttons in project properties
- IResource resource = (IResource) getElement();
- try {
- String value =
- (useProjectSettingsButton.getSelection()) ? TRUE : FALSE;
- resource.setPersistentProperty(
- new QualifiedName(pageId, USEPROJECTSETTINGS),
- value);
- } catch (CoreException e) {
- }
- }
- return result;
- }
-
- /**
- * We override the performDefaults method. In case of property pages we
- * switch back to the workspace settings and disable the page controls.
- *
- * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
- */
- protected void performDefaults() {
- if (isPropertyPage()) {
- useWorkspaceSettingsButton.setSelection(true);
- useProjectSettingsButton.setSelection(false);
- configureButton.setEnabled(true);
- setControlsEnabled();
- }
- super.performDefaults();
- }
-
- /**
- * Creates a new preferences page and opens it
- */
- protected void configureWorkspaceSettings() {
- try {
- // create a new instance of the current class
- IPreferencePage page =
- (IPreferencePage) this.getClass().newInstance();
- page.setTitle(getTitle());
- page.setImageDescriptor(image);
- // and show it
- showPreferencePage(pageId, page);
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Show a single preference pages
- * @param id - the preference page identification
- * @param page - the preference page
- */
- protected void showPreferencePage(String id, IPreferencePage page) {
- final IPreferenceNode targetNode = new PreferenceNode(id, page);
- PreferenceManager manager = new PreferenceManager();
- manager.addToRoot(targetNode);
- final PreferenceDialog dialog =
- new PreferenceDialog(getControl().getShell(), manager);
- BusyIndicator.showWhile(getControl().getDisplay(), new Runnable() {
- public void run() {
- dialog.create();
- dialog.setMessage(targetNode.getLabelText());
- dialog.open();
- }
- });
- }
-
-}
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java
index a2adeb4f82e..43620980c77 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.preferences;
+import org.eclipse.cdt.codan.core.PreferenceConstants;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java
index cca679dc72c..a280447b0a0 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java
@@ -10,14 +10,16 @@
*******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.preferences;
-import org.eclipse.cdt.codan.core.model.CheckersRegisry;
+import org.eclipse.cdt.codan.core.PreferenceConstants;
+import org.eclipse.cdt.codan.core.builder.CodanPreferencesLoader;
import org.eclipse.cdt.codan.core.model.CodanProblem;
-import org.eclipse.cdt.codan.core.model.CodanSeverity;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemCategory;
+import org.eclipse.cdt.codan.core.model.IProblemsProfile;
import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.ICheckStateProvider;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -28,9 +30,70 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TreeColumn;
public class ProblemsTreeEditor extends CheckedTreeEditor {
+ private CodanPreferencesLoader codanPreferencesLoader = new CodanPreferencesLoader();
+
public ProblemsTreeEditor() {
super();
- // TODO Auto-generated constructor stub
+ }
+
+ class ProblemsCheckStateProvider implements ICheckStateProvider {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ICheckStateProvider#isChecked(java.lang
+ * .Object)
+ */
+ public boolean isChecked(Object element) {
+ if (element instanceof IProblem) {
+ IProblem p = (IProblem) element;
+ return p.isEnabled();
+ }
+ if (element instanceof IProblemCategory) {
+ // checked if at least one is checked (buy grayed)
+ IProblemCategory p = (IProblemCategory) element;
+ Object[] children = p.getChildren();
+ for (int i = 0; i < children.length; i++) {
+ Object object = children[i];
+ if (isChecked(object)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ICheckStateProvider#isGrayed(java.lang.
+ * Object)
+ */
+ public boolean isGrayed(Object element) {
+ if (element instanceof IProblem) {
+ return false;
+ }
+ if (element instanceof IProblemCategory) {
+ // checked if at least one is checked (buy grayed)
+ IProblemCategory p = (IProblemCategory) element;
+ Object[] children = p.getChildren();
+ boolean all_checked = true;
+ boolean all_unchecked = true;
+ for (int i = 0; i < children.length; i++) {
+ Object object = children[i];
+ if (isChecked(object)) {
+ all_unchecked = false;
+ } else {
+ all_checked = false;
+ }
+ }
+ if (all_checked || all_unchecked)
+ return false;
+ return true;
+ }
+ return false;
+ }
}
class ProblemsContentProvider implements IContentProvider,
@@ -49,6 +112,10 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
if (parentElement instanceof IProblemCategory) {
return ((IProblemCategory) parentElement).getChildren();
}
+ if (parentElement instanceof IProblemsProfile) {
+ return ((IProblemsProfile) parentElement).getRoot()
+ .getChildren();
+ }
return new Object[0];
}
@@ -89,35 +156,6 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
}
}
- @Override
- protected String unparseElement(Object element) {
- IProblem p = ((IProblem) element);
- return p.getId() + ":" + p.getSeverity();
- }
-
- @Override
- protected Object parseObject(String string) {
- String[] pair = string.split(":");
- if (pair.length == 0)
- return null;
- String id = pair[0];
- String arg = "";
- if (pair.length > 1) {
- arg = pair[1];
- }
- CodanSeverity sev;
- try {
- sev = CodanSeverity.valueOf(arg);
- } catch (RuntimeException e) {
- sev = CodanSeverity.Warning;
- }
- IProblem prob = CheckersRegisry.getInstance().findProblem(id);
- if (prob instanceof CodanProblem) {
- ((CodanProblem) prob).setSeverity(sev);
- }
- return prob;
- }
-
public void checkStateChanged(CheckStateChangedEvent event) {
Object element = event.getElement();
if (element instanceof CodanProblem) {
@@ -125,13 +163,14 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
}
}
- public ProblemsTreeEditor(Composite parent) {
- super("problems", "Problems", parent);
+ public ProblemsTreeEditor(Composite parent, IProblemsProfile profile) {
+ super(PreferenceConstants.P_PROBLEMS, "Problems", parent);
setEmptySelectionAllowed(true);
getTreeViewer().getTree().setHeaderVisible(true);
// getTreeViewer().getTree().
getTreeViewer().setContentProvider(new ProblemsContentProvider());
getTreeViewer().setLabelProvider(new ProblemsLabelProvider());
+ getTreeViewer().setCheckStateProvider(new ProblemsCheckStateProvider());
// column Name
TreeColumn column = new TreeColumn(getTreeViewer().getTree(), SWT.NONE);
column.setWidth(300);
@@ -140,7 +179,30 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
TreeColumn column2 = new TreeColumn(getTreeViewer().getTree(), SWT.NONE);
column2.setWidth(100);
column2.setText("Severity");
- getTreeViewer().setInput(
- CheckersRegisry.getInstance().getProblemsTree());
+ codanPreferencesLoader.setInput(profile);
+ getViewer().setInput(profile);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.cdt.codan.internal.ui.preferences.CheckedTreeEditor#
+ * modelFromString(java.lang.String)
+ */
+ @Override
+ protected Object modelFromString(String s) {
+ return codanPreferencesLoader.modelFromString(s);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.cdt.codan.internal.ui.preferences.CheckedTreeEditor#modelToString
+ * (java.lang.Object)
+ */
+ @Override
+ protected String modelToString(Object model) {
+ return codanPreferencesLoader.modelToString(model);
}
}
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PropertyStore.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PropertyStore.java
deleted file mode 100644
index cb30907d4e2..00000000000
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PropertyStore.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003 Berthold Daum.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * Berthold Daum
- *******************************************************************************/
-
-package org.eclipse.cdt.codan.internal.ui.preferences;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceStore;
-
-/**
- * @author Berthold Daum
- *
- */
-public class PropertyStore extends PreferenceStore {
-
- private IResource resource;
- private IPreferenceStore workbenchStore;
- private String pageId;
- private boolean inserting = false;
-
- public PropertyStore(
- IResource resource,
- IPreferenceStore workbenchStore,
- String pageId) {
- this.resource = resource;
- this.workbenchStore = workbenchStore;
- this.pageId = pageId;
- }
-
- /*** Write modified values back to properties ***/
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPersistentPreferenceStore#save()
- */
- public void save() throws IOException {
- writeProperties();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferenceStore#save(java.io.OutputStream, java.lang.String)
- */
- public void save(OutputStream out, String header) throws IOException {
- writeProperties();
- }
-
- /**
- * Writes modified preferences into resource properties.
- */
- private void writeProperties() throws IOException {
- String[] preferences = super.preferenceNames();
- for (int i = 0; i < preferences.length; i++) {
- String name = preferences[i];
- try {
- setProperty(name, getString(name));
- } catch (CoreException e) {
- throw new IOException(Messages.getString("PropertyStore.Cannot_write_resource_property") + name); //$NON-NLS-1$
- }
- }
- }
-
- /**
- * Convenience method to set a property
- * @param name - the preference name
- * @param value - the property value or null to delete the property
- * @throws CoreException
- */
- private void setProperty(String name, String value) throws CoreException {
- resource.setPersistentProperty(new QualifiedName(pageId, name), value);
- }
-
- /*** Get default values (Delegate to workbench store) ***/
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultBoolean(java.lang.String)
- */
- public boolean getDefaultBoolean(String name) {
- return workbenchStore.getDefaultBoolean(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultDouble(java.lang.String)
- */
- public double getDefaultDouble(String name) {
- return workbenchStore.getDefaultDouble(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultFloat(java.lang.String)
- */
- public float getDefaultFloat(String name) {
- return workbenchStore.getDefaultFloat(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultInt(java.lang.String)
- */
- public int getDefaultInt(String name) {
- return workbenchStore.getDefaultInt(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultLong(java.lang.String)
- */
- public long getDefaultLong(String name) {
- return workbenchStore.getDefaultLong(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultString(java.lang.String)
- */
- public String getDefaultString(String name) {
- return workbenchStore.getDefaultString(name);
- }
-
- /*** Get property values ***/
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getBoolean(java.lang.String)
- */
- public boolean getBoolean(String name) {
- insertValue(name);
- return super.getBoolean(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getDouble(java.lang.String)
- */
- public double getDouble(String name) {
- insertValue(name);
- return super.getDouble(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getFloat(java.lang.String)
- */
- public float getFloat(String name) {
- insertValue(name);
- return super.getFloat(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getInt(java.lang.String)
- */
- public int getInt(String name) {
- insertValue(name);
- return super.getInt(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getLong(java.lang.String)
- */
- public long getLong(String name) {
- insertValue(name);
- return super.getLong(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#getString(java.lang.String)
- */
- public String getString(String name) {
- insertValue(name);
- return super.getString(name);
- }
-
- /**
- * @param name
- */
- private synchronized void insertValue(String name) {
- if (inserting)
- return;
- if (super.contains(name))
- return;
- inserting = true;
- String prop = null;
- try {
- prop = getProperty(name);
- } catch (CoreException e) {
- }
- if (prop == null)
- prop = workbenchStore.getString(name);
- if (prop != null)
- setValue(name, prop);
- inserting = false;
- }
-
- /**
- * Convenience method to fetch a property
- * @param name - the preference name
- * @return - the property value
- * @throws CoreException
- */
- private String getProperty(String name) throws CoreException {
- return resource.getPersistentProperty(new QualifiedName(pageId, name));
- }
-
- /*** Misc ***/
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#contains(java.lang.String)
- */
- public boolean contains(String name) {
- return workbenchStore.contains(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#setToDefault(java.lang.String)
- */
- public void setToDefault(String name) {
- setValue(name, getDefaultString(name));
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.IPreferenceStore#isDefault(java.lang.String)
- */
- public boolean isDefault(String name) {
- String defaultValue = getDefaultString(name);
- if (defaultValue == null) return false;
- return defaultValue.equals(getString(name));
- }
-
-}
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java
index 5f8a439861f..39f52b6e0ce 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java
@@ -14,6 +14,7 @@ import java.util.Iterator;
import org.eclipse.cdt.codan.core.builder.CodanBuilder;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -25,7 +26,6 @@ public class RunCodeAnalysis implements IObjectActionDelegate {
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
// TODO Auto-generated method stub
-
}
public void run(IAction action) {
@@ -34,14 +34,17 @@ public class RunCodeAnalysis implements IObjectActionDelegate {
Object o = iterator.next();
if (o instanceof IResource) {
IResource res = (IResource) o;
- new CodanBuilder().new CodanResourceVisitor().visit(res);
+ try {
+ res.accept(new CodanBuilder().new CodanResourceVisitor());
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
}
-
}
public void selectionChanged(IAction action, ISelection selection) {
this.sel = selection;
-
}
}