1 11 package org.eclipse.ui.internal.progress; 12 13 import org.eclipse.jface.viewers.IContentProvider; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.events.MouseAdapter; 16 import org.eclipse.swt.events.MouseEvent; 17 import org.eclipse.swt.graphics.GC; 18 import org.eclipse.swt.graphics.Point; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.layout.GridLayout; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Control; 23 import org.eclipse.ui.internal.TrimUtil; 24 import org.eclipse.ui.internal.WorkbenchMessages; 25 import org.eclipse.ui.internal.WorkbenchWindow; 26 import org.eclipse.ui.internal.layout.IWindowTrim; 27 28 32 public class ProgressRegion implements IWindowTrim { 33 ProgressCanvasViewer viewer; 34 35 ProgressAnimationItem animationItem; 36 37 Composite region; 38 39 WorkbenchWindow workbenchWindow; 40 41 private int fWidthHint = SWT.DEFAULT; 42 43 private int fHeightHint = SWT.DEFAULT; 44 45 48 private int side = SWT.BOTTOM; 49 50 private boolean forceHorizontal; 51 52 55 public ProgressRegion() { 56 } 58 59 69 public Control createContents(Composite parent, WorkbenchWindow window) { 70 workbenchWindow = window; 71 72 GC gc = new GC(parent); 77 gc.setAdvanced(true); 78 forceHorizontal = !gc.getAdvanced(); 79 gc.dispose(); 80 81 region = new Composite(parent, SWT.NONE) { 82 88 public Point computeSize(int wHint, int hHint, boolean changed) { 89 Point size = super.computeSize(wHint, hHint, changed); 90 if (isHorizontal(side)) 91 size.y = TrimUtil.TRIM_DEFAULT_HEIGHT; 92 else { 93 size.x = TrimUtil.TRIM_DEFAULT_HEIGHT; 94 } 95 return size; 96 } 97 }; 98 99 GridLayout gl = new GridLayout(); 100 gl.marginHeight = 0; 101 gl.marginWidth = 0; 102 if (isHorizontal(side)) 103 gl.numColumns = 3; 104 region.setLayout(gl); 105 106 viewer = new ProgressCanvasViewer(region, SWT.NO_FOCUS, 1, 36, isHorizontal(side) ? SWT.HORIZONTAL : SWT.VERTICAL); 107 viewer.setUseHashlookup(true); 108 Control viewerControl = viewer.getControl(); 109 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); 110 Point viewerSizeHints = viewer.getSizeHints(); 111 if (isHorizontal(side)) { 112 gd.widthHint = viewerSizeHints.x; 113 gd.heightHint = viewerSizeHints.y; 114 } else { 115 gd.widthHint = viewerSizeHints.y; 116 gd.heightHint = viewerSizeHints.x; 117 } 118 viewerControl.setLayoutData(gd); 119 120 int widthPreference = AnimationManager.getInstance() 121 .getPreferredWidth() + 25; 122 animationItem = new ProgressAnimationItem(this, isHorizontal(side) ? SWT.HORIZONTAL : SWT.VERTICAL); 123 animationItem.createControl(region); 124 125 animationItem.setAnimationContainer(new AnimationItem.IAnimationContainer() { 126 129 public void animationDone() { 130 if (viewer.getControl().isDisposed()) { 133 return; 134 } 135 viewer.refresh(); 136 } 137 138 141 public void animationStart() { 142 144 } 145 }); 146 if (isHorizontal(side)) { 147 gd = new GridData(GridData.FILL_VERTICAL); 148 gd.widthHint = widthPreference; 149 } else { 150 gd = new GridData(GridData.FILL_HORIZONTAL); 151 gd.heightHint = widthPreference; 152 } 153 154 animationItem.getControl().setLayoutData(gd); 155 156 viewerControl.addMouseListener(new MouseAdapter() { 157 162 public void mouseDoubleClick(MouseEvent e) { 163 processDoubleClick(); 164 } 165 }); 166 167 IContentProvider provider = new ProgressViewerContentProvider(viewer, 169 false,false); 170 viewer.setContentProvider(provider); 171 viewer.setInput(provider); 172 viewer.setLabelProvider(new ProgressViewerLabelProvider(viewerControl)); 173 viewer.setComparator(ProgressManagerUtil.getProgressViewerComparator()); 174 return region; 175 } 176 177 182 public AnimationItem getAnimationItem() { 183 return animationItem; 184 } 185 186 191 public Control getControl() { 192 return region; 193 } 194 195 198 public void processDoubleClick() { 199 ProgressManagerUtil.openProgressView(workbenchWindow); 200 } 201 202 205 public void dock(int dropSide) { 206 int oldSide = side; 207 side = dropSide; 208 if (oldSide == dropSide || (isVertical(oldSide) && isVertical(dropSide)) || (isHorizontal(oldSide) && isHorizontal(dropSide))) 209 return; 210 recreate(); 211 212 } 213 214 220 private boolean isHorizontal(int dropSide) { 221 if (forceHorizontal) 222 return true; 223 return dropSide == SWT.TOP || dropSide == SWT.BOTTOM; 224 } 225 226 227 233 private boolean isVertical(int dropSide) { 234 if (forceHorizontal) 235 return false; 236 return dropSide == SWT.LEFT || dropSide == SWT.RIGHT; 237 } 238 239 242 private void recreate() { 243 if (region != null && !region.isDisposed()) { 244 Composite parent = region.getParent(); 245 boolean animating = animationItem.animationRunning(); 246 AnimationManager.getInstance().removeItem(animationItem); 247 region.dispose(); 248 createContents(parent, workbenchWindow); 249 if (animating) 250 animationItem.animationStart(); 251 } 252 } 253 254 257 public String getId() { 258 return "org.eclipse.ui.internal.progress.ProgressRegion"; } 260 261 public String getDisplayName() { 262 return WorkbenchMessages.TrimCommon_Progress_TrimName; 263 } 264 265 268 public int getValidSides() { 269 return SWT.BOTTOM | SWT.TOP | SWT.LEFT | SWT.RIGHT ; 270 } 271 272 275 public boolean isCloseable() { 276 return false; 277 } 278 279 282 public void handleClose() { 283 } 285 286 291 public int getWidthHint() { 292 return fWidthHint; 293 } 294 295 299 public void setWidthHint(int w) { 300 fWidthHint = w; 301 } 302 303 308 public int getHeightHint() { 309 return fHeightHint; 310 } 311 312 316 public void setHeightHint(int h) { 317 fHeightHint = h; 318 } 319 320 323 public boolean isResizeable() { 324 return false; 325 } 326 } 327 | Popular Tags |