mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-14 11:45:38 +02:00
- initial commit
This commit is contained in:
parent
10ffd0daca
commit
724390a35f
20 changed files with 2135 additions and 0 deletions
7
codan/org.eclipse.cdt.codan.ui/.classpath
Normal file
7
codan/org.eclipse.cdt.codan.ui/.classpath
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
28
codan/org.eclipse.cdt.codan.ui/.project
Normal file
28
codan/org.eclipse.cdt.codan.ui/.project
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.eclipse.cdt.codan.ui</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,8 @@
|
|||
#Fri Apr 03 21:34:42 EDT 2009
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
15
codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF
Normal file
15
codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF
Normal file
|
@ -0,0 +1,15 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Code Analyzers Framework
|
||||
Bundle-SymbolicName: org.eclipse.cdt.codan.ui; singleton:=true
|
||||
Bundle-Version: 1.0.0
|
||||
Bundle-Activator: org.eclipse.cdt.codan.ui.Activator
|
||||
Bundle-Vendor: Eclipse
|
||||
Require-Bundle: org.eclipse.ui,
|
||||
org.eclipse.core.runtime,
|
||||
org.eclipse.core.resources,
|
||||
org.eclipse.cdt.core;bundle-version="5.1.0",
|
||||
org.eclipse.cdt.codan.core;bundle-version="1.0.0"
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Bundle-ActivationPolicy: lazy
|
||||
|
5
codan/org.eclipse.cdt.codan.ui/build.properties
Normal file
5
codan/org.eclipse.cdt.codan.ui/build.properties
Normal file
|
@ -0,0 +1,5 @@
|
|||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = plugin.xml,\
|
||||
META-INF/,\
|
||||
.
|
65
codan/org.eclipse.cdt.codan.ui/plugin.xml
Normal file
65
codan/org.eclipse.cdt.codan.ui/plugin.xml
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.popupMenus">
|
||||
<objectContribution
|
||||
adaptable="true"
|
||||
objectClass="org.eclipse.core.resources.IProject"
|
||||
nameFilter="*"
|
||||
id="org.eclipse.cdt.codan.ui.runaction">
|
||||
<action
|
||||
label="Run Code Analysis"
|
||||
class="org.eclipse.cdt.codan.ui.actions.RunCodeAnalysis"
|
||||
menubarPath="additions"
|
||||
enablesFor="+"
|
||||
id="org.eclipse.cdt.codan.ui.actions.RunCodeAnalysis">
|
||||
</action>
|
||||
</objectContribution>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.preferencePages">
|
||||
<page
|
||||
category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
|
||||
class="org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage"
|
||||
id="org.eclipse.cdt.codan.ui.preferences.CodanPreferencePage"
|
||||
name="Code Analysis">
|
||||
</page>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.propertyPages">
|
||||
<page
|
||||
name="C/C++ Code Analysis "
|
||||
|
||||
class="org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage"
|
||||
id="org.eclipse.cdt.codan.ui.properties.codanProblemsPropertyPage">
|
||||
<enabledWhen>
|
||||
<instanceof
|
||||
value="org.eclipse.core.resources.IProject">
|
||||
</instanceof>
|
||||
</enabledWhen>
|
||||
</page>
|
||||
<page
|
||||
category="org.eclipse.cdt.codan.ui.properties.codanProblemsPropertyPage"
|
||||
class="org.eclipse.cdt.codan.internal.ui.preferences.BuildPropertyPage"
|
||||
id="org.eclipse.cdt.codan.ui.properties.buildPropertyPage"
|
||||
name="Build">
|
||||
<enabledWhen>
|
||||
<instanceof
|
||||
value="org.eclipse.core.resources.IProject">
|
||||
</instanceof>
|
||||
</enabledWhen>
|
||||
</page>
|
||||
</extension>
|
||||
|
||||
|
||||
<extension
|
||||
point="org.eclipse.core.runtime.preferences">
|
||||
<initializer
|
||||
class="org.eclipse.cdt.codan.internal.ui.preferences.PreferenceInitializer">
|
||||
</initializer>
|
||||
</extension>
|
||||
</plugin>
|
|
@ -0,0 +1,88 @@
|
|||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.codan.ui.actions.ToggleNatureAction;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jface.preference.BooleanFieldEditor;
|
||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||
import org.eclipse.ui.IWorkbenchPropertyPage;
|
||||
|
||||
public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
||||
IWorkbenchPropertyPage {
|
||||
private IAdaptable element;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public BuildPropertyPage() {
|
||||
setPreferenceStore(org.eclipse.cdt.codan.ui.Activator.getDefault()
|
||||
.getPreferenceStore());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors
|
||||
* ()
|
||||
*/
|
||||
@Override
|
||||
protected void createFieldEditors() {
|
||||
addField(new BooleanFieldEditor(PreferenceConstants.P_RUN_ON_BUILD,
|
||||
"&Run with Build", getFieldEditorParent()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performOk() {
|
||||
boolean result = super.performOk();
|
||||
if (result) {
|
||||
IAdaptable res = getElement();
|
||||
if (res instanceof IProject) {
|
||||
boolean runOnBuild = getPreferenceStore().getBoolean(
|
||||
PreferenceConstants.P_RUN_ON_BUILD);
|
||||
new ToggleNatureAction().toggleNature((IProject) res,
|
||||
runOnBuild);
|
||||
// if (runOnBuild == false) {
|
||||
// boolean openQuestion = MessageDialog
|
||||
// .openQuestion(
|
||||
// getShell(),
|
||||
// "Confirmation",
|
||||
// "Do you want to remove existing problems? If build is disabled they won't be updated anymore.");
|
||||
// if (openQuestion == true) {
|
||||
// ErrorReporter.deleteAllMarkers();
|
||||
// }
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
|
||||
*/
|
||||
public IAdaptable getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime
|
||||
* .IAdaptable)
|
||||
*/
|
||||
public void setElement(IAdaptable element) {
|
||||
this.element = element;
|
||||
setPreferenceStore(new PropertyStore((IResource) getElement(),
|
||||
org.eclipse.cdt.codan.ui.Activator.getDefault()
|
||||
.getPreferenceStore(), getPageId()));
|
||||
}
|
||||
|
||||
protected String getPageId() {
|
||||
return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,417 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jface.preference.FieldEditor;
|
||||
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
||||
import org.eclipse.jface.viewers.CheckboxTreeViewer;
|
||||
import org.eclipse.jface.viewers.ICheckStateListener;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.StructuredViewer;
|
||||
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.Control;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
|
||||
/**
|
||||
* An abstract field editor that manages a checked tree. Values in the tree
|
||||
* should be set outside by setting getTreeViewer().setContentProvider() and
|
||||
* getTreeViewer().setInput() Control stores checked elements only in preference
|
||||
* storage.
|
||||
*
|
||||
* <p>
|
||||
* Subclasses may implement the <code>parseString</code>,
|
||||
* <code>createList</code>, <code>storeValue</code> and
|
||||
* <code>getListSeparator</code> framework methods.
|
||||
* </p>
|
||||
*/
|
||||
public class CheckedTreeEditor extends FieldEditor implements
|
||||
ICheckStateListener {
|
||||
/**
|
||||
* The list widget; <code>null</code> if none (before creation or after
|
||||
* disposal).
|
||||
*/
|
||||
private CheckboxTreeViewer treeViewer;
|
||||
private Composite listParent;
|
||||
private boolean isValid;
|
||||
private static String LIST_SEP = ",";
|
||||
private boolean emptySelectionAllowed = false;
|
||||
|
||||
/**
|
||||
* Creates a new list field editor
|
||||
*/
|
||||
protected CheckedTreeEditor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list field editor.
|
||||
*
|
||||
* @param name
|
||||
* the name of the preference this field editor works on
|
||||
* @param labelText
|
||||
* the label text of the field editor
|
||||
* @param parent
|
||||
* the parent of the field editor's control
|
||||
*/
|
||||
public CheckedTreeEditor(String name, String labelText, Composite parent) {
|
||||
init(name, labelText);
|
||||
createControl(parent);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc) Method declared on FieldEditor.
|
||||
*/
|
||||
protected void adjustForNumColumns(int numColumns) {
|
||||
Control control = getLabelControl();
|
||||
if (control != null) {
|
||||
((GridData) control.getLayoutData()).horizontalSpan = numColumns;
|
||||
((GridData) getTreeControl().getLayoutData()).horizontalSpan = numColumns;
|
||||
} else {
|
||||
((GridData) getTreeControl().getLayoutData()).horizontalSpan = numColumns;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc) Method declared on FieldEditor.
|
||||
*/
|
||||
protected void doFillIntoGrid(Composite parent, int numColumns) {
|
||||
doFillLabelIntoGrid(parent, numColumns);
|
||||
doFillBoxIntoGrid(parent, numColumns);
|
||||
}
|
||||
|
||||
protected void doFillLabelIntoGrid(Composite parent, int numColumns) {
|
||||
String text = getLabelText();
|
||||
if (text != null && text.length() > 0) {
|
||||
Control control = getLabelControl(parent);
|
||||
GridData gd = new GridData();
|
||||
gd.horizontalSpan = numColumns;
|
||||
control.setLayoutData(gd);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doFillBoxIntoGrid(Composite parent, int numColumns) {
|
||||
GridData gd;
|
||||
Control list = createListControl(parent);
|
||||
gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.verticalAlignment = GridData.FILL;
|
||||
gd.horizontalSpan = numColumns;
|
||||
gd.grabExcessHorizontalSpace = true;
|
||||
gd.grabExcessVerticalSpace = true;
|
||||
list.setLayoutData(gd);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc) Method declared on FieldEditor.
|
||||
*/
|
||||
protected void doLoad() {
|
||||
if (getTreeControl() != null) {
|
||||
String s = getPreferenceStore().getString(getPreferenceName());
|
||||
setTreeData(parseString(s));
|
||||
}
|
||||
}
|
||||
|
||||
Control getTreeControl() {
|
||||
if (treeViewer == null)
|
||||
return null;
|
||||
return treeViewer.getControl();
|
||||
}
|
||||
|
||||
public CheckboxTreeViewer getTreeViewer() {
|
||||
return treeViewer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param map
|
||||
*/
|
||||
private void setTreeData(Map<Object, Boolean> 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)
|
||||
*/
|
||||
public void checkStateChanged(CheckStateChangedEvent event) {
|
||||
Object element = event.getElement();
|
||||
treeViewer.setGrayed(element, false);
|
||||
treeViewer.setSubtreeChecked(element, event.getChecked());
|
||||
Object parent = getContentProvider().getParent(element);
|
||||
if (parent != null) {
|
||||
updateCheckedState(parent);
|
||||
treeViewer.setParentsGrayed(parent, true);
|
||||
}
|
||||
refreshValidState();
|
||||
}
|
||||
|
||||
private ITreeContentProvider getContentProvider() {
|
||||
return ((ITreeContentProvider) treeViewer.getContentProvider());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
* @param event
|
||||
*/
|
||||
private void updateCheckedState(Object parent) {
|
||||
Object[] children = getContentProvider().getChildren(parent);
|
||||
int i, count = 0;
|
||||
for (i = 0; i < children.length; i++) {
|
||||
Object object = children[i];
|
||||
if (treeViewer.getChecked(object)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
treeViewer.setChecked(parent, true);
|
||||
}
|
||||
if (count == 0) {
|
||||
treeViewer.setGrayed(parent, false);
|
||||
treeViewer.setChecked(parent, false);
|
||||
return;
|
||||
}
|
||||
if (count < i) {
|
||||
treeViewer.setGrayed(parent, true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc) Method declared on FieldEditor.
|
||||
*/
|
||||
protected void doLoadDefault() {
|
||||
if (getTreeControl() != null) {
|
||||
treeViewer.refresh();
|
||||
String s = getPreferenceStore().getDefaultString(
|
||||
getPreferenceName());
|
||||
setTreeData(parseString(s));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc) Method declared on FieldEditor.
|
||||
*/
|
||||
protected void doStore() {
|
||||
String s = unparseTree();
|
||||
if (s != null) {
|
||||
getPreferenceStore().setValue(getPreferenceName(), s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this field editor's list control.
|
||||
*
|
||||
* @param parent
|
||||
* the parent control
|
||||
* @return the list control
|
||||
*/
|
||||
public Tree createListControl(Composite parent) {
|
||||
Tree table = (Tree) getTreeControl();
|
||||
if (table == null) {
|
||||
listParent = parent;
|
||||
treeViewer = new CheckboxTreeViewer(parent, SWT.BORDER | SWT.MULTI
|
||||
| SWT.V_SCROLL | SWT.H_SCROLL);
|
||||
table = treeViewer.getTree();
|
||||
table.setFont(parent.getFont());
|
||||
treeViewer.addCheckStateListener(this);
|
||||
} else {
|
||||
checkParent(table, parent);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
public StructuredViewer getViewer() {
|
||||
return treeViewer;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc) Method declared on FieldEditor.
|
||||
*/
|
||||
public int getNumberOfControls() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this field editor's shell.
|
||||
* <p>
|
||||
* This method is internal to the framework; subclassers should not call
|
||||
* this method.
|
||||
* </p>
|
||||
*
|
||||
* @return the shell
|
||||
*/
|
||||
protected Shell getShell() {
|
||||
return treeViewer.getControl().getShell();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stored as element=true|false,...
|
||||
*
|
||||
* @param stringList
|
||||
* @return
|
||||
*/
|
||||
public Map<Object, Boolean> parseString(String stringList) {
|
||||
Map<Object, Boolean> data = new HashMap<Object, Boolean>();
|
||||
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.
|
||||
*/
|
||||
public void setFocus() {
|
||||
if (getTreeControl() != null) {
|
||||
getTreeControl().setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see FieldEditor.setEnabled(boolean,Composite).
|
||||
*/
|
||||
public void setEnabled(boolean enabled, Composite parent) {
|
||||
super.setEnabled(enabled, parent);
|
||||
createListControl(parent).setEnabled(enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines the given list of items into a single string. This method is the
|
||||
* converse of <code>parseString</code>.
|
||||
* <p>
|
||||
* Subclasses may implement this method.
|
||||
* </p>
|
||||
*
|
||||
* @return the combined string
|
||||
* @see #parseString
|
||||
*/
|
||||
protected String unparseTree() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
Map<Object, Boolean> map = fillElementsFromUi(treeViewer.getInput(),
|
||||
new HashMap<Object, Boolean>());
|
||||
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<Object, Boolean> fillElementsFromUi(Object root,
|
||||
Map<Object, Boolean> 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 void createControl(Composite parent) {
|
||||
GridLayout ly = (GridLayout) parent.getLayout();
|
||||
doFillIntoGrid(parent, ly.numColumns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setEnabled(boolean b) {
|
||||
setEnabled(b, listParent);
|
||||
}
|
||||
|
||||
public Composite getTreeParent() {
|
||||
return listParent;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc) Method declared on FieldEditor.
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return isValid;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc) Method declared on FieldEditor.
|
||||
*/
|
||||
protected void refreshValidState() {
|
||||
isValid = checkState();
|
||||
}
|
||||
|
||||
protected boolean checkState() {
|
||||
if (!emptySelectionAllowed) {
|
||||
Object[] checkedElements = getTreeViewer().getCheckedElements();
|
||||
if (checkedElements.length == 0) {
|
||||
showErrorMessage("Selection cannot be empty");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
clearErrorMessage();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public final boolean isEmptySelectionAllowed() {
|
||||
return emptySelectionAllowed;
|
||||
}
|
||||
|
||||
public final void setEmptySelectionAllowed(boolean emptySelectionAllowed) {
|
||||
this.emptySelectionAllowed = emptySelectionAllowed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*******************************************************************************
|
||||
* 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.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||
|
||||
/**
|
||||
* This class represents a preference page that is contributed to the
|
||||
* Preferences dialog. By subclassing <samp>FieldEditorPreferencePage</samp>, we
|
||||
* can use the field support built into JFace that allows us to create a page
|
||||
* that is small and knows how to save, restore and apply itself.
|
||||
* <p>
|
||||
* This page is used to modify preferences only. They are stored in the
|
||||
* preference store that belongs to the main plug-in class. That way,
|
||||
* preferences can be accessed directly via the preference store.
|
||||
*/
|
||||
public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||
IWorkbenchPreferencePage {
|
||||
public CodanPreferencePage() {
|
||||
super(GRID);
|
||||
setPreferenceStore(new ScopedPreferenceStore(new InstanceScope(),
|
||||
CodanCorePlugin.PLUGIN_ID));
|
||||
setDescription("Code Analyzers Preference Page");
|
||||
}
|
||||
|
||||
protected String getPageId() {
|
||||
return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the field editors. Field editors are abstractions of the common
|
||||
* GUI blocks needed to manipulate various types of preferences. Each field
|
||||
* editor knows how to save and restore itself.
|
||||
*/
|
||||
public void createFieldEditors() {
|
||||
CheckedTreeEditor checkedTreeEditor = new ProblemsTreeEditor(
|
||||
getFieldEditorParent());
|
||||
addField(checkedTreeEditor);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
|
||||
*/
|
||||
public void init(IWorkbench workbench) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,356 @@
|
|||
/*******************************************************************************
|
||||
* 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.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.eclipse.jface.preference.FieldEditor;
|
||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||
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.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.ui.IWorkbenchPropertyPage;
|
||||
|
||||
/**
|
||||
* @author Berthold Daum
|
||||
*/
|
||||
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;
|
||||
|
||||
// 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
|
||||
*/
|
||||
public FieldEditorOverlayPage(int style) {
|
||||
super(style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param title - title string
|
||||
* @param style - layout style
|
||||
*/
|
||||
public FieldEditorOverlayPage(String title, int style) {
|
||||
super(title, style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param title - title string
|
||||
* @param image - title image
|
||||
* @param style - layout 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.
|
||||
*
|
||||
* @return - the qualifier
|
||||
*/
|
||||
protected abstract String getPageId();
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delivers the object that owns the properties shown in this property page.
|
||||
* @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
|
||||
*/
|
||||
public IAdaptable getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#addField(org.eclipse.jface.preference.FieldEditor)
|
||||
*/
|
||||
protected void addField(FieldEditor editor) {
|
||||
editors.add(editor);
|
||||
super.addField(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
*/
|
||||
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 state of all subclass controls
|
||||
if (isPropertyPage())
|
||||
updateFieldEditors();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
protected Control createContents(Composite parent) {
|
||||
if (isPropertyPage())
|
||||
createSelectionGroup(parent);
|
||||
return super.createContents(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
updateFieldEditors();
|
||||
}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
if (isPropertyPage())
|
||||
return overlayStore;
|
||||
return super.getPreferenceStore();
|
||||
}
|
||||
|
||||
/*
|
||||
* Enables or disables the field editors and buttons of this page
|
||||
*/
|
||||
private void updateFieldEditors() {
|
||||
// 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
|
||||
*/
|
||||
protected void updateFieldEditors(boolean enabled) {
|
||||
Composite parent = getFieldEditorParent();
|
||||
Iterator it = editors.iterator();
|
||||
while (it.hasNext()) {
|
||||
FieldEditor editor = (FieldEditor) it.next();
|
||||
editor.setEnabled(enabled, parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
*/
|
||||
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 field editors.
|
||||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
|
||||
*/
|
||||
protected void performDefaults() {
|
||||
if (isPropertyPage()) {
|
||||
useWorkspaceSettingsButton.setSelection(true);
|
||||
useProjectSettingsButton.setSelection(false);
|
||||
configureButton.setEnabled(true);
|
||||
updateFieldEditors();
|
||||
}
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*******************************************************************************
|
||||
* 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.util.ResourceBundle;
|
||||
|
||||
|
||||
public class Messages {
|
||||
|
||||
private final static String RESOURCE_BUNDLE = "org.eclipse.cdt.codan.internal.ui.preferences.Messages";//$NON-NLS-1$
|
||||
|
||||
private static ResourceBundle fgResourceBundle = null;
|
||||
|
||||
private static boolean notRead = true;
|
||||
|
||||
public Messages() {
|
||||
}
|
||||
public static ResourceBundle getResourceBundle() {
|
||||
if (notRead) {
|
||||
notRead = false;
|
||||
try {
|
||||
fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
return fgResourceBundle;
|
||||
}
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return getResourceBundle().getString(key);
|
||||
} catch (Exception e) {
|
||||
return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
OverlayPage.Use_Workspace_Settings=Use &workspace settings
|
||||
OverlayPage.Use_Project_Settings=Use pr&oject settings
|
||||
OverlayPage.Configure_Workspace_Settings=&Configure Workspace Settings ...
|
||||
PropertyStore.Cannot_write_resource_property=Cannot write resource property
|
|
@ -0,0 +1,334 @@
|
|||
/*******************************************************************************
|
||||
* 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* 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.internal.ui.preferences;
|
||||
|
||||
/**
|
||||
* Constant definitions for plug-in preferences
|
||||
*/
|
||||
public class PreferenceConstants {
|
||||
public static final String P_RUN_ON_BUILD = "booleanPreference";
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*******************************************************************************
|
||||
* 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.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
|
||||
/**
|
||||
* Class used to initialize default preference values.
|
||||
*/
|
||||
public class PreferenceInitializer extends AbstractPreferenceInitializer {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
|
||||
*/
|
||||
public void initializeDefaultPreferences() {
|
||||
IPreferenceStore store = org.eclipse.cdt.codan.ui.Activator
|
||||
.getDefault().getPreferenceStore();
|
||||
store.setDefault(PreferenceConstants.P_RUN_ON_BUILD, false);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
/*******************************************************************************
|
||||
* 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.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.codan.core.model.CheckersRegisry;
|
||||
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.jface.viewers.BaseLabelProvider;
|
||||
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
||||
import org.eclipse.jface.viewers.IBaseLabelProvider;
|
||||
import org.eclipse.jface.viewers.IContentProvider;
|
||||
import org.eclipse.jface.viewers.ITableLabelProvider;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.TreeColumn;
|
||||
|
||||
public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||
public ProblemsTreeEditor() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
class ProblemsContentProvider implements IContentProvider,
|
||||
ITreeContentProvider {
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
if (parentElement instanceof Object[])
|
||||
return (Object[]) parentElement;
|
||||
if (parentElement instanceof IProblemCategory) {
|
||||
return ((IProblemCategory) parentElement).getChildren();
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
public Object getParent(Object element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasChildren(Object element) {
|
||||
return getChildren(element).length > 0;
|
||||
}
|
||||
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return getChildren(inputElement);
|
||||
}
|
||||
}
|
||||
|
||||
class ProblemsLabelProvider extends BaseLabelProvider implements
|
||||
IBaseLabelProvider, ITableLabelProvider {
|
||||
public Image getColumnImage(Object element, int columnIndex) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getColumnText(Object element, int columnIndex) {
|
||||
if (element instanceof IProblem) {
|
||||
IProblem p = (IProblem) element;
|
||||
if (columnIndex == 0)
|
||||
return p.getName();
|
||||
if (columnIndex == 1)
|
||||
return p.getSeverity().toString();
|
||||
}
|
||||
if (element instanceof IProblemCategory) {
|
||||
IProblemCategory p = (IProblemCategory) element;
|
||||
if (columnIndex == 0)
|
||||
return p.getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
((CodanProblem) element).setEnabled(event.getChecked());
|
||||
}
|
||||
}
|
||||
|
||||
public ProblemsTreeEditor(Composite parent) {
|
||||
super("problems", "Problems", parent);
|
||||
setEmptySelectionAllowed(true);
|
||||
getTreeViewer().getTree().setHeaderVisible(true);
|
||||
// getTreeViewer().getTree().
|
||||
getTreeViewer().setContentProvider(new ProblemsContentProvider());
|
||||
getTreeViewer().setLabelProvider(new ProblemsLabelProvider());
|
||||
// column Name
|
||||
TreeColumn column = new TreeColumn(getTreeViewer().getTree(), SWT.NONE);
|
||||
column.setWidth(300);
|
||||
column.setText("Name");
|
||||
// column Severity
|
||||
TreeColumn column2 = new TreeColumn(getTreeViewer().getTree(), SWT.NONE);
|
||||
column2.setWidth(100);
|
||||
column2.setText("Severity");
|
||||
getTreeViewer().setInput(
|
||||
CheckersRegisry.getInstance().getProblemsTree());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,234 @@
|
|||
/*******************************************************************************
|
||||
* 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));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package org.eclipse.cdt.codan.ui;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle
|
||||
*/
|
||||
public class Activator extends AbstractUIPlugin {
|
||||
|
||||
// The plug-in ID
|
||||
public static final String PLUGIN_ID = "org.eclipse.cdt.codan.ui";
|
||||
|
||||
// The shared instance
|
||||
private static Activator plugin;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
public Activator() {
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
plugin = null;
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance
|
||||
*
|
||||
* @return the shared instance
|
||||
*/
|
||||
public static Activator getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image descriptor for the image file at the given
|
||||
* plug-in relative path
|
||||
*
|
||||
* @param path the path
|
||||
* @return the image descriptor
|
||||
*/
|
||||
public static ImageDescriptor getImageDescriptor(String path) {
|
||||
return imageDescriptorFromPlugin(PLUGIN_ID, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the specified status with this plug-in's log.
|
||||
*
|
||||
* @param status
|
||||
* status to log
|
||||
*/
|
||||
public static void log(IStatus status) {
|
||||
getDefault().getLog().log(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an internal error with the specified throwable
|
||||
*
|
||||
* @param e
|
||||
* the exception to be logged
|
||||
*/
|
||||
public static void log(Throwable e) {
|
||||
log(new Status(IStatus.ERROR, PLUGIN_ID, 1, "Internal Error", e)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an internal error with the specified message.
|
||||
*
|
||||
* @param message
|
||||
* the error message to log
|
||||
*/
|
||||
public static void log(String message) {
|
||||
log(new Status(IStatus.ERROR, PLUGIN_ID, 1, message, null));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*******************************************************************************
|
||||
* 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.ui.actions;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.codan.core.builder.CodanBuilder;
|
||||
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 RunCodeAnalysis implements IObjectActionDelegate {
|
||||
private ISelection sel;
|
||||
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void run(IAction action) {
|
||||
for (Iterator iterator = ((IStructuredSelection) sel).iterator(); iterator
|
||||
.hasNext();) {
|
||||
Object o = iterator.next();
|
||||
if (o instanceof IResource) {
|
||||
IResource res = (IResource) o;
|
||||
new CodanBuilder().new CodanResourceVisitor().visit(res);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
this.sel = selection;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
/*******************************************************************************
|
||||
* 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.ui.actions;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.codan.core.builder.CodeAnlysisNature;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
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 ToggleNatureAction implements IObjectActionDelegate {
|
||||
private ISelection selection;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
|
||||
*/
|
||||
public void run(IAction action) {
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
for (Iterator it = ((IStructuredSelection) selection).iterator(); it
|
||||
.hasNext();) {
|
||||
Object element = it.next();
|
||||
IProject project = null;
|
||||
if (element instanceof IProject) {
|
||||
project = (IProject) element;
|
||||
} else if (element instanceof IAdaptable) {
|
||||
project = (IProject) ((IAdaptable) element)
|
||||
.getAdapter(IProject.class);
|
||||
}
|
||||
if (project != null) {
|
||||
toggleNature(project, !hasCodanNature(project));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action
|
||||
* .IAction, org.eclipse.jface.viewers.ISelection)
|
||||
*/
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
this.selection = selection;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.
|
||||
* action.IAction, org.eclipse.ui.IWorkbenchPart)
|
||||
*/
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
}
|
||||
|
||||
public boolean hasCodanNature(IProject project) {
|
||||
IProjectDescription description;
|
||||
try {
|
||||
description = project.getDescription();
|
||||
String[] natures = description.getNatureIds();
|
||||
for (int i = 0; i < natures.length; ++i) {
|
||||
if (CodeAnlysisNature.NATURE_ID.equals(natures[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles sample nature on a project
|
||||
*
|
||||
* @param project
|
||||
* to have sample nature added or removed
|
||||
*/
|
||||
public void toggleNature(IProject project, boolean add) {
|
||||
try {
|
||||
IProjectDescription description = project.getDescription();
|
||||
String[] natures = description.getNatureIds();
|
||||
for (int i = 0; i < natures.length; ++i) {
|
||||
if (CodeAnlysisNature.NATURE_ID.equals(natures[i])) {
|
||||
if (add == false) {
|
||||
// Remove the nature
|
||||
String[] newNatures = new String[natures.length - 1];
|
||||
System.arraycopy(natures, 0, newNatures, 0, i);
|
||||
System.arraycopy(natures, i + 1, newNatures, i,
|
||||
natures.length - i - 1);
|
||||
description.setNatureIds(newNatures);
|
||||
project.setDescription(description, null);
|
||||
return;
|
||||
} else {
|
||||
// already there no need to add
|
||||
add = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (add) {
|
||||
// Add the nature
|
||||
String[] newNatures = new String[natures.length + 1];
|
||||
System.arraycopy(natures, 0, newNatures, 0, natures.length);
|
||||
newNatures[natures.length] = CodeAnlysisNature.NATURE_ID;
|
||||
description.setNatureIds(newNatures);
|
||||
project.setDescription(description, null);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue