From 4e112eca7750a4f530c986be55c178c43c16d3ea Mon Sep 17 00:00:00 2001 From: Elliott Baron Date: Sat, 26 Jun 2010 22:27:34 -0400 Subject: Update codan plugins to CDT 7.0. * org.eclipse.cdt.codan.checkers.ui: Updated. * org.eclipse.cdt.codan.checkers: Updated. * org.eclipse.cdt.codan.core: Updated. * org.eclipse.cdt.codan.ui: Updated. * org.eclipse.cdt.codan.core.cxx: Added. * org.eclipse.cdt.codan.extension/META-INF/MANIFEST.MF: Import org.eclipse.cdt.codan.core.cxx.model. * org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/checkers/AbstractPropSimChecker.java: Superclass moved. --- org.eclipse.cdt.codan.ui/src/CVS/Tag | 1 + org.eclipse.cdt.codan.ui/src/org/CVS/Tag | 1 + org.eclipse.cdt.codan.ui/src/org/eclipse/CVS/Tag | 1 + .../src/org/eclipse/cdt/CVS/Tag | 1 + .../src/org/eclipse/cdt/codan/CVS/Tag | 1 + .../src/org/eclipse/cdt/codan/internal/CVS/Tag | 1 + .../org/eclipse/cdt/codan/internal/ui/CVS/Entries | 8 + .../src/org/eclipse/cdt/codan/internal/ui/CVS/Tag | 1 + .../ui/CodanProblemMarkerResolutionGenerator.java | 145 ++++++++++ .../cdt/codan/internal/ui/CodanUIActivator.java | 134 +++++++++ .../cdt/codan/internal/ui/CodanUIMessages.java | 85 ++++++ .../cdt/codan/internal/ui/actions/CVS/Entries | 2 + .../cdt/codan/internal/ui/actions/CVS/Repository | 1 + .../eclipse/cdt/codan/internal/ui/actions/CVS/Root | 1 + .../eclipse/cdt/codan/internal/ui/actions/CVS/Tag | 1 + .../cdt/codan/internal/ui/actions/CVS/Template | 0 .../codan/internal/ui/actions/RunCodeAnalysis.java | 70 +++++ .../internal/ui/actions/ToggleNatureAction.java | 130 +++++++++ .../cdt/codan/internal/ui/dialogs/CVS/Entries | 2 + .../cdt/codan/internal/ui/dialogs/CVS/Repository | 1 + .../eclipse/cdt/codan/internal/ui/dialogs/CVS/Root | 1 + .../eclipse/cdt/codan/internal/ui/dialogs/CVS/Tag | 1 + .../cdt/codan/internal/ui/dialogs/CVS/Template | 0 .../ui/dialogs/CustomizeProblemDialog.java | 87 ++++++ .../ui/dialogs/ExclusionInclusionEntryDialog.java | 284 +++++++++++++++++++ .../cdt/codan/internal/ui/messages.properties | 85 ++++++ .../internal/ui/preferences/BuildPropertyPage.java | 45 +-- .../cdt/codan/internal/ui/preferences/CVS/Entries | 15 +- .../cdt/codan/internal/ui/preferences/CVS/Tag | 1 + .../internal/ui/preferences/CheckedTreeEditor.java | 5 +- .../ui/preferences/CodanPreferencePage.java | 210 +++++++++++++- .../ui/preferences/FieldEditorOverlayPage.java | 34 ++- .../ui/preferences/FileScopePreferencePage.java | 312 +++++++++++++++++++++ .../codan/internal/ui/preferences/Messages.java | 47 ---- .../internal/ui/preferences/Messages.properties | 4 - .../ui/preferences/PreferenceInitializer.java | 13 +- .../ui/preferences/ProblemsTreeEditor.java | 100 ++++--- .../cdt/codan/internal/ui/views/CVS/Entries | 3 + .../cdt/codan/internal/ui/views/CVS/Repository | 1 + .../eclipse/cdt/codan/internal/ui/views/CVS/Root | 1 + .../eclipse/cdt/codan/internal/ui/views/CVS/Tag | 1 + .../views/GenericCodanProblemDetailsProvider.java | 23 ++ .../codan/internal/ui/views/ProblemDetails.java | 169 +++++++++++ .../ui/views/ProblemDetailsExtensions.java | 138 +++++++++ .../internal/ui/widgets/BasicElementLabels.java | 157 +++++++++++ .../cdt/codan/internal/ui/widgets/CVS/Entries | 4 + .../cdt/codan/internal/ui/widgets/CVS/Repository | 1 + .../eclipse/cdt/codan/internal/ui/widgets/CVS/Root | 1 + .../eclipse/cdt/codan/internal/ui/widgets/CVS/Tag | 1 + .../ui/widgets/CustomizeProblemComposite.java | 86 ++++++ .../internal/ui/widgets/FileScopeComposite.java | 100 +++++++ .../internal/ui/widgets/ParametersComposite.java | 261 +++++++++++++++++ .../codan/ui/AbstarctCodanCMarkerResolution.java | 91 ++++++ .../ui/AbstractCodanProblemDetailsProvider.java | 114 ++++++++ .../src/org/eclipse/cdt/codan/ui/Activator.java | 98 ------- .../src/org/eclipse/cdt/codan/ui/CVS/Entries | 8 +- .../src/org/eclipse/cdt/codan/ui/CVS/Tag | 1 + .../src/org/eclipse/cdt/codan/ui/CVS/Template | 0 .../org/eclipse/cdt/codan/ui/CodanCReconciler.java | 71 ----- .../eclipse/cdt/codan/ui/CodanEditorUtility.java | 111 ++++++++ .../src/org/eclipse/cdt/codan/ui/Startup.java | 93 ------ .../org/eclipse/cdt/codan/ui/actions/CVS/Entries | 2 - .../eclipse/cdt/codan/ui/actions/CVS/Repository | 1 - .../src/org/eclipse/cdt/codan/ui/actions/CVS/Root | 1 - .../org/eclipse/cdt/codan/ui/actions/CVS/Template | 0 .../cdt/codan/ui/actions/RunCodeAnalysis.java | 69 ----- .../cdt/codan/ui/actions/ToggleNatureAction.java | 130 --------- .../org/eclipse/cdt/codan/ui/handlers/CVS/Entries | 1 + .../eclipse/cdt/codan/ui/handlers/CVS/Repository | 1 + .../src/org/eclipse/cdt/codan/ui/handlers/CVS/Root | 1 + .../src/org/eclipse/cdt/codan/ui/handlers/CVS/Tag | 1 + .../cdt/codan/ui/handlers/RunCodanCommand.java | 37 +++ 72 files changed, 3001 insertions(+), 608 deletions(-) create mode 100644 org.eclipse.cdt.codan.ui/src/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanProblemMarkerResolutionGenerator.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIActivator.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIMessages.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Entries create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Repository create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Root create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/RunCodeAnalysis.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/ToggleNatureAction.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Entries create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Repository create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Root create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CustomizeProblemDialog.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/ExclusionInclusionEntryDialog.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/messages.properties create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FileScopePreferencePage.java delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/Messages.java delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/Messages.properties create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Entries create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Repository create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Root create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/GenericCodanProblemDetailsProvider.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetailsExtensions.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/BasicElementLabels.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Entries create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Repository create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Root create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CustomizeProblemComposite.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/FileScopeComposite.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/ParametersComposite.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Tag delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Template delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanCReconciler.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanEditorUtility.java delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Startup.java delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Entries delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Repository delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Root delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Template delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java delete mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/ToggleNatureAction.java create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Entries create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Repository create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Root create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Tag create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/RunCodanCommand.java (limited to 'org.eclipse.cdt.codan.ui/src') diff --git a/org.eclipse.cdt.codan.ui/src/CVS/Tag b/org.eclipse.cdt.codan.ui/src/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CVS/Entries index f769284..089fc52 100644 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CVS/Entries +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CVS/Entries @@ -1 +1,9 @@ +/CodanProblemMarkerResolutionGenerator.java/1.3/Thu Jun 3 17:01:39 2010//TCDT_7_0_0 +/CodanUIActivator.java/1.4/Sun Jun 27 01:30:36 2010//TCDT_7_0_0 +/CodanUIMessages.java/1.5/Mon May 24 15:05:36 2010//TCDT_7_0_0 +D/actions//// +D/dialogs//// +/messages.properties/1.8/Thu Jun 3 17:01:39 2010//TCDT_7_0_0 D/preferences//// +D/views//// +D/widgets//// diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanProblemMarkerResolutionGenerator.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanProblemMarkerResolutionGenerator.java new file mode 100644 index 0000000..690f87b --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanProblemMarkerResolutionGenerator.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Andrew Gvozdev + * 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: + * Andrew Gvozdev - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.regex.Pattern; + +import org.eclipse.cdt.codan.ui.AbstarctCodanCMarkerResolution; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; +import org.eclipse.ui.IMarkerResolution; +import org.eclipse.ui.IMarkerResolutionGenerator; + +public class CodanProblemMarkerResolutionGenerator implements + IMarkerResolutionGenerator { + private static final String EXTENSION_POINT_NAME = "codanMarkerResolution"; //$NON-NLS-1$ + private static Map> resolutions = new HashMap>(); + private static boolean resolutionsLoaded = false; + + static class ConditionalResolution { + IMarkerResolution res; + String messagePattern; + + public ConditionalResolution(IMarkerResolution res2, + String messagePattern2) { + res = res2; + messagePattern = messagePattern2; + } + } + + public IMarkerResolution[] getResolutions(IMarker marker) { + if (resolutionsLoaded == false) { + readExtensions(); + } + String id = marker.getAttribute(IMarker.PROBLEM, null); + if (id == null) + return new IMarkerResolution[0]; + String message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$ + Collection collection = resolutions.get(id); + if (collection != null) { + ArrayList list = new ArrayList(); + for (Iterator iterator = collection + .iterator(); iterator.hasNext();) { + ConditionalResolution res = iterator.next(); + if (res.messagePattern != null) { + if (!message.matches(res.messagePattern)) + continue; + } + if (res.res instanceof AbstarctCodanCMarkerResolution) { + if (!((AbstarctCodanCMarkerResolution)res.res).isApplicable(marker)) + continue; + } + list.add(res.res); + } + if (list.size() > 0) + return list.toArray(new IMarkerResolution[list.size()]); + } + return new IMarkerResolution[0]; + } + + private static synchronized void readExtensions() { + IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint( + CodanUIActivator.PLUGIN_ID, EXTENSION_POINT_NAME); + if (ep == null) + return; + try { + IConfigurationElement[] elements = ep.getConfigurationElements(); + // process categories + for (int i = 0; i < elements.length; i++) { + IConfigurationElement configurationElement = elements[i]; + processResolution(configurationElement); + } + } finally { + resolutionsLoaded = true; + } + } + + /** + * @param configurationElement + */ + private static void processResolution( + IConfigurationElement configurationElement) { + if (configurationElement.getName().equals("resolution")) { //$NON-NLS-1$ + String id = configurationElement.getAttribute("problemId"); //$NON-NLS-1$ + if (id == null) { + CodanUIActivator.log("Extension for " + EXTENSION_POINT_NAME //$NON-NLS-1$ + + " problemId is not defined"); //$NON-NLS-1$ + return; + } + IMarkerResolution res; + try { + res = (IMarkerResolution) configurationElement + .createExecutableExtension("class");//$NON-NLS-1$ + } catch (CoreException e) { + CodanUIActivator.log(e); + return; + } + String messagePattern = configurationElement + .getAttribute("messagePattern"); //$NON-NLS-1$ + if (messagePattern != null) { + try { + Pattern.compile(messagePattern); + } catch (Exception e) { + // bad pattern log and ignore + CodanUIActivator.log("Extension for " //$NON-NLS-1$ + + EXTENSION_POINT_NAME + + " messagePattern is invalid: " + e.getMessage()); //$NON-NLS-1$ + return; + } + } + ConditionalResolution co = new ConditionalResolution(res, + messagePattern); + addResolution(id, co); + } + } + + public static void addResolution(String id, IMarkerResolution res, + String messagePattern) { + addResolution(id, new ConditionalResolution(res, messagePattern)); + } + + private static void addResolution(String id, ConditionalResolution res) { + Collection collection = resolutions.get(id); + if (collection == null) { + collection = new ArrayList(); + resolutions.put(id, collection); + } + collection.add(res); + } +} \ No newline at end of file diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIActivator.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIActivator.java new file mode 100644 index 0000000..e530269 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIActivator.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui; + +import org.eclipse.cdt.codan.core.CodanCorePlugin; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.ui.preferences.ScopedPreferenceStore; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class CodanUIActivator extends AbstractUIPlugin { + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.cdt.codan.ui"; //$NON-NLS-1$ + // The shared instance + private static CodanUIActivator plugin; + private IPreferenceStore preferenceCoreStore; + + /** + * The constructor + */ + public CodanUIActivator() { + } + + /* + * (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 CodanUIActivator 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)); + } + + /** + * @return + */ + public IPreferenceStore getCorePreferenceStore() { + if (preferenceCoreStore == null) { + preferenceCoreStore = new ScopedPreferenceStore( + new InstanceScope(), CodanCorePlugin.PLUGIN_ID); + } + return preferenceCoreStore; + } + + public IPreferenceStore getPreferenceStore(IProject project) { + ProjectScope ps = new ProjectScope(project); + ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, PLUGIN_ID); + scoped.setSearchContexts(new IScopeContext[] { ps, new InstanceScope() }); + return scoped; + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIMessages.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIMessages.java new file mode 100644 index 0000000..5b3134e --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIMessages.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2009,2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui; + +import org.eclipse.osgi.util.NLS; + +/** + * Externalized messages + */ +public class CodanUIMessages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.codan.internal.ui.messages"; //$NON-NLS-1$ + public static String BuildPropertyPage_RunAsYouType; + public static String BuildPropertyPage_RunWithBuild; + public static String CheckedTreeEditor_SelectionCannotBeEmpty; + public static String CodanPreferencePage_Customize; + public static String CodanPreferencePage_Description; + public static String CodanPreferencePage_HasPreferences; + public static String CodanPreferencePage_Info; + public static String CodanPreferencePage_MessageLabel; + public static String CodanPreferencePage_NoInfo; + public static String CodanPreferencePage_Parameters; + public static String ProblemsTreeEditor_NameColumn; + public static String ProblemsTreeEditor_Problems; + public static String ProblemsTreeEditor_SeverityColumn; + public static String OverlayPage_Use_Workspace_Settings; + public static String OverlayPage_Use_Project_Settings; + public static String OverlayPage_Configure_Workspace_Settings; + public static String PropertyStore_Cannot_write_resource_property; + public static String CustomizeProblemComposite_TabParameters; + public static String CustomizeProblemComposite_TabScope; + public static String CustomizeProblemDialog_Message; + public static String CustomizeProblemDialog_Title; + public static String Job_TitleRunningAnalysis; + public static String ParametersComposite_NewValue; + public static String ParametersComposite_None; + // + public static String ExclusionInclusionDialog_title; + public static String ExclusionInclusionDialog_description; + public static String ExclusionInclusionDialog_description2; + public static String ExclusionInclusionDialog_exclusion_pattern_label; + public static String ExclusionInclusionDialog_inclusion_pattern_label; + public static String ExclusionInclusionDialog_inclusion_pattern_add; + public static String ExclusionInclusionDialog_inclusion_pattern_add_multiple; + public static String ExclusionInclusionDialog_inclusion_pattern_remove; + public static String ExclusionInclusionDialog_inclusion_pattern_edit; + public static String ExclusionInclusionDialog_exclusion_pattern_add; + public static String ExclusionInclusionDialog_exclusion_pattern_add_multiple; + public static String ExclusionInclusionDialog_exclusion_pattern_remove; + public static String ExclusionInclusionDialog_exclusion_pattern_edit; + public static String ExclusionInclusionDialog_ChooseExclusionPattern_title; + public static String ExclusionInclusionDialog_ChooseExclusionPattern_description; + public static String ExclusionInclusionDialog_ChooseInclusionPattern_title; + public static String ExclusionInclusionDialog_ChooseInclusionPattern_description; + public static String ExclusionInclusionEntryDialog_exclude_add_title; + public static String ExclusionInclusionEntryDialog_exclude_edit_title; + public static String ExclusionInclusionEntryDialog_exclude_description; + public static String ExclusionInclusionEntryDialog_exclude_pattern_label; + public static String ExclusionInclusionEntryDialog_include_add_title; + public static String ExclusionInclusionEntryDialog_include_edit_title; + public static String ExclusionInclusionEntryDialog_include_description; + public static String ExclusionInclusionEntryDialog_include_pattern_label; + public static String ExclusionInclusionEntryDialog_pattern_button; + public static String ExclusionInclusionEntryDialog_error_empty; + public static String ExclusionInclusionEntryDialog_error_notrelative; + public static String ExclusionInclusionEntryDialog_error_exists; + public static String ExclusionInclusionEntryDialog_ChooseExclusionPattern_title; + public static String ExclusionInclusionEntryDialog_ChooseExclusionPattern_description; + public static String ExclusionInclusionEntryDialog_ChooseInclusionPattern_title; + public static String ExclusionInclusionEntryDialog_ChooseInclusionPattern_description; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, CodanUIMessages.class); + } + + private CodanUIMessages() { + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Entries new file mode 100644 index 0000000..a8f550a --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Entries @@ -0,0 +1,2 @@ +/RunCodeAnalysis.java/1.4/Sun Jun 27 01:30:36 2010//TCDT_7_0_0 +/ToggleNatureAction.java/1.2/Sun Jun 27 01:30:36 2010//TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Repository b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Repository new file mode 100644 index 0000000..6f71b9e --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.cdt/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Root b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/RunCodeAnalysis.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/RunCodeAnalysis.java new file mode 100644 index 0000000..3d1198b --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/RunCodeAnalysis.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui.actions; + +import java.util.Iterator; + +import org.eclipse.cdt.codan.core.CodanRuntime; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.jobs.Job; +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) { + // nothing + } + + public void run(IAction action) { + Job job = new Job(CodanUIMessages.Job_TitleRunningAnalysis) { + @SuppressWarnings("unchecked") + @Override + protected IStatus run(final IProgressMonitor monitor) { + IStructuredSelection ss = (IStructuredSelection) sel; + int count = ss.size(); + monitor.beginTask(getName(), count * 100); + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; + for (Iterator iterator = ss.iterator(); iterator.hasNext();) { + Object o = iterator.next(); + if (o instanceof IResource) { + IResource res = (IResource) o; + SubProgressMonitor subMon = new SubProgressMonitor( + monitor, 100); + CodanRuntime.getInstance().getBuilder() + .processResource(res, subMon); + if (subMon.isCanceled()) + return Status.CANCEL_STATUS; + } + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; + } + return Status.OK_STATUS; + } + }; + job.setUser(true); + job.schedule(); + } + + public void selectionChanged(IAction action, ISelection selection) { + this.sel = selection; + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/ToggleNatureAction.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/ToggleNatureAction.java new file mode 100644 index 0000000..94c51f0 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/actions/ToggleNatureAction.java @@ -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.internal.ui.actions; + +import java.util.Iterator; + +import org.eclipse.cdt.codan.core.CodanCorePlugin; +import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; +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 (CodanCorePlugin.NATURE_ID.equals(natures[i])) { + return true; + } + } + } catch (CoreException e) { + CodanUIActivator.log(e); + } + return false; + } + + /** + * Toggles codan nature on a project + * + * @param project + * to have codan 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 (CodanCorePlugin.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; + } + // 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] = CodanCorePlugin.NATURE_ID; + description.setNatureIds(newNatures); + project.setDescription(description, null); + } + } catch (CoreException e) { + CodanUIActivator.log(e); + } + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Entries new file mode 100644 index 0000000..87cd5d6 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Entries @@ -0,0 +1,2 @@ +/CustomizeProblemDialog.java/1.5/Sun Jun 27 01:30:36 2010//TCDT_7_0_0 +/ExclusionInclusionEntryDialog.java/1.2/Thu Jun 3 17:01:39 2010//TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Repository b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Repository new file mode 100644 index 0000000..a829e01 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.cdt/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Root b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CustomizeProblemDialog.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CustomizeProblemDialog.java new file mode 100644 index 0000000..8b35f1d --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/CustomizeProblemDialog.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui.dialogs; + +import org.eclipse.cdt.codan.core.model.IProblem; +import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; +import org.eclipse.cdt.codan.internal.ui.widgets.CustomizeProblemComposite; +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +/** + * Dialog that allows to customise problems + * + */ +public class CustomizeProblemDialog extends TitleAreaDialog { + private CustomizeProblemComposite comp; + private IProblem problem; + private IResource resource; + + /** + * @param parentShell + * @param selectedProblem + * @param iResource + */ + public CustomizeProblemDialog(Shell parentShell, IProblem selectedProblem, + IResource resource) { + super(parentShell); + this.problem = selectedProblem; + this.resource = resource; + setShellStyle(getShellStyle() | SWT.RESIZE); + } + + /** + * Stores edit values into problem working copy + * + * @param problem + * - problem working copy + */ + public void save(IProblemWorkingCopy problem) { + comp.save(problem); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse + * .swt.widgets.Composite) + */ + @Override + protected Control createDialogArea(Composite parent) { + getShell().setText(CodanUIMessages.CustomizeProblemDialog_Title); + setTitle(problem.getName()); + setMessage(CodanUIMessages.CustomizeProblemDialog_Message); + Composite area = (Composite) super.createDialogArea(parent); + comp = new CustomizeProblemComposite(area, problem, resource); + GridData ld = new GridData(GridData.FILL_BOTH); + ld.minimumHeight = 300; + comp.setLayoutData(ld); + return area; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + @Override + protected void okPressed() { + save((IProblemWorkingCopy) problem); + super.okPressed(); + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/ExclusionInclusionEntryDialog.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/ExclusionInclusionEntryDialog.java new file mode 100644 index 0000000..5367e8b --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/ExclusionInclusionEntryDialog.java @@ -0,0 +1,284 @@ +/******************************************************************************* + * Copyright (c) 2010 Alena Laskavaia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui.dialogs; + +import java.text.MessageFormat; +import java.util.List; + +import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; +import org.eclipse.cdt.codan.internal.ui.widgets.BasicElementLabels; +import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; +import org.eclipse.cdt.internal.ui.dialogs.TypedElementSelectionValidator; +import org.eclipse.cdt.internal.ui.dialogs.TypedViewerFilter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IStringButtonAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.StatusDialog; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; +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.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; +import org.eclipse.ui.dialogs.ISelectionStatusValidator; +import org.eclipse.ui.model.WorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.views.navigator.ResourceComparator; + +public class ExclusionInclusionEntryDialog extends StatusDialog { + private StringButtonDialogField fExclusionPatternDialog; + private StatusInfo fExclusionPatternStatus; + private IContainer fCurrSourceFolder; + private String fExclusionPattern; + private List fExistingPatterns; + private boolean fIsExclusion; + + public ExclusionInclusionEntryDialog(Shell parent, boolean isExclusion, + String patternToEdit, List existingPatterns, + FileScopeProblemPreference entryToEdit) { + super(parent); + fIsExclusion = isExclusion; + fExistingPatterns = existingPatterns; + String title, message; + if (isExclusion) { + if (patternToEdit == null) { + title = CodanUIMessages.ExclusionInclusionEntryDialog_exclude_add_title; + } else { + title = CodanUIMessages.ExclusionInclusionEntryDialog_exclude_edit_title; + } + message = MessageFormat + .format(CodanUIMessages.ExclusionInclusionEntryDialog_exclude_pattern_label, + BasicElementLabels.getPathLabel( + entryToEdit.getPath(), false)); + } else { + if (patternToEdit == null) { + title = CodanUIMessages.ExclusionInclusionEntryDialog_include_add_title; + } else { + title = CodanUIMessages.ExclusionInclusionEntryDialog_include_edit_title; + } + message = MessageFormat + .format(CodanUIMessages.ExclusionInclusionEntryDialog_include_pattern_label, + BasicElementLabels.getPathLabel( + entryToEdit.getPath(), false)); + } + setTitle(title); + if (patternToEdit != null) { + fExistingPatterns.remove(patternToEdit); + } + IProject currProject = entryToEdit.getProject(); + IWorkspaceRoot root = currProject != null ? currProject.getWorkspace() + .getRoot() : ResourcesPlugin.getWorkspace().getRoot(); + IResource res = root.findMember(entryToEdit.getPath()); + if (res instanceof IContainer) { + fCurrSourceFolder = (IContainer) res; + } + fExclusionPatternStatus = new StatusInfo(); + ExclusionPatternAdapter adapter = new ExclusionPatternAdapter(); + fExclusionPatternDialog = new StringButtonDialogField(adapter); + fExclusionPatternDialog.setLabelText(message); + fExclusionPatternDialog + .setButtonLabel(CodanUIMessages.ExclusionInclusionEntryDialog_pattern_button); + fExclusionPatternDialog.setDialogFieldListener(adapter); + fExclusionPatternDialog.enableButton(fCurrSourceFolder != null); + if (patternToEdit == null) { + fExclusionPatternDialog.setText(""); //$NON-NLS-1$ + } else { + fExclusionPatternDialog.setText(patternToEdit.toString()); + } + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + int widthHint = convertWidthInCharsToPixels(60); + Composite inner = new Composite(composite, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 2; + inner.setLayout(layout); + Label description = new Label(inner, SWT.WRAP); + if (fIsExclusion) { + description + .setText(CodanUIMessages.ExclusionInclusionEntryDialog_exclude_description); + } else { + description + .setText(CodanUIMessages.ExclusionInclusionEntryDialog_include_description); + } + GridData gd = new GridData(); + gd.horizontalSpan = 2; + gd.widthHint = convertWidthInCharsToPixels(80); + description.setLayoutData(gd); + fExclusionPatternDialog.doFillIntoGrid(inner, 3); + LayoutUtil.setWidthHint(fExclusionPatternDialog.getLabelControl(null), + widthHint); + LayoutUtil.setHorizontalSpan( + fExclusionPatternDialog.getLabelControl(null), 2); + LayoutUtil.setWidthHint(fExclusionPatternDialog.getTextControl(null), + widthHint); + LayoutUtil.setHorizontalGrabbing(fExclusionPatternDialog + .getTextControl(null)); + fExclusionPatternDialog.postSetFocusOnDialogField(parent.getDisplay()); + applyDialogFont(composite); + return composite; + } + + // -------- ExclusionPatternAdapter -------- + private class ExclusionPatternAdapter implements IDialogFieldListener, + IStringButtonAdapter { + // -------- IDialogFieldListener + public void dialogFieldChanged(DialogField field) { + doStatusLineUpdate(); + } + + public void changeControlPressed(DialogField field) { + doChangeControlPressed(); + } + } + + protected void doChangeControlPressed() { + IPath pattern = chooseExclusionPattern(); + if (pattern != null) { + fExclusionPatternDialog.setText(pattern.toString()); + } + } + + protected void doStatusLineUpdate() { + checkIfPatternValid(); + updateStatus(fExclusionPatternStatus); + } + + protected void checkIfPatternValid() { + String pattern = fExclusionPatternDialog.getText().trim(); + if (pattern.length() == 0) { + fExclusionPatternStatus + .setError(CodanUIMessages.ExclusionInclusionEntryDialog_error_empty); + return; + } + IPath path = new Path(pattern); + if (path.isAbsolute() || path.getDevice() != null) { + fExclusionPatternStatus + .setError(CodanUIMessages.ExclusionInclusionEntryDialog_error_notrelative); + return; + } + if (fExistingPatterns.contains(pattern)) { + fExclusionPatternStatus + .setError(CodanUIMessages.ExclusionInclusionEntryDialog_error_exists); + return; + } + fExclusionPattern = pattern; + fExclusionPatternStatus.setOK(); + } + + public String getExclusionPattern() { + return fExclusionPattern; + } + + /* + * @see org.eclipse.jface.window.Window#configureShell(Shell) + */ + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + } + + // ---------- util method ------------ + private IPath chooseExclusionPattern() { + String title, message; + if (fIsExclusion) { + title = CodanUIMessages.ExclusionInclusionEntryDialog_ChooseExclusionPattern_title; + message = CodanUIMessages.ExclusionInclusionEntryDialog_ChooseExclusionPattern_description; + } else { + title = CodanUIMessages.ExclusionInclusionEntryDialog_ChooseInclusionPattern_title; + message = CodanUIMessages.ExclusionInclusionEntryDialog_ChooseInclusionPattern_description; + } + IPath initialPath = new Path(fExclusionPatternDialog.getText()); + IPath[] res = chooseExclusionPattern(getShell(), fCurrSourceFolder, + title, message, initialPath, false); + if (res == null) { + return null; + } + return res[0]; + } + + public static IPath[] chooseExclusionPattern(Shell shell, + IContainer currentSourceFolder, String title, String message, + IPath initialPath, boolean multiSelection) { + Class[] acceptedClasses = new Class[] { IFolder.class, IFile.class, + IProject.class }; + ISelectionStatusValidator validator = new TypedElementSelectionValidator( + acceptedClasses, multiSelection); + ViewerFilter filter = new TypedViewerFilter(acceptedClasses); + ILabelProvider lp = new WorkbenchLabelProvider(); + ITreeContentProvider cp = new WorkbenchContentProvider(); + IResource initialElement = null; + if (initialPath != null) { + IContainer curr = currentSourceFolder; + int nSegments = initialPath.segmentCount(); + for (int i = 0; i < nSegments; i++) { + IResource elem = curr.findMember(initialPath.segment(i)); + if (elem != null) { + initialElement = elem; + } + if (elem instanceof IContainer) { + curr = (IContainer) elem; + } else { + break; + } + } + } + ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog( + shell, lp, cp); + dialog.setTitle(title); + dialog.setValidator(validator); + dialog.setMessage(message); + dialog.addFilter(filter); + dialog.setInput(currentSourceFolder); + dialog.setInitialSelection(initialElement); + dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); + dialog.setHelpAvailable(false); + if (dialog.open() == Window.OK) { + Object[] objects = dialog.getResult(); + int existingSegments = currentSourceFolder.getFullPath() + .segmentCount(); + IPath[] resArr = new IPath[objects.length]; + for (int i = 0; i < objects.length; i++) { + IResource currRes = (IResource) objects[i]; + IPath path = currRes.getFullPath() + .removeFirstSegments(existingSegments).makeRelative(); + if (currRes instanceof IContainer) { + path = path.addTrailingSeparator(); + } + resArr[i] = path; + } + return resArr; + } + return null; + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/messages.properties b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/messages.properties new file mode 100644 index 0000000..ff8fe4c --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/messages.properties @@ -0,0 +1,85 @@ +############################################################################### +# Copyright (c) 2010 Alena Laskavaia and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Alena Laskavaia - initial API and implementation +############################################################################### +BuildPropertyPage_RunAsYouType=Run as you &type (selected checkers) +BuildPropertyPage_RunWithBuild=&Run with build +CheckedTreeEditor_SelectionCannotBeEmpty=Selection cannot be empty +CodanPreferencePage_Customize=Customize... +CodanPreferencePage_Description=Description: +CodanPreferencePage_HasPreferences=This problem has extra preferences +CodanPreferencePage_Info=Info +CodanPreferencePage_MessageLabel=Message: +CodanPreferencePage_NoInfo=Not defined +CodanPreferencePage_Parameters=Parameters: +CustomizeProblemComposite_TabParameters=Preferences +CustomizeProblemComposite_TabScope=Scope +CustomizeProblemDialog_Message=Edit problem preferences, scope and launch options +CustomizeProblemDialog_Title=Customize Problem... +Job_TitleRunningAnalysis=Running Code Analysis +ParametersComposite_NewValue=New Value +ParametersComposite_None=No extra preferences +ProblemsTreeEditor_NameColumn=Name +ProblemsTreeEditor_Problems=Problems +ProblemsTreeEditor_SeverityColumn=Severity +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 + +# ------- ExclusionInclusionDialog ------- + +ExclusionInclusionDialog_title=Inclusion and Exclusion Patterns +ExclusionInclusionDialog_description=Included and excluded resources for ''{0}''. +ExclusionInclusionDialog_description2=Add or remove inclusion and exclusion patterns to resources for which problem is reported + +ExclusionInclusionDialog_exclusion_pattern_label=E&xclusion patterns: +ExclusionInclusionDialog_inclusion_pattern_label=I&nclusion patterns: + +ExclusionInclusionDialog_inclusion_pattern_add=A&dd... +ExclusionInclusionDialog_inclusion_pattern_add_multiple=Add &Multiple... +ExclusionInclusionDialog_inclusion_pattern_remove=&Remove +ExclusionInclusionDialog_inclusion_pattern_edit=&Edit... + +ExclusionInclusionDialog_exclusion_pattern_add=&Add... +ExclusionInclusionDialog_exclusion_pattern_add_multiple=Add M&ultiple... +ExclusionInclusionDialog_exclusion_pattern_remove=Rem&ove +ExclusionInclusionDialog_exclusion_pattern_edit=Edi&t... + +ExclusionInclusionDialog_ChooseExclusionPattern_title=Exclusion Pattern Selection +ExclusionInclusionDialog_ChooseExclusionPattern_description=&Choose folders or files to exclude: + +ExclusionInclusionDialog_ChooseInclusionPattern_title=Inclusion Pattern Selection +ExclusionInclusionDialog_ChooseInclusionPattern_description=&Choose folders or files to include: + +# ------- ExclusionInclusionEntryDialog ------- + +ExclusionInclusionEntryDialog_exclude_add_title=Add Exclusion Pattern +ExclusionInclusionEntryDialog_exclude_edit_title=Edit Exclusion Pattern +ExclusionInclusionEntryDialog_exclude_description=Enter a pattern for excluding files from the source folder. Allowed wildcards are '*', '?' and '**'. Examples: 'src/util/a*.c', 'src/util/', '**/Test*'. + +ExclusionInclusionEntryDialog_exclude_pattern_label=E&xclusion pattern (Path relative to ''{0}''): + +ExclusionInclusionEntryDialog_include_add_title=Add Inclusion Pattern +ExclusionInclusionEntryDialog_include_edit_title=Edit Inclusion Pattern +ExclusionInclusionEntryDialog_include_description=Enter a pattern for including files to the source folder. Allowed wildcards are '*', '?' and '**'. Examples: 'src/util/a*.c', 'src/util/', '**/Test*'. + +ExclusionInclusionEntryDialog_include_pattern_label=I&nclusion pattern (Path relative to ''{0}''): + +ExclusionInclusionEntryDialog_pattern_button=Bro&wse... + +ExclusionInclusionEntryDialog_error_empty=Enter a pattern. +ExclusionInclusionEntryDialog_error_notrelative=Pattern must be a relative path. +ExclusionInclusionEntryDialog_error_exists=Pattern already exists. + +ExclusionInclusionEntryDialog_ChooseExclusionPattern_title=Exclusion Pattern Selection +ExclusionInclusionEntryDialog_ChooseExclusionPattern_description=&Choose a folder or file to exclude: + +ExclusionInclusionEntryDialog_ChooseInclusionPattern_title=Inclusion Pattern Selection +ExclusionInclusionEntryDialog_ChooseInclusionPattern_description=&Choose a folder or file to include: \ No newline at end of file diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/BuildPropertyPage.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/BuildPropertyPage.java index 95f7ff6..4155cce 100644 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/BuildPropertyPage.java +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/BuildPropertyPage.java @@ -1,17 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2010 Alena Laskavaia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.codan.internal.ui.preferences; -import org.eclipse.cdt.codan.core.CodanCorePlugin; import org.eclipse.cdt.codan.core.PreferenceConstants; -import org.eclipse.cdt.codan.ui.actions.ToggleNatureAction; +import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; +import org.eclipse.cdt.codan.internal.ui.actions.ToggleNatureAction; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.preferences.IScopeContext; -import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.IWorkbenchPropertyPage; -import org.eclipse.ui.preferences.ScopedPreferenceStore; public class BuildPropertyPage extends FieldEditorPreferencePage implements IWorkbenchPropertyPage { @@ -21,8 +29,7 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements * */ public BuildPropertyPage() { - setPreferenceStore(org.eclipse.cdt.codan.ui.Activator.getDefault() - .getPreferenceStore()); + setPreferenceStore(CodanUIActivator.getDefault().getPreferenceStore()); } /* @@ -35,7 +42,9 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements @Override protected void createFieldEditors() { addField(new BooleanFieldEditor(PreferenceConstants.P_RUN_ON_BUILD, - "&Run with Build", getFieldEditorParent())); + CodanUIMessages.BuildPropertyPage_RunWithBuild, getFieldEditorParent())); + addField(new BooleanFieldEditor(PreferenceConstants.P_RUN_IN_EDITOR, + CodanUIMessages.BuildPropertyPage_RunAsYouType, getFieldEditorParent())); } @Override @@ -70,7 +79,9 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements * @see org.eclipse.ui.IWorkbenchPropertyPage#getElement() */ public IAdaptable getElement() { - return element; + if (element.getAdapter(IProject.class) != null) + return (IProject) element.getAdapter(IProject.class); + return null; } /* @@ -82,16 +93,14 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements */ public void setElement(IAdaptable element) { this.element = element; - ProjectScope ps = new ProjectScope((IProject) getElement()); - ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, - CodanCorePlugin.PLUGIN_ID); - scoped - .setSearchContexts(new IScopeContext[] { ps, - new InstanceScope() }); - setPreferenceStore(scoped); + if (getElement() != null) { + IPreferenceStore scoped = CodanUIActivator.getDefault() + .getPreferenceStore(((IProject) getElement())); + setPreferenceStore(scoped); + } } protected String getPageId() { - return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage"; + return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage"; //$NON-NLS-1$ } } diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Entries index 980f899..f152569 100644 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Entries +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Entries @@ -1,8 +1,7 @@ -/BuildPropertyPage.java/1.4/Sat Aug 22 21:16:50 2009// -/CheckedTreeEditor.java/1.4/Wed Apr 22 01:26:58 2009// -/CodanPreferencePage.java/1.4/Sat Aug 22 21:16:50 2009// -/FieldEditorOverlayPage.java/1.3/Sat Apr 18 04:01:44 2009// -/Messages.java/1.1/Thu Apr 9 12:47:54 2009// -/Messages.properties/1.1/Thu Apr 9 12:47:54 2009// -/PreferenceInitializer.java/1.2/Thu Apr 16 01:46:56 2009// -/ProblemsTreeEditor.java/1.8/Wed Dec 16 21:48:50 2009// +/BuildPropertyPage.java/1.10/Sun Jun 27 01:30:36 2010//TCDT_7_0_0 +/CheckedTreeEditor.java/1.7/Sun Jun 27 01:30:36 2010//TCDT_7_0_0 +/CodanPreferencePage.java/1.16/Sun Jun 27 01:30:36 2010//TCDT_7_0_0 +/FieldEditorOverlayPage.java/1.7/Sun Jun 27 01:30:36 2010//TCDT_7_0_0 +/FileScopePreferencePage.java/1.2/Thu Jun 3 17:01:39 2010//TCDT_7_0_0 +/PreferenceInitializer.java/1.6/Sun Jun 27 01:30:36 2010//TCDT_7_0_0 +/ProblemsTreeEditor.java/1.17/Sun Jun 27 01:30:36 2010//TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CheckedTreeEditor.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CheckedTreeEditor.java index 7c98ef4..ce55a32 100644 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CheckedTreeEditor.java +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CheckedTreeEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.codan.internal.ui.preferences; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; import org.eclipse.jface.preference.FieldEditor; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTreeViewer; @@ -312,7 +313,7 @@ public abstract class CheckedTreeEditor extends FieldEditor implements if (!emptySelectionAllowed) { Object[] checkedElements = getTreeViewer().getCheckedElements(); if (checkedElements.length == 0) { - showErrorMessage("Selection cannot be empty"); + showErrorMessage(CodanUIMessages.CheckedTreeEditor_SelectionCannotBeEmpty); return false; } } diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java index 35b9a8f..825e8cd 100644 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Alena Laskavaia + * Copyright (c) 2009, 2010 Alena Laskavaia * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,12 +10,37 @@ *******************************************************************************/ package org.eclipse.cdt.codan.internal.ui.preferences; +import java.text.MessageFormat; + import org.eclipse.cdt.codan.core.CodanCorePlugin; import org.eclipse.cdt.codan.core.CodanRuntime; import org.eclipse.cdt.codan.core.model.ICheckersRegistry; +import org.eclipse.cdt.codan.core.model.IProblem; import org.eclipse.cdt.codan.core.model.IProblemProfile; +import org.eclipse.cdt.codan.core.param.IProblemPreference; +import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; +import org.eclipse.cdt.codan.internal.ui.dialogs.CustomizeProblemDialog; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.preferences.ScopedPreferenceStore; @@ -33,16 +58,39 @@ import org.eclipse.ui.preferences.ScopedPreferenceStore; public class CodanPreferencePage extends FieldEditorOverlayPage implements IWorkbenchPreferencePage { private IProblemProfile profile; + private ISelectionChangedListener problemSelectionListener; + private IProblem selectedProblem; + private Group info; + private Label infoDesc; + private Label infoMessage; + private Label infoParams; + private Button infoButton; + private ProblemsTreeEditor checkedTreeEditor; public CodanPreferencePage() { super(GRID); setPreferenceStore(new ScopedPreferenceStore(new InstanceScope(), CodanCorePlugin.PLUGIN_ID)); - setDescription("Code Analyzers Preference Page"); + // setDescription("Code Analysis Preference Page"); + problemSelectionListener = new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + if (info != null) { + if (event.getSelection() instanceof ITreeSelection) { + ITreeSelection s = (ITreeSelection) event + .getSelection(); + if (s.getFirstElement() instanceof IProblem) + setSelectedProblem((IProblem) s.getFirstElement()); + else + setSelectedProblem(null); + } + } + } + }; } + @Override protected String getPageId() { - return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage"; + return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage"; //$NON-NLS-1$ } /** @@ -50,13 +98,93 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements * GUI blocks needed to manipulate various types of preferences. Each field * editor knows how to save and restore itself. */ + @Override public void createFieldEditors() { profile = isPropertyPage() ? getRegistry() .getResourceProfileWorkingCopy((IResource) getElement()) : getRegistry().getWorkspaceProfile(); - CheckedTreeEditor checkedTreeEditor = new ProblemsTreeEditor( - getFieldEditorParent(), profile); + checkedTreeEditor = new ProblemsTreeEditor(getFieldEditorParent(), + profile); addField(checkedTreeEditor); + checkedTreeEditor.getTreeViewer().addSelectionChangedListener( + problemSelectionListener); + checkedTreeEditor.getTreeViewer().addDoubleClickListener( + new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) { + openCustomizeDialog(); + } + }); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.internal.ui.preferences.FieldEditorOverlayPage# + * createContents(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createContents(Composite parent) { + Composite comp = (Composite) super.createContents(parent); + createInfoControl(comp); + return comp; + } + + /** + * @param comp + */ + private void createInfoControl(Composite comp) { + info = new Group(comp, SWT.NONE); + info.setLayoutData(new GridData(GridData.FILL_BOTH)); + info.setLayout(new GridLayout(3, false)); + info.setText(CodanUIMessages.CodanPreferencePage_Info); + GridDataFactory gdLab = GridDataFactory.swtDefaults() + .align(SWT.BEGINNING, SWT.BEGINNING).grab(false, false); + GridDataFactory gdFact = GridDataFactory.swtDefaults() + .align(SWT.BEGINNING, SWT.BEGINNING).grab(true, true); + // message + Label labelMessage = new Label(info, SWT.NONE); + labelMessage.setText(CodanUIMessages.CodanPreferencePage_MessageLabel); + labelMessage.setLayoutData(gdLab.create()); + infoMessage = new Label(info, SWT.WRAP); + infoMessage.setLayoutData(gdFact.copy().span(2, 1).create()); + // description + Label labelDesc = new Label(info, SWT.NONE); + labelDesc.setText(CodanUIMessages.CodanPreferencePage_Description); + labelDesc.setLayoutData(gdLab.create()); + infoDesc = new Label(info, SWT.WRAP); + PixelConverter pixelConverter = new PixelConverter(comp); + infoDesc.setLayoutData(gdFact + .copy() + .span(2, 1) + .hint(pixelConverter.convertWidthInCharsToPixels(60), + pixelConverter.convertHeightInCharsToPixels(3)) + .create()); + // params + Label labelParams = new Label(info, SWT.NONE); + labelParams.setText(CodanUIMessages.CodanPreferencePage_Parameters); + labelParams.setLayoutData(gdLab.create()); + infoParams = new Label(info, SWT.NONE); + infoParams.setLayoutData(gdFact.create()); + infoButton = new Button(info, SWT.PUSH); + infoButton.setLayoutData(GridDataFactory.swtDefaults() + .align(SWT.END, SWT.BEGINNING).create()); + infoButton.setText(CodanUIMessages.CodanPreferencePage_Customize); + infoButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + openCustomizeDialog(); + } + }); + restoreWidgetValues(); + } + + /** + * @param selection + */ + protected void setSelectedProblem(IProblem problem) { + this.selectedProblem = problem; + updateProblemInfo(); } /** @@ -73,11 +201,70 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements */ @Override public boolean performOk() { - if (isPropertyPage()) - getRegistry().updateProfile((IResource) getElement(), null); + saveWidgetValues(); + // if (isPropertyPage()) + getRegistry().updateProfile((IResource) getElement(), null); return super.performOk(); } + /** + * + */ + private void saveWidgetValues() { + CodanUIActivator + .getDefault() + .getDialogSettings() + .put(getWidgetId(), + selectedProblem == null ? "" : selectedProblem.getId()); //$NON-NLS-1$ + } + + private void restoreWidgetValues() { + String id = CodanUIActivator.getDefault().getDialogSettings() + .get(getWidgetId()); + if (id != null && id.length() > 0) { + checkedTreeEditor.getTreeViewer().setSelection( + new StructuredSelection(profile.findProblem(id)), true); + } else { + setSelectedProblem(null); + } + } + + /** + * @return + */ + protected String getWidgetId() { + return getPageId() + ".selection"; //$NON-NLS-1$ + } + + /** + * + */ + private void updateProblemInfo() { + if (selectedProblem == null) { + infoMessage.setText(""); //$NON-NLS-1$ + infoDesc.setText(""); //$NON-NLS-1$ + infoParams.setText(""); //$NON-NLS-1$ + infoButton.setEnabled(false); + } else { + IProblemPreference pref = selectedProblem.getPreference(); + String description = selectedProblem.getDescription(); + if (description == null) + description = CodanUIMessages.CodanPreferencePage_NoInfo; + String messagePattern = selectedProblem.getMessagePattern(); + String message = CodanUIMessages.CodanPreferencePage_NoInfo; + if (messagePattern != null) { + message = MessageFormat.format(messagePattern, "X", "Y", "Z"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + infoMessage.setText(message); + infoDesc.setText(description); + infoParams + .setText(pref == null ? CodanUIMessages.CodanPreferencePage_NoInfo + : CodanUIMessages.CodanPreferencePage_HasPreferences); + infoButton.setEnabled(true); + } + info.layout(true); + } + /* * (non-Javadoc) * @@ -86,4 +273,13 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements */ public void init(IWorkbench workbench) { } + + /** + * + */ + protected void openCustomizeDialog() { + CustomizeProblemDialog d = new CustomizeProblemDialog(getShell(), + selectedProblem, (IResource) getElement()); + d.open(); + } } \ No newline at end of file diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java index e617a75..714d841 100644 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003 Berthold Daum. + * Copyright (c) 2003, 2010 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 @@ -16,6 +16,7 @@ import java.util.List; import org.eclipse.cdt.codan.core.CodanCorePlugin; import org.eclipse.cdt.codan.core.PreferenceConstants; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.runtime.IAdaptable; @@ -121,6 +122,10 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage * @see org.eclipse.ui.IWorkbenchPropertyPage#getElement() */ public IAdaptable getElement() { + if (element == null) + return element; + if (!(element instanceof IProject)) + return (IAdaptable) element.getAdapter(IProject.class); return element; } @@ -157,12 +162,15 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage // Cache the page id pageId = getPageId(); // Create an overlay preference store and fill it with properties - ProjectScope ps = new ProjectScope((IProject) getElement()); - ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, - CodanCorePlugin.PLUGIN_ID); - scoped.setSearchContexts(new IScopeContext[] { ps, - new InstanceScope() }); - overlayStore = scoped; + IAdaptable e = getElement(); + if (e != null) { + ProjectScope ps = new ProjectScope((IProject) e); + 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); @@ -200,13 +208,12 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage 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, + CodanUIMessages.OverlayPage_Use_Workspace_Settings); + useProjectSettingsButton = createRadioButton(radioGroup, + CodanUIMessages.OverlayPage_Use_Project_Settings); configureButton = new Button(comp, SWT.PUSH); - configureButton.setText(Messages - .getString("OverlayPage.Configure_Workspace_Settings")); //$NON-NLS-1$ + configureButton.setText(CodanUIMessages.OverlayPage_Use_Workspace_Settings); configureButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { configureWorkspaceSettings(); @@ -322,6 +329,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage /** * Creates a new preferences page and opens it */ + @SuppressWarnings("cast") protected void configureWorkspaceSettings() { try { // create a new instance of the current class diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FileScopePreferencePage.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FileScopePreferencePage.java new file mode 100644 index 0000000..149dee9 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FileScopePreferencePage.java @@ -0,0 +1,312 @@ +/******************************************************************************* + * Copyright (c) 2010 Alena Laskavaia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui.preferences; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference; +import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; +import org.eclipse.cdt.codan.internal.ui.dialogs.ExclusionInclusionEntryDialog; +import org.eclipse.cdt.codan.internal.ui.widgets.BasicElementLabels; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IListAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +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; + +public class FileScopePreferencePage extends PreferencePage { + private ListDialogField fInclusionPatternList; + private ListDialogField fExclusionPatternList; + private FileScopeProblemPreference fCurrElement; + private IProject fCurrProject; + private IContainer fCurrSourceFolder; + private static final int IDX_ADD = 0; + private static final int IDX_ADD_MULTIPLE = 1; + private static final int IDX_EDIT = 2; + private static final int IDX_REMOVE = 4; + + public FileScopePreferencePage(FileScopeProblemPreference entryToEdit) { + setTitle(CodanUIMessages.ExclusionInclusionDialog_title); + setDescription(CodanUIMessages.ExclusionInclusionDialog_description2); + fCurrElement = entryToEdit; + fCurrProject = entryToEdit.getProject(); + IWorkspaceRoot root = fCurrProject != null ? fCurrProject + .getWorkspace().getRoot() : ResourcesPlugin.getWorkspace() + .getRoot(); + IResource res = root.findMember(entryToEdit.getPath()); + if (res instanceof IContainer) { + fCurrSourceFolder = (IContainer) res; + } + if (res == null) + fCurrSourceFolder = root; + String excLabel = CodanUIMessages.ExclusionInclusionDialog_exclusion_pattern_label; + ImageDescriptor excDescriptor = null; //JavaPluginImages.DESC_OBJS_EXCLUSION_FILTER_ATTRIB; + String[] excButtonLabels = new String[] { + CodanUIMessages.ExclusionInclusionDialog_exclusion_pattern_add, + CodanUIMessages.ExclusionInclusionDialog_exclusion_pattern_add_multiple, + CodanUIMessages.ExclusionInclusionDialog_exclusion_pattern_edit, + null, + CodanUIMessages.ExclusionInclusionDialog_exclusion_pattern_remove }; + String incLabel = CodanUIMessages.ExclusionInclusionDialog_inclusion_pattern_label; + ImageDescriptor incDescriptor = null; //JavaPluginImages.DESC_OBJS_INCLUSION_FILTER_ATTRIB; + String[] incButtonLabels = new String[] { + CodanUIMessages.ExclusionInclusionDialog_inclusion_pattern_add, + CodanUIMessages.ExclusionInclusionDialog_inclusion_pattern_add_multiple, + CodanUIMessages.ExclusionInclusionDialog_inclusion_pattern_edit, + null, + CodanUIMessages.ExclusionInclusionDialog_inclusion_pattern_remove }; + fExclusionPatternList = createListContents(entryToEdit, + FileScopeProblemPreference.EXCLUSION, excLabel, null, + excButtonLabels); + fInclusionPatternList = createListContents(entryToEdit, + FileScopeProblemPreference.INCLUSION, incLabel, null, + incButtonLabels); + } + + @Override + protected Control createContents(Composite parent) { + Composite inner = new Composite(parent, SWT.NONE); + inner.setFont(parent.getFont()); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 2; + inner.setLayout(layout); + inner.setLayoutData(new GridData(GridData.FILL_BOTH)); + fInclusionPatternList.doFillIntoGrid(inner, 3); + LayoutUtil.setHorizontalSpan( + fInclusionPatternList.getLabelControl(null), 2); + LayoutUtil.setHorizontalGrabbing(fInclusionPatternList + .getListControl(null)); + fExclusionPatternList.doFillIntoGrid(inner, 3); + LayoutUtil.setHorizontalSpan( + fExclusionPatternList.getLabelControl(null), 2); + LayoutUtil.setHorizontalGrabbing(fExclusionPatternList + .getListControl(null)); + setControl(inner); + Dialog.applyDialogFont(inner); + return inner; + } + + private static class ExclusionInclusionLabelProvider extends LabelProvider { + private Image fElementImage; + + public ExclusionInclusionLabelProvider(String descriptorPath) { + if (descriptorPath != null) { + ImageDescriptor d = CodanUIActivator + .getImageDescriptor(descriptorPath); + } + fElementImage = null; // XXX + } + + @Override + public Image getImage(Object element) { + return fElementImage; + } + + @Override + public String getText(Object element) { + return BasicElementLabels.getFilePattern((String) element); + } + } + + private ListDialogField createListContents( + FileScopeProblemPreference entryToEdit, String key, String label, + String descriptor, String[] buttonLabels) { + ExclusionPatternAdapter adapter = new ExclusionPatternAdapter(); + ListDialogField patternList = new ListDialogField(adapter, + buttonLabels, new ExclusionInclusionLabelProvider(descriptor)); + patternList.setDialogFieldListener(adapter); + patternList.setLabelText(label); + patternList.enableButton(IDX_EDIT, false); + IPath[] pattern = entryToEdit.getAttribute(key); + ArrayList elements = new ArrayList(pattern.length); + for (int i = 0; i < pattern.length; i++) { + String patternName = pattern[i].toString(); + if (patternName.length() > 0) + elements.add(patternName); + } + patternList.setElements(elements); + patternList.selectFirstElement(); + patternList.enableButton(IDX_ADD_MULTIPLE, fCurrSourceFolder != null); + patternList.setViewerComparator(new ViewerComparator()); + return patternList; + } + + protected void doCustomButtonPressed(ListDialogField field, int index) { + if (index == IDX_ADD) { + addEntry(field); + } else if (index == IDX_EDIT) { + editEntry(field); + } else if (index == IDX_ADD_MULTIPLE) { + addMultipleEntries(field); + } else if (index == IDX_REMOVE) { + field.removeElements(field.getSelectedElements()); + } + updateStatus(); + } + + private void updateStatus() { + fCurrElement.setAttribute(FileScopeProblemPreference.INCLUSION, + getInclusionPattern()); + fCurrElement.setAttribute(FileScopeProblemPreference.EXCLUSION, + getExclusionPattern()); + } + + protected void doDoubleClicked(ListDialogField field) { + editEntry(field); + updateStatus(); + } + + protected void doSelectionChanged(ListDialogField field) { + List selected = field.getSelectedElements(); + field.enableButton(IDX_EDIT, canEdit(selected)); + } + + private boolean canEdit(List selected) { + return selected.size() == 1; + } + + private void editEntry(ListDialogField field) { + List selElements = field.getSelectedElements(); + if (selElements.size() != 1) { + return; + } + List existing = field.getElements(); + String entry = (String) selElements.get(0); + ExclusionInclusionEntryDialog dialog = new ExclusionInclusionEntryDialog( + getShell(), isExclusion(field), entry, existing, fCurrElement); + if (dialog.open() == Window.OK) { + field.replaceElement(entry, dialog.getExclusionPattern()); + } + } + + private boolean isExclusion(ListDialogField field) { + return field == fExclusionPatternList; + } + + private void addEntry(ListDialogField field) { + List existing = field.getElements(); + ExclusionInclusionEntryDialog dialog = new ExclusionInclusionEntryDialog( + getShell(), isExclusion(field), null, existing, fCurrElement); + if (dialog.open() == Window.OK) { + field.addElement(dialog.getExclusionPattern()); + } + } + + // -------- ExclusionPatternAdapter -------- + private class ExclusionPatternAdapter implements IListAdapter, + IDialogFieldListener { + /** + * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#customButtonPressed(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField, + * int) + */ + public void customButtonPressed(ListDialogField field, int index) { + doCustomButtonPressed(field, index); + } + + /** + * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#selectionChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField) + */ + public void selectionChanged(ListDialogField field) { + doSelectionChanged(field); + } + + /** + * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#doubleClicked(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField) + */ + public void doubleClicked(ListDialogField field) { + doDoubleClicked(field); + } + + /** + * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField) + */ + public void dialogFieldChanged(DialogField field) { + } + } + + protected void doStatusLineUpdate() { + } + + protected void checkIfPatternValid() { + } + + private IPath[] getPattern(ListDialogField field) { + Object[] arr = field.getElements().toArray(); + Arrays.sort(arr); + IPath[] res = new IPath[arr.length]; + for (int i = 0; i < res.length; i++) { + res[i] = new Path((String) arr[i]); + } + return res; + } + + public IPath[] getExclusionPattern() { + return getPattern(fExclusionPatternList); + } + + public IPath[] getInclusionPattern() { + return getPattern(fInclusionPatternList); + } + + /* + * @see org.eclipse.jface.window.Window#configureShell(Shell) + */ + protected void configureShell(Shell newShell) { + } + + private void addMultipleEntries(ListDialogField field) { + String title, message; + if (isExclusion(field)) { + title = CodanUIMessages.ExclusionInclusionDialog_ChooseExclusionPattern_title; + message = CodanUIMessages.ExclusionInclusionDialog_ChooseExclusionPattern_description; + } else { + title = CodanUIMessages.ExclusionInclusionDialog_ChooseInclusionPattern_title; + message = CodanUIMessages.ExclusionInclusionDialog_ChooseInclusionPattern_description; + } + IPath[] res = ExclusionInclusionEntryDialog.chooseExclusionPattern( + getShell(), fCurrSourceFolder, title, message, null, true); + if (res != null) { + for (int i = 0; i < res.length; i++) { + field.addElement(res[i].toString()); + } + } + } + + @Override + public void noDefaultAndApplyButton() { + super.noDefaultAndApplyButton(); + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/Messages.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/Messages.java deleted file mode 100644 index 4ef5f89..0000000 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/Messages.java +++ /dev/null @@ -1,47 +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.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$ - } - } -} - diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/Messages.properties b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/Messages.properties deleted file mode 100644 index 689b7ee..0000000 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/Messages.properties +++ /dev/null @@ -1,4 +0,0 @@ -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 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java index 4362098..645a892 100644 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Alena Laskavaia + * Copyright (c) 2009, 2010 Alena Laskavaia * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,6 +11,7 @@ package org.eclipse.cdt.codan.internal.ui.preferences; import org.eclipse.cdt.codan.core.PreferenceConstants; +import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.jface.preference.IPreferenceStore; @@ -18,16 +19,16 @@ 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() + * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer# + * initializeDefaultPreferences() */ public void initializeDefaultPreferences() { - IPreferenceStore store = org.eclipse.cdt.codan.ui.Activator - .getDefault().getPreferenceStore(); + IPreferenceStore store = CodanUIActivator.getDefault() + .getPreferenceStore(); store.setDefault(PreferenceConstants.P_RUN_ON_BUILD, false); + store.setDefault(PreferenceConstants.P_RUN_IN_EDITOR, true); } - } diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java index 26e433e..4547028 100644 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Alena Laskavaia + * Copyright (c) 2009, 2010 Alena Laskavaia * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,24 +14,27 @@ import org.eclipse.cdt.codan.core.PreferenceConstants; 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.IProblemElement; import org.eclipse.cdt.codan.core.model.IProblemProfile; +import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; import org.eclipse.cdt.codan.internal.core.CodanPreferencesLoader; -import org.eclipse.jface.viewers.BaseLabelProvider; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; +import org.eclipse.core.resources.IMarker; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.ComboBoxCellEditor; import org.eclipse.jface.viewers.EditingSupport; -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; import org.eclipse.jface.viewers.TreeViewerColumn; 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.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; public class ProblemsTreeEditor extends CheckedTreeEditor { private CodanPreferencesLoader codanPreferencesLoader = new CodanPreferencesLoader(); @@ -136,39 +139,26 @@ public class ProblemsTreeEditor extends CheckedTreeEditor { } } + @Override public void checkStateChanged(CheckStateChangedEvent event) { Object element = event.getElement(); - if (element instanceof IProblem) { - ((IProblem) element).setEnabled(event.getChecked()); - } - } - - 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(); + if (element instanceof IProblemWorkingCopy) { + ((IProblemWorkingCopy) element).setEnabled(event.getChecked()); + } else if (element instanceof IProblemCategory) { + IProblemCategory cat = (IProblemCategory) element; + IProblemElement[] children = cat.getChildren(); + for (int i = 0; i < children.length; i++) { + IProblemElement pe = children[i]; + checkStateChanged(new CheckStateChangedEvent(getTreeViewer(), + pe, event.getChecked())); } - return null; } + getTreeViewer().refresh(); } public ProblemsTreeEditor(Composite parent, IProblemProfile profile) { - super(PreferenceConstants.P_PROBLEMS, "Problems", parent); + super(PreferenceConstants.P_PROBLEMS, + CodanUIMessages.ProblemsTreeEditor_Problems, parent); setEmptySelectionAllowed(true); getTreeViewer().getTree().setHeaderVisible(true); // getTreeViewer().getTree(). @@ -178,8 +168,10 @@ public class ProblemsTreeEditor extends CheckedTreeEditor { TreeViewerColumn column1 = new TreeViewerColumn(getTreeViewer(), SWT.NONE); column1.getColumn().setWidth(300); - column1.getColumn().setText("Name"); + column1.getColumn().setText( + CodanUIMessages.ProblemsTreeEditor_NameColumn); column1.setLabelProvider(new ColumnLabelProvider() { + @Override public String getText(Object element) { if (element instanceof IProblem) { IProblem p = (IProblem) element; @@ -196,8 +188,31 @@ public class ProblemsTreeEditor extends CheckedTreeEditor { TreeViewerColumn column2 = new TreeViewerColumn(getTreeViewer(), SWT.NONE); column2.getColumn().setWidth(100); - column2.getColumn().setText("Severity"); + column2.getColumn().setText( + CodanUIMessages.ProblemsTreeEditor_SeverityColumn); column2.setLabelProvider(new ColumnLabelProvider() { + @Override + public Image getImage(Object element) { + final ISharedImages images = PlatformUI.getWorkbench() + .getSharedImages(); + if (element instanceof IProblem) { + IProblem p = (IProblem) element; + switch (p.getSeverity().intValue()) { + case IMarker.SEVERITY_INFO: + return images + .getImage(ISharedImages.IMG_OBJS_INFO_TSK); + case IMarker.SEVERITY_WARNING: + return images + .getImage(ISharedImages.IMG_OBJS_WARN_TSK); + case IMarker.SEVERITY_ERROR: + return images + .getImage(ISharedImages.IMG_OBJS_ERROR_TSK); + } + } + return null; + } + + @Override public String getText(Object element) { if (element instanceof IProblem) { IProblem p = (IProblem) element; @@ -207,23 +222,27 @@ public class ProblemsTreeEditor extends CheckedTreeEditor { } }); column2.setEditingSupport(new EditingSupport(getTreeViewer()) { + @Override protected boolean canEdit(Object element) { return element instanceof IProblem; } + @Override protected CellEditor getCellEditor(Object element) { return new ComboBoxCellEditor(getTreeViewer().getTree(), CodanSeverity.stringValues()); } + @Override protected Object getValue(Object element) { return ((IProblem) element).getSeverity().intValue(); } + @Override protected void setValue(Object element, Object value) { int index = ((Integer) value).intValue(); CodanSeverity val = CodanSeverity.values()[index]; - ((IProblem) element).setSeverity(val); + ((IProblemWorkingCopy) element).setSeverity(val); getTreeViewer().update(element, null); } }); @@ -245,6 +264,9 @@ public class ProblemsTreeEditor extends CheckedTreeEditor { for (int i = 0; i < probs.length; i++) { String id = probs[i].getId(); String s = getPreferenceStore().getString(id); + if (s == null || s.length() == 0) { + s = codanPreferencesLoader.getProperty(id); + } codanPreferencesLoader.setProperty(id, s); } getViewer().setInput(codanPreferencesLoader.getInput()); @@ -258,6 +280,9 @@ public class ProblemsTreeEditor extends CheckedTreeEditor { for (int i = 0; i < probs.length; i++) { String id = probs[i].getId(); String s = getPreferenceStore().getDefaultString(id); + if (s == null || s.length() == 0) { + s = codanPreferencesLoader.getProperty(id); + } codanPreferencesLoader.setProperty(id, s); } getViewer().setInput(codanPreferencesLoader.getInput()); @@ -272,12 +297,17 @@ public class ProblemsTreeEditor extends CheckedTreeEditor { */ @Override protected void doStore() { - codanPreferencesLoader.setInput(getViewer().getInput()); + codanPreferencesLoader.setInput((IProblemProfile) getViewer() + .getInput()); IProblem[] probs = codanPreferencesLoader.getProblems(); for (int i = 0; i < probs.length; i++) { String id = probs[i].getId(); String s = codanPreferencesLoader.getProperty(id); getPreferenceStore().setValue(id, s); + String params = codanPreferencesLoader.getPreferencesString(id); + if (params != null) + getPreferenceStore().setValue( + codanPreferencesLoader.getPreferencesKey(id), params); } } @@ -301,6 +331,6 @@ public class ProblemsTreeEditor extends CheckedTreeEditor { */ @Override protected String modelToString(Object model) { - return ""; + return ""; //$NON-NLS-1$ } } diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Entries new file mode 100644 index 0000000..58fdd77 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Entries @@ -0,0 +1,3 @@ +/GenericCodanProblemDetailsProvider.java/1.2/Sat May 1 00:41:55 2010//TCDT_7_0_0 +/ProblemDetails.java/1.5/Wed May 5 20:48:28 2010//TCDT_7_0_0 +/ProblemDetailsExtensions.java/1.2/Sat May 1 00:41:55 2010//TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Repository b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Repository new file mode 100644 index 0000000..b01fe09 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.cdt/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Root b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/GenericCodanProblemDetailsProvider.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/GenericCodanProblemDetailsProvider.java new file mode 100644 index 0000000..0afb53c --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/GenericCodanProblemDetailsProvider.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui.views; + +import org.eclipse.cdt.codan.ui.AbstractCodanProblemDetailsProvider; + +/** + * This provides details for errors that do not have own details provider + */ +public class GenericCodanProblemDetailsProvider extends AbstractCodanProblemDetailsProvider { + @Override + public boolean isApplicable(String id) { + return true; + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java new file mode 100644 index 0000000..3f164af --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui.views; + +import java.util.Collection; + +import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; +import org.eclipse.cdt.codan.ui.AbstractCodanProblemDetailsProvider; +import org.eclipse.cdt.codan.ui.CodanEditorUtility; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Link; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.part.ViewPart; + +/** + * Problems Details view show details for selected problem marker. + * Other plugins can contribute to override default behaviour using + * codanProblemDetails extension point. + */ +public class ProblemDetails extends ViewPart { + /** + * The ID of the view as specified by the extension. + */ + public static final String ID = "org.eclipse.cdt.codan.internal.ui.views.ProblemDetails"; //$NON-NLS-1$ + private Composite area; + /** + * Control for problem message, which can include location + */ + private Link message; + /** + * Control for problem description which can include links to help or web-sites with extra info + */ + private Link description; + private GenericCodanProblemDetailsProvider genProvider = new GenericCodanProblemDetailsProvider(); + private AbstractCodanProblemDetailsProvider curProvider = genProvider; + + /** + * The constructor. + */ + public ProblemDetails() { + } + + /** + * This is a callback that will allow us + * to create the area and initialize it. + */ + public void createPartControl(Composite parent) { + final String problemsViewId = "org.eclipse.ui.views.ProblemView"; //$NON-NLS-1$ + area = new Composite(parent, SWT.NONE); + area.setLayout(new GridLayout()); + SelectionAdapter linkSelAdapter = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + String link = e.text; + if (link == null) + return; + if (link.startsWith("http")) { //$NON-NLS-1$ + org.eclipse.swt.program.Program.launch(e.text); + return; + } + // link file format example "file:/tmp/file.c#42", 42 is the line number + if (link.startsWith("file:")) { //$NON-NLS-1$ + try { + CodanEditorUtility.openInEditor(link, curProvider.getMarker().getResource()); + } catch (PartInitException e1) { + CodanUIActivator.log(e1); + } + return; + } + if (link.startsWith("help:")) { //$NON-NLS-1$ + // open in eclipse help TODO + return; + } + } + }; + message = new Link(area, SWT.WRAP); + message.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + message.addSelectionListener(linkSelAdapter); + description = new Link(area, SWT.WRAP); + description.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + description.addSelectionListener(linkSelAdapter); + ISelectionService ser = (ISelectionService) getSite().getService(ISelectionService.class); + ser.addSelectionListener(new ISelectionListener() { + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if (part.getSite().getId().equals(problemsViewId)) { + processSelection(selection); + } + } + }); + ISelection selection = ser.getSelection(problemsViewId); + processSelection(selection); + } + + protected void processSelection(ISelection selection) { + if (selection == null || selection.isEmpty()) + return; + if (selection instanceof IStructuredSelection) { + Object firstElement = ((IStructuredSelection) selection).getFirstElement(); + IMarker marker = null; + if (firstElement instanceof IAdaptable) { + marker = (IMarker) ((IAdaptable) firstElement).getAdapter(IMarker.class); + } else if (firstElement instanceof IMarker) { + marker = (IMarker) firstElement; + } + if (marker != null) { + queryProviders(marker); + area.layout(); + } + } + } + + private void queryProviders(IMarker marker) { + String id = marker.getAttribute(IMarker.PROBLEM, "id"); //$NON-NLS-1$ + Collection providers = ProblemDetailsExtensions.getProviders(id); + for (AbstractCodanProblemDetailsProvider provider : providers) { + synchronized (provider) { + provider.setMarker(marker); + if (provider.isApplicable(id)) { + applyProvider(provider); + return; + } + } + } + genProvider.setMarker(marker); + applyProvider(genProvider); + } + + private void applyProvider(AbstractCodanProblemDetailsProvider provider) { + curProvider = provider; + setTextSafe(message, provider, provider.getStyledProblemMessage()); + setTextSafe(description, provider, provider.getStyledProblemDescription()); + } + + protected void setTextSafe(Link control, AbstractCodanProblemDetailsProvider provider, String text) { + try { + control.setText(text); + } catch (Exception e) { + // this is debug message + control.setText("failed to set text: " + provider.getClass() + " " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + /** + * Passing the focus request to the area's control. + */ + public void setFocus() { + message.setFocus(); + } +} \ No newline at end of file diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetailsExtensions.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetailsExtensions.java new file mode 100644 index 0000000..689d9d8 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetailsExtensions.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui.views; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; + +import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; +import org.eclipse.cdt.codan.ui.AbstractCodanProblemDetailsProvider; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; + +/** + * Class that can load extension for problemDetails + */ +public class ProblemDetailsExtensions { + public static final String ALL = "*";//$NON-NLS-1$ + private static final String EXTENSION_POINT_NAME = "codanProblemDetails"; //$NON-NLS-1$ + private static boolean extensionsLoaded; + private static HashMap> map = new HashMap>(); + + private static synchronized void readExtensions() { + if (extensionsLoaded) return; + IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(CodanUIActivator.PLUGIN_ID, EXTENSION_POINT_NAME); + if (ep == null) + return; + try { + IConfigurationElement[] elements = ep.getConfigurationElements(); + // process categories + for (int i = 0; i < elements.length; i++) { + IConfigurationElement configurationElement = elements[i]; + processDetails(configurationElement); + } + } finally { + extensionsLoaded = true; + } + } + + /** + * @param configurationElement + */ + private static void processDetails(IConfigurationElement configurationElement) { + if (configurationElement.getName().equals("problemDetails")) { //$NON-NLS-1$ + String id = configurationElement.getAttribute("problemId"); //$NON-NLS-1$ + if (id == null) { + id = ALL; + } + addExtension(id, configurationElement); + } + } + + public static AbstractCodanProblemDetailsProvider resolveClass(IConfigurationElement configurationElement) { + AbstractCodanProblemDetailsProvider res; + try { + res = (AbstractCodanProblemDetailsProvider) configurationElement.createExecutableExtension("class");//$NON-NLS-1$ + } catch (CoreException e) { + CodanUIActivator.log(e); + return null; + } + return res; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + private static void addExtension(String id, IConfigurationElement configurationElement) { + Collection collection = getCollection(id); + collection.add(configurationElement); + } + + /** + * Remove provider from the list + * @param id - codan problem id or ALL + * @param el - details provider (class extending AbstractCodanProblemDetailsProvider) or ElementConfiguration (user internally) + */ + @SuppressWarnings("rawtypes") + public static void removeExtension(String id, Object el) { + Collection collection = getCollection(id); + collection.remove(el); + } + + @SuppressWarnings("rawtypes") + private static Collection getCollection(String id) { + Collection collection = map.get(id); + if (collection == null) { + collection = new ArrayList(); + map.put(id, collection); + } + return collection; + } + + public static Collection getProviders(String id) { + readExtensions(); + Collection providers = new ArrayList(); + Collection collection1 = getCollection(id); + Collection collection2 = getCollection(ALL); + providers.addAll(resolveProviders(collection1)); + providers.addAll(resolveProviders(collection2)); + return providers; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static Collection resolveProviders(Collection collection) { + Collection res = new ArrayList(collection); + for (Iterator iterator = res.iterator(); iterator.hasNext();) { + Object object = iterator.next(); + if (object instanceof IConfigurationElement) { + // resolve + collection.remove(object); + AbstractCodanProblemDetailsProvider provider = resolveClass((IConfigurationElement) object); + if (provider!=null) + collection.add(provider); + } + } + return collection; + } + + /** + * Add extension (details provider) using API + * @param id - codan problem id or ALL + * @param provider - class extending AbstractCodanProblemDetailsProvider + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static void addExtension(String id, AbstractCodanProblemDetailsProvider provider) { + Collection collection = getCollection(id); + collection.add(provider); + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/BasicElementLabels.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/BasicElementLabels.java new file mode 100644 index 0000000..cc2f966 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/BasicElementLabels.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2010 Alena Laskavaia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui.widgets; + +import java.io.File; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.osgi.util.TextProcessor; +import org.eclipse.ui.IWorkingSet; + +/** + * A label provider for basic elements like paths. The label provider will make + * sure that the labels are correctly + * shown in RTL environments. + * + * @since 3.4 + */ +public class BasicElementLabels { + // TextProcessor delimiters + private static final String CODE_DELIMITERS = TextProcessor + .getDefaultDelimiters() + "<>()?,{}+-*!%=^|&;[]~"; //$NON-NLS-1$ + private static final String FILE_PATTERN_DELIMITERS = TextProcessor + .getDefaultDelimiters() + "*.?"; //$NON-NLS-1$ + private static final String URL_DELIMITERS = TextProcessor + .getDefaultDelimiters() + ":@?-"; //$NON-NLS-1$ + + /** + * Returns the label of a path. + * + * @param path + * the path + * @param isOSPath + * if true, the path represents an OS path, if + * false it is a workspace path. + * @return the label of the path to be used in the UI. + */ + public static String getPathLabel(IPath path, boolean isOSPath) { + String label; + if (isOSPath) { + label = path.toOSString(); + } else { + label = path.makeRelative().toString(); + } + return markLTR(label); + } + + /** + * Returns the label of the path of a file. + * + * @param file + * the file + * @return the label of the file path to be used in the UI. + */ + public static String getPathLabel(File file) { + return markLTR(file.getAbsolutePath()); + } + + /** + * Returns the label for a file pattern like '*.java' + * + * @param name + * the pattern + * @return the label of the pattern. + */ + public static String getFilePattern(String name) { + return markLTR(name, FILE_PATTERN_DELIMITERS); + } + + /** + * Returns the label for a URL, URI or URL part. Example is + * 'http://www.x.xom/s.html#1' + * + * @param name + * the URL string + * @return the label of the URL. + */ + public static String getURLPart(String name) { + return markLTR(name, URL_DELIMITERS); + } + + /** + * Returns a label for a resource name. + * + * @param resource + * the resource + * @return the label of the resource name. + */ + public static String getResourceName(IResource resource) { + return markLTR(resource.getName()); + } + + /** + * Returns a label for a resource name. + * + * @param resourceName + * the resource name + * @return the label of the resource name. + */ + public static String getResourceName(String resourceName) { + return markLTR(resourceName); + } + + /** + * Returns a label for Java code snippet used in a label. Example is 'Test + * test= new Test() { ...}'. + * + * @param string + * the Java code snippet + * @return the label for the Java code snippet + */ + public static String getJavaCodeString(String string) { + return markLTR(string, CODE_DELIMITERS); + } + + /** + * Returns a label for a version name. Example is '1.4.1' + * + * @param name + * the version string + * @return the version label + */ + public static String getVersionName(String name) { + return markLTR(name); + } + + /** + * Returns a label for a working set + * + * @param set + * the working set + * @return the label of the working set + */ + public static String getWorkingSetLabel(IWorkingSet set) { + return markLTR(set.getLabel()); + } + + /** + * It does not do anything now, but just in case we need to do the same as + * JDT does (see String.markLTR in JDT) + */ + private static String markLTR(String label) { + return label; + } + + private static String markLTR(String label, String delim) { + return label; + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Entries new file mode 100644 index 0000000..6bad80f --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Entries @@ -0,0 +1,4 @@ +/BasicElementLabels.java/1.2/Thu Jun 3 17:01:40 2010//TCDT_7_0_0 +/CustomizeProblemComposite.java/1.2/Thu Jun 3 17:01:40 2010//TCDT_7_0_0 +/FileScopeComposite.java/1.2/Thu Jun 3 17:01:40 2010//TCDT_7_0_0 +/ParametersComposite.java/1.2/Thu Jun 3 17:01:40 2010//TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Repository b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Repository new file mode 100644 index 0000000..905430a --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.cdt/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Root b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CustomizeProblemComposite.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CustomizeProblemComposite.java new file mode 100644 index 0000000..32ba550 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/CustomizeProblemComposite.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui.widgets; + +import org.eclipse.cdt.codan.core.model.IProblem; +import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; +import org.eclipse.core.resources.IResource; +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.TabFolder; +import org.eclipse.swt.widgets.TabItem; + +/** + * Composite for problem customisable parameters + * + */ +public class CustomizeProblemComposite extends Composite { + private Composite parametersTab; + private IProblem problem; + private ParametersComposite problemsComposite; + private FileScopeComposite scopeComposite; + private IResource resource; + + /** + * @param parent + * @param selectedProblem + * @param resource + * @param style + */ + public CustomizeProblemComposite(Composite parent, + IProblem selectedProblem, IResource resource) { + super(parent, SWT.NONE); + this.setLayout(new GridLayout(1, false)); + this.problem = selectedProblem; + this.resource = resource; + final TabFolder tabFolder = new TabFolder(this, SWT.TOP); + tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH)); + // createMainTab(tabFolder); + createParamtersTab(tabFolder); + createScopeTab(tabFolder); + } + + public void save(IProblemWorkingCopy problem) { + problemsComposite.save(problem); + scopeComposite.save(problem); + } + + /** + * @param tabFolder + */ + private void createParamtersTab(TabFolder tabFolder) { + TabItem tabItem1 = new TabItem(tabFolder, SWT.NULL); + tabItem1.setText(CodanUIMessages.CustomizeProblemComposite_TabParameters); + parametersTab = new Composite(tabFolder, SWT.NONE); + tabItem1.setControl(parametersTab); + parametersTab.setLayout(new GridLayout()); + problemsComposite = new ParametersComposite(parametersTab, problem); + problemsComposite.setLayoutData(new GridData(SWT.BEGINNING, + SWT.BEGINNING, true, false)); + } + + /** + * @param tabFolder + */ + private void createScopeTab(TabFolder tabFolder) { + TabItem tabItem1 = new TabItem(tabFolder, SWT.NULL); + tabItem1.setText(CodanUIMessages.CustomizeProblemComposite_TabScope); + Composite comp = new Composite(tabFolder, SWT.NONE); + tabItem1.setControl(comp); + comp.setLayout(new GridLayout()); + scopeComposite = new FileScopeComposite(comp, problem, resource); + scopeComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, + true, false)); + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/FileScopeComposite.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/FileScopeComposite.java new file mode 100644 index 0000000..1a8536c --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/FileScopeComposite.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui.widgets; + +import org.eclipse.cdt.codan.core.model.IProblem; +import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; +import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference; +import org.eclipse.cdt.codan.core.param.IProblemPreference; +import org.eclipse.cdt.codan.core.param.MapProblemPreference; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; +import org.eclipse.cdt.codan.internal.ui.preferences.FileScopePreferencePage; +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.preference.PreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +/** + * Composite to show problem scope + * + */ +public class FileScopeComposite extends Composite { + private FileScopePreferencePage page; + private IProblem problem; + private PreferenceStore prefStore; + private FileScopeProblemPreference scope; + + /** + * @param parent + * @param problem + * @param resource + * @param style + */ + public FileScopeComposite(Composite parent, final IProblem problem, + IResource resource) { + super(parent, SWT.NONE); + if (problem == null) + throw new NullPointerException(); + this.setLayout(new GridLayout(2, false)); + this.problem = problem; + this.prefStore = new PreferenceStore(); + IProblemPreference info = problem.getPreference(); + FileScopeProblemPreference scopeIn = null; + if (info == null + || (!(info instanceof MapProblemPreference)) + || ((scopeIn = (FileScopeProblemPreference) ((MapProblemPreference) info) + .getChildDescriptor(FileScopeProblemPreference.KEY)) == null)) { + Label label = new Label(this, 0); + label.setText(CodanUIMessages.ParametersComposite_None); + return; + } + scope = (FileScopeProblemPreference) scopeIn.clone(); + scope.setResource(resource); + initPrefStore(); + page = new FileScopePreferencePage(scope); + page.setPreferenceStore(prefStore); + page.noDefaultAndApplyButton(); + page.createControl(parent); + page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); + } + + public void save(IProblemWorkingCopy problem) { + if (page != null) + page.performOk(); + savePrefStore(); + } + + private void savePrefStore() { + if (scope == null) + return; + String key = scope.getQualifiedKey(); + ((MapProblemPreference) problem.getPreference()).setChildValue( + FileScopeProblemPreference.KEY, scope); + prefStore.setValue(key, scope.exportValue()); + } + + private void initPrefStore() { + if (scope == null) + return; + String key = scope.getQualifiedKey(); + prefStore.setValue(key, scope.exportValue()); + } + + /** + * @return the problem + */ + public IProblem getProblem() { + return problem; + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/ParametersComposite.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/ParametersComposite.java new file mode 100644 index 0000000..26e58fc --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/ParametersComposite.java @@ -0,0 +1,261 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.ui.widgets; + +import java.io.File; + +import org.eclipse.cdt.codan.core.model.IProblem; +import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; +import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference; +import org.eclipse.cdt.codan.core.param.IProblemPreference; +import org.eclipse.cdt.codan.core.param.IProblemPreferenceCompositeDescriptor; +import org.eclipse.cdt.codan.core.param.ListProblemPreference; +import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.FileFieldEditor; +import org.eclipse.jface.preference.ListEditor; +import org.eclipse.jface.preference.PreferenceStore; +import org.eclipse.jface.preference.StringFieldEditor; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +/** + * Composite to show problem preferences + * + */ +public class ParametersComposite extends Composite { + private FieldEditorPreferencePage page; + private IProblem problem; + private PreferenceStore prefStore; + + /** + * @param parent + * @param problem + * @param style + */ + public ParametersComposite(Composite parent, final IProblem problem) { + super(parent, SWT.NONE); + if (problem == null) + throw new NullPointerException(); + this.setLayout(new GridLayout(2, false)); + this.problem = problem; + this.prefStore = new PreferenceStore(); + page = new FieldEditorPreferencePage() { + @Override + protected void createFieldEditors() { + noDefaultAndApplyButton(); + IProblemPreference pref = problem.getPreference(); + createFieldEditorsForParameters(pref); + } + + /** + * @param info + */ + private void createFieldEditorsForParameters( + final IProblemPreference info) { + if (info == null) + return; + if (info.getKey() == FileScopeProblemPreference.KEY) + return; // skip the scope + switch (info.getType()) { + case TYPE_STRING: { + StringFieldEditor fe = new StringFieldEditor( + info.getQualifiedKey(), info.getLabel(), + getFieldEditorParent()); + addField(fe); + break; + } + case TYPE_BOOLEAN: { + BooleanFieldEditor fe = new BooleanFieldEditor( + info.getQualifiedKey(), info.getLabel(), + getFieldEditorParent()); + addField(fe); + break; + } + case TYPE_LIST: + ListEditor le = new ListEditor(info.getQualifiedKey(), + info.getLabel(), getFieldEditorParent()) { + @Override + protected String[] parseString(String stringList) { + ListProblemPreference list = (ListProblemPreference) info; + IProblemPreference[] childDescriptors = list + .getChildDescriptors(); + if (childDescriptors.length == 0) + return new String[0]; + String res[] = new String[childDescriptors.length]; + for (int i = 0; i < childDescriptors.length; i++) { + IProblemPreference item = childDescriptors[i]; + res[i] = String.valueOf(item.getValue()); + } + return res; + } + + @Override + protected String getNewInputObject() { + ListProblemPreference list = (ListProblemPreference) info; + String label = list.getChildDescriptor() + .getLabel(); + InputDialog dialog = new InputDialog( + getShell(), + CodanUIMessages.ParametersComposite_NewValue, + label, "", null); //$NON-NLS-1$ + if (dialog.open() == Window.OK) { + return dialog.getValue(); + } + return null; + } + + @Override + protected String createList(String[] items) { + ListProblemPreference list = (ListProblemPreference) info + .clone(); + list.clear(); + for (int i = 0; i < items.length; i++) { + String val = items[i]; + list.addChildValue(val); + } + return list.exportValue(); + } + }; + addField(le); + break; + case TYPE_MAP: + IProblemPreference[] childrenDescriptor = ((IProblemPreferenceCompositeDescriptor) info) + .getChildDescriptors(); + for (int i = 0; i < childrenDescriptor.length; i++) { + IProblemPreference desc = childrenDescriptor[i]; + createFieldEditorsForParameters(desc); + } + break; + case TYPE_CUSTOM: { + StringFieldEditor fe = new StringFieldEditor( + info.getQualifiedKey(), info.getLabel(), + getFieldEditorParent()); + addField(fe); + break; + } + case TYPE_FILE: { + FileFieldEditor fe = new FileFieldEditor( + info.getQualifiedKey(), info.getLabel(), + getFieldEditorParent()); + addField(fe); + break; + } + default: + throw new UnsupportedOperationException(info.getType() + .toString()); + } + } + }; + IProblemPreference info = problem.getPreference(); + if (info == null) { + Label label = new Label(this, 0); + label.setText(CodanUIMessages.ParametersComposite_None); + } else { + initPrefStore(info); + } + page.setPreferenceStore(prefStore); + page.createControl(parent); + page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); + } + + public void save(IProblemWorkingCopy problem) { + page.performOk(); + savePrefStore(problem.getPreference()); + } + + private void savePrefStore(IProblemPreference desc) { + if (desc == null) + return; + String key = desc.getQualifiedKey(); + switch (desc.getType()) { + case TYPE_STRING: + desc.setValue(prefStore.getString(key)); + break; + case TYPE_BOOLEAN: + desc.setValue(prefStore.getBoolean(key)); + break; + case TYPE_INTEGER: + desc.setValue(prefStore.getInt(key)); + break; + case TYPE_FILE: + desc.setValue(new File(prefStore.getString(key))); + break; + case TYPE_LIST: + desc.importValue(prefStore.getString(key)); + break; + case TYPE_CUSTOM: + desc.importValue(prefStore.getString(key)); + break; + case TYPE_MAP: + IProblemPreference[] childrenDescriptor = ((IProblemPreferenceCompositeDescriptor) desc) + .getChildDescriptors(); + for (int i = 0; i < childrenDescriptor.length; i++) { + IProblemPreference chi = childrenDescriptor[i]; + savePrefStore(chi); + } + break; + default: + throw new UnsupportedOperationException(desc.getType() + .toString()); + } + } + + private void initPrefStore(IProblemPreference desc) { + if (desc == null) + return; + String key = desc.getQualifiedKey(); + switch (desc.getType()) { + case TYPE_STRING: + prefStore.setValue(key, (String) desc.getValue()); + break; + case TYPE_BOOLEAN: + prefStore.setValue(key, (Boolean) desc.getValue()); + break; + case TYPE_INTEGER: + prefStore.setValue(key, (Integer) desc.getValue()); + break; + case TYPE_FILE: + prefStore.setValue(key, ((File) desc.getValue()).getPath()); + break; + case TYPE_LIST: + prefStore.setValue(key, desc.exportValue()); + break; + case TYPE_CUSTOM: + prefStore.setValue(key, desc.exportValue()); + break; + case TYPE_MAP: + IProblemPreference[] childrenDescriptor = ((IProblemPreferenceCompositeDescriptor) desc) + .getChildDescriptors(); + for (int i = 0; i < childrenDescriptor.length; i++) { + IProblemPreference chi = childrenDescriptor[i]; + initPrefStore(chi); + } + break; + default: + throw new UnsupportedOperationException(desc.getType() + .toString()); + } + } + + /** + * @return the problem + */ + public IProblem getProblem() { + return problem; + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java new file mode 100644 index 0000000..6a36763 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.ui; + +import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; +import org.eclipse.core.resources.IMarker; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IMarkerResolution; +import org.eclipse.ui.IMarkerResolution2; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * Generic class for codan marker resolution (for quick fix). Use as a base + * class for codanMarkerResolution extension. To add specific icon and + * description client class should additionally implement + * {@link IMarkerResolution2} + */ +public abstract class AbstarctCodanCMarkerResolution implements IMarkerResolution { + /** + * Get position offset from marker. If CHAR_START attribute is not set for + * marker, line and document would be used. + * + * @param marker + * @param doc + * @return + */ + public int getOffset(IMarker marker, IDocument doc) { + int charStart = marker.getAttribute(IMarker.CHAR_START, -1); + int position; + if (charStart > 0) { + position = charStart; + } else { + int line = marker.getAttribute(IMarker.LINE_NUMBER, -1) - 1; + try { + position = doc.getLineOffset(line); + } catch (BadLocationException e) { + return -1; + } + } + return position; + } + + /** + * Runs this resolution. + * + * @param marker + * the marker to resolve + */ + public void run(IMarker marker) { + IEditorPart editorPart; + try { + editorPart = CodanEditorUtility.openInEditor(marker); + } catch (PartInitException e) { + CodanUIActivator.log(e); + return; + } + if (editorPart instanceof ITextEditor) { + ITextEditor editor = (ITextEditor) editorPart; + IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); + apply(marker, doc); + } + } + + /** + * Apply marker resolution for given marker in given open document. + * + * @param marker + * @param document + */ + public abstract void apply(IMarker marker, IDocument document); + + /** + * Override is extra checks is required to determine appicablity of marker resolution + * @param marker + * @return + */ + public boolean isApplicable(IMarker marker) { + return true; + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java new file mode 100644 index 0000000..4fff924 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.ui; + +import org.eclipse.cdt.codan.core.CodanRuntime; +import org.eclipse.cdt.codan.core.model.IProblem; +import org.eclipse.core.resources.IMarker; + +/** + * Abstract class that provides stubs for problems details. + * This class intended to be extended by the users of codanProblemDetails extension point. + * One instance of this class would exists at runtime. To query for results, framework + * would synchronize on this class object, set setMarker then call other getStyled* methods + * to obtain data. + */ +public abstract class AbstractCodanProblemDetailsProvider { + protected IMarker marker; + + public AbstractCodanProblemDetailsProvider() { + } + + /** + * sets the marker, called from framework to initialize provider + */ + public void setMarker(IMarker marker) { + this.marker = marker; + } + + /** + * Get marker associated with this provider + * @return + */ + public IMarker getMarker() { + return marker; + } + + /** + * Convenience method to return marker message + * @return + */ + protected String getProblemMessage() { + String message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$ + return message; + } + + /** + * Convenience method to return codan problem id + * @return + */ + protected String getProblemId() { + String id = marker.getAttribute(IMarker.PROBLEM, (String) null); + return id; + } + + /** + * return true if provider can provide details for given marker (previously set by setMarker) + * @param id - id of the problem + * @return true if details are available for given marker + */ + public abstract boolean isApplicable(String id); + + /** + * Return styled problem message. This text would be used in Link widget. + * String can include tags to which would be + * visible as hyperlinks and newline characters (\n). Default message if + * marker message plus location. Ampersand (&) should be escape because + * it is interpreted as mnemonic for control navigation (can use espaceForLink method).
+ * This method intended to be overriden by the client. + */ + public String getStyledProblemMessage() { + String message = escapeForLink(getProblemMessage()); + String href = getLocationHRef(); + String link = href.replaceFirst("^file:", ""); //$NON-NLS-1$ //$NON-NLS-2$ + link = link.replaceFirst("#(\\d+)$", ":$1"); //$NON-NLS-1$//$NON-NLS-2$ + return "
" + link + " \n" + message; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + } + protected String getLocationHRef() { + return CodanEditorUtility.getLocationHRef(marker); + } + /** + * Return styled problem description. This text would be used in Link widget. + * String can include tags to which would be + * visible as hyperlinks and newline characters (\n). + * Ampersand (&) should be escape because + * it is interpreted as mnemonic for control navigation (can use espaceForLink method). + * + * Default implementation return desciption of codan problem.
+ * This method intended to be overriden by the client. + * + */ + public String getStyledProblemDescription() { + String id = getProblemId(); + if (id == null) + return ""; //$NON-NLS-1$ + IProblem problem = CodanRuntime.getInstance().getChechersRegistry().getDefaultProfile().findProblem(id); + return escapeForLink(problem.getDescription()); + } + + /** + * Method to escape characters which are interpreted by Link swt control, + * such as & (mnemonic) + */ + protected String escapeForLink(String text) { + return text.replaceAll("&", "&&"); //$NON-NLS-1$//$NON-NLS-2$ + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java deleted file mode 100644 index 849993a..0000000 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java +++ /dev/null @@ -1,98 +0,0 @@ -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)); - } -} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Entries index 4387fb2..e02c292 100644 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Entries +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Entries @@ -1,4 +1,6 @@ -/Activator.java/1.2/Fri Apr 24 12:49:44 2009// -/CodanCReconciler.java/1.3/Sat Aug 22 21:16:50 2009// -/Startup.java/1.1/Fri Apr 24 12:49:44 2009// +/AbstarctCodanCMarkerResolution.java/1.4/Thu Jun 3 17:01:40 2010//TCDT_7_0_0 +/AbstractCodanProblemDetailsProvider.java/1.7/Sat May 8 01:19:46 2010//TCDT_7_0_0 +/CodanEditorUtility.java/1.1/Wed May 5 19:59:17 2010//TCDT_7_0_0 D/actions//// +D/handlers//// +D/views//// diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Template deleted file mode 100644 index e69de29..0000000 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanCReconciler.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanCReconciler.java deleted file mode 100644 index 5bec1c1..0000000 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanCReconciler.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.cdt.codan.core.CodanRuntime; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.internal.ui.editor.CEditor; -import org.eclipse.cdt.internal.ui.text.ICReconcilingListener; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.ui.texteditor.ITextEditor; - -/** - * @author Alena - * - */ -public class CodanCReconciler implements ICReconcilingListener { - void install(ITextEditor editor) { - if (editor instanceof CEditor) { - initialize(); - ((CEditor) editor).addReconcileListener(this); - } - } - - void uninstall(ITextEditor editor) { - if (editor instanceof CEditor) { - initialize(); - ((CEditor) editor).removeReconcileListener(this); - } - } - - /** - * - */ - private void initialize() { - // TODO Auto-generated method stub - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.cdt.internal.ui.text.ICReconcilingListener#aboutToBeReconciled - * () - */ - public void aboutToBeReconciled() { - // TODO Auto-generated method stub - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.cdt.internal.ui.text.ICReconcilingListener#reconciled(org - * .eclipse.cdt.core.dom.ast.IASTTranslationUnit, boolean, - * org.eclipse.core.runtime.IProgressMonitor) - */ - public void reconciled(IASTTranslationUnit ast, boolean force, - IProgressMonitor progressMonitor) { - CodanRuntime.getInstance().getAstQuickBuilder().reconcileAst(ast, - progressMonitor); - // System.err.println("ast reconsiled"); - } -} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanEditorUtility.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanEditorUtility.java new file mode 100644 index 0000000..1cdc5ef --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanEditorUtility.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * $QNXLicenseC: + * Copyright 2008, QNX Software Systems. All Rights Reserved. + * + * You must obtain a written license from and pay applicable license fees to QNX + * Software Systems before you may reproduce, modify or distribute this software, + * or any work that includes all or part of this software. Free development + * licenses are available for evaluation and non-commercial purposes. For more + * information visit http://licensing.qnx.com or email licensing@qnx.com. + * + * This file may contain contributions from others. Please review this entire + * file for other proprietary rights or license notices, as well as the QNX + * Development Suite License Guide at http://licensing.qnx.com/license-guide/ + * for other information. + * $ + *******************************************************************************/ +/* + * Created by: Elena Laskavaia + * Created on: 2010-05-05 + * Last modified by: $Author: elaskavaia $ + */ +package org.eclipse.cdt.codan.ui; + +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.util.EditorUtility; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * Utility tools to open editor and highlight the line + */ +public class CodanEditorUtility { + /** + * @param fileUrl - file "url", like file:/tmp/a.c#22 + * @throws PartInitException + * @throws BadLocationException + */ + public static void openFileURL(String fileUrl, IResource markerResource) throws PartInitException, BadLocationException { + String file = getFileFromURL(fileUrl); + + IEditorPart part = openInEditor(file, markerResource); + int line = getLineFromURL(fileUrl); + revealLine(part, line); + } + + /** + * Line is the part the follows # in this URL + * @return -1 if not line found in URL, and line number if there is + */ + public static int getLineFromURL(String fileUrl) { + String sline = fileUrl.replaceAll(".*#(\\d+)$", "$1"); //$NON-NLS-1$ //$NON-NLS-2$ + int line = -1; + try { + line = Integer.parseInt(sline); + } catch (NumberFormatException e2) { + // no line + } + return line; + } + + public static String getFileFromURL(String link) { + String file = link.replaceFirst("^file:", ""); //$NON-NLS-1$ //$NON-NLS-2$ + file = file.replaceAll("#\\d+$", ""); //$NON-NLS-1$//$NON-NLS-2$ + return file; + } + + public static void revealLine(IEditorPart part, int line) throws BadLocationException { + if (line > 0) { + if (part instanceof ITextEditor) { + ITextEditor textEditor = (ITextEditor) part; + IDocument document = textEditor.getDocumentProvider().getDocument(part.getEditorInput()); + textEditor.selectAndReveal(document.getLineOffset(line - 1), 0); + } + } + } + + @SuppressWarnings("restriction") + public static IEditorPart openInEditor(String file, IResource markerResource) throws PartInitException { + IPath pfile = new Path(file); + ICElement element = null; + if (markerResource != null) + CoreModel.getDefault().create(markerResource); + IEditorPart part = EditorUtility.openInEditor(pfile, element); + return part; + } + + public static IEditorPart openInEditor(IMarker marker) throws PartInitException { + String href = getLocationHRef(marker); + String file = getFileFromURL(href); + return openInEditor(file, marker.getResource()); + } + + public static String getLocationHRef(IMarker marker) { + String loc = marker.getResource().getLocationURI().toString(); + String loc2 = marker.getAttribute(IMarker.LOCATION, ""); //$NON-NLS-1$ + int line = marker.getAttribute(IMarker.LINE_NUMBER, 0); + if (loc2.length() > 0) { + loc = "file:" + loc2.replaceAll("[^:]*: ", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + String href = loc + "#" + line; //$NON-NLS-1$ + return href; + } +} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Startup.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Startup.java deleted file mode 100644 index 41fbf89..0000000 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Startup.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.ui.IEditorReference; -import org.eclipse.ui.IPartListener2; -import org.eclipse.ui.IStartup; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchPartReference; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.ITextEditor; - -/** - * @author Alena - * - */ -public class Startup implements IStartup { - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IStartup#earlyStartup() - */ - public void earlyStartup() { - registerListeners(); - } - - /** - * Register part listener for editor to install c ast reconcile listener - */ - private void registerListeners() { - final IWorkbench workbench = PlatformUI.getWorkbench(); - workbench.getDisplay().asyncExec(new Runnable() { - public void run() { - IWorkbenchWindow active = workbench.getActiveWorkbenchWindow(); - final IWorkbenchPage page = active.getActivePage(); - IPartListener2 partListener = new IPartListener2() { - CodanCReconciler reconsiler = new CodanCReconciler(); - - public void partActivated(IWorkbenchPartReference partRef) { - } - - public void partDeactivated(IWorkbenchPartReference partRef) { - } - - public void partOpened(IWorkbenchPartReference partRef) { - IWorkbenchPart editor = partRef.getPart(false); - if (editor instanceof ITextEditor) { - reconsiler.install((ITextEditor) editor); - } - } - - public void partHidden(IWorkbenchPartReference partRef) { - } - - public void partVisible(IWorkbenchPartReference partRef) { - } - - public void partClosed(IWorkbenchPartReference partRef) { - IWorkbenchPart part = partRef.getPart(false); - if (part instanceof ITextEditor) { - reconsiler.uninstall((ITextEditor) part); - } - } - - public void partBroughtToTop(IWorkbenchPartReference partRef) { - } - - public void partInputChanged(IWorkbenchPartReference partRef) { - } - }; - page.addPartListener(partListener); - // check current open editors - IEditorReference[] editorReferences = page - .getEditorReferences(); - for (int i = 0; i < editorReferences.length; i++) { - IEditorReference ref = editorReferences[i]; - partListener.partOpened(ref); - } - } - }); - } -} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Entries deleted file mode 100644 index 30cf7ec..0000000 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Entries +++ /dev/null @@ -1,2 +0,0 @@ -/RunCodeAnalysis.java/1.3/Sat Aug 22 21:16:50 2009// -/ToggleNatureAction.java/1.2/Sat Aug 22 21:16:50 2009// diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Repository b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Repository deleted file mode 100644 index 09c1aeb..0000000 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Repository +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.cdt/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Root b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Root deleted file mode 100644 index 04efa23..0000000 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Root +++ /dev/null @@ -1 +0,0 @@ -:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Template deleted file mode 100644 index e69de29..0000000 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java deleted file mode 100644 index 01d7c25..0000000 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * 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.CodanRuntime; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.core.runtime.jobs.Job; -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) { - // nothing - } - - public void run(IAction action) { - Job job = new Job("Running Code Analysis") { - @SuppressWarnings("unchecked") - @Override - protected IStatus run(final IProgressMonitor monitor) { - IStructuredSelection ss = (IStructuredSelection) sel; - int count = ss.size(); - monitor.beginTask(getName(), count * 100); - if (monitor.isCanceled()) - return Status.CANCEL_STATUS; - for (Iterator iterator = ss.iterator(); iterator.hasNext();) { - Object o = iterator.next(); - if (o instanceof IResource) { - IResource res = (IResource) o; - SubProgressMonitor subMon = new SubProgressMonitor( - monitor, 100); - CodanRuntime.getInstance().getBuilder() - .processResource(res, subMon); - if (subMon.isCanceled()) - return Status.CANCEL_STATUS; - } - if (monitor.isCanceled()) - return Status.CANCEL_STATUS; - } - return Status.OK_STATUS; - } - }; - job.setUser(true); - job.schedule(); - } - - public void selectionChanged(IAction action, ISelection selection) { - this.sel = selection; - } -} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/ToggleNatureAction.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/ToggleNatureAction.java deleted file mode 100644 index 3993621..0000000 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/ToggleNatureAction.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * 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.CodanCorePlugin; -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 (CodanCorePlugin.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 (CodanCorePlugin.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] = CodanCorePlugin.NATURE_ID; - description.setNatureIds(newNatures); - project.setDescription(description, null); - } - } catch (CoreException e) { - } - } -} diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Entries new file mode 100644 index 0000000..8a29f40 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Entries @@ -0,0 +1 @@ +/RunCodanCommand.java/1.3/Thu Jun 3 17:01:40 2010//TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Repository b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Repository new file mode 100644 index 0000000..c8ef8af --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.cdt/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Root b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/RunCodanCommand.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/RunCodanCommand.java new file mode 100644 index 0000000..d0999a8 --- /dev/null +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/RunCodanCommand.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2010 Alena Laskavaia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.ui.handlers; + +import org.eclipse.cdt.codan.internal.ui.actions.RunCodeAnalysis; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Command to run code analysis on selected resources + * @see org.eclipse.core.commands.IHandler + * @see org.eclipse.core.commands.AbstractHandler + */ +public class RunCodanCommand extends AbstractHandler { + + public RunCodanCommand() { + } + + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection currentSelection = HandlerUtil.getCurrentSelection(event); + RunCodeAnalysis action = new RunCodeAnalysis(); + action.selectionChanged(null, currentSelection); + action.run(null); + return null; + } +} -- cgit