001: /*******************************************************************************
002: * Copyright (c) 2000, 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 org.eclipse.core.runtime.CoreException;
013: import org.eclipse.swt.graphics.Image;
014: import org.eclipse.swt.widgets.Composite;
015: import org.eclipse.swt.widgets.Control;
016: import org.eclipse.swt.widgets.Display;
017: import org.eclipse.swt.widgets.Shell;
018: import org.eclipse.ui.PlatformUI;
019: import org.eclipse.ui.WorkbenchException;
020: import org.eclipse.ui.internal.presentations.PresentationFactoryUtil;
021: import org.eclipse.ui.presentations.AbstractPresentationFactory;
022: import org.eclipse.ui.tests.performance.UIPerformancePlugin;
023: import org.eclipse.ui.tests.performance.presentations.PresentationTestbed;
024: import org.eclipse.ui.tests.performance.presentations.TestPresentablePart;
025:
026: public class PresentationWidgetFactory extends TestWidgetFactory {
027:
028: private AbstractPresentationFactory factory;
029: private int type;
030: private Shell shell;
031: private Image img;
032: private Control ctrl;
033: private int numParts;
034:
035: public PresentationWidgetFactory(
036: AbstractPresentationFactory factory, int type, int numParts) {
037: this .factory = factory;
038: this .type = type;
039: this .numParts = numParts;
040: }
041:
042: public void init() throws CoreException, WorkbenchException {
043: super .init();
044:
045: img = UIPerformancePlugin.getImageDescriptor(
046: "icons/anything.gif").createImage();
047: Display display = PlatformUI.getWorkbench()
048: .getActiveWorkbenchWindow().getShell().getDisplay();
049:
050: shell = new Shell(display);
051:
052: TestPresentablePart selection = null;
053: PresentationTestbed testBed = new PresentationTestbed(shell,
054: factory, type);
055: for (int partCount = 0; partCount < numParts; partCount++) {
056: TestPresentablePart part = new TestPresentablePart(shell,
057: img);
058: part.setName("Some part");
059: part.setContentDescription("Description");
060: part.setTitle("Some title");
061: part.setDirty(partCount % 2 == 0);
062: part.setTooltip("This is a tooltip");
063: testBed.add(part);
064: selection = part;
065: }
066:
067: testBed.setSelection(selection);
068:
069: ctrl = testBed.getControl();
070: shell.setBounds(0, 0, 1024, 768);
071: ctrl.setBounds(shell.getClientArea());
072: shell.setVisible(true);
073: }
074:
075: public void done() throws CoreException, WorkbenchException {
076: shell.dispose();
077: img.dispose();
078:
079: super .done();
080: }
081:
082: public static String describePresentation(
083: AbstractPresentationFactory factory, int type) {
084: String typeDesc = "unknown";
085:
086: switch (type) {
087: case PresentationFactoryUtil.ROLE_EDITOR:
088: typeDesc = "editor";
089: break;
090: case PresentationFactoryUtil.ROLE_STANDALONE:
091: typeDesc = "standalone with title";
092: break;
093: case PresentationFactoryUtil.ROLE_STANDALONE_NOTITLE:
094: typeDesc = "standalone without title";
095: break;
096: case PresentationFactoryUtil.ROLE_VIEW:
097: typeDesc = "view";
098: break;
099: }
100:
101: return "Presentation " + factory.getId() + " " + typeDesc;
102:
103: }
104:
105: public String getName() {
106: return describePresentation(factory, type);
107: }
108:
109: public Composite getControl() throws CoreException,
110: WorkbenchException {
111: return (Composite) ctrl;
112: }
113:
114: }
|