|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Common Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/cpl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.tests.presentation; |
| 12 |
|
| 13 |
import java.util.ArrayList; |
| 14 |
import java.util.List; |
| 15 |
|
| 16 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 17 |
import org.eclipse.swt.SWT; |
| 18 |
import org.eclipse.swt.graphics.Image; |
| 19 |
import org.eclipse.swt.graphics.Point; |
| 20 |
import org.eclipse.swt.graphics.Rectangle; |
| 21 |
import org.eclipse.swt.layout.FillLayout; |
| 22 |
import org.eclipse.swt.widgets.Composite; |
| 23 |
import org.eclipse.swt.widgets.Control; |
| 24 |
import org.eclipse.swt.widgets.Text; |
| 25 |
import org.eclipse.swt.widgets.ToolBar; |
| 26 |
import org.eclipse.swt.widgets.ToolItem; |
| 27 |
import org.eclipse.ui.IPropertyListener; |
| 28 |
import org.eclipse.ui.presentations.IPartMenu; |
| 29 |
import org.eclipse.ui.presentations.IPresentablePart; |
| 30 |
|
| 31 |
/** |
| 32 |
* @since 3.1 |
| 33 |
*/ |
| 34 |
public class TestPresentablePart implements IPresentablePart { |
| 35 |
|
| 36 |
private Composite ctrl; |
| 37 |
private Control toolbar = null; |
| 38 |
private List listeners = new ArrayList(); |
| 39 |
private String name = ""; |
| 40 |
private String title = ""; |
| 41 |
private String contentDescription = ""; |
| 42 |
private Image titleImage = ImageDescriptor.getMissingImageDescriptor().createImage(); |
| 43 |
private boolean dirty = false; |
| 44 |
private String toolTip = ""; |
| 45 |
private boolean busy = false; |
| 46 |
private boolean closeable = true; |
| 47 |
private boolean hasMenu = false; |
| 48 |
private IPartMenu testMenu = new IPartMenu() { |
| 49 |
/* (non-Javadoc) |
| 50 |
* @see org.eclipse.ui.presentations.IPartMenu#showMenu(org.eclipse.swt.graphics.Point) |
| 51 |
*/ |
| 52 |
public void showMenu(Point location) { |
| 53 |
|
| 54 |
} |
| 55 |
}; |
| 56 |
|
| 57 |
public TestPresentablePart(Composite parent) { |
| 58 |
ctrl = new Composite(parent, SWT.NONE); |
| 59 |
ctrl.setLayout(new FillLayout()); |
| 60 |
// Create a text box so that we can accept focus |
| 61 |
new Text(parent, SWT.BORDER); |
| 62 |
} |
| 63 |
|
| 64 |
/* (non-Javadoc) |
| 65 |
* @see org.eclipse.ui.presentations.IPresentablePart#setBounds(org.eclipse.swt.graphics.Rectangle) |
| 66 |
*/ |
| 67 |
public void setBounds(Rectangle bounds) { |
| 68 |
if (!ctrl.isDisposed()) { |
| 69 |
ctrl.setBounds(bounds); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/* (non-Javadoc) |
| 74 |
* @see org.eclipse.ui.presentations.IPresentablePart#setVisible(boolean) |
| 75 |
*/ |
| 76 |
public void setVisible(boolean isVisible) { |
| 77 |
if (!ctrl.isDisposed()) { |
| 78 |
ctrl.setVisible(isVisible); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
/* (non-Javadoc) |
| 83 |
* @see org.eclipse.ui.presentations.IPresentablePart#setFocus() |
| 84 |
*/ |
| 85 |
public void setFocus() { |
| 86 |
if (!ctrl.isDisposed()) { |
| 87 |
ctrl.setFocus(); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
/* (non-Javadoc) |
| 92 |
* @see org.eclipse.ui.presentations.IPresentablePart#addPropertyListener(org.eclipse.ui.IPropertyListener) |
| 93 |
*/ |
| 94 |
public void addPropertyListener(IPropertyListener listener) { |
| 95 |
listeners.add(listener); |
| 96 |
} |
| 97 |
|
| 98 |
/* (non-Javadoc) |
| 99 |
* @see org.eclipse.ui.presentations.IPresentablePart#removePropertyListener(org.eclipse.ui.IPropertyListener) |
| 100 |
*/ |
| 101 |
public void removePropertyListener(IPropertyListener listener) { |
| 102 |
listeners.remove(listener); |
| 103 |
} |
| 104 |
|
| 105 |
/* (non-Javadoc) |
| 106 |
* @see org.eclipse.ui.presentations.IPresentablePart#getName() |
| 107 |
*/ |
| 108 |
public String getName() { |
| 109 |
return name; |
| 110 |
} |
| 111 |
|
| 112 |
/* (non-Javadoc) |
| 113 |
* @see org.eclipse.ui.presentations.IPresentablePart#getTitle() |
| 114 |
*/ |
| 115 |
public String getTitle() { |
| 116 |
return title; |
| 117 |
} |
| 118 |
|
| 119 |
/* (non-Javadoc) |
| 120 |
* @see org.eclipse.ui.presentations.IPresentablePart#getTitleStatus() |
| 121 |
*/ |
| 122 |
public String getTitleStatus() { |
| 123 |
return contentDescription; |
| 124 |
} |
| 125 |
|
| 126 |
/* (non-Javadoc) |
| 127 |
* @see org.eclipse.ui.presentations.IPresentablePart#getTitleImage() |
| 128 |
*/ |
| 129 |
public Image getTitleImage() { |
| 130 |
return titleImage; |
| 131 |
} |
| 132 |
|
| 133 |
/* (non-Javadoc) |
| 134 |
* @see org.eclipse.ui.presentations.IPresentablePart#getTitleToolTip() |
| 135 |
*/ |
| 136 |
public String getTitleToolTip() { |
| 137 |
return toolTip; |
| 138 |
} |
| 139 |
|
| 140 |
/* (non-Javadoc) |
| 141 |
* @see org.eclipse.ui.presentations.IPresentablePart#isDirty() |
| 142 |
*/ |
| 143 |
public boolean isDirty() { |
| 144 |
return dirty; |
| 145 |
} |
| 146 |
|
| 147 |
/* (non-Javadoc) |
| 148 |
* @see org.eclipse.ui.presentations.IPresentablePart#isBusy() |
| 149 |
*/ |
| 150 |
public boolean isBusy() { |
| 151 |
return busy; |
| 152 |
} |
| 153 |
|
| 154 |
/* (non-Javadoc) |
| 155 |
* @see org.eclipse.ui.presentations.IPresentablePart#isCloseable() |
| 156 |
*/ |
| 157 |
public boolean isCloseable() { |
| 158 |
return closeable; |
| 159 |
} |
| 160 |
|
| 161 |
/* (non-Javadoc) |
| 162 |
* @see org.eclipse.ui.presentations.IPresentablePart#getToolBar() |
| 163 |
*/ |
| 164 |
public Control getToolBar() { |
| 165 |
return toolbar; |
| 166 |
} |
| 167 |
|
| 168 |
/* (non-Javadoc) |
| 169 |
* @see org.eclipse.ui.presentations.IPresentablePart#getMenu() |
| 170 |
*/ |
| 171 |
public IPartMenu getMenu() { |
| 172 |
return hasMenu ? testMenu : null; |
| 173 |
} |
| 174 |
|
| 175 |
/* (non-Javadoc) |
| 176 |
* @see org.eclipse.ui.presentations.IPresentablePart#getControl() |
| 177 |
*/ |
| 178 |
public Control getControl() { |
| 179 |
return ctrl; |
| 180 |
} |
| 181 |
|
| 182 |
public void firePropertyChange(int propertyId) { |
| 183 |
for (int i = 0; i < listeners.size(); i++) { |
| 184 |
((IPropertyListener) listeners.get(i)).propertyChanged(this, |
| 185 |
propertyId); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
public boolean hasToolbar() { |
| 190 |
return toolbar != null; |
| 191 |
} |
| 192 |
|
| 193 |
public boolean hasListeners() { |
| 194 |
return !listeners.isEmpty(); |
| 195 |
} |
| 196 |
|
| 197 |
public void enableToolbar(boolean enable) { |
| 198 |
if (enable == hasToolbar()) { |
| 199 |
return; |
| 200 |
} |
| 201 |
|
| 202 |
if (enable) { |
| 203 |
ToolBar tb = new ToolBar(ctrl.getParent(), SWT.FLAT | SWT.WRAP); |
| 204 |
toolbar = tb; |
| 205 |
new ToolItem(tb, SWT.PUSH); |
| 206 |
} else { |
| 207 |
toolbar.dispose(); |
| 208 |
toolbar = null; |
| 209 |
} |
| 210 |
|
| 211 |
firePropertyChange(IPresentablePart.PROP_TOOLBAR); |
| 212 |
} |
| 213 |
|
| 214 |
public void enableViewMenu(boolean enabled) { |
| 215 |
if (hasMenu == enabled) { |
| 216 |
return; |
| 217 |
} |
| 218 |
|
| 219 |
hasMenu = enabled; |
| 220 |
firePropertyChange(IPresentablePart.PROP_PANE_MENU); |
| 221 |
} |
| 222 |
|
| 223 |
public void dispose() { |
| 224 |
ctrl.dispose(); |
| 225 |
enableToolbar(false); |
| 226 |
} |
| 227 |
} |