EMMA Coverage Report (generated Mon Sep 29 15:05:28 EDT 2008)
[all classes][org.eclipse.ui.internal.actions]

COVERAGE SUMMARY FOR SOURCE FILE [PinEditorContributionItem.java]

nameclass, %method, %block, %line, %
PinEditorContributionItem.java67%  (2/3)71%  (5/7)48%  (71/147)59%  (21.9/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PinEditorContributionItem$20%   (0/1)0%   (0/2)0%   (0/13)0%   (0/4)
PinEditorContributionItem$2 (PinEditorContributionItem$1): void 0%   (0/1)0%   (0/6)0%   (0/2)
run (): void 0%   (0/1)0%   (0/7)0%   (0/2)
     
class PinEditorContributionItem$1100% (1/1)100% (2/2)18%  (12/65)31%  (5/16)
propertyChange (PropertyChangeEvent): void 100% (1/1)10%  (6/59)21%  (3/14)
PinEditorContributionItem$1 (PinEditorContributionItem): void 100% (1/1)100% (6/6)100% (2/2)
     
class PinEditorContributionItem100% (1/1)100% (3/3)86%  (59/69)92%  (18.4/20)
isVisible (): boolean 100% (1/1)50%  (5/10)50%  (0.5/1)
PinEditorContributionItem (PinEditorAction, IWorkbenchWindow): void 100% (1/1)90%  (46/51)92%  (13.9/15)
dispose (): void 100% (1/1)100% (8/8)100% (4/4)

1/*******************************************************************************
2 * Copyright (c) 2003, 2007 IBM Corporation 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 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.ui.internal.actions;
12 
13import org.eclipse.jface.action.ActionContributionItem;
14import org.eclipse.jface.preference.IPreferenceStore;
15import org.eclipse.jface.util.IPropertyChangeListener;
16import org.eclipse.jface.util.PropertyChangeEvent;
17import org.eclipse.ui.IWorkbenchWindow;
18import org.eclipse.ui.internal.IPreferenceConstants;
19import org.eclipse.ui.internal.PinEditorAction;
20import org.eclipse.ui.internal.WorkbenchPlugin;
21import org.eclipse.ui.internal.tweaklets.TabBehaviour;
22import org.eclipse.ui.internal.tweaklets.Tweaklets;
23 
24/**
25 * This contribution item controls the visibility of the pin editor
26 * action based on the current preference value for reusing editors.
27 * 
28 * @since 3.0
29 */
30public class PinEditorContributionItem extends ActionContributionItem {
31    private IWorkbenchWindow window = null;
32 
33    private boolean reuseEditors = false;
34 
35    private IPropertyChangeListener prefListener = new IPropertyChangeListener() {
36        public void propertyChange(PropertyChangeEvent event) {
37            if (event.getProperty().equals(
38                                        IPreferenceConstants.REUSE_EDITORS_BOOLEAN)) {
39                if (getParent() != null) {
40                    IPreferenceStore store = WorkbenchPlugin.getDefault()
41                            .getPreferenceStore();
42                                        reuseEditors = store
43                                                        .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN)
44                                                        || ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).alwaysShowPinAction();
45                    setVisible(reuseEditors);
46                    getParent().markDirty();
47                    if (window.getShell() != null
48                            && !window.getShell().isDisposed()) {
49                        // this property change notification could be from a non-ui thread
50                        window.getShell().getDisplay().syncExec(new Runnable() {
51                            public void run() {
52                                getParent().update(false);
53                            }
54                        });
55                    }
56                }
57            }
58        }
59    };
60 
61    /**
62     * @param action
63     */
64    public PinEditorContributionItem(PinEditorAction action,
65            IWorkbenchWindow window) {
66        super(action);
67 
68        if (window == null) {
69            throw new IllegalArgumentException();
70        }
71        this.window = window;
72 
73        IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
74                reuseEditors = store
75                                .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN)
76                                || ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).alwaysShowPinAction();
77        setVisible(reuseEditors);
78        WorkbenchPlugin.getDefault().getPreferenceStore()
79                .addPropertyChangeListener(prefListener);
80    }
81 
82    /* (non-Javadoc)
83     * @see org.eclipse.jface.action.IContributionItem#isVisible()
84     */
85    public boolean isVisible() {
86        // @issue the ActionContributionItem implementation of this method ignores the "visible" value set
87        return super.isVisible() && reuseEditors;
88    }
89 
90    /* (non-Javadoc)
91     * @see org.eclipse.jface.action.IContributionItem#dispose()
92     */
93    public void dispose() {
94        super.dispose();
95        WorkbenchPlugin.getDefault().getPreferenceStore()
96                .removePropertyChangeListener(prefListener);
97    }
98}

[all classes][org.eclipse.ui.internal.actions]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov