001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.tests.performance.layout;
011:
012: import junit.framework.Assert;
013:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.swt.graphics.Point;
016: import org.eclipse.swt.widgets.Composite;
017: import org.eclipse.swt.widgets.Control;
018: import org.eclipse.ui.IViewPart;
019: import org.eclipse.ui.IWorkbenchPage;
020: import org.eclipse.ui.IWorkbenchWindow;
021: import org.eclipse.ui.PlatformUI;
022: import org.eclipse.ui.WorkbenchException;
023: import org.eclipse.ui.internal.PartPane;
024: import org.eclipse.ui.internal.ViewSite;
025: import org.eclipse.ui.tests.harness.util.EmptyPerspective;
026: import org.eclipse.ui.tests.harness.util.UITestCase;
027: import org.eclipse.ui.tests.performance.BasicPerformanceTest;
028:
029: /**
030: * @since 3.1
031: */
032: public class ViewWidgetFactory extends TestWidgetFactory {
033:
034: private String viewId;
035: private Control ctrl;
036: private IWorkbenchWindow window;
037:
038: public ViewWidgetFactory(String viewId) {
039: this .viewId = viewId;
040: Assert.assertNotNull(viewId);
041: }
042:
043: /* (non-Javadoc)
044: * @see org.eclipse.ui.tests.performance.TestWidgetFactory#getMaxSize()
045: */
046: public Point getMaxSize() {
047: return new Point(1024, 768);
048: }
049:
050: public static Composite getControl(IViewPart part) {
051: ViewSite site = (ViewSite) part.getSite();
052:
053: PartPane pane = site.getPane();
054:
055: return (Composite) pane.getControl();
056: }
057:
058: /* (non-Javadoc)
059: * @see org.eclipse.ui.tests.performance.TestWidgetFactory#init()
060: */
061: public void init() throws CoreException, WorkbenchException {
062: // open the view in a new window
063: window = PlatformUI.getWorkbench().openWorkbenchWindow(
064: EmptyPerspective.PERSP_ID, UITestCase.getPageInput());
065: IWorkbenchPage page = window.getActivePage();
066: Assert.assertNotNull(page);
067:
068: IViewPart part = page.showView(viewId, null,
069: IWorkbenchPage.VIEW_ACTIVATE);
070:
071: BasicPerformanceTest.waitForBackgroundJobs();
072:
073: ctrl = getControl(part);
074:
075: Point size = getMaxSize();
076: ctrl.setBounds(0, 0, size.x, size.y);
077: window.getShell().setSize(size);
078: }
079:
080: /* (non-Javadoc)
081: * @see org.eclipse.ui.tests.performance.TestWidgetFactory#getName()
082: */
083: public String getName() {
084: return "View " + viewId;
085: }
086:
087: /* (non-Javadoc)
088: * @see org.eclipse.ui.tests.performance.TestWidgetFactory#getControl()
089: */
090: public Composite getControl() throws CoreException,
091: WorkbenchException {
092: return (Composite) ctrl;
093: }
094:
095: /* (non-Javadoc)
096: * @see org.eclipse.ui.tests.performance.layout.TestWidgetFactory#done()
097: */
098: public void done() throws CoreException, WorkbenchException {
099: window.close();
100: super.done();
101: }
102:
103: }
|