Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 84766 Details for
Bug 212071
GalleryTreeViewer
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Updated patch with item rendering and insertion support
GalleryTreeViewer.patch (text/plain), 61.48 KB, created by
Peter Centgraf
on 2007-12-07 13:56:20 EST
(
hide
)
Description:
Updated patch with item rendering and insertion support
Filename:
MIME Type:
Creator:
Peter Centgraf
Created:
2007-12-07 13:56:20 EST
Size:
61.48 KB
patch
obsolete
>Index: src/org/eclipse/nebula/widgets/gallery/GalleryItem.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.gallery/src/org/eclipse/nebula/widgets/gallery/GalleryItem.java,v >retrieving revision 1.9 >diff -u -r1.9 GalleryItem.java >--- src/org/eclipse/nebula/widgets/gallery/GalleryItem.java 7 Dec 2007 09:24:47 -0000 1.9 >+++ src/org/eclipse/nebula/widgets/gallery/GalleryItem.java 7 Dec 2007 18:51:45 -0000 >@@ -1,440 +1,458 @@ >-/******************************************************************************* >- * Copyright (c) 2006-2007 Nicolas Richeton. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors : >- * Nicolas Richeton (nicolas.richeton@gmail.com) - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.nebula.widgets.gallery; >- >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.graphics.Color; >-import org.eclipse.swt.graphics.Font; >-import org.eclipse.swt.graphics.Rectangle; >-import org.eclipse.swt.widgets.Item; >- >-/** >- * Gallery Item<br/> >- * >- * <p> >- * NOTE: THIS WIDGET AND ITS API ARE STILL UNDER DEVELOPMENT. THIS IS A >- * PRE-RELEASE ALPHA VERSION. USERS SHOULD EXPECT API CHANGES IN FUTURE >- * VERSIONS. >- * </p> >- * >- * @author Nicolas Richeton (nicolas.richeton@gmail.com) >- * >- */ >- >-public class GalleryItem extends Item { >- >- private String description = null; >- >- // This is managed by the Gallery >- /** >- * Children of this item. Only used when groups are enabled. >- */ >- protected GalleryItem[] items = null; >- >- /** >- * Bounds of this items in the current Gallery. >- * >- * X and Y values are used for vertical or horizontal offset depending on >- * the Gallery settings. Only used when groups are enabled. >- * >- * Width and hei >- */ >- // protected Rectangle bounds = new Rectangle(0, 0, 0, 0); >- protected int x = 0; >- >- protected int y = 0; >- >- /** >- * Size of the group, including its title. >- */ >- protected int width = 0; >- >- protected int height = 0; >- >- protected int marginBottom = 0; >- >- protected int hCount = 0; >- >- protected int vCount = 0; >- >- /** >- * Last result of indexOf( GalleryItem). Used for optimisation. >- */ >- protected int lastIndexOf = 0; >- >- /** >- * itemCount stores the number of children of this group. It is used when >- * the Gallery was created with SWT.VIRTUAL >- */ >- private int itemCount = 0; >- >- /** >- * True if the Gallery was created wih SWT.VIRTUAL >- */ >- private boolean virtualGallery; >- >- private Gallery parent; >- >- private GalleryItem parentItem; >- >- protected int[] selectionIndices = null; >- >- protected Font font; >- >- protected Color foreground; >- >- protected Color background; >- >- /** >- * >- */ >- private boolean expanded; >- >- public Gallery getParent() { >- return parent; >- } >- >- protected void setParent(Gallery parent) { >- this.parent = parent; >- } >- >- public GalleryItem getParentItem() { >- return parentItem; >- } >- >- protected void setParentItem(GalleryItem parentItem) { >- this.parentItem = parentItem; >- } >- >- public GalleryItem(Gallery parent, int style) { >- super(parent, style); >- this.parent = parent; >- >- if ((parent.getStyle() & SWT.VIRTUAL) > 0) { >- virtualGallery = true; >- } else { >- parent.addItem(this); >- } >- >- } >- >- public GalleryItem(Gallery parent, int style, int index) { >- super(parent, style); >- this.parent = parent; >- >- if ((parent.getStyle() & SWT.VIRTUAL) > 0) { >- virtualGallery = true; >- } else { >- parent.addItem(this, index); >- } >- >- } >- >- public GalleryItem(GalleryItem parent, int style) { >- super(parent, style); >- this.parent = parent.parent; >- this.parentItem = parent; >- if ((parent.getStyle() & SWT.VIRTUAL) > 0) { >- virtualGallery = true; >- } else { >- parent.addItem(this); >- } >- } >- >- public GalleryItem(GalleryItem parent, int style, int index) { >- super(parent, style); >- this.parent = parent.parent; >- this.parentItem = parent; >- if ((parent.getStyle() & SWT.VIRTUAL) > 0) { >- virtualGallery = true; >- } else { >- parent.addItem(this, index); >- } >- } >- >- /** >- * Only work when the table was not created with SWT.VIRTUAL >- * >- * @param item >- */ >- protected void addItem(GalleryItem item) { >- _addItem(item, -1); >- } >- >- protected void addItem(GalleryItem item, int position) { >- if (position < 0 || position > getItemCount()) { >- throw new IllegalArgumentException("ERROR_INVALID_RANGE "); >- } >- _addItem(item, position); >- } >- >- private void _addItem(GalleryItem item, int position) { >- // Items can only be added in a standard gallery (not using SWT.VIRTUAL) >- if (!virtualGallery) { >- >- // Insert item >- items = (GalleryItem[]) parent._arrayAddItem(items, item, position); >- >- // Update Gallery >- parent.updateStructuralValues(false); >- parent.updateScrollBarsProperties(); >- >- } >- } >- >- /** >- * Returns the number of items contained in the receiver that are direct >- * item children of the receiver. >- * >- * @return >- */ >- public int getItemCount() { >- if (virtualGallery) >- return itemCount; >- >- if (items == null) >- return 0; >- >- return items.length; >- } >- >- /** >- * Only work when the table was created with SWT.VIRTUAL >- * >- * @param itemCount >- */ >- public void setItemCount(int count) { >- if (virtualGallery) { >- if (count == 0) { >- // No items >- items = null; >- } else { >- // At least one item, create a new array and copy data from the >- // old one. >- GalleryItem[] newItems = new GalleryItem[count]; >- if (items != null) { >- System.arraycopy(items, 0, newItems, 0, Math.min(count, items.length)); >- } >- items = newItems; >- } >- this.itemCount = count; >- >- } >- >- } >- >- /** >- * Searches the receiver's list starting at the first item (index 0) until >- * an item is found that is equal to the argument, and returns the index of >- * that item. <br/> If SWT.VIRTUAL is used and the item has not been used >- * yet, the item is created and a SWT.SetData event is fired. >- * >- * @param index : >- * index of the item. >- * @return : the GalleryItem or null if index is out of bounds >- */ >- public GalleryItem getItem(int index) { >- checkWidget(); >- return parent._getItem(this, index); >- } >- >- public GalleryItem[] getItems() { >- checkWidget(); >- if( items == null ) >- return new GalleryItem[0]; >- >- GalleryItem[] itemsLocal = new GalleryItem[this.items.length]; >- System.arraycopy(items, 0, itemsLocal, 0, this.items.length); >- >- return itemsLocal; >- } >- >- /** >- * Returns the index of childItem within this item or -1 if childItem is not >- * found. The search is only one level deep. >- * >- * @param childItem >- * @return >- */ >- public int indexOf(GalleryItem childItem) { >- checkWidget(); >- >- return parent._indexOf(this, childItem); >- } >- >- /** >- * Returns true if the receiver is expanded, and false otherwise. >- * >- * @return >- */ >- public boolean isExpanded() { >- return expanded; >- } >- >- /** >- * Sets the expanded state of the receiver. >- * >- * @param expanded >- */ >- public void setExpanded(boolean expanded) { >- this.expanded = expanded; >- } >- >- public String getDescription() { >- return description; >- } >- >- public void setDescription(String description) { >- this.description = description; >- } >- >- /** >- * Deselect all children of this item >- */ >- protected void deselectAll() { >- checkWidget(); >- _deselectAll(); >- parent.redraw(); >- } >- >- protected void _deselectAll() { >- this.selectionIndices = null; >- if (items == null) >- return; >- for (int i = 0; i < items.length; i++) { >- if (items[i] != null) >- items[i]._deselectAll(); >- } >- } >- >- protected void _addSelection(GalleryItem item) { >- // Deselect all items is multi selection is disabled >- if (!parent.multi) { >- _deselectAll(); >- } >- >- if (item.getParentItem() == this) { >- if (selectionIndices == null) { >- selectionIndices = new int[1]; >- } else { >- int[] oldSelection = selectionIndices; >- selectionIndices = new int[oldSelection.length + 1]; >- System.arraycopy(oldSelection, 0, selectionIndices, 0, oldSelection.length); >- } >- selectionIndices[selectionIndices.length - 1] = indexOf(item); >- >- } >- } >- >- protected boolean isSelected(GalleryItem item) { >- if (item == null) >- return false; >- >- if (item.getParentItem() == this) { >- if (selectionIndices == null) >- return false; >- >- int index = indexOf(item); >- for (int i = 0; i < selectionIndices.length; i++) { >- if (selectionIndices[i] == index) >- return true; >- } >- } >- return false; >- } >- >- protected void select(int from, int to) { >- if (Gallery.DEBUG) >- System.out.println("GalleryItem.select( " + from + "," + to + ")"); >- >- for (int i = from; i <= to; i++) { >- GalleryItem item = getItem(i); >- parent._addSelection(item); >- item._selectAll(); >- } >- } >- >- /** >- * Return the current bounds of the item. This method may return negative >- * values if it is not visible. >- * >- * @return >- */ >- public Rectangle getBounds() { >- // The y coords is relative to the client area because it may return >- // wrong values >- // on win32 when using the scroll bars. Instead, I use the absolute >- // position and make is relative using the current translation. >- >- if (parent.isVertical()) { >- return new Rectangle(x, y - parent.translate, width, height); >- } else { >- return new Rectangle(x - parent.translate, y, width, height); >- } >- } >- >- public Font getFont() { >- return font; >- } >- >- public void setFont(Font font) { >- this.font = font; >- } >- >- public Color getForeground() { >- return foreground; >- } >- >- public void setForeground(Color foreground) { >- this.foreground = foreground; >- } >- >- public Color getBackground() { >- return background; >- } >- >- public void setBackground(Color background) { >- this.background = background; >- } >- >- /** >- * Selects all of the items in the receiver. >- */ >- public void selectAll() { >- checkWidget(); >- _selectAll(); >- parent.redraw(); >- } >- >- protected void _selectAll() { >- select(0, this.getItemCount() - 1); >- } >- >- public void remove(int index) { >- checkWidget(); >- parent._remove(this, index); >- } >- >- public void remove(GalleryItem item) { >- checkWidget(); >- int index = parent._indexOf(this, item); >- parent._remove(this, index); >- } >- >- public void dispose() { >- super.dispose(); >- if (parentItem != null) { >- parentItem.remove(this); >- } else { >- parent.remove(this); >- } >- } >-} >+/******************************************************************************* >+ * Copyright (c) 2006-2007 Nicolas Richeton. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors : >+ * Nicolas Richeton (nicolas.richeton@gmail.com) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.nebula.widgets.gallery; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Item; >+ >+/** >+ * Gallery Item<br/> >+ * >+ * <p> >+ * NOTE: THIS WIDGET AND ITS API ARE STILL UNDER DEVELOPMENT. THIS IS A >+ * PRE-RELEASE ALPHA VERSION. USERS SHOULD EXPECT API CHANGES IN FUTURE >+ * VERSIONS. >+ * </p> >+ * >+ * @author Nicolas Richeton (nicolas.richeton@gmail.com) >+ * >+ */ >+ >+public class GalleryItem extends Item { >+ >+ private String description = null; >+ >+ // This is managed by the Gallery >+ /** >+ * Children of this item. Only used when groups are enabled. >+ */ >+ protected GalleryItem[] items = null; >+ >+ /** >+ * Bounds of this items in the current Gallery. >+ * >+ * X and Y values are used for vertical or horizontal offset depending on >+ * the Gallery settings. Only used when groups are enabled. >+ * >+ * Width and hei >+ */ >+ // protected Rectangle bounds = new Rectangle(0, 0, 0, 0); >+ protected int x = 0; >+ >+ protected int y = 0; >+ >+ /** >+ * Size of the group, including its title. >+ */ >+ protected int width = 0; >+ >+ protected int height = 0; >+ >+ protected int marginBottom = 0; >+ >+ protected int hCount = 0; >+ >+ protected int vCount = 0; >+ >+ /** >+ * Last result of indexOf( GalleryItem). Used for optimisation. >+ */ >+ protected int lastIndexOf = 0; >+ >+ /** >+ * itemCount stores the number of children of this group. It is used when >+ * the Gallery was created with SWT.VIRTUAL >+ */ >+ private int itemCount = 0; >+ >+ /** >+ * True if the Gallery was created wih SWT.VIRTUAL >+ */ >+ private boolean virtualGallery; >+ >+ private Gallery parent; >+ >+ private GalleryItem parentItem; >+ >+ protected int[] selectionIndices = null; >+ >+ protected Font font; >+ >+ protected Color foreground; >+ >+ protected Color background; >+ >+ /** >+ * >+ */ >+ private boolean expanded; >+ >+ public Gallery getParent() { >+ return parent; >+ } >+ >+ protected void setParent(Gallery parent) { >+ this.parent = parent; >+ } >+ >+ public GalleryItem getParentItem() { >+ return parentItem; >+ } >+ >+ protected void setParentItem(GalleryItem parentItem) { >+ this.parentItem = parentItem; >+ } >+ >+ public GalleryItem(Gallery parent, int style) { >+ super(parent, style); >+ this.parent = parent; >+ >+ if ((parent.getStyle() & SWT.VIRTUAL) > 0) { >+ virtualGallery = true; >+ } else { >+ parent.addItem(this); >+ } >+ >+ } >+ >+ public GalleryItem(Gallery parent, int style, int index) { >+ super(parent, style); >+ this.parent = parent; >+ >+ if ((parent.getStyle() & SWT.VIRTUAL) > 0) { >+ virtualGallery = true; >+ } else { >+ parent.addItem(this, index); >+ } >+ >+ } >+ >+ public GalleryItem(GalleryItem parent, int style) { >+ super(parent, style); >+ this.parent = parent.parent; >+ this.parentItem = parent; >+ if ((parent.getStyle() & SWT.VIRTUAL) > 0) { >+ virtualGallery = true; >+ } else { >+ parent.addItem(this); >+ } >+ } >+ >+ public GalleryItem(GalleryItem parent, int style, int index) { >+ super(parent, style); >+ this.parent = parent.parent; >+ this.parentItem = parent; >+ if ((parent.getStyle() & SWT.VIRTUAL) > 0) { >+ virtualGallery = true; >+ } else { >+ parent.addItem(this, index); >+ } >+ } >+ >+ /** >+ * Only work when the table was not created with SWT.VIRTUAL >+ * >+ * @param item >+ */ >+ protected void addItem(GalleryItem item) { >+ _addItem(item, -1); >+ } >+ >+ protected void addItem(GalleryItem item, int position) { >+ if (position < 0 || position > getItemCount()) { >+ throw new IllegalArgumentException("ERROR_INVALID_RANGE "); >+ } >+ _addItem(item, position); >+ } >+ >+ private void _addItem(GalleryItem item, int position) { >+ // Items can only be added in a standard gallery (not using SWT.VIRTUAL) >+ if (!virtualGallery) { >+ >+ // Insert item >+ items = (GalleryItem[]) parent._arrayAddItem(items, item, position); >+ >+ // Update Gallery >+ parent.updateStructuralValues(false); >+ parent.updateScrollBarsProperties(); >+ >+ } >+ } >+ >+ /** >+ * Returns the number of items contained in the receiver that are direct >+ * item children of the receiver. >+ * >+ * @return >+ */ >+ public int getItemCount() { >+ if (virtualGallery) >+ return itemCount; >+ >+ if (items == null) >+ return 0; >+ >+ return items.length; >+ } >+ >+ /** >+ * Only work when the table was created with SWT.VIRTUAL >+ * >+ * @param itemCount >+ */ >+ public void setItemCount(int count) { >+ if (virtualGallery) { >+ if (count == 0) { >+ // No items >+ items = null; >+ } else { >+ // At least one item, create a new array and copy data from the >+ // old one. >+ GalleryItem[] newItems = new GalleryItem[count]; >+ if (items != null) { >+ System.arraycopy(items, 0, newItems, 0, Math.min(count, items.length)); >+ } >+ items = newItems; >+ } >+ this.itemCount = count; >+ >+ } >+ >+ } >+ >+ /** >+ * Searches the receiver's list starting at the first item (index 0) until >+ * an item is found that is equal to the argument, and returns the index of >+ * that item. <br/> If SWT.VIRTUAL is used and the item has not been used >+ * yet, the item is created and a SWT.SetData event is fired. >+ * >+ * @param index : >+ * index of the item. >+ * @return : the GalleryItem or null if index is out of bounds >+ */ >+ public GalleryItem getItem(int index) { >+ checkWidget(); >+ return parent._getItem(this, index); >+ } >+ >+ public GalleryItem[] getItems() { >+ checkWidget(); >+ if( items == null ) >+ return new GalleryItem[0]; >+ >+ GalleryItem[] itemsLocal = new GalleryItem[this.items.length]; >+ System.arraycopy(items, 0, itemsLocal, 0, this.items.length); >+ >+ return itemsLocal; >+ } >+ >+ /** >+ * Returns the index of childItem within this item or -1 if childItem is not >+ * found. The search is only one level deep. >+ * >+ * @param childItem >+ * @return >+ */ >+ public int indexOf(GalleryItem childItem) { >+ checkWidget(); >+ >+ return parent._indexOf(this, childItem); >+ } >+ >+ /** >+ * Returns true if the receiver is expanded, and false otherwise. >+ * >+ * @return >+ */ >+ public boolean isExpanded() { >+ return expanded; >+ } >+ >+ /** >+ * Sets the expanded state of the receiver. >+ * >+ * @param expanded >+ */ >+ public void setExpanded(boolean expanded) { >+ this.expanded = expanded; >+ } >+ >+ public String getDescription() { >+ return description; >+ } >+ >+ public void setDescription(String description) { >+ this.description = description; >+ } >+ >+ /** >+ * Deselect all children of this item >+ */ >+ protected void deselectAll() { >+ checkWidget(); >+ _deselectAll(); >+ parent.redraw(); >+ } >+ >+ protected void _deselectAll() { >+ this.selectionIndices = null; >+ if (items == null) >+ return; >+ for (int i = 0; i < items.length; i++) { >+ if (items[i] != null) >+ items[i]._deselectAll(); >+ } >+ } >+ >+ protected void _addSelection(GalleryItem item) { >+ // Deselect all items is multi selection is disabled >+ if (!parent.multi) { >+ _deselectAll(); >+ } >+ >+ if (item.getParentItem() == this) { >+ if (selectionIndices == null) { >+ selectionIndices = new int[1]; >+ } else { >+ int[] oldSelection = selectionIndices; >+ selectionIndices = new int[oldSelection.length + 1]; >+ System.arraycopy(oldSelection, 0, selectionIndices, 0, oldSelection.length); >+ } >+ selectionIndices[selectionIndices.length - 1] = indexOf(item); >+ >+ } >+ } >+ >+ protected boolean isSelected(GalleryItem item) { >+ if (item == null) >+ return false; >+ >+ if (item.getParentItem() == this) { >+ if (selectionIndices == null) >+ return false; >+ >+ int index = indexOf(item); >+ for (int i = 0; i < selectionIndices.length; i++) { >+ if (selectionIndices[i] == index) >+ return true; >+ } >+ } >+ return false; >+ } >+ >+ protected void select(int from, int to) { >+ if (Gallery.DEBUG) >+ System.out.println("GalleryItem.select( " + from + "," + to + ")"); >+ >+ for (int i = from; i <= to; i++) { >+ GalleryItem item = getItem(i); >+ parent._addSelection(item); >+ item._selectAll(); >+ } >+ } >+ >+ /** >+ * Return the current bounds of the item. This method may return negative >+ * values if it is not visible. >+ * >+ * @return >+ */ >+ public Rectangle getBounds() { >+ // The y coords is relative to the client area because it may return >+ // wrong values >+ // on win32 when using the scroll bars. Instead, I use the absolute >+ // position and make is relative using the current translation. >+ >+ if (parent.isVertical()) { >+ return new Rectangle(x, y - parent.translate, width, height); >+ } else { >+ return new Rectangle(x - parent.translate, y, width, height); >+ } >+ } >+ >+ public Font getFont() { >+ checkWidget (); >+ return font; >+ } >+ >+ public void setFont(Font font) { >+ checkWidget (); >+ if (font != null && font.isDisposed ()) { >+ SWT.error (SWT.ERROR_INVALID_ARGUMENT); >+ } >+ this.font = font; >+ this.parent.redraw(this); >+ } >+ >+ public Color getForeground() { >+ checkWidget (); >+ return foreground; >+ } >+ >+ public void setForeground(Color foreground) { >+ checkWidget(); >+ if (foreground != null && foreground.isDisposed ()) { >+ SWT.error (SWT.ERROR_INVALID_ARGUMENT); >+ } >+ this.foreground = foreground; >+ this.parent.redraw(this); >+ } >+ >+ public Color getBackground() { >+ checkWidget (); >+ return background; >+ } >+ >+ public void setBackground(Color background) { >+ checkWidget(); >+ if (background != null && background.isDisposed ()) { >+ SWT.error (SWT.ERROR_INVALID_ARGUMENT); >+ } >+ this.background = background; >+ this.parent.redraw(this); >+ } >+ >+ /** >+ * Selects all of the items in the receiver. >+ */ >+ public void selectAll() { >+ checkWidget(); >+ _selectAll(); >+ parent.redraw(); >+ } >+ >+ protected void _selectAll() { >+ select(0, this.getItemCount() - 1); >+ } >+ >+ public void remove(int index) { >+ checkWidget(); >+ parent._remove(this, index); >+ } >+ >+ public void remove(GalleryItem item) { >+ checkWidget(); >+ int index = parent._indexOf(this, item); >+ parent._remove(this, index); >+ } >+ >+ public void dispose() { >+ super.dispose(); >+ if (parentItem != null) { >+ parentItem.remove(this); >+ } else { >+ parent.remove(this); >+ } >+ } >+} >Index: src/org/eclipse/nebula/widgets/gallery/Gallery.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.gallery/src/org/eclipse/nebula/widgets/gallery/Gallery.java,v >retrieving revision 1.24 >diff -u -r1.24 Gallery.java >--- src/org/eclipse/nebula/widgets/gallery/Gallery.java 7 Dec 2007 09:22:55 -0000 1.24 >+++ src/org/eclipse/nebula/widgets/gallery/Gallery.java 7 Dec 2007 18:51:45 -0000 >@@ -143,8 +143,6 @@ > > private GalleryItem lastSingleClick = null; > >- private Color backgroundColor; >- > /** > * Current translation. Can be used by renderer during paint. > */ >@@ -399,7 +397,7 @@ > virtual = (style & SWT.VIRTUAL) > 0; > vertical = (style & SWT.V_SCROLL) > 0; > multi = (style & SWT.MULTI) > 0; >- backgroundColor = getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); >+ setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); > > // Dispose renderers on dispose > this.addDisposeListener(new DisposeListener() { >@@ -925,9 +923,6 @@ > } > > Rectangle clipping = newGC.getClipping(); >- gc.setBackground(backgroundColor); >- drawBackground(newGC, clipping.x, clipping.y, clipping.width, clipping.height); >- > int[] indexes = getVisibleItems(clipping); > > if (indexes != null && indexes.length > 0) { >@@ -993,6 +988,10 @@ > > public void redraw(GalleryItem item) { > checkWidget(); >+ >+ // Redraw only the item's bounds >+ Rectangle bounds = item.getBounds(); >+ redraw(bounds.x, bounds.y, bounds.width, bounds.height, true); > } > > /** >@@ -1787,12 +1786,4 @@ > > return newArray; > } >- >- public Color getBackgroundColor() { >- return backgroundColor; >- } >- >- public void setBackgroundColor(Color backgroundColor) { >- this.backgroundColor = backgroundColor; >- } > } >Index: src/org/eclipse/nebula/widgets/gallery/DefaultGalleryItemRenderer.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.gallery/src/org/eclipse/nebula/widgets/gallery/DefaultGalleryItemRenderer.java,v >retrieving revision 1.10 >diff -u -r1.10 DefaultGalleryItemRenderer.java >--- src/org/eclipse/nebula/widgets/gallery/DefaultGalleryItemRenderer.java 4 Aug 2007 12:39:09 -0000 1.10 >+++ src/org/eclipse/nebula/widgets/gallery/DefaultGalleryItemRenderer.java 7 Dec 2007 18:51:45 -0000 >@@ -48,14 +48,8 @@ > > Color selectionBackgroundColor; > >- Color foregroundColor; >- >- Color backgroundColor; >- > boolean showLabels = true; > >- private Font font = null; >- > public boolean isShowLabels() { > return showLabels; > } >@@ -66,8 +60,6 @@ > > public DefaultGalleryItemRenderer() { > // Set defaults >- foregroundColor = Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND); >- backgroundColor = Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND); > selectionForegroundColor = Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT); > selectionBackgroundColor = Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION); > >@@ -76,8 +68,14 @@ > } > > public void draw(GC gc, GalleryItem item, int index, int x, int y, int width, int height) { >+ Color backgroundColor = getBackground(item); >+ Color foregroundColor = getForeground(item); >+ // Set up the GC >+ gc.setForeground(foregroundColor); >+ gc.setBackground(backgroundColor); >+ gc.setFont(getFont(item)); >+ > Image itemImage = item.getImage(); >- gc.setFont(font); > > int useableHeight = height; > int fontHeight = 0; >@@ -118,11 +116,12 @@ > if (selected) { > gc.setBackground(selectionBackgroundColor); > gc.setForeground(selectionBackgroundColor); >- gc.fillRoundRectangle(x, y, width, useableHeight, 15, 15); >- >- if (item.getText() != null && showLabels) { >- gc.fillRoundRectangle(x, y + height - fontHeight, width, fontHeight, 15, 15); >- } >+ } >+ >+ // Even if the widget is not selected, redraw the background >+ gc.fillRoundRectangle(x, y, width, useableHeight, 15, 15); >+ if (item.getText() != null && showLabels) { >+ gc.fillRoundRectangle(x, y + height - fontHeight, width, fontHeight, 15, 15); > } > > // Draw image >@@ -134,9 +133,8 @@ > > // Draw label > if (item.getText() != null && showLabels) { >- // Set up the GC >- gc.setBackground(this.backgroundColor); >- gc.setForeground(selected ? this.selectionForegroundColor : this.foregroundColor); >+ gc.setBackground(backgroundColor); >+ gc.setForeground(selected ? this.selectionForegroundColor : foregroundColor); > gc.setBackground(selected ? selectionBackgroundColor : this.selectionBackgroundColor); > > // Create label >@@ -151,6 +149,52 @@ > } > } > >+ /** >+ * @param item >+ * @return the background Color to use for this item >+ */ >+ protected Color getBackground(GalleryItem item) { >+ Color backgroundColor = item.getBackground(); >+ if (backgroundColor == null) { >+ backgroundColor = item.getParent().getBackground(); >+ } >+ if (backgroundColor == null) { >+ backgroundColor = item.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); >+ } >+ return backgroundColor; >+ } >+ >+ >+ /** >+ * @param item >+ * @return the foreground Color to use for this item >+ */ >+ protected Color getForeground(GalleryItem item) { >+ Color foregroundColor = item.getForeground(); >+ if (foregroundColor == null) { >+ foregroundColor = item.getParent().getForeground(); >+ } >+ if (foregroundColor == null) { >+ foregroundColor = item.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND); >+ } >+ return foregroundColor; >+ } >+ >+ /** >+ * @param item >+ * @return the Font to use for this item >+ */ >+ protected Font getFont(GalleryItem item) { >+ Font font = item.getFont(); >+ if (font == null) { >+ font = item.getParent().getFont(); >+ } >+ if (font == null) { >+ font = item.getDisplay().getSystemFont(); >+ } >+ return font; >+ } >+ > public void setDropShadowsSize(int dropShadowsSize) { > this.dropShadowsSize = dropShadowsSize; > this.dropShadowsAlphaStep = (dropShadowsSize == 0) ? 0 : (200 / dropShadowsSize); >@@ -197,31 +241,6 @@ > return dropShadowsSize; > } > >- /** >- * Returns the font used for drawing item label or <tt>null</tt> if system >- * font is used. >- * >- * @return the font >- */ >- public Font getFont() { >- return font; >- } >- >- /** >- * Set the font for drawing item label or <tt>null</tt> to use system >- * font. >- * >- * @param font >- * the font to set >- */ >- public void setFont(Font font) { >- if (this.font != font) { >- this.font = font; >- if (getGallery() != null) >- getGallery().redraw(); >- } >- } >- > public void dispose() { > freeDropShadowsColors(); > } >@@ -238,14 +257,6 @@ > return new Point(newWidth, newHeight); > } > >- public Color getForegroundColor() { >- return foregroundColor; >- } >- >- public void setForegroundColor(Color foregroundColor) { >- this.foregroundColor = foregroundColor; >- } >- > public Color getSelectionForegroundColor() { > return selectionForegroundColor; > } >@@ -261,12 +272,4 @@ > public void setSelectionBackgroundColor(Color selectionBackgroundColor) { > this.selectionBackgroundColor = selectionBackgroundColor; > } >- >- public Color getBackgroundColor() { >- return backgroundColor; >- } >- >- public void setBackgroundColor(Color backgroundColor) { >- this.backgroundColor = backgroundColor; >- } > } >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.gallery/META-INF/MANIFEST.MF,v >retrieving revision 1.5 >diff -u -r1.5 MANIFEST.MF >--- META-INF/MANIFEST.MF 22 May 2007 17:01:47 -0000 1.5 >+++ META-INF/MANIFEST.MF 7 Dec 2007 18:51:45 -0000 >@@ -4,6 +4,8 @@ > Bundle-SymbolicName: org.eclipse.nebula.widgets.gallery > Bundle-Version: 1.0.0.qualifier > Bundle-RequiredExecutionEnvironment: J2SE-1.4 >-Require-Bundle: org.eclipse.swt >+Require-Bundle: org.eclipse.swt, >+ org.eclipse.jface;bundle-version="3.3.0";resolution:=optional, >+ org.eclipse.core.runtime;bundle-version="3.3.0";resolution:=optional > Export-Package: org.eclipse.nebula.widgets.gallery > Bundle-Vendor: Nicolas Richeton >Index: build.properties >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.gallery/build.properties,v >retrieving revision 1.5 >diff -u -r1.5 build.properties >--- build.properties 23 Mar 2007 14:06:28 -0000 1.5 >+++ build.properties 7 Dec 2007 18:51:45 -0000 >@@ -7,4 +7,7 @@ > javadoc.packages=org.eclipse.nebula.widgets.gallery.* > javadoc.exclude= > snippets.path=org/eclipse/swt/nebula/snippets/gallery >-src.includes = src/ >+src.includes = src/,\ >+ build.properties,\ >+ .project,\ >+ .classpath >Index: src/org/eclipse/nebula/jface/galleryviewer/GalleryTreeViewer.java >=================================================================== >RCS file: src/org/eclipse/nebula/jface/galleryviewer/GalleryTreeViewer.java >diff -N src/org/eclipse/nebula/jface/galleryviewer/GalleryTreeViewer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/nebula/jface/galleryviewer/GalleryTreeViewer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,472 @@ >+package org.eclipse.nebula.jface.galleryviewer; >+ >+ >+import java.util.Arrays; >+import java.util.Iterator; >+import java.util.LinkedList; >+import java.util.List; >+ >+import org.eclipse.jface.viewers.AbstractTreeViewer; >+import org.eclipse.jface.viewers.ColumnViewerEditor; >+import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; >+import org.eclipse.jface.viewers.IContentProvider; >+import org.eclipse.jface.viewers.IStructuredContentProvider; >+import org.eclipse.jface.viewers.ITreeContentProvider; >+import org.eclipse.jface.viewers.ITreePathContentProvider; >+import org.eclipse.jface.viewers.TreePath; >+import org.eclipse.jface.viewers.TreeSelection; >+import org.eclipse.jface.viewers.ViewerCell; >+import org.eclipse.jface.viewers.ViewerRow; >+import org.eclipse.nebula.widgets.gallery.DefaultGalleryGroupRenderer; >+import org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRenderer; >+import org.eclipse.nebula.widgets.gallery.Gallery; >+import org.eclipse.nebula.widgets.gallery.GalleryItem; >+import org.eclipse.nebula.widgets.gallery.NoGroupRenderer; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.TreeListener; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Item; >+import org.eclipse.swt.widgets.Widget; >+ >+/** >+ * @author pcentgraf >+ */ >+public class GalleryTreeViewer extends AbstractTreeViewer { >+ >+ protected Gallery gallery; >+ >+ /** >+ * true if we are inside a preservingSelection() call >+ */ >+ protected boolean preservingSelection; >+ >+ /** >+ * The row object reused >+ */ >+ private GalleryViewerRow cachedRow; >+ >+ /** >+ * Creates a gallery viewer on a newly-created gallery control under the given >+ * parent. The gallery control is created using the SWT style bits >+ * <code>MULTI, V_SCROLL,</code> and <code>BORDER</code>. The >+ * viewer has no input, no content provider, a default label provider, no >+ * sorter, and no filters. >+ * >+ * @param parent >+ * the parent control >+ */ >+ public GalleryTreeViewer(Composite parent) { >+ this(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER); >+ } >+ >+ /** >+ * Creates a gallery viewer on a newly-created gallery control under the given >+ * parent. The gallery control is created using the given SWT style bits. The >+ * viewer has no input, no content provider, a default label provider, no >+ * sorter, and no filters. >+ * >+ * @param parent >+ * the parent control >+ * @param style >+ * the SWT style bits used to create the gallery. >+ */ >+ public GalleryTreeViewer(Composite parent, int style) { >+ gallery = new Gallery(parent, style); >+ gallery.setGroupRenderer(new DefaultGalleryGroupRenderer()); >+ gallery.setItemRenderer(new DefaultGalleryItemRenderer()); >+ super.setAutoExpandLevel(ALL_LEVELS); >+ >+ hookControl(gallery); >+ } >+ >+ /** >+ * Creates a gallery viewer on the given gallery control. The viewer has no input, >+ * no content provider, a default label provider, no sorter, and no filters. >+ * >+ * @param gallery >+ * the gallery control >+ */ >+ public GalleryTreeViewer(Gallery gallery) { >+ super(); >+ this.gallery = gallery; >+ super.setAutoExpandLevel(ALL_LEVELS); >+ >+ hookControl(gallery); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#addTreeListener(org.eclipse.swt.widgets.Control, org.eclipse.swt.events.TreeListener) >+ */ >+ protected void addTreeListener(Control control, TreeListener listener) { >+ ((Gallery) control).addTreeListener(listener); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#getChild(org.eclipse.swt.widgets.Widget, >+ * int) >+ */ >+ protected Item getChild(Widget widget, int index) { >+ if (widget instanceof GalleryItem) { >+ return ((GalleryItem) widget).getItem(index); >+ } >+ if (widget instanceof Gallery) { >+ return ((Gallery) widget).getItem(index); >+ } >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#getChildren(org.eclipse.swt.widgets.Widget) >+ */ >+ protected Item[] getChildren(Widget widget) { >+ if (widget instanceof GalleryItem) { >+ return getItems((Item) widget); >+ } >+ if (widget instanceof Gallery) { >+ Gallery gallery = (Gallery) widget; >+ if (gallery.getItemCount() > 0) { >+ return gallery.getItems(); >+ } >+ else { >+ return new GalleryItem[0]; >+ } >+ } >+ return null; >+ } >+ >+ >+ protected Widget getColumnViewerOwner(int columnIndex) { >+ if (columnIndex == 0) { >+ return getGallery(); >+ } >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#getExpanded(org.eclipse.swt.widgets.Item) >+ */ >+ protected boolean getExpanded(Item item) { >+ return ((GalleryItem)item).isExpanded(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#getItemCount(org.eclipse.swt.widgets.Control) >+ */ >+ protected int getItemCount(Control control) { >+ return ((Gallery)control).getItemCount(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#getItemCount(org.eclipse.swt.widgets.Item) >+ */ >+ protected int getItemCount(Item item) { >+ return ((GalleryItem)item).getItemCount(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#getItems(org.eclipse.swt.widgets.Item) >+ */ >+ protected Item[] getItems(Item item) { >+ GalleryItem gItem = (GalleryItem) item; >+ GalleryItem[] items = new GalleryItem[gItem.getItemCount()]; >+ for (int i = 0; i < items.length; i++) { >+ items[i] = gItem.getItem(i); >+ } >+ return items; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#getParentItem(org.eclipse.swt.widgets.Item) >+ */ >+ protected Item getParentItem(Item item) { >+ return ((GalleryItem)item).getParentItem(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#getSelection(org.eclipse.swt.widgets.Control) >+ */ >+ protected Item[] getSelection(Control control) { >+ Item[] selection = ((Gallery)control).getSelection(); >+ if (selection == null) { >+ return new GalleryItem[0]; >+ } >+ else { >+ return selection; >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#newItem(org.eclipse.swt.widgets.Widget, int, int) >+ */ >+ protected Item newItem(Widget parent, int style, int index) { >+ >+ GalleryItem item; >+ >+ if (parent instanceof GalleryItem) { >+ item = (GalleryItem) createNewRowPart(getViewerRowFromItem(parent), >+ style, index).getItem(); >+ } else { >+ item = (GalleryItem) createNewRowPart(null, style, index).getItem(); >+ } >+ >+ return item; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#removeAll(org.eclipse.swt.widgets.Control) >+ */ >+ protected void removeAll(Control control) { >+ ((Gallery)control).clearAll(); >+ } >+ >+ >+ public void setAutoExpandLevel(int level) { >+ throw new UnsupportedOperationException("Gallery must be fully expanded."); >+ } >+ >+ /** >+ * <p> >+ * Gallery expects contents to have exactly 2 levels of hierarchy, with groups >+ * as the root elements and image thumbnails as direct children of the groups. >+ * This method accepts ITreeContentProvider and ITreePathContentProvider as-is, and >+ * relies on the providers to return contents with the correct structure. >+ * </p> >+ * <p> >+ * This method also accepts IStructuredContentProvider and wraps it in a >+ * FlatTreeContentProvider with an empty string as the root node. If you need a >+ * different root node, construct your own FlatTreeContentProvider and pass it here. >+ * If you want the Gallery to suppress the collapsable group header, call >+ * </p> >+ * <code>getGallery().setGroupRenderer(new NoGroupRenderer());</code> >+ */ >+ public void setContentProvider(IContentProvider provider) { >+ if (provider instanceof IStructuredContentProvider >+ && !(provider instanceof ITreeContentProvider >+ || provider instanceof ITreePathContentProvider)) { >+ // Wrap a table-style contents with a single root node. >+ super.setContentProvider( >+ new FlatTreeContentProvider((IStructuredContentProvider) provider)); >+ } >+ else { >+ super.setContentProvider(provider); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#setExpanded(org.eclipse.swt.widgets.Item, boolean) >+ */ >+ protected void setExpanded(Item item, boolean expand) { >+ ((GalleryItem)item).setExpanded(expand); >+// if (contentProviderIsLazy) { >+// // force repaints to happen >+// getControl().update(); >+// } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#setSelection(java.util.List) >+ */ >+ protected void setSelection(List items) { >+ Item[] current = getSelection(getGallery()); >+ >+ // Don't bother resetting the same selection >+ if (isSameSelection(items, current)) { >+ return; >+ } >+ >+ GalleryItem[] newItems = new GalleryItem[items.size()]; >+ items.toArray(newItems); >+ getGallery().setSelection(newItems); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#showItem(org.eclipse.swt.widgets.Item) >+ */ >+ protected void showItem(Item item) { >+ gallery.showItem((GalleryItem)item); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.Viewer#getControl() >+ */ >+ public Control getControl() { >+ return gallery; >+ } >+ >+ /** >+ * Returns this gallery viewer's gallery. >+ * >+ * @return the gallery control >+ */ >+ public Gallery getGallery() { >+ return gallery; >+ } >+ >+ >+ protected Item getItemAt(Point point) { >+ return gallery.getItem(point); >+ } >+ >+ >+ protected ColumnViewerEditor createViewerEditor() { >+ // TODO: implement editing support >+ return null; >+ } >+ >+ /** >+ * For a GalleryViewer with a gallery with the VIRTUAL style bit set, set the >+ * number of children of the given element or tree path. To set the number >+ * of children of the invisible root of the gallery, you can pass the input >+ * object or an empty tree path. >+ * >+ * @param elementOrTreePath >+ * the element, or tree path >+ * @param count >+ * >+ * @since 3.2 >+ */ >+ public void setChildCount(final Object elementOrTreePath, final int count) { >+// if (isBusy()) >+// return; >+ preservingSelection(new Runnable() { >+ public void run() { >+ if (internalIsInputOrEmptyPath(elementOrTreePath)) { >+ getGallery().setItemCount(count); >+ return; >+ } >+ Widget[] items = internalFindItems(elementOrTreePath); >+ for (int i = 0; i < items.length; i++) { >+ GalleryItem galleryItem = (GalleryItem) items[i]; >+ galleryItem.setItemCount(count); >+ } >+ } >+ }); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.ColumnViewer#getRowPartFromItem(org.eclipse.swt.widgets.Widget) >+ */ >+ protected ViewerRow getViewerRowFromItem(Widget item) { >+ if( cachedRow == null ) { >+ cachedRow = new GalleryViewerRow((GalleryItem) item); >+ } else { >+ cachedRow.setItem((GalleryItem) item); >+ } >+ >+ return cachedRow; >+ } >+ >+ /** >+ * Create a new ViewerRow at rowIndex >+ * >+ * @param parent >+ * @param style >+ * @param rowIndex >+ * @return ViewerRow >+ */ >+ private ViewerRow createNewRowPart(ViewerRow parent, int style, int rowIndex) { >+ if (parent == null) { >+ if (rowIndex >= 0) { >+ return getViewerRowFromItem(new GalleryItem(gallery, style, rowIndex)); >+ } >+ return getViewerRowFromItem(new GalleryItem(gallery, style)); >+ } >+ >+ if (rowIndex >= 0) { >+ return getViewerRowFromItem(new GalleryItem((GalleryItem) parent.getItem(), >+ SWT.NONE, rowIndex)); >+ } >+ >+ return getViewerRowFromItem(new GalleryItem((GalleryItem) parent.getItem(), >+ SWT.NONE)); >+ } >+ >+ /** >+ * Removes the element at the specified index of the parent. The selection is updated if required. >+ * >+ * @param parentOrTreePath the parent element, the input element, or a tree path to the parent element >+ * @param index child index >+ * @since 3.3 >+ */ >+ public void remove(final Object parentOrTreePath, final int index) { >+// if (isBusy()) >+// return; >+ final List oldSelection = new LinkedList(Arrays >+ .asList(((TreeSelection) getSelection()).getPaths())); >+ preservingSelection(new Runnable() { >+ public void run() { >+ TreePath removedPath = null; >+ if (internalIsInputOrEmptyPath(parentOrTreePath)) { >+ Gallery gallery = (Gallery) getControl(); >+ if (index < gallery.getItemCount()) { >+ GalleryItem item = gallery.getItem(index); >+ if (item.getData() != null) { >+ removedPath = getTreePathFromItem(item); >+ disassociate(item); >+ } >+ item.dispose(); >+ } >+ } else { >+ Widget[] parentItems = internalFindItems(parentOrTreePath); >+ for (int i = 0; i < parentItems.length; i++) { >+ GalleryItem parentItem = (GalleryItem) parentItems[i]; >+ if (index < parentItem.getItemCount()) { >+ GalleryItem item = parentItem.getItem(index); >+ if (item.getData() != null) { >+ removedPath = getTreePathFromItem(item); >+ disassociate(item); >+ } >+ item.dispose(); >+ } >+ } >+ } >+ if (removedPath != null) { >+ boolean removed = false; >+ for (Iterator it = oldSelection.iterator(); it >+ .hasNext();) { >+ TreePath path = (TreePath) it.next(); >+ if (path.startsWith(removedPath, getComparer())) { >+ it.remove(); >+ removed = true; >+ } >+ } >+ if (removed) { >+ setSelection(new TreeSelection( >+ (TreePath[]) oldSelection >+ .toArray(new TreePath[oldSelection >+ .size()]), getComparer()), >+ false); >+ } >+ >+ } >+ } >+ }); >+ } >+ >+ public void editElement(Object element, int column) { >+ if( element instanceof TreePath ) { >+ setSelection(new TreeSelection((TreePath) element)); >+ GalleryItem[] items = gallery.getSelection(); >+ >+ if( items.length == 1 ) { >+ ViewerRow row = getViewerRowFromItem(items[0]); >+ >+ if (row != null) { >+ ViewerCell cell = row.getCell(column); >+ if (cell != null) { >+ getControl().setRedraw(false); >+ triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell)); >+ getControl().setRedraw(true); >+ } >+ } >+ } >+ } else { >+ super.editElement(element, column); >+ } >+ } >+ >+} >Index: src/org/eclipse/nebula/jface/galleryviewer/GalleryViewerTester.java >=================================================================== >RCS file: src/org/eclipse/nebula/jface/galleryviewer/GalleryViewerTester.java >diff -N src/org/eclipse/nebula/jface/galleryviewer/GalleryViewerTester.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/nebula/jface/galleryviewer/GalleryViewerTester.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,170 @@ >+package org.eclipse.nebula.jface.galleryviewer; >+ >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.Comparator; >+ >+import org.eclipse.jface.layout.GridDataFactory; >+import org.eclipse.jface.layout.GridLayoutFactory; >+import org.eclipse.jface.viewers.IColorProvider; >+import org.eclipse.jface.viewers.IFontProvider; >+import org.eclipse.jface.viewers.IStructuredContentProvider; >+import org.eclipse.jface.viewers.ITreeContentProvider; >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.jface.viewers.ViewerComparator; >+import org.eclipse.jface.viewers.ViewerFilter; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.FontData; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.program.Program; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * Simple visual test harness for GalleryTreeViewer. >+ * >+ * @author pcentgraf >+ * @since Dec 5, 2007 >+ */ >+public class GalleryViewerTester { >+ >+ protected static class GalleryTestContentProvider >+ implements ITreeContentProvider { >+// implements IStructuredContentProvider { // Use this to test FlatTreeContentProvider >+ public static final int NUM_GROUPS = 10; >+ public static final int NUM_ITEMS = 20; >+ >+ String[] groups = new String[NUM_GROUPS]; >+ String[][] items = new String[NUM_GROUPS][NUM_ITEMS]; >+ >+ public GalleryTestContentProvider() { >+ for (int i = 0; i < NUM_GROUPS; i++) { >+ groups[i]= "Group "+(i+1); >+ for (int j = 0; j < NUM_ITEMS; j++) { >+ items[i][j] = "Item "+(j+1); >+ } >+ } >+ } >+ >+ public Object[] getChildren(Object parentElement) { >+ int idx = Arrays.asList(groups).indexOf(parentElement); >+ return items[idx]; >+ } >+ >+ public Object getParent(Object element) { >+ return null; >+ } >+ >+ public boolean hasChildren(Object element) { >+ return ((String)element).startsWith("Group"); >+ } >+ >+ public Object[] getElements(Object inputElement) { >+ return groups; >+ } >+ >+ public void dispose() { >+ } >+ >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ } >+ } >+ >+ protected static class GalleryTestLabelProvider extends LabelProvider >+ implements IColorProvider, IFontProvider { >+ protected static Image itemImage = >+ new Image(Display.getCurrent(), Program.findProgram("jpg").getImageData()); >+ >+ public Image getImage(Object element) { >+ return itemImage; >+ } >+ >+ public Color getBackground(Object element) { >+ String label = (String) element; >+ if (Integer.parseInt(label.substring(label.indexOf(' ')+1))%2 > 0) { >+ return Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW); >+ } >+ else { >+ return null; >+ } >+ } >+ >+ public Color getForeground(Object element) { >+ String label = (String) element; >+ if (Integer.parseInt(label.substring(label.indexOf(' ')+1))%2 > 0) { >+ return null; >+ } >+ else { >+ return Display.getCurrent().getSystemColor(SWT.COLOR_BLUE); >+ } >+ } >+ >+ public Font getFont(Object element) { >+ String label = (String) element; >+ if (Integer.parseInt(label.substring(label.indexOf(' ')+1))%2 > 0) { >+ return null; >+ } >+ else { >+ FontData sysFontData = Display.getCurrent().getSystemFont().getFontData()[0]; >+ sysFontData.setStyle(SWT.BOLD | SWT.ITALIC); >+ return new Font(Display.getCurrent(), sysFontData); >+ } >+ } >+ } >+ >+ protected static class OddNumbersFilter extends ViewerFilter { >+ public boolean select(Viewer viewer, Object parentElement, Object element) { >+ try { >+ String label = (String) element; >+ return (Integer.parseInt(label.substring(label.indexOf(' ')+1))%2 > 0); >+ } >+ catch (Exception e) { >+ return true; >+ } >+ } >+ } >+ >+ protected static final int WIDTH = 800; >+ protected static final int HEIGHT = 600; >+ protected Shell shell; >+ >+ public GalleryViewerTester() { >+ // Initialize the containing Shell >+ Display display = new Display(); >+ shell = new Shell(display); >+ shell.setSize(WIDTH, HEIGHT); >+ shell.setBackground(display.getSystemColor(SWT.COLOR_RED)); >+ GridLayoutFactory.fillDefaults().applyTo(shell); >+ >+ GalleryTreeViewer viewer = new GalleryTreeViewer(shell); >+ GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getGallery()); >+ viewer.setContentProvider(new GalleryTestContentProvider()); >+ viewer.setLabelProvider(new GalleryTestLabelProvider()); >+ viewer.setComparator(new ViewerComparator()); >+// viewer.addFilter(new OddNumbersFilter()); >+ viewer.setInput(new Object()); >+ >+ // Show the Shell >+ shell.open(); >+ shell.layout(); >+ >+ // Run the event loop >+ while (!shell.isDisposed()) { >+ if (!display.readAndDispatch()) >+ display.sleep(); >+ } >+ display.dispose(); >+ } >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ new GalleryViewerTester(); >+ } >+ >+} >Index: src/org/eclipse/nebula/jface/galleryviewer/GalleryViewerRow.java >=================================================================== >RCS file: src/org/eclipse/nebula/jface/galleryviewer/GalleryViewerRow.java >diff -N src/org/eclipse/nebula/jface/galleryviewer/GalleryViewerRow.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/nebula/jface/galleryviewer/GalleryViewerRow.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,235 @@ >+package org.eclipse.nebula.jface.galleryviewer; >+ >+ >+import java.util.LinkedList; >+ >+import org.eclipse.jface.viewers.TreePath; >+import org.eclipse.jface.viewers.ViewerRow; >+import org.eclipse.nebula.widgets.gallery.GalleryItem; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Widget; >+ >+/** >+ * ViewerRow adapter for the Nebula Gallery widget. >+ * >+ * @author pcentgraf >+ * @since Dec 5, 2007 >+ */ >+public class GalleryViewerRow extends ViewerRow { >+ >+ protected GalleryItem item; >+ >+ /** >+ * Constructs a ViewerRow adapter for a GalleryItem. >+ * >+ * @param item the GalleryItem to adapt >+ */ >+ public GalleryViewerRow(GalleryItem item) { >+ this.item = item; >+ } >+ >+ public void setItem(GalleryItem item) { >+ this.item = item; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#clone() >+ */ >+ public Object clone() { >+ return new GalleryViewerRow(item); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getBackground(int) >+ */ >+ public Color getBackground(int columnIndex) { >+ // XXX: should this use getBackgroundColor() instead? >+ return item.getBackground(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getBounds() >+ */ >+ public Rectangle getBounds() { >+ return item.getBounds(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getBounds(int) >+ */ >+ public Rectangle getBounds(int columnIndex) { >+ return item.getBounds(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getColumnCount() >+ */ >+ public int getColumnCount() { >+ return 0; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getControl() >+ */ >+ public Control getControl() { >+ return item.getParent(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getElement() >+ */ >+ public Object getElement() { >+ return item.getData(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getFont(int) >+ */ >+ public Font getFont(int columnIndex) { >+ return item.getFont(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getForeground(int) >+ */ >+ public Color getForeground(int columnIndex) { >+ return item.getForeground(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getImage(int) >+ */ >+ public Image getImage(int columnIndex) { >+ return item.getImage(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getItem() >+ */ >+ public Widget getItem() { >+ return item; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getNeighbor(int, boolean) >+ */ >+ public ViewerRow getNeighbor(int direction, boolean sameLevel) { >+ if( direction == ViewerRow.ABOVE ) { >+ // TODO: handle grouping >+ return getRowAbove(); >+ } else if( direction == ViewerRow.BELOW ) { >+ // TODO: handle grouping >+ return getRowBelow(); >+ } else { >+ throw new IllegalArgumentException("Illegal value of direction argument."); //$NON-NLS-1$ >+ } >+ } >+ >+ protected ViewerRow getRowAbove() { >+ if (item.getParentItem() == null) { >+ int index = item.getParent().indexOf(item) - 1; >+ >+ if( index >= 0 ) { >+ return new GalleryViewerRow(item.getParent().getItem(index)); >+ } >+ } >+ else { >+ GalleryItem parentItem = item.getParentItem(); >+ int index = parentItem.indexOf(item) -1; >+ >+ if (index >= 0) { >+ return new GalleryViewerRow(parentItem.getItem(index)); >+ } >+ } >+ >+ return null; >+ } >+ >+ protected ViewerRow getRowBelow() { >+ if (item.getParentItem() == null) { >+ int index = item.getParent().indexOf(item) + 1; >+ >+ if( index < item.getParent().getItemCount() ) { >+ GalleryItem tmp = item.getParent().getItem(index); >+ if( tmp != null ) { >+ return new GalleryViewerRow(tmp); >+ } >+ } >+ } >+ else { >+ GalleryItem parentItem = item.getParentItem(); >+ int index = parentItem.indexOf(item) +1; >+ >+ if (index < parentItem.getItemCount()) { >+ GalleryItem tmp = parentItem.getItem(index); >+ if( tmp != null ) { >+ return new GalleryViewerRow(tmp); >+ } >+ } >+ } >+ >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getText(int) >+ */ >+ public String getText(int columnIndex) { >+ return item.getText(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#getTreePath() >+ */ >+ public TreePath getTreePath() { >+ LinkedList path = new LinkedList(); >+ path.add(item.getData()); >+ >+ GalleryItem curItem = item; >+ while (curItem.getParentItem() != null) { >+ path.addFirst(curItem.getParentItem().getData()); >+ curItem = curItem.getParentItem(); >+ } >+ return new TreePath(path.toArray()); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#setBackground(int, org.eclipse.swt.graphics.Color) >+ */ >+ public void setBackground(int columnIndex, Color color) { >+ item.setBackground(color); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#setFont(int, org.eclipse.swt.graphics.Font) >+ */ >+ public void setFont(int columnIndex, Font font) { >+ item.setFont(font); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#setForeground(int, org.eclipse.swt.graphics.Color) >+ */ >+ public void setForeground(int columnIndex, Color color) { >+ item.setForeground(color); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#setImage(int, org.eclipse.swt.graphics.Image) >+ */ >+ public void setImage(int columnIndex, Image image) { >+ item.setImage(image); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerRow#setText(int, java.lang.String) >+ */ >+ public void setText(int columnIndex, String text) { >+ item.setText(text); >+ } >+ >+} >Index: src/org/eclipse/nebula/jface/galleryviewer/FlatTreeContentProvider.java >=================================================================== >RCS file: src/org/eclipse/nebula/jface/galleryviewer/FlatTreeContentProvider.java >diff -N src/org/eclipse/nebula/jface/galleryviewer/FlatTreeContentProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/nebula/jface/galleryviewer/FlatTreeContentProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,94 @@ >+package org.eclipse.nebula.jface.galleryviewer; >+ >+ >+import org.eclipse.jface.viewers.IStructuredContentProvider; >+import org.eclipse.jface.viewers.ITreeContentProvider; >+import org.eclipse.jface.viewers.Viewer; >+ >+/** >+ * Adaptor that converts an {@link IStructuredContentProvider} into an >+ * {@link ITreeContentProvider} that places the nested contents inside >+ * a single root node. >+ * >+ * @author pcentgraf >+ * @since Dec 6, 2007 >+ */ >+public class FlatTreeContentProvider implements ITreeContentProvider { >+ >+ protected final Object rootNode; >+ protected final IStructuredContentProvider provider; >+ protected final Object[] roots; >+ >+ /** >+ * Adapts an {@link IStructuredContentProvider} into an {@link ITreeContentProvider} >+ * that places the nested contents inside a single root node. >+ * >+ * @param provider the {@link IStructuredContentProvider} to adapt >+ */ >+ public FlatTreeContentProvider(IStructuredContentProvider provider) { >+ this(provider, ""); >+ } >+ >+ /** >+ * Adapts an {@link IStructuredContentProvider} into an {@link ITreeContentProvider} >+ * that places the nested contents inside the given root node. >+ * >+ * @param provider the {@link IStructuredContentProvider} to adapt >+ * @param the single root node for the tree >+ */ >+ public FlatTreeContentProvider(IStructuredContentProvider provider, Object rootNode) { >+ this.provider = provider; >+ this.rootNode = rootNode; >+ >+ roots = new Object[] {rootNode}; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) >+ */ >+ public Object getParent(Object element) { >+ if (element == rootNode) { >+ return null; >+ } >+ else { >+ return rootNode; >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) >+ */ >+ public boolean hasChildren(Object element) { >+ return element == rootNode; >+ } >+ >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) >+ */ >+ public Object[] getElements(Object inputElement) { >+ return roots; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) >+ */ >+ public Object[] getChildren(Object parentElement) { >+ return provider.getElements(parentElement); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.IContentProvider#dispose() >+ */ >+ public void dispose() { >+ provider.dispose(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) >+ */ >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ provider.inputChanged(viewer, oldInput, newInput); >+ } >+ >+} >Index: .settings/org.eclipse.jdt.core.prefs >=================================================================== >RCS file: .settings/org.eclipse.jdt.core.prefs >diff -N .settings/org.eclipse.jdt.core.prefs >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ .settings/org.eclipse.jdt.core.prefs 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,12 @@ >+#Fri Dec 07 12:30:12 EST 2007 >+eclipse.preferences.version=1 >+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled >+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 >+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve >+org.eclipse.jdt.core.compiler.compliance=1.4 >+org.eclipse.jdt.core.compiler.debug.lineNumber=generate >+org.eclipse.jdt.core.compiler.debug.localVariable=generate >+org.eclipse.jdt.core.compiler.debug.sourceFile=generate >+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning >+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning >+org.eclipse.jdt.core.compiler.source=1.3
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Flags:
nicolas.richeton
:
iplog+
Actions:
View
Attachments on
bug 212071
:
84678
| 84766 |
87569
|
87570