1
/*******************************************************************************
2
* Copyright (c) 2004, 2008 Mylyn project committers and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
7
*******************************************************************************/
9
package org.eclipse.cdt.mylyn.internal.ui;
11
import org.eclipse.cdt.core.model.ICElement;
12
import org.eclipse.cdt.internal.ui.util.IProblemChangedListener;
13
import org.eclipse.cdt.ui.CUIPlugin;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
18
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.mylyn.commons.core.StatusHandler;
21
import org.eclipse.mylyn.context.core.IInteractionElement;
22
import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
26
* @author Jeff Johnston
28
public class InterestInducingProblemListener implements IProblemChangedListener, IPropertyChangeListener {
30
public static final String PREDICTED_INTEREST_ERRORS = "org.eclipse.cdt.mylyn.ui.interest.prediction.errors"; // $NON-NLS-1$
32
// TODO: consider getting rid of this
33
private CDTStructureBridge cdtStructureBridge = new CDTStructureBridge();
35
public void problemsChanged(IResource[] changedResources, boolean isMarkerChange) {
37
if (!ContextCorePlugin.getContextManager().isContextActive()) {
40
for (int i = 0; i < changedResources.length; i++) {
41
IResource resource = changedResources[i];
42
if (resource instanceof IFile) {
43
ICElement cdtElement = (ICElement) resource.getAdapter(ICElement.class);
44
if (cdtElement != null) {
45
IInteractionElement element = ContextCorePlugin.getContextManager().getElement(
46
CDTStructureBridge.getHandleForElement(cdtElement));
47
if (!cdtStructureBridge.containsProblem(element)) {
48
ContextCorePlugin.getContextManager().removeErrorPredictedInterest(
49
element.getHandleIdentifier(), CDTStructureBridge.CONTENT_TYPE, true);
51
ContextCorePlugin.getContextManager().addErrorPredictedInterest(
52
element.getHandleIdentifier(), CDTStructureBridge.CONTENT_TYPE, true);
58
} catch (Exception e) {
59
StatusHandler.log(new Status(IStatus.ERROR, CDTUIBridgePlugin.PLUGIN_ID,
60
CDTUIBridgePlugin.getResourceString("MylynCDT.updateMarkerFailure"), e)); // $NON-NLS-1$
64
public void propertyChange(PropertyChangeEvent event) {
65
if (PREDICTED_INTEREST_ERRORS.equals(event.getProperty())) {
66
if (CDTUIBridgePlugin.getDefault().getPreferenceStore().getBoolean(PREDICTED_INTEREST_ERRORS)) {
74
public void enable() {
75
CUIPlugin.getDefault().getProblemMarkerManager().addListener(this);
78
public void disable() {
79
CUIPlugin.getDefault().getProblemMarkerManager().removeListener(this);