comparison org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/TableTreeItem.d @ 0:6dd524f61e62

add dwt win and basic java stuff
author Frank Benoit <benoit@tionex.de>
date Mon, 02 Mar 2009 14:44:16 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6dd524f61e62
1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.swt.custom.TableTreeItem;
14
15
16
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.SWTException;
19 import org.eclipse.swt.graphics.Color;
20 import org.eclipse.swt.graphics.Font;
21 import org.eclipse.swt.graphics.GC;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.swt.graphics.Rectangle;
24 import org.eclipse.swt.widgets.Event;
25 import org.eclipse.swt.widgets.Item;
26 import org.eclipse.swt.widgets.Table;
27 import org.eclipse.swt.widgets.TableItem;
28 import org.eclipse.swt.widgets.Widget;
29 import org.eclipse.swt.custom.TableTree;
30 import java.lang.all;
31
32
33 /**
34 * A TableTreeItem is a selectable user interface object
35 * that represents an item in a hierarchy of items in a
36 * TableTree.
37 *
38 * @deprecated As of 3.1 use Tree, TreeItem and TreeColumn
39 */
40 public class TableTreeItem : Item {
41 TableItem tableItem;
42 TableTree parent;
43 TableTreeItem parentItem;
44 TableTreeItem [] items;
45 String[] texts;
46 Image[] images;
47 Color background;
48 Color foreground;
49 Font font;
50 bool expanded;
51 bool checked;
52 bool grayed;
53
54 /**
55 * Constructs a new instance of this class given its parent
56 * (which must be a <code>TableTree</code>)
57 * and a style value describing its behavior and appearance.
58 * The item is added to the end of the items maintained by its parent.
59 * <p>
60 * The style value is either one of the style constants defined in
61 * class <code>SWT</code> which is applicable to instances of this
62 * class, or must be built by <em>bitwise OR</em>'ing together
63 * (that is, using the <code>int</code> "|" operator) two or more
64 * of those <code>SWT</code> style constants. The class description
65 * lists the style constants that are applicable to the class.
66 * Style bits are also inherited from superclasses.
67 * </p>
68 *
69 * @param parent a composite control which will be the parent of the new instance (cannot be null)
70 * @param style the style of control to construct
71 *
72 * @exception IllegalArgumentException <ul>
73 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
74 * </ul>
75 * @exception SWTException <ul>
76 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
77 * </ul>
78 *
79 * @see SWT
80 * @see Widget#getStyle()
81 */
82 public this(TableTree parent, int style) {
83 this (parent, style, parent.getItemCount());
84 }
85
86 /**
87 * Constructs a new instance of this class given its parent
88 * (which must be a <code>TableTree</code>,
89 * a style value describing its behavior and appearance, and the index
90 * at which to place it in the items maintained by its parent.
91 * <p>
92 * The style value is either one of the style constants defined in
93 * class <code>SWT</code> which is applicable to instances of this
94 * class, or must be built by <em>bitwise OR</em>'ing together
95 * (that is, using the <code>int</code> "|" operator) two or more
96 * of those <code>SWT</code> style constants. The class description
97 * lists the style constants that are applicable to the class.
98 * Style bits are also inherited from superclasses.
99 * </p>
100 *
101 * @param parent a composite control which will be the parent of the new instance (cannot be null)
102 * @param style the style of control to construct
103 * @param index the index to store the receiver in its parent
104 *
105 * @exception IllegalArgumentException <ul>
106 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
107 * </ul>
108 * @exception SWTException <ul>
109 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
110 * </ul>
111 *
112 * @see SWT
113 * @see Widget#getStyle()
114 */
115 public this(TableTree parent, int style, int index) {
116 this (parent, null, style, index);
117 }
118
119 /**
120 * Constructs a new instance of this class given its parent
121 * (which must be a <code>TableTreeItem</code>)
122 * and a style value describing its behavior and appearance.
123 * The item is added to the end of the items maintained by its parent.
124 * <p>
125 * The style value is either one of the style constants defined in
126 * class <code>SWT</code> which is applicable to instances of this
127 * class, or must be built by <em>bitwise OR</em>'ing together
128 * (that is, using the <code>int</code> "|" operator) two or more
129 * of those <code>SWT</code> style constants. The class description
130 * lists the style constants that are applicable to the class.
131 * Style bits are also inherited from superclasses.
132 * </p>
133 *
134 * @param parent a composite control which will be the parent of the new instance (cannot be null)
135 * @param style the style of control to construct
136 *
137 * @exception IllegalArgumentException <ul>
138 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
139 * </ul>
140 * @exception SWTException <ul>
141 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
142 * </ul>
143 *
144 * @see SWT
145 * @see Widget#getStyle()
146 */
147 public this(TableTreeItem parent, int style) {
148 this (parent, style, parent.getItemCount());
149 }
150
151 /**
152 * Constructs a new instance of this class given its parent
153 * (which must be a <code>TableTreeItem</code>),
154 * a style value describing its behavior and appearance, and the index
155 * at which to place it in the items maintained by its parent.
156 * <p>
157 * The style value is either one of the style constants defined in
158 * class <code>SWT</code> which is applicable to instances of this
159 * class, or must be built by <em>bitwise OR</em>'ing together
160 * (that is, using the <code>int</code> "|" operator) two or more
161 * of those <code>SWT</code> style constants. The class description
162 * lists the style constants that are applicable to the class.
163 * Style bits are also inherited from superclasses.
164 * </p>
165 *
166 * @param parent a composite control which will be the parent of the new instance (cannot be null)
167 * @param style the style of control to construct
168 * @param index the index to store the receiver in its parent
169 *
170 * @exception IllegalArgumentException <ul>
171 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
172 * </ul>
173 * @exception SWTException <ul>
174 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
175 * </ul>
176 *
177 * @see SWT
178 * @see Widget#getStyle()
179 */
180 public this(TableTreeItem parent, int style, int index) {
181 this (parent.getParent(), parent, style, index);
182 }
183
184 this(TableTree parent, TableTreeItem parentItem, int style, int index) {
185
186 items = TableTree.EMPTY_ITEMS;
187 texts = TableTree.EMPTY_TEXTS;
188 images = TableTree.EMPTY_IMAGES;
189
190 super(parent, style);
191 this.parent = parent;
192 this.parentItem = parentItem;
193 if (parentItem is null) {
194
195 /* Root items are visible immediately */
196 int tableIndex = parent.addItem(this, index);
197 tableItem = new TableItem(parent.getTable(), style, tableIndex);
198 tableItem.setData(TableTree.ITEMID, this);
199 addCheck();
200 /*
201 * Feature in the Table. The table uses the first image that
202 * is inserted into the table to size the table rows. If the
203 * user is allowed to insert the first image, this will cause
204 * the +/- images to be scaled. The fix is to insert a dummy
205 * image to force the size.
206 */
207 if (parent.sizeImage is null) {
208 int itemHeight = parent.getItemHeight();
209 parent.sizeImage = new Image(parent.getDisplay(), itemHeight, itemHeight);
210 GC gc = new GC (parent.sizeImage);
211 gc.setBackground(parent.getBackground());
212 gc.fillRectangle(0, 0, itemHeight, itemHeight);
213 gc.dispose();
214 tableItem.setImage(0, parent.sizeImage);
215 }
216 } else {
217 parentItem.addItem(this, index);
218 }
219 }
220 void addCheck() {
221 Table table = parent.getTable();
222 if ((table.getStyle() & SWT.CHECK) is 0) return;
223 tableItem.setChecked(checked);
224 tableItem.setGrayed(grayed);
225 }
226 void addItem(TableTreeItem item, int index) {
227 if (item is null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
228 if (index < 0 || index > items.length) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
229
230 /* Now that item has a sub-node it must indicate that it can be expanded */
231 if (items.length is 0 && index is 0) {
232 if (tableItem !is null) {
233 Image image = expanded ? parent.getMinusImage() : parent.getPlusImage();
234 tableItem.setImage(0, image);
235 }
236 }
237
238 /* Put the item in the items list */
239 TableTreeItem[] newItems = new TableTreeItem[items.length + 1];
240 System.arraycopy(items, 0, newItems, 0, index);
241 newItems[index] = item;
242 System.arraycopy(items, index, newItems, index + 1, items.length - index);
243 items = newItems;
244 if (expanded) item.setVisible(true);
245 }
246
247 /**
248 * Returns the receiver's background color.
249 *
250 * @return the background color
251 *
252 * @exception SWTException <ul>
253 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
254 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
255 * </ul>
256 *
257 * @since 2.0
258 *
259 */
260 public Color getBackground () {
261 checkWidget ();
262 return (background is null) ? parent.getBackground() : background;
263 }
264
265 /**
266 * Returns a rectangle describing the receiver's size and location
267 * relative to its parent.
268 *
269 * @return the receiver's bounding rectangle
270 *
271 * @exception SWTException <ul>
272 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
273 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
274 * </ul>
275 */
276 public Rectangle getBounds (int index) {
277 checkWidget();
278 if (tableItem !is null) {
279 return tableItem.getBounds(index);
280 } else {
281 return new Rectangle(0, 0, 0, 0);
282 }
283 }
284 /**
285 * Returns <code>true</code> if the receiver is checked,
286 * and false otherwise. When the parent does not have
287 * the <code>CHECK style, return false.
288 *
289 * @return the checked state of the checkbox
290 *
291 * @exception SWTException <ul>
292 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
293 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
294 * </ul>
295 */
296 public bool getChecked () {
297 checkWidget();
298 if (tableItem is null) return checked;
299 return tableItem.getChecked();
300 }
301
302 /**
303 * Returns <code>true</code> if the receiver is grayed,
304 * and false otherwise. When the parent does not have
305 * the <code>CHECK</code> style, return false.
306 *
307 * @return the grayed state of the checkbox
308 *
309 * @exception SWTException <ul>
310 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
311 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
312 * </ul>
313 *
314 * @since 2.1
315 */
316 public bool getGrayed () {
317 checkWidget();
318 if (tableItem is null) return grayed;
319 return tableItem.getGrayed();
320 }
321
322 /**
323 * Returns <code>true</code> if the receiver is expanded,
324 * and false otherwise.
325 * <p>
326 *
327 * @return the expanded state
328 */
329 public bool getExpanded () {
330 //checkWidget();
331 return expanded;
332 }
333
334 /**
335 * Returns the font that the receiver will use to paint textual information for this item.
336 *
337 * @return the receiver's font
338 *
339 * @exception SWTException <ul>
340 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
341 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
342 * </ul>
343 *
344 * @since 3.0
345 */
346 public Font getFont () {
347 checkWidget ();
348 return (font is null) ? parent.getFont() : font;
349 }
350 /**
351 * Returns the foreground color that the receiver will use to draw.
352 *
353 * @return the receiver's foreground color
354 *
355 * @exception SWTException <ul>
356 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
357 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
358 * </ul>
359 *
360 * @since 2.0
361 *
362 */
363 public Color getForeground () {
364 checkWidget ();
365 return (foreground is null) ? parent.getForeground() : foreground;
366 }
367 /**
368 * Gets the first image.
369 * <p>
370 * The image in column 0 is reserved for the [+] and [-]
371 * images of the tree, therefore getImage(0) will return null.
372 *
373 * @return the image at index 0
374 *
375 * @exception SWTException <ul>
376 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
377 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
378 * </ul>
379 */
380 public override Image getImage () {
381 checkWidget();
382 return getImage(0);
383 }
384
385 /**
386 * Gets the image at the specified index.
387 * <p>
388 * Indexing is zero based. The image can be null.
389 * The image in column 0 is reserved for the [+] and [-]
390 * images of the tree, therefore getImage(0) will return null.
391 * Return null if the index is out of range.
392 *
393 * @param index the index of the image
394 * @return the image at the specified index or null
395 */
396 public Image getImage (int index) {
397 //checkWidget();
398 if (0 < index && index < images.length) return images[index];
399 return null;
400 }
401
402 int getIndent() {
403 if (parentItem is null) return 0;
404 return parentItem.getIndent() + 1;
405 }
406
407 /**
408 * Returns the item at the given, zero-relative index in the
409 * receiver. Throws an exception if the index is out of range.
410 *
411 * @param index the index of the item to return
412 * @return the item at the given index
413 *
414 * @exception IllegalArgumentException <ul>
415 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
416 * </ul>
417 * @exception SWTException <ul>
418 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
419 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
420 * </ul>
421 *
422 * @since 3.1
423 */
424 public TableTreeItem getItem (int index) {
425 checkWidget();
426 int count = items.length;
427 if (!(0 <= index && index < count)) SWT.error (SWT.ERROR_INVALID_RANGE);
428 return items [index];
429 }
430
431 /**
432 * Returns the number of items contained in the receiver
433 * that are direct item children of the receiver.
434 *
435 * @return the number of items
436 */
437 public int getItemCount () {
438 //checkWidget();
439 return items.length;
440 }
441
442 /**
443 * Returns an array of <code>TableTreeItem</code>s which are the
444 * direct item children of the receiver.
445 * <p>
446 * Note: This is not the actual structure used by the receiver
447 * to maintain its list of items, so modifying the array will
448 * not affect the receiver.
449 * </p>
450 *
451 * @return the receiver's items
452 */
453 public TableTreeItem[] getItems () {
454 //checkWidget();
455 TableTreeItem[] newItems = new TableTreeItem[items.length];
456 System.arraycopy(items, 0, newItems, 0, items.length);
457 return newItems;
458 }
459
460 TableTreeItem getItem(TableItem tableItem) {
461 if (tableItem is null) return null;
462 if (this.tableItem is tableItem) return this;
463 for (int i = 0; i < items.length; i++) {
464 TableTreeItem item = items[i].getItem(tableItem);
465 if (item !is null) return item;
466 }
467 return null;
468 }
469
470 /**
471 * Returns the receiver's parent, which must be a <code>TableTree</code>.
472 *
473 * @return the receiver's parent
474 */
475 public TableTree getParent () {
476 //checkWidget();
477 return parent;
478 }
479
480 /**
481 * Returns the receiver's parent item, which must be a
482 * <code>TableTreeItem</code> or null when the receiver is a
483 * root.
484 *
485 * @return the receiver's parent item
486 */
487 public TableTreeItem getParentItem () {
488 //checkWidget();
489 return parentItem;
490 }
491 public override String getText () {
492 checkWidget();
493 return getText(0);
494 }
495
496 /**
497 * Gets the item text at the specified index.
498 * <p>
499 * Indexing is zero based.
500 *
501 * This operation will fail when the index is out
502 * of range or an item could not be queried from
503 * the OS.
504 *
505 * @param index the index of the item
506 * @return the item text at the specified index, which can be null
507 */
508 public String getText(int index) {
509 //checkWidget();
510 if (0 <= index && index < texts.length) return texts[index];
511 return null;
512 }
513
514 bool getVisible () {
515 return tableItem !is null;
516 }
517
518 /**
519 * Gets the index of the specified item.
520 *
521 * <p>The widget is searched starting at 0 until an
522 * item is found that is equal to the search item.
523 * If no item is found, -1 is returned. Indexing
524 * is zero based. This index is relative to the parent only.
525 *
526 * @param item the search item
527 * @return the index of the item or -1 if the item is not found
528 *
529 */
530 public int indexOf (TableTreeItem item) {
531 //checkWidget();
532 for (int i = 0; i < items.length; i++) {
533 if (items[i] is item) return i;
534 }
535 return -1;
536 }
537
538 void expandAll(bool notify) {
539 if (items.length is 0) return;
540 if (!expanded) {
541 setExpanded(true);
542 if (notify) {
543 Event event = new Event();
544 event.item = this;
545 parent.notifyListeners(SWT.Expand, event);
546 }
547 }
548 for (int i = 0; i < items.length; i++) {
549 items[i].expandAll(notify);
550 }
551 }
552 int expandedIndexOf (TableTreeItem item) {
553 int index = 0;
554 for (int i = 0; i < items.length; i++) {
555 if (items[i] is item) return index;
556 if (items[i].expanded) index += items[i].visibleChildrenCount ();
557 index++;
558 }
559 return -1;
560 }
561
562 int visibleChildrenCount () {
563 int count = 0;
564 for (int i = 0; i < items.length; i++) {
565 if (items[i].getVisible ()) {
566 count += 1 + items[i].visibleChildrenCount ();
567 }
568 }
569 return count;
570 }
571
572 public override void dispose () {
573 if (isDisposed()) return;
574 for (int i = items.length - 1; i >= 0; i--) {
575 items[i].dispose();
576 }
577 super.dispose();
578 if (!parent.inDispose) {
579 if (parentItem !is null) {
580 parentItem.removeItem(this);
581 } else {
582 parent.removeItem(this);
583 }
584 if (tableItem !is null) tableItem.dispose();
585 }
586 items = null;
587 parentItem = null;
588 parent = null;
589 images = null;
590 texts = null;
591 tableItem = null;
592 foreground = null;
593 background = null;
594 font = null;
595 }
596
597 void removeItem(TableTreeItem item) {
598 int index = 0;
599 while (index < items.length && items[index] !is item) index++;
600 if (index is items.length) return;
601 TableTreeItem[] newItems = new TableTreeItem[items.length - 1];
602 System.arraycopy(items, 0, newItems, 0, index);
603 System.arraycopy(items, index + 1, newItems, index, items.length - index - 1);
604 items = newItems;
605 if (items.length is 0) {
606 if (tableItem !is null) tableItem.setImage(0, null);
607 }
608 }
609
610 /**
611 * Sets the receiver's background color to the color specified
612 * by the argument, or to the default system color for the item
613 * if the argument is null.
614 *
615 * @param color the new color (or null)
616 *
617 * @exception IllegalArgumentException <ul>
618 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
619 * </ul>
620 * @exception SWTException <ul>
621 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
622 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
623 * </ul>
624 *
625 * @since 2.0
626 *
627 */
628 public void setBackground (Color color) {
629 checkWidget ();
630 if (color !is null && color.isDisposed ()) {
631 SWT.error (SWT.ERROR_INVALID_ARGUMENT);
632 }
633 if (tableItem !is null) {
634 tableItem.setBackground(color);
635 }
636 background = color;
637 }
638
639 /**
640 * Sets the checked state of the checkbox for this item. This state change
641 * only applies if the Table was created with the SWT.CHECK style.
642 *
643 * @param checked the new checked state of the checkbox
644 *
645 * @exception SWTException <ul>
646 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
647 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
648 * </ul>
649 */
650 public void setChecked (bool checked) {
651 checkWidget();
652 Table table = parent.getTable();
653 if ((table.getStyle() & SWT.CHECK) is 0) return;
654 if (tableItem !is null) {
655 tableItem.setChecked(checked);
656 }
657 this.checked = checked;
658 }
659
660 /**
661 * Sets the grayed state of the checkbox for this item. This state change
662 * only applies if the Table was created with the SWT.CHECK style.
663 *
664 * @param grayed the new grayed state of the checkbox;
665 *
666 * @exception SWTException <ul>
667 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
668 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
669 * </ul>
670 *
671 * @since 2.1
672 */
673 public void setGrayed (bool grayed) {
674 checkWidget();
675 Table table = parent.getTable();
676 if ((table.getStyle() & SWT.CHECK) is 0) return;
677 if (tableItem !is null) {
678 tableItem.setGrayed(grayed);
679 }
680 this.grayed = grayed;
681 }
682
683 /**
684 * Sets the expanded state.
685 * <p>
686 * @param expanded the new expanded state.
687 *
688 * @exception SWTException <ul>
689 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
690 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
691 * </ul>
692 */
693 public void setExpanded (bool expanded) {
694 checkWidget();
695 if (items.length is 0) return;
696 if (this.expanded is expanded) return;
697 this.expanded = expanded;
698 if (tableItem is null) return;
699 parent.setRedraw(false);
700 for (int i = 0; i < items.length; i++) {
701 items[i].setVisible(expanded);
702 }
703 Image image = expanded ? parent.getMinusImage() : parent.getPlusImage();
704 tableItem.setImage(0, image);
705 parent.setRedraw(true);
706 }
707
708 /**
709 * Sets the font that the receiver will use to paint textual information
710 * for this item to the font specified by the argument, or to the default font
711 * for that kind of control if the argument is null.
712 *
713 * @param font the new font (or null)
714 *
715 * @exception IllegalArgumentException <ul>
716 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
717 * </ul>
718 * @exception SWTException <ul>
719 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
720 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
721 * </ul>
722 *
723 * @since 3.0
724 */
725 public void setFont (Font font){
726 checkWidget ();
727 if (font !is null && font.isDisposed ()) {
728 SWT.error (SWT.ERROR_INVALID_ARGUMENT);
729 }
730 if (tableItem !is null) {
731 tableItem.setFont(font);
732 }
733 this.font = font;
734 }
735 /**
736 * Sets the receiver's foreground color to the color specified
737 * by the argument, or to the default system color for the item
738 * if the argument is null.
739 *
740 * @param color the new color (or null)
741 *
742 * @since 2.0
743 *
744 * @exception IllegalArgumentException <ul>
745 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
746 * </ul>
747 * @exception SWTException <ul>
748 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
749 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
750 * </ul>
751 *
752 * @since 2.0
753 *
754 */
755 public void setForeground (Color color) {
756 checkWidget ();
757 if (color !is null && color.isDisposed ()) {
758 SWT.error (SWT.ERROR_INVALID_ARGUMENT);
759 }
760 if (tableItem !is null) {
761 tableItem.setForeground(color);
762 }
763 foreground = color;
764 }
765
766 /**
767 * Sets the image at an index.
768 * <p>
769 * The image can be null.
770 * The image in column 0 is reserved for the [+] and [-]
771 * images of the tree, therefore do nothing if index is 0.
772 *
773 * @param image the new image or null
774 *
775 * @exception SWTException <ul>
776 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
777 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
778 * </ul>
779 */
780 public void setImage (int index, Image image) {
781 checkWidget();
782 int columnCount = Math.max(parent.getTable().getColumnCount(), 1);
783 if (index <= 0 || index >= columnCount) return;
784 if (images.length < columnCount) {
785 Image[] newImages = new Image[columnCount];
786 System.arraycopy(images, 0, newImages, 0, images.length);
787 images = newImages;
788 }
789 images[index] = image;
790 if (tableItem !is null) tableItem.setImage(index, image);
791 }
792
793 /**
794 * Sets the first image.
795 * <p>
796 * The image can be null.
797 * The image in column 0 is reserved for the [+] and [-]
798 * images of the tree, therefore do nothing.
799 *
800 * @param image the new image or null
801 *
802 * @exception SWTException <ul>
803 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
804 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
805 * </ul>
806 */
807 public override void setImage (Image image) {
808 setImage(0, image);
809 }
810
811 /**
812 * Sets the widget text.
813 * <p>
814 *
815 * The widget text for an item is the label of the
816 * item or the label of the text specified by a column
817 * number.
818 *
819 * @param index the column number
820 * @param text the new text
821 *
822 * @exception SWTException <ul>
823 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
824 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
825 * </ul>
826 */
827 public void setText(int index, String text) {
828 checkWidget();
829 // SWT extension: allow null for zero length string
830 //if (text is null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
831 int columnCount = Math.max(parent.getTable().getColumnCount(), 1);
832 if (index < 0 || index >= columnCount) return;
833 if (texts.length < columnCount) {
834 String[] newTexts = new String[columnCount];
835 System.arraycopy(texts, 0, newTexts, 0, texts.length);
836 texts = newTexts;
837 }
838 texts[index] = text;
839 if (tableItem !is null) tableItem.setText(index, text);
840 }
841 public override void setText (String string) {
842 setText(0, string);
843 }
844
845 void setVisible (bool show) {
846 if (parentItem is null) return; // this is a root and can not be toggled between visible and hidden
847 if (getVisible() is show) return;
848
849 if (show) {
850 if (!parentItem.getVisible()) return; // parentItem must already be visible
851 // create underlying table item and set data in table item to stored data
852 Table table = parent.getTable();
853 int parentIndex = table.indexOf(parentItem.tableItem);
854 int index = parentItem.expandedIndexOf(this) + parentIndex + 1;
855 if (index < 0) return;
856 tableItem = new TableItem(table, getStyle(), index);
857 tableItem.setData(TableTree.ITEMID, this);
858 tableItem.setImageIndent(getIndent());
859 if (background !is null) tableItem.setBackground(background);
860 if (foreground !is null) tableItem.setForeground(foreground);
861 if (font !is null) tableItem.setFont(font);
862 addCheck();
863
864 // restore fields to item
865 // ignore any images in the first column
866 int columnCount = Math.max(table.getColumnCount(), 1);
867 for (int i = 0; i < columnCount; i++) {
868 if (i < texts.length && texts[i] !is null) setText(i, texts[i]);
869 if (i < images.length && images[i] !is null) setImage(i, images[i]);
870 }
871
872 // display the children and the appropriate [+]/[-] symbol as required
873 if (items.length !is 0) {
874 if (expanded) {
875 tableItem.setImage(0, parent.getMinusImage());
876 for (int i = 0, length = items.length; i < length; i++) {
877 items[i].setVisible(true);
878 }
879 } else {
880 tableItem.setImage(0, parent.getPlusImage());
881 }
882 }
883
884 } else {
885
886 for (int i = 0, length = items.length; i < length; i++) {
887 items[i].setVisible(false);
888 }
889 // remove row from table
890 tableItem.dispose();
891 tableItem = null;
892 }
893 }
894 }