Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 913984ff8f1513b87fd854fb4e97528e6c4d86af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*******************************************************************************
 * Copyright (c) 2000, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.ui;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.breakpoints.provisional.OtherBreakpointCategory;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

/**
 * Common function for breakpoint organizer delegates.
 * <p>
 * Clients implementing <code>IBreakpointOrganizerDelegate</code> must subclass this class.
 * </p>
 * @since 3.1
 */
public abstract class AbstractBreakpointOrganizerDelegate implements IBreakpointOrganizerDelegate {
    
    // property change listeners
    private ListenerList fListeners = new ListenerList();

    /* (non-Javadoc)
     * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#addBreakpoint(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.runtime.IAdaptable)
     */
    @Override
	public void addBreakpoint(IBreakpoint breakpoint, IAdaptable category) {
        // do noting, not supported by default
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
     */
    @Override
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
        fListeners.add(listener);
    }
    
    /* (non-Javadoc)
     * 
     * Subclasses that override should return super.canAdd(...) when they are not able to add
     * the breakpoint.
     * 
     * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#canAdd(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.runtime.IAdaptable)
     */
    @Override
	public boolean canAdd(IBreakpoint breakpoint, IAdaptable category) {
        return category instanceof OtherBreakpointCategory;
    }
    
    /* (non-Javadoc)
     * 
     * Subclasses that override should return super.canRemove(...) when they are not able to remove
     * the breakpoint.
     * 
     * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#canRemove(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.runtime.IAdaptable)
     */
    @Override
	public boolean canRemove(IBreakpoint breakpoint, IAdaptable category) {
        return category instanceof OtherBreakpointCategory;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#dispose()
     */
    @Override
	public void dispose() {
        fListeners = new ListenerList();
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#removeBreakpoint(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.runtime.IAdaptable)
     */
    @Override
	public void removeBreakpoint(IBreakpoint breakpoint, IAdaptable category) {
        // do nothing, not supported by default
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
     */
    @Override
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
        fListeners.remove(listener);
    }
    
    /**
     * Fires a property change notification for the given category.
     * 
     * @param category category that has changed
     */
    protected void fireCategoryChanged(IAdaptable category) {
        if (fListeners.isEmpty()) {
            return;
        }
        final PropertyChangeEvent event = new PropertyChangeEvent(this, P_CATEGORY_CHANGED, category, null);
        Object[] listeners = fListeners.getListeners();
        for (int i = 0; i < listeners.length; i++) {
            final IPropertyChangeListener listener = (IPropertyChangeListener) listeners[i];
            ISafeRunnable runnable = new ISafeRunnable() {
                @Override
				public void handleException(Throwable exception) {
                    DebugUIPlugin.log(exception);
                }
                @Override
				public void run() throws Exception {
                    listener.propertyChange(event);
                }
            };
            SafeRunner.run(runnable);
        }
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#getCategories()
     */
    @Override
	public IAdaptable[] getCategories() {
        return null;
    }
}

Back to the top