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

COVERAGE SUMMARY FOR SOURCE FILE [TabBehaviourMRU.java]

nameclass, %method, %block, %line, %
TabBehaviourMRU.java100% (1/1)75%  (3/4)7%   (14/203)10%  (6/63)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TabBehaviourMRU100% (1/1)75%  (3/4)7%   (14/203)10%  (6/63)
reuseInternalEditor (WorkbenchPage, EditorManager, EditorAreaHelper, EditorDe... 0%   (0/1)0%   (0/75)0%   (0/19)
findReusableEditor (WorkbenchPage): IEditorReference 100% (1/1)7%   (9/123)10%  (4/42)
TabBehaviourMRU (): void 100% (1/1)100% (3/3)100% (1/1)
alwaysShowPinAction (): boolean 100% (1/1)100% (2/2)100% (1/1)

1/*******************************************************************************
2 * Copyright (c) 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 ******************************************************************************/
11 
12package org.eclipse.ui.internal.tweaklets;
13 
14import org.eclipse.jface.dialogs.IDialogConstants;
15import org.eclipse.jface.dialogs.MessageDialog;
16import org.eclipse.jface.dialogs.ProgressMonitorDialog;
17import org.eclipse.osgi.util.NLS;
18import org.eclipse.ui.IEditorInput;
19import org.eclipse.ui.IEditorPart;
20import org.eclipse.ui.IEditorReference;
21import org.eclipse.ui.IReusableEditor;
22import org.eclipse.ui.internal.EditorAreaHelper;
23import org.eclipse.ui.internal.EditorManager;
24import org.eclipse.ui.internal.EditorReference;
25import org.eclipse.ui.internal.EditorSite;
26import org.eclipse.ui.internal.IPreferenceConstants;
27import org.eclipse.ui.internal.Workbench;
28import org.eclipse.ui.internal.WorkbenchMessages;
29import org.eclipse.ui.internal.WorkbenchPage;
30import org.eclipse.ui.internal.WorkbenchPlugin;
31import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
32import org.eclipse.ui.internal.registry.EditorDescriptor;
33 
34/**
35 * @since 3.3
36 * 
37 */
38public class TabBehaviourMRU extends TabBehaviour {
39 
40        public boolean alwaysShowPinAction() {
41                return false;
42        }
43 
44        public IEditorReference findReusableEditor(WorkbenchPage page) {
45                boolean reuse = WorkbenchPlugin.getDefault().getPreferenceStore()
46                                .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN);
47                if (!reuse) {
48                        return null;
49                }
50 
51                IEditorReference editors[] = page.getSortedEditors();
52                if (editors.length < page.getEditorReuseThreshold()) {
53                        return null;
54                }
55 
56                IEditorReference dirtyEditor = null;
57 
58                // Find a editor to be reused
59                for (int i = 0; i < editors.length; i++) {
60                        IEditorReference editor = editors[i];
61                        // if(editor == activePart)
62                        // continue;
63                        if (editor.isPinned()) {
64                                continue;
65                        }
66                        if (editor.isDirty()) {
67                                if (dirtyEditor == null) {
68                                        dirtyEditor = editor;
69                                }
70                                continue;
71                        }
72                        return editor;
73                }
74                if (dirtyEditor == null) {
75                        return null;
76                }
77 
78                /* fix for 11122 */
79                boolean reuseDirty = WorkbenchPlugin.getDefault().getPreferenceStore()
80                                .getBoolean(IPreferenceConstants.REUSE_DIRTY_EDITORS);
81                if (!reuseDirty) {
82                        return null;
83                }
84 
85                MessageDialog dialog = new MessageDialog(page.getWorkbenchWindow()
86                                .getShell(),
87                                WorkbenchMessages.EditorManager_reuseEditorDialogTitle,
88                                null, // accept the default window icon
89                                NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion,
90                                                dirtyEditor.getName()), MessageDialog.QUESTION,
91                                new String[] { IDialogConstants.YES_LABEL,
92                                                IDialogConstants.NO_LABEL,
93                                                WorkbenchMessages.EditorManager_openNewEditorLabel }, 0);
94                int result = dialog.open();
95                if (result == 0) { // YES
96                        ProgressMonitorDialog pmd = new ProgressMonitorJobsDialog(dialog
97                                        .getShell());
98                        pmd.open();
99                        dirtyEditor.getEditor(true).doSave(pmd.getProgressMonitor());
100                        pmd.close();
101                } else if ((result == 2) || (result == -1)) {
102                        return null;
103                }
104                return dirtyEditor;
105        }
106 
107        public IEditorReference reuseInternalEditor(WorkbenchPage page,
108                        EditorManager manager, EditorAreaHelper editorPresentation,
109                        EditorDescriptor desc, IEditorInput input,
110                        IEditorReference reusableEditorRef) {
111                IEditorPart reusableEditor = reusableEditorRef.getEditor(false);
112                if (reusableEditor == null) {
113                        IEditorReference result = new EditorReference(manager, input, desc);
114                        page.closeEditor(reusableEditorRef, false);
115                        return result;
116                }
117 
118                EditorSite site = (EditorSite) reusableEditor.getEditorSite();
119                EditorDescriptor oldDesc = site.getEditorDescriptor();
120                if ((desc.getId().equals(oldDesc.getId()))
121                                && (reusableEditor instanceof IReusableEditor)) {
122                        Workbench wb = (Workbench) page.getWorkbenchWindow().getWorkbench();
123                        editorPresentation.moveEditor(reusableEditor, -1);
124                        wb.getEditorHistory().add(reusableEditor.getEditorInput(),
125                                        site.getEditorDescriptor());
126                        page.reuseEditor((IReusableEditor) reusableEditor, input);
127                        return reusableEditorRef;
128                }
129                // findReusableEditor(...) checks pinned and saves editor if
130                // necessary, so it's OK to close "reusableEditor"
131                IEditorReference ref = new EditorReference(manager, input, desc);
132                reusableEditor.getEditorSite().getPage().closeEditor(reusableEditor,
133                                false);
134                return ref;
135        }
136 
137}

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