1 11 package org.eclipse.ui.internal.progress; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.jface.dialogs.IDialogConstants; 17 import org.eclipse.jface.resource.JFaceResources; 18 import org.eclipse.jface.viewers.ViewerComparator; 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.custom.ScrolledComposite; 21 import org.eclipse.swt.events.ControlEvent; 22 import org.eclipse.swt.events.ControlListener; 23 import org.eclipse.swt.events.FocusAdapter; 24 import org.eclipse.swt.events.FocusEvent; 25 import org.eclipse.swt.graphics.Point; 26 import org.eclipse.swt.layout.GridData; 27 import org.eclipse.swt.layout.GridLayout; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.swt.widgets.Control; 30 import org.eclipse.swt.widgets.Text; 31 import org.eclipse.swt.widgets.Widget; 32 import org.eclipse.ui.PlatformUI; 33 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 34 35 42 public class DetailedProgressViewer extends AbstractProgressViewer { 43 44 Composite control; 45 46 private ScrolledComposite scrolled; 47 48 private Composite noEntryArea; 49 50 57 public DetailedProgressViewer(Composite parent, int style) { 58 scrolled = new ScrolledComposite(parent, SWT.V_SCROLL | style); 59 int height = JFaceResources.getDefaultFont().getFontData()[0] 60 .getHeight(); 61 scrolled.getVerticalBar().setIncrement(height * 2); 62 scrolled.setExpandHorizontal(true); 63 scrolled.setExpandVertical(true); 64 65 control = new Composite(scrolled, SWT.NONE); 66 GridLayout layout = new GridLayout(); 67 layout.marginHeight = 0; 68 layout.marginWidth = 0; 69 control.setLayout(layout); 70 control.setBackground(parent.getDisplay().getSystemColor( 71 SWT.COLOR_LIST_BACKGROUND)); 72 73 control.addFocusListener(new FocusAdapter() { 74 75 private boolean settingFocus = false; 76 77 82 public void focusGained(FocusEvent e) { 83 if (!settingFocus) { 84 settingFocus = true; 86 setFocus(); 87 settingFocus = false; 88 } 89 } 90 }); 91 92 control.addControlListener(new ControlListener() { 93 98 public void controlMoved(ControlEvent e) { 99 updateVisibleItems(); 100 101 } 102 103 108 public void controlResized(ControlEvent e) { 109 updateVisibleItems(); 110 } 111 }); 112 113 PlatformUI.getWorkbench().getHelpSystem().setHelp(control, 114 IWorkbenchHelpContextIds.RESPONSIVE_UI); 115 116 scrolled.setContent(control); 117 hookControl(control); 118 119 noEntryArea = new Composite(scrolled, SWT.NONE); 120 noEntryArea.setLayout(new GridLayout()); 121 122 Text noEntryLabel = new Text(noEntryArea, SWT.SINGLE); 123 noEntryLabel.setText(ProgressMessages.ProgressView_NoOperations); 124 noEntryLabel.setBackground(noEntryArea.getDisplay().getSystemColor( 125 SWT.COLOR_WIDGET_BACKGROUND)); 126 GridData textData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); 127 noEntryLabel.setLayoutData(textData); 128 noEntryLabel.setEditable(false); 129 130 PlatformUI.getWorkbench().getHelpSystem().setHelp(noEntryLabel, 131 IWorkbenchHelpContextIds.RESPONSIVE_UI); 132 133 } 134 135 140 public void add(Object [] elements) { 141 ViewerComparator sorter = getComparator(); 142 ArrayList newItems = new ArrayList (control.getChildren().length 143 + elements.length); 144 145 Control[] existingChildren = control.getChildren(); 146 for (int i = 0; i < existingChildren.length; i++) { 147 newItems.add(existingChildren[i].getData()); 148 } 149 150 for (int i = 0; i < elements.length; i++) { 151 newItems.add(elements[i]); 152 } 153 154 JobTreeElement[] infos = new JobTreeElement[newItems.size()]; 155 newItems.toArray(infos); 156 157 if (sorter != null) { 158 sorter.sort(this, infos); 159 } 160 161 for (int i = 0; i < existingChildren.length; i++) { 163 ((ProgressInfoItem) existingChildren[i]).dispose(); 164 } 165 166 for (int i = 0; i < newItems.size(); i++) { 167 ProgressInfoItem item = createNewItem(infos[i]); 168 item.setColor(i); 169 } 170 171 control.layout(true); 172 updateForShowingProgress(); 173 } 174 175 178 private void updateForShowingProgress() { 179 if (control.getChildren().length > 0) { 180 scrolled.setContent(control); 181 } else { 182 scrolled.setContent(noEntryArea); 183 } 184 } 185 186 192 private ProgressInfoItem createNewItem(JobTreeElement info) { 193 final ProgressInfoItem item = new ProgressInfoItem(control, SWT.NONE, 194 info); 195 196 item.setIndexListener(new ProgressInfoItem.IndexListener() { 197 202 public void selectNext() { 203 DetailedProgressViewer.this.selectNext(item); 204 205 } 206 207 212 public void selectPrevious() { 213 DetailedProgressViewer.this.selectPrevious(item); 214 215 } 216 217 222 public void select() { 223 224 Control[] children = control.getChildren(); 225 for (int i = 0; i < children.length; i++) { 226 ProgressInfoItem child = (ProgressInfoItem) children[i]; 227 if (!item.equals(child)) { 228 child.selectWidgets(false); 229 } 230 } 231 item.selectWidgets(true); 232 233 } 234 }); 235 236 item.refresh(); 238 return item; 239 } 240 241 246 protected void selectPrevious(ProgressInfoItem item) { 247 Control[] children = control.getChildren(); 248 for (int i = 0; i < children.length; i++) { 249 ProgressInfoItem child = (ProgressInfoItem) children[i]; 250 if (item.equals(child)) { 251 ProgressInfoItem previous; 252 if (i == 0) { 253 previous = (ProgressInfoItem) children[children.length - 1]; 254 } else { 255 previous = (ProgressInfoItem) children[i - 1]; 256 } 257 258 item.selectWidgets(false); 259 previous.selectWidgets(true); 260 return; 261 } 262 } 263 } 264 265 270 protected void selectNext(ProgressInfoItem item) { 271 Control[] children = control.getChildren(); 272 for (int i = 0; i < children.length; i++) { 273 ProgressInfoItem child = (ProgressInfoItem) children[i]; 274 if (item.equals(child)) { 275 ProgressInfoItem next; 276 if (i == children.length - 1) { 277 next = (ProgressInfoItem) children[0]; 278 } else { 279 next = (ProgressInfoItem) children[i + 1]; 280 } 281 item.selectWidgets(false); 282 next.selectWidgets(true); 283 284 return; 285 } 286 } 287 288 } 289 290 295 protected Widget doFindInputItem(Object element) { 296 return null; 297 } 298 299 304 protected Widget doFindItem(Object element) { 305 Control[] existingChildren = control.getChildren(); 306 for (int i = 0; i < existingChildren.length; i++) { 307 if (existingChildren[i].isDisposed() 308 || existingChildren[i].getData() == null) { 309 continue; 310 } 311 if (existingChildren[i].getData().equals(element)) { 312 return existingChildren[i]; 313 } 314 } 315 return null; 316 } 317 318 324 protected void doUpdateItem(Widget item, Object element, boolean fullMap) { 325 if (usingElementMap()) { 326 unmapElement(item); 327 } 328 item.dispose(); 329 add(new Object [] { element }); 330 } 331 332 337 public Control getControl() { 338 return scrolled; 339 } 340 341 346 protected List getSelectionFromWidget() { 347 return new ArrayList (0); 348 } 349 350 356 protected void inputChanged(Object input, Object oldInput) { 357 super.inputChanged(input, oldInput); 358 refreshAll(); 359 updateForShowingProgress(); 360 } 361 362 367 protected void internalRefresh(Object element) { 368 if (element == null) { 369 return; 370 } 371 372 if (element.equals(getRoot())) { 373 refreshAll(); 374 return; 375 } 376 Widget widget = findItem(element); 377 if (widget == null) { 378 add(new Object [] { element }); 379 return; 380 } 381 ((ProgressInfoItem) widget).refresh(); 382 383 Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT); 385 size.x += IDialogConstants.HORIZONTAL_SPACING; 386 size.y += IDialogConstants.VERTICAL_SPACING; 387 388 scrolled.setMinSize(size); 389 } 390 391 396 public void remove(Object [] elements) { 397 398 for (int i = 0; i < elements.length; i++) { 399 400 if (((JobTreeElement) elements[i]).isJobInfo() 402 && FinishedJobs.getInstance().isFinished( 403 (JobInfo) elements[i])) { 404 Widget item = doFindItem(elements[i]); 405 if (item != null) { 406 ((ProgressInfoItem) item).refresh(); 407 } 408 409 } else { 410 Widget item = doFindItem(elements[i]); 411 if (item != null) { 412 unmapElement(elements[i]); 413 item.dispose(); 414 } 415 } 416 } 417 418 Control[] existingChildren = control.getChildren(); 419 for (int i = 0; i < existingChildren.length; i++) { 420 ProgressInfoItem item = (ProgressInfoItem) existingChildren[i]; 421 item.setColor(i); 422 } 423 control.layout(true); 424 updateForShowingProgress(); 425 } 426 427 432 public void reveal(Object element) { 433 434 } 435 436 442 protected void setSelectionToWidget(List l, boolean reveal) { 443 444 } 445 446 450 public void cancelSelection() { 451 452 } 453 454 458 public void setFocus() { 459 Control[] children = control.getChildren(); 460 if (children.length > 0) { 461 for (int i = 0; i < children.length; i++) { 462 ProgressInfoItem item = (ProgressInfoItem) children[i]; 463 item.setButtonFocus(); 464 return; 465 } 466 } else 467 noEntryArea.setFocus(); 468 } 469 470 473 private void refreshAll() { 474 475 Object [] infos = getSortedChildren(getRoot()); 476 Control[] existingChildren = control.getChildren(); 477 478 for (int i = 0; i < existingChildren.length; i++) { 479 existingChildren[i].dispose(); 480 481 } 482 for (int i = 0; i < infos.length; i++) { 484 ProgressInfoItem item = createNewItem((JobTreeElement) infos[i]); 485 item.setColor(i); 486 } 487 488 control.layout(true); 489 updateForShowingProgress(); 490 491 } 492 493 497 private void updateVisibleItems() { 498 Control[] children = control.getChildren(); 499 int top = scrolled.getOrigin().y; 500 int bottom = top + scrolled.getParent().getBounds().height; 501 for (int i = 0; i < children.length; i++) { 502 ProgressInfoItem item = (ProgressInfoItem) children[i]; 503 item.setDisplayed(top, bottom); 504 505 } 506 } 507 508 } 509 | Popular Tags |