001: /*******************************************************************************
002: * Copyright (c) 2004 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Common Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/cpl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.examples.presentation.barebones;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.events.DisposeEvent;
014: import org.eclipse.swt.events.DisposeListener;
015: import org.eclipse.swt.graphics.Point;
016: import org.eclipse.swt.graphics.Rectangle;
017: import org.eclipse.swt.widgets.Composite;
018: import org.eclipse.swt.widgets.Control;
019: import org.eclipse.ui.presentations.IPresentablePart;
020: import org.eclipse.ui.presentations.IStackPresentationSite;
021: import org.eclipse.ui.presentations.StackDropResult;
022: import org.eclipse.ui.presentations.StackPresentation;
023:
024: /**
025: * Bare-bones stack presentation. The currently selected part fills the entire
026: * presentation area, and all other parts are invisible. Does not provide a
027: * system menu, pane menu, trim, drag/drop, toolbars, or any way to switch
028: * parts.
029: */
030: public class BareBonesPartPresentation extends StackPresentation {
031:
032: /**
033: * Main widget for the presentation
034: */
035: private Composite presentationControl;
036:
037: /**
038: * Currently selected part
039: */
040: private IPresentablePart current;
041:
042: /**
043: * Creates a new bare-bones part presentation, given the parent composite and
044: * an IStackPresentationSite interface that will be used to communicate with
045: * the workbench.
046: *
047: * @param stackSite interface to the workbench
048: */
049: public BareBonesPartPresentation(Composite parent,
050: IStackPresentationSite stackSite) {
051: super (stackSite);
052:
053: // Create a top-level control for the presentation.
054: presentationControl = new Composite(parent, SWT.NONE);
055:
056: // Add a dispose listener. This will call the presentationDisposed()
057: // method when the widget is destroyed.
058: presentationControl.addDisposeListener(new DisposeListener() {
059: public void widgetDisposed(DisposeEvent e) {
060: presentationDisposed();
061: }
062: });
063: }
064:
065: public void dispose() {
066: // Dispose the main presentation widget. This will cause
067: // presentationDisposed to be called, which will do the real cleanup.
068: presentationControl.dispose();
069: }
070:
071: /**
072: * Perform any cleanup. This method should remove any listeners that were
073: * attached to other objects. This gets called when the presentation
074: * widget is disposed. This is safer than cleaning up in the dispose()
075: * method, since this code will run even if some unusual circumstance
076: * destroys the Shell without first calling dispose().
077: */
078: protected void presentationDisposed() {
079: // Remove any listeners that were attached to any IPresentableParts or
080: // global Eclipse resources. This is necessary in order to prevent
081: // memory leaks. Currently, there is nothing to do.
082: }
083:
084: public void setBounds(Rectangle bounds) {
085: // Set the bounds of the presentation widget
086: presentationControl.setBounds(bounds);
087:
088: // Update the bounds of the currently visible part
089: updatePartBounds();
090: }
091:
092: private void updatePartBounds() {
093: if (current != null) {
094: current.setBounds(presentationControl.getBounds());
095: }
096: }
097:
098: public Point computeMinimumSize() {
099: return new Point(16, 16);
100: }
101:
102: public void setVisible(boolean isVisible) {
103:
104: // Make the presentation widget visible
105: presentationControl.setVisible(isVisible);
106:
107: // Make the currently visible part visible
108: if (current != null) {
109: current.setVisible(isVisible);
110: }
111:
112: if (isVisible) {
113: // Restore the bounds of the currently visible part.
114: // IPartPresentations can be used by multiple StackPresentations,
115: // although only one such presentation is ever visible at a time.
116: // It is possible that some other presentation has changed the
117: // bounds of the part since it was last visible, so we need to
118: // update the part's bounds when the presentation becomes visible.
119: updatePartBounds();
120: }
121: }
122:
123: public void selectPart(IPresentablePart toSelect) {
124: // Ignore redundant selections
125: if (toSelect == current) {
126: return;
127: }
128:
129: // If there was an existing part selected, make it invisible
130: if (current != null) {
131: current.setVisible(false);
132: }
133:
134: // Select the new part
135: current = toSelect;
136:
137: // Ordering is important here. We need to make the part
138: // visible before updating its bounds, or the call to setBounds
139: // may be ignored.
140:
141: if (current != null) {
142: // Make the newly selected part visible
143: current.setVisible(true);
144: }
145:
146: // Update the bounds of the newly selected part
147: updatePartBounds();
148: }
149:
150: public Control[] getTabList(IPresentablePart part) {
151: return new Control[] { part.getControl() };
152: }
153:
154: public Control getControl() {
155: return presentationControl;
156: }
157:
158: // Methods that don't do anything yet
159: public void setActive(int newState) {
160: }
161:
162: public void setState(int state) {
163: }
164:
165: public void addPart(IPresentablePart newPart, Object cookie) {
166: }
167:
168: public void removePart(IPresentablePart oldPart) {
169: }
170:
171: public StackDropResult dragOver(Control currentControl,
172: Point location) {
173: return null;
174: }
175:
176: public void showSystemMenu() {
177: }
178:
179: public void showPaneMenu() {
180: }
181: }
|