Added
Link Here
|
1 |
/****************************************************************************** |
2 |
* Copyright (c) 2008 Versant 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 |
* Remy Chi Jian Suen (Versant Corporation) - initial API and implementation |
10 |
******************************************************************************/ |
11 |
package org.eclipse.ui.tests.progress; |
12 |
|
13 |
import org.eclipse.core.resources.IProject; |
14 |
import org.eclipse.core.runtime.CoreException; |
15 |
import org.eclipse.swt.SWT; |
16 |
import org.eclipse.swt.custom.CTabFolder; |
17 |
import org.eclipse.swt.custom.CTabItem; |
18 |
import org.eclipse.swt.graphics.Font; |
19 |
import org.eclipse.swt.graphics.FontData; |
20 |
import org.eclipse.ui.IEditorPart; |
21 |
import org.eclipse.ui.IViewPart; |
22 |
import org.eclipse.ui.IWorkbenchPage; |
23 |
import org.eclipse.ui.PartInitException; |
24 |
import org.eclipse.ui.ide.IDE; |
25 |
import org.eclipse.ui.internal.EditorSashContainer; |
26 |
import org.eclipse.ui.internal.ViewPane; |
27 |
import org.eclipse.ui.internal.WorkbenchPage; |
28 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
29 |
import org.eclipse.ui.progress.IWorkbenchSiteProgressService; |
30 |
import org.eclipse.ui.tests.api.MockViewPart; |
31 |
import org.eclipse.ui.tests.harness.util.FileUtil; |
32 |
import org.eclipse.ui.tests.harness.util.UITestCase; |
33 |
|
34 |
public class IWorkbenchSiteProgressServiceTest extends UITestCase { |
35 |
|
36 |
private IWorkbenchPage activePage; |
37 |
|
38 |
private IProject project; |
39 |
|
40 |
public IWorkbenchSiteProgressServiceTest(String testName) { |
41 |
super(testName); |
42 |
} |
43 |
|
44 |
protected void doSetUp() throws Exception { |
45 |
super.doSetUp(); |
46 |
activePage = openTestWindow().getActivePage(); |
47 |
} |
48 |
|
49 |
protected void doTearDown() throws Exception { |
50 |
if (project != null) { |
51 |
FileUtil.deleteProject(project); |
52 |
} |
53 |
super.doTearDown(); |
54 |
} |
55 |
|
56 |
public void testWarnOfContentChangeForViews() throws CoreException, |
57 |
PartInitException { |
58 |
activePage.setPerspective(WorkbenchPlugin.getDefault() |
59 |
.getPerspectiveRegistry().findPerspectiveWithId( |
60 |
"org.eclipse.ui.tests.api.ViewPerspective")); |
61 |
|
62 |
// show one view and activate it |
63 |
IViewPart hiddenView = activePage.showView(MockViewPart.ID, null, |
64 |
IWorkbenchPage.VIEW_ACTIVATE); |
65 |
// show the second view and activate it, |
66 |
IViewPart activeView = activePage.showView(MockViewPart.ID2, null, |
67 |
IWorkbenchPage.VIEW_ACTIVATE); |
68 |
|
69 |
assertFalse( |
70 |
"Another view that was activated should have prevented this view from being visible", //$NON-NLS-1$ |
71 |
activePage.isPartVisible(hiddenView)); |
72 |
assertTrue("View was shown and activate but appears to not be visible", //$NON-NLS-1$ |
73 |
activePage.isPartVisible(activeView)); |
74 |
|
75 |
// retrieve the IWorkbenchSiteProgressService from the first view |
76 |
// that's behind in the view stack |
77 |
IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) hiddenView |
78 |
.getSite().getService(IWorkbenchSiteProgressService.class); |
79 |
assertNotNull( |
80 |
"Could not retrieve an IWorkbenchSiteProgressService from getService(Class)", //$NON-NLS-1$ |
81 |
service); |
82 |
|
83 |
// warn of content change |
84 |
service.warnOfContentChange(); |
85 |
|
86 |
WorkbenchPage page = (WorkbenchPage) activePage; |
87 |
// find the view pane for our test view, our first one and the one |
88 |
// that should be hidden |
89 |
ViewPane pane = (ViewPane) page.getPerspectivePresentation().findPart( |
90 |
MockViewPart.ID, null); |
91 |
assertNotNull("Could not find the ViewPane for " + MockViewPart.ID, //$NON-NLS-1$ |
92 |
pane); |
93 |
|
94 |
// retrieve the SWT CTabFolder |
95 |
CTabFolder tabFolder = (CTabFolder) pane.getStack().getControl(); |
96 |
// index is 0 because 1 is the one that's activated and in front, our |
97 |
// hidden view is 0 and is behind it |
98 |
CTabItem item = tabFolder.getItem(0); |
99 |
|
100 |
// get the CTabItem's font |
101 |
Font font = item.getFont(); |
102 |
FontData[] data = font.getFontData(); |
103 |
// check that it's been bolded, have discussed with SWT and we only need |
104 |
// to check the first FontData because if the first one is not bolded, |
105 |
// then the rest of the FontData (if any) in the array will also not be |
106 |
// bolded |
107 |
assertTrue("Font does not have a bold style", //$NON-NLS-1$ |
108 |
(data[0].getStyle() & SWT.BOLD) == SWT.BOLD); |
109 |
} |
110 |
|
111 |
public void testWarnOfContentChangeForEditors() throws CoreException, |
112 |
PartInitException { |
113 |
project = FileUtil.createProject("testWarnOfContentPage"); |
114 |
|
115 |
// open two editors |
116 |
IEditorPart hiddenEditor = IDE.openEditor(activePage, FileUtil |
117 |
.createFile("a.mock1", project), true); |
118 |
IEditorPart visibleEditor = IDE.openEditor(activePage, FileUtil |
119 |
.createFile("b.mock1", project), true); |
120 |
|
121 |
// first one shouldn't be visible since we opened a second one |
122 |
assertFalse("Editor is visible when another editor has been activated", //$NON-NLS-1$ |
123 |
activePage.isPartVisible(hiddenEditor)); |
124 |
// the second one should be visible |
125 |
assertTrue("Editor is not visible when it was activated", activePage //$NON-NLS-1$ |
126 |
.isPartVisible(visibleEditor)); |
127 |
|
128 |
// retrive an IWorkbenchSiteProgressService from the first editor that |
129 |
// is behind in the editor stack |
130 |
IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) hiddenEditor |
131 |
.getSite().getService(IWorkbenchSiteProgressService.class); |
132 |
assertNotNull( |
133 |
"Could not retrieve an IWorkbenchSiteProgressService from getService(Class)", |
134 |
service); |
135 |
|
136 |
// warn of content change |
137 |
service.warnOfContentChange(); |
138 |
|
139 |
WorkbenchPage page = (WorkbenchPage) activePage; |
140 |
EditorSashContainer container = (EditorSashContainer) page |
141 |
.getEditorPresentation().getLayoutPart(); |
142 |
// retrieve the SWT CTabFolder |
143 |
CTabFolder tabFolder = (CTabFolder) container.getActiveWorkbook() |
144 |
.getControl(); |
145 |
// index is 0 since we want the editor that's behind in the editor |
146 |
// stack, 1 should be the second one that we activated |
147 |
CTabItem item = tabFolder.getItem(0); |
148 |
|
149 |
// get the CTabItem's font |
150 |
Font font = item.getFont(); |
151 |
FontData[] data = font.getFontData(); |
152 |
// check that it's been bolded, have discussed with SWT and we only need |
153 |
// to check the first FontData because if the first one is not bolded, |
154 |
// then the rest of the FontData (if any) in the array will also not be |
155 |
// bolded |
156 |
assertTrue("Font does not have a bold style", //$NON-NLS-1$ |
157 |
(data[0].getStyle() & SWT.BOLD) == SWT.BOLD); |
158 |
} |
159 |
|
160 |
} |