001: /*******************************************************************************
002: * Copyright (c) 2004, 2005 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.examples.components.views;
011:
012: import org.eclipse.jface.resource.DeviceResourceException;
013: import org.eclipse.jface.resource.ImageDescriptor;
014: import org.eclipse.jface.resource.ResourceManager;
015: import org.eclipse.swt.SWT;
016: import org.eclipse.swt.graphics.Image;
017: import org.eclipse.swt.layout.GridData;
018: import org.eclipse.swt.layout.GridLayout;
019: import org.eclipse.swt.widgets.Composite;
020: import org.eclipse.swt.widgets.Label;
021: import org.eclipse.ui.IViewSite;
022: import org.eclipse.ui.PartInitException;
023: import org.eclipse.ui.internal.components.framework.ComponentException;
024: import org.eclipse.ui.internal.components.framework.Components;
025: import org.eclipse.ui.internal.part.components.services.IPluginResources;
026: import org.eclipse.ui.internal.part.components.services.ISystemLog;
027: import org.eclipse.ui.part.ViewPart;
028:
029: /**
030: * @since 3.1
031: */
032: public class OldStyleViewThatUsesNewDependencies extends ViewPart {
033:
034: private ResourceManager resources;
035: private IPluginResources pluginData;
036: private ISystemLog log;
037:
038: /* (non-Javadoc)
039: * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
040: */
041: public void init(IViewSite site) throws PartInitException {
042: super .init(site);
043:
044: // It's usually best to query for required services inside a view's
045: // init method since it's easy to abort creation of the part by throwing
046: // a PartInitException.
047:
048: // Unfortunatley, many services can only be accessed once the part's createPartControl
049: // method has been called, so this pattern isn't always possible.
050:
051: try {
052: log = (ISystemLog) Components.queryInterface(site,
053: ISystemLog.class);
054: resources = (ResourceManager) Components.queryInterface(
055: site, ResourceManager.class);
056: pluginData = (IPluginResources) Components.queryInterface(
057: site, IPluginResources.class);
058: } catch (ComponentException e) {
059: throw new PartInitException(
060: "Unable to create OldStyleViewThatUsesNewDependencies",
061: e);
062: }
063: }
064:
065: /* (non-Javadoc)
066: * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
067: */
068: public void createPartControl(Composite parent) {
069: ImageDescriptor titleImage = pluginData
070: .getImage("/icons/binary_co.gif");
071: ImageDescriptor labelImage = pluginData
072: .getImage("/icons/run_co.gif");
073: try {
074: Image realImage = resources.createImage(titleImage);
075: setTitleImage(realImage);
076: } catch (DeviceResourceException e) {
077: log.log(e);
078: }
079:
080: GridLayout parentLayout = new GridLayout();
081: parentLayout.numColumns = 1;
082: parent.setLayout(parentLayout);
083:
084: Label helloWorld = new Label(parent, SWT.NONE);
085: helloWorld.setText("Hello world");
086: helloWorld.setLayoutData(new GridData(GridData.FILL_BOTH));
087:
088: Label middleIcon = new Label(parent, SWT.NONE);
089: middleIcon.setLayoutData(new GridData(GridData.FILL_BOTH));
090:
091: try {
092: Image realImage = resources.createImage(labelImage);
093: middleIcon.setImage(realImage);
094: } catch (DeviceResourceException e) {
095: log.log(e);
096: }
097: }
098:
099: /* (non-Javadoc)
100: * @see org.eclipse.ui.IWorkbenchPart#setFocus()
101: */
102: public void setFocus() {
103:
104: }
105:
106: }
|