Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » [GalleryTreeViewer] Now groups added via refresh() appear collapsed
[GalleryTreeViewer] Now groups added via refresh() appear collapsed [message #59181] Thu, 18 September 2008 13:35 Go to next message
Justin Dolezy is currently offline Justin DolezyFriend
Messages: 68
Registered: July 2009
Member
Hi,

GalleryTreeViewer is set to auto expand all levels. However when my
content updates with a new group and I call
GalleryTreeViewer.refresh(true) the new group appears in the collapsed
state rather than the expanded state I expect (and want!).

Not sure if anyone else has come across this or not. I'll try to provide a
snippet based on SnippetGalleryViewerTester that'll hopefully demonstrate
this.

Cheers,
Justin
Re: [GalleryTreeViewer] New groups added via refresh() appear collapsed [message #59207 is a reply to message #59181] Thu, 18 September 2008 13:37 Go to previous messageGo to next message
Justin Dolezy is currently offline Justin DolezyFriend
Messages: 68
Registered: July 2009
Member
Obviously the title should read "NEW groups added via refresh() appear
collapsed" 8)

Justin
Re: [GalleryTreeViewer] New groups added via refresh() appear collapsed [message #59231 is a reply to message #59181] Fri, 19 September 2008 09:32 Go to previous messageGo to next message
Justin Dolezy is currently offline Justin DolezyFriend
Messages: 68
Registered: July 2009
Member
Here's an example demostrating this. I've just modified the existing
snippet to add some new groups periodically.


/*********************************************************** ********************
* Copyright (c) 2007-2008 Peter Centgraf.
* 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 :
* Peter Centgraf - initial implementation
************************************************************ *******************/
package com.neckdiagrams.instruments.ui.internal;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

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.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.nebula.jface.galleryviewer.GalleryTreeViewer;
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 Peter Centgraf
* @since Dec 5, 2007
*/
public class SnippetGalleryViewerTester {

protected static class GalleryTestContentProvider implements
ITreeContentProvider {
// implements IStructuredContentProvider { // Use this to test
// FlatTreeContentProvider
public static final int NUM_GROUPS = 1;
public static final int NUM_ITEMS = 9;

List<String> groups = new ArrayList<String>();
HashMap<String, List<String>> itemsByGroup = new HashMap<String,
List<String>>();

public GalleryTestContentProvider() {
for (int i = 0; i < NUM_GROUPS; i++) {
addNewGroup();
}
}

public Object[] getChildren(Object parentElement) {
return itemsByGroup.get(parentElement).toArray();
}

public Object getParent(Object element) {
return null;
}

public boolean hasChildren(Object element) {
return ((String) element).startsWith("Group");
}

public Object[] getElements(Object inputElement) {
return groups.toArray();
}

public void dispose() {
}

public void inputChanged(Viewer viewer, Object oldInput, Object
newInput) {
}

public void addNewGroup() {
List<String> items = new ArrayList<String>();
for (int j = 0; j < NUM_ITEMS; j++) {
items.add("Item " + (j + 1));
}
final String group = "Group " + (groups.size() + 1);
itemsByGroup.put(group, items);
groups.add(group);
}
}

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 SnippetGalleryViewerTester() {
// Initialize the containing Shell
final Display display = new Display();
shell = new Shell(display);
shell.setSize(WIDTH, HEIGHT);
shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
GridLayoutFactory.fillDefaults().applyTo(shell);

final GalleryTreeViewer viewer = new GalleryTreeViewer(shell);
GridDataFactory.fillDefaults().grab(true,
true).applyTo(viewer.getGallery());
final GalleryTestContentProvider contentProvider = new
GalleryTestContentProvider();
viewer.setContentProvider(contentProvider);
viewer.setLabelProvider(new GalleryTestLabelProvider());
viewer.setComparator(new ViewerComparator());
// viewer.addFilter(new OddNumbersFilter());
viewer.setInput(new Object());

// Show the Shell
shell.open();
shell.layout();

final Runnable runnable = new Runnable() {
public void run() {
contentProvider.addNewGroup();
viewer.refresh();
if (contentProvider.groups.size() < 7) display.timerExec(3000, this);
}
};
display.timerExec(3000, runnable);

// Run the event loop
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

/**
* @param args
*/
public static void main(String[] args) {
new SnippetGalleryViewerTester();
}

}
Re: [GalleryTreeViewer] New groups added via refresh() appear collapsed [message #59391 is a reply to message #59231] Wed, 24 September 2008 16:02 Go to previous messageGo to next message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Hi Justin,

I'll take a look at your snippet as soon as I get some free time. Until
then, please open a bug for this.

There are many changes from Peter that I need to commit so maybe the
problem is already solved.

--
Nicolas.

Justin a écrit :
> Here's an example demostrating this. I've just modified the existing
> snippet to add some new groups periodically.
>
>
> /*********************************************************** ********************
>
> * Copyright (c) 2007-2008 Peter Centgraf.
> * 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 :
> * Peter Centgraf - initial implementation
> ************************************************************ *******************/
>
> package com.neckdiagrams.instruments.ui.internal;
>
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.List;
>
> 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.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.nebula.jface.galleryviewer.GalleryTreeViewer;
> 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 Peter Centgraf
> * @since Dec 5, 2007
> */
> public class SnippetGalleryViewerTester {
>
> protected static class GalleryTestContentProvider implements
> ITreeContentProvider {
> // implements IStructuredContentProvider { // Use this to test
> // FlatTreeContentProvider
> public static final int NUM_GROUPS = 1;
> public static final int NUM_ITEMS = 9;
>
> List<String> groups = new ArrayList<String>();
> HashMap<String, List<String>> itemsByGroup = new HashMap<String,
> List<String>>();
>
> public GalleryTestContentProvider() {
> for (int i = 0; i < NUM_GROUPS; i++) {
> addNewGroup();
> }
> }
>
> public Object[] getChildren(Object parentElement) {
> return itemsByGroup.get(parentElement).toArray();
> }
>
> public Object getParent(Object element) {
> return null;
> }
>
> public boolean hasChildren(Object element) {
> return ((String) element).startsWith("Group");
> }
>
> public Object[] getElements(Object inputElement) {
> return groups.toArray();
> }
>
> public void dispose() {
> }
>
> public void inputChanged(Viewer viewer, Object oldInput, Object
> newInput) {
> }
>
> public void addNewGroup() {
> List<String> items = new ArrayList<String>();
> for (int j = 0; j < NUM_ITEMS; j++) {
> items.add("Item " + (j + 1));
> }
> final String group = "Group " + (groups.size() + 1);
> itemsByGroup.put(group, items);
> groups.add(group);
> }
> }
>
> 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 SnippetGalleryViewerTester() {
> // Initialize the containing Shell
> final Display display = new Display();
> shell = new Shell(display);
> shell.setSize(WIDTH, HEIGHT);
> shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
> GridLayoutFactory.fillDefaults().applyTo(shell);
>
> final GalleryTreeViewer viewer = new GalleryTreeViewer(shell);
> GridDataFactory.fillDefaults().grab(true,
> true).applyTo(viewer.getGallery());
> final GalleryTestContentProvider contentProvider = new
> GalleryTestContentProvider();
> viewer.setContentProvider(contentProvider);
> viewer.setLabelProvider(new GalleryTestLabelProvider());
> viewer.setComparator(new ViewerComparator());
> // viewer.addFilter(new OddNumbersFilter());
> viewer.setInput(new Object());
>
> // Show the Shell
> shell.open();
> shell.layout();
>
> final Runnable runnable = new Runnable() {
> public void run() {
> contentProvider.addNewGroup();
> viewer.refresh();
> if (contentProvider.groups.size() < 7)
> display.timerExec(3000, this);
> }
> };
> display.timerExec(3000, runnable);
>
> // Run the event loop
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> new SnippetGalleryViewerTester();
> }
>
> }
>
>
>
Re: [GalleryTreeViewer] New groups added via refresh() appear collapsed [message #59416 is a reply to message #59231] Wed, 24 September 2008 18:50 Go to previous messageGo to next message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Hi Justin,

I'll take a look at your snippet as soon as I get some free time. Until
then, please open a bug for this.

There are many changes from Peter that I need to commit so maybe the
problem is already solved.

--
Nicolas.

Justin a écrit :
> Here's an example demostrating this. I've just modified the existing
> snippet to add some new groups periodically.
>
>
> /*********************************************************** ********************
>
> * Copyright (c) 2007-2008 Peter Centgraf.
> * 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 :
> * Peter Centgraf - initial implementation
> ************************************************************ *******************/
>
> package com.neckdiagrams.instruments.ui.internal;
>
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.List;
>
> 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.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.nebula.jface.galleryviewer.GalleryTreeViewer;
> 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 Peter Centgraf
> * @since Dec 5, 2007
> */
> public class SnippetGalleryViewerTester {
>
> protected static class GalleryTestContentProvider implements
> ITreeContentProvider {
> // implements IStructuredContentProvider { // Use this to test
> // FlatTreeContentProvider
> public static final int NUM_GROUPS = 1;
> public static final int NUM_ITEMS = 9;
>
> List<String> groups = new ArrayList<String>();
> HashMap<String, List<String>> itemsByGroup = new HashMap<String,
> List<String>>();
>
> public GalleryTestContentProvider() {
> for (int i = 0; i < NUM_GROUPS; i++) {
> addNewGroup();
> }
> }
>
> public Object[] getChildren(Object parentElement) {
> return itemsByGroup.get(parentElement).toArray();
> }
>
> public Object getParent(Object element) {
> return null;
> }
>
> public boolean hasChildren(Object element) {
> return ((String) element).startsWith("Group");
> }
>
> public Object[] getElements(Object inputElement) {
> return groups.toArray();
> }
>
> public void dispose() {
> }
>
> public void inputChanged(Viewer viewer, Object oldInput, Object
> newInput) {
> }
>
> public void addNewGroup() {
> List<String> items = new ArrayList<String>();
> for (int j = 0; j < NUM_ITEMS; j++) {
> items.add("Item " + (j + 1));
> }
> final String group = "Group " + (groups.size() + 1);
> itemsByGroup.put(group, items);
> groups.add(group);
> }
> }
>
> 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 SnippetGalleryViewerTester() {
> // Initialize the containing Shell
> final Display display = new Display();
> shell = new Shell(display);
> shell.setSize(WIDTH, HEIGHT);
> shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
> GridLayoutFactory.fillDefaults().applyTo(shell);
>
> final GalleryTreeViewer viewer = new GalleryTreeViewer(shell);
> GridDataFactory.fillDefaults().grab(true,
> true).applyTo(viewer.getGallery());
> final GalleryTestContentProvider contentProvider = new
> GalleryTestContentProvider();
> viewer.setContentProvider(contentProvider);
> viewer.setLabelProvider(new GalleryTestLabelProvider());
> viewer.setComparator(new ViewerComparator());
> // viewer.addFilter(new OddNumbersFilter());
> viewer.setInput(new Object());
>
> // Show the Shell
> shell.open();
> shell.layout();
>
> final Runnable runnable = new Runnable() {
> public void run() {
> contentProvider.addNewGroup();
> viewer.refresh();
> if (contentProvider.groups.size() < 7)
> display.timerExec(3000, this);
> }
> };
> display.timerExec(3000, runnable);
>
> // Run the event loop
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> new SnippetGalleryViewerTester();
> }
>
> }
>
>
>
Re: [GalleryTreeViewer] New groups added via refresh() appear collapsed [message #59513 is a reply to message #59391] Fri, 26 September 2008 09:30 Go to previous message
Justin Dolezy is currently offline Justin DolezyFriend
Messages: 68
Registered: July 2009
Member
Salut Nicolas,

Bug raised: https://bugs.eclipse.org/bugs/show_bug.cgi?id=248700

Cheers,
Justin


Nicolas Richeton wrote:

> Hi Justin,

> I'll take a look at your snippet as soon as I get some free time. Until
> then, please open a bug for this.

> There are many changes from Peter that I need to commit so maybe the
> problem is already solved.

> --
> Nicolas.
Re: [GalleryTreeViewer] New groups added via refresh() appear collapsed [message #592250 is a reply to message #59181] Thu, 18 September 2008 13:37 Go to previous message
Justin Dolezy is currently offline Justin DolezyFriend
Messages: 68
Registered: July 2009
Member
Obviously the title should read "NEW groups added via refresh() appear
collapsed" 8)

Justin
Re: [GalleryTreeViewer] New groups added via refresh() appear collapsed [message #592259 is a reply to message #59181] Fri, 19 September 2008 09:32 Go to previous message
Justin Dolezy is currently offline Justin DolezyFriend
Messages: 68
Registered: July 2009
Member
Here's an example demostrating this. I've just modified the existing
snippet to add some new groups periodically.


/*********************************************************** ********************
* Copyright (c) 2007-2008 Peter Centgraf.
* 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 :
* Peter Centgraf - initial implementation
************************************************************ *******************/
package com.neckdiagrams.instruments.ui.internal;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

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.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.nebula.jface.galleryviewer.GalleryTreeViewer;
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 Peter Centgraf
* @since Dec 5, 2007
*/
public class SnippetGalleryViewerTester {

protected static class GalleryTestContentProvider implements
ITreeContentProvider {
// implements IStructuredContentProvider { // Use this to test
// FlatTreeContentProvider
public static final int NUM_GROUPS = 1;
public static final int NUM_ITEMS = 9;

List<String> groups = new ArrayList<String>();
HashMap<String, List<String>> itemsByGroup = new HashMap<String,
List<String>>();

public GalleryTestContentProvider() {
for (int i = 0; i < NUM_GROUPS; i++) {
addNewGroup();
}
}

public Object[] getChildren(Object parentElement) {
return itemsByGroup.get(parentElement).toArray();
}

public Object getParent(Object element) {
return null;
}

public boolean hasChildren(Object element) {
return ((String) element).startsWith("Group");
}

public Object[] getElements(Object inputElement) {
return groups.toArray();
}

public void dispose() {
}

public void inputChanged(Viewer viewer, Object oldInput, Object
newInput) {
}

public void addNewGroup() {
List<String> items = new ArrayList<String>();
for (int j = 0; j < NUM_ITEMS; j++) {
items.add("Item " + (j + 1));
}
final String group = "Group " + (groups.size() + 1);
itemsByGroup.put(group, items);
groups.add(group);
}
}

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 SnippetGalleryViewerTester() {
// Initialize the containing Shell
final Display display = new Display();
shell = new Shell(display);
shell.setSize(WIDTH, HEIGHT);
shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
GridLayoutFactory.fillDefaults().applyTo(shell);

final GalleryTreeViewer viewer = new GalleryTreeViewer(shell);
GridDataFactory.fillDefaults().grab(true,
true).applyTo(viewer.getGallery());
final GalleryTestContentProvider contentProvider = new
GalleryTestContentProvider();
viewer.setContentProvider(contentProvider);
viewer.setLabelProvider(new GalleryTestLabelProvider());
viewer.setComparator(new ViewerComparator());
// viewer.addFilter(new OddNumbersFilter());
viewer.setInput(new Object());

// Show the Shell
shell.open();
shell.layout();

final Runnable runnable = new Runnable() {
public void run() {
contentProvider.addNewGroup();
viewer.refresh();
if (contentProvider.groups.size() < 7) display.timerExec(3000, this);
}
};
display.timerExec(3000, runnable);

// Run the event loop
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

/**
* @param args
*/
public static void main(String[] args) {
new SnippetGalleryViewerTester();
}

}
Re: [GalleryTreeViewer] New groups added via refresh() appear collapsed [message #592314 is a reply to message #59231] Wed, 24 September 2008 16:02 Go to previous message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Hi Justin,

I'll take a look at your snippet as soon as I get some free time. Until
then, please open a bug for this.

There are many changes from Peter that I need to commit so maybe the
problem is already solved.

--
Nicolas.

Justin a écrit :
> Here's an example demostrating this. I've just modified the existing
> snippet to add some new groups periodically.
>
>
> /*********************************************************** ********************
>
> * Copyright (c) 2007-2008 Peter Centgraf.
> * 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 :
> * Peter Centgraf - initial implementation
> ************************************************************ *******************/
>
> package com.neckdiagrams.instruments.ui.internal;
>
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.List;
>
> 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.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.nebula.jface.galleryviewer.GalleryTreeViewer;
> 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 Peter Centgraf
> * @since Dec 5, 2007
> */
> public class SnippetGalleryViewerTester {
>
> protected static class GalleryTestContentProvider implements
> ITreeContentProvider {
> // implements IStructuredContentProvider { // Use this to test
> // FlatTreeContentProvider
> public static final int NUM_GROUPS = 1;
> public static final int NUM_ITEMS = 9;
>
> List<String> groups = new ArrayList<String>();
> HashMap<String, List<String>> itemsByGroup = new HashMap<String,
> List<String>>();
>
> public GalleryTestContentProvider() {
> for (int i = 0; i < NUM_GROUPS; i++) {
> addNewGroup();
> }
> }
>
> public Object[] getChildren(Object parentElement) {
> return itemsByGroup.get(parentElement).toArray();
> }
>
> public Object getParent(Object element) {
> return null;
> }
>
> public boolean hasChildren(Object element) {
> return ((String) element).startsWith("Group");
> }
>
> public Object[] getElements(Object inputElement) {
> return groups.toArray();
> }
>
> public void dispose() {
> }
>
> public void inputChanged(Viewer viewer, Object oldInput, Object
> newInput) {
> }
>
> public void addNewGroup() {
> List<String> items = new ArrayList<String>();
> for (int j = 0; j < NUM_ITEMS; j++) {
> items.add("Item " + (j + 1));
> }
> final String group = "Group " + (groups.size() + 1);
> itemsByGroup.put(group, items);
> groups.add(group);
> }
> }
>
> 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 SnippetGalleryViewerTester() {
> // Initialize the containing Shell
> final Display display = new Display();
> shell = new Shell(display);
> shell.setSize(WIDTH, HEIGHT);
> shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
> GridLayoutFactory.fillDefaults().applyTo(shell);
>
> final GalleryTreeViewer viewer = new GalleryTreeViewer(shell);
> GridDataFactory.fillDefaults().grab(true,
> true).applyTo(viewer.getGallery());
> final GalleryTestContentProvider contentProvider = new
> GalleryTestContentProvider();
> viewer.setContentProvider(contentProvider);
> viewer.setLabelProvider(new GalleryTestLabelProvider());
> viewer.setComparator(new ViewerComparator());
> // viewer.addFilter(new OddNumbersFilter());
> viewer.setInput(new Object());
>
> // Show the Shell
> shell.open();
> shell.layout();
>
> final Runnable runnable = new Runnable() {
> public void run() {
> contentProvider.addNewGroup();
> viewer.refresh();
> if (contentProvider.groups.size() < 7)
> display.timerExec(3000, this);
> }
> };
> display.timerExec(3000, runnable);
>
> // Run the event loop
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> new SnippetGalleryViewerTester();
> }
>
> }
>
>
>
Re: [GalleryTreeViewer] New groups added via refresh() appear collapsed [message #592324 is a reply to message #59231] Wed, 24 September 2008 18:50 Go to previous message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Hi Justin,

I'll take a look at your snippet as soon as I get some free time. Until
then, please open a bug for this.

There are many changes from Peter that I need to commit so maybe the
problem is already solved.

--
Nicolas.

Justin a écrit :
> Here's an example demostrating this. I've just modified the existing
> snippet to add some new groups periodically.
>
>
> /*********************************************************** ********************
>
> * Copyright (c) 2007-2008 Peter Centgraf.
> * 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 :
> * Peter Centgraf - initial implementation
> ************************************************************ *******************/
>
> package com.neckdiagrams.instruments.ui.internal;
>
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.List;
>
> 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.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.nebula.jface.galleryviewer.GalleryTreeViewer;
> 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 Peter Centgraf
> * @since Dec 5, 2007
> */
> public class SnippetGalleryViewerTester {
>
> protected static class GalleryTestContentProvider implements
> ITreeContentProvider {
> // implements IStructuredContentProvider { // Use this to test
> // FlatTreeContentProvider
> public static final int NUM_GROUPS = 1;
> public static final int NUM_ITEMS = 9;
>
> List<String> groups = new ArrayList<String>();
> HashMap<String, List<String>> itemsByGroup = new HashMap<String,
> List<String>>();
>
> public GalleryTestContentProvider() {
> for (int i = 0; i < NUM_GROUPS; i++) {
> addNewGroup();
> }
> }
>
> public Object[] getChildren(Object parentElement) {
> return itemsByGroup.get(parentElement).toArray();
> }
>
> public Object getParent(Object element) {
> return null;
> }
>
> public boolean hasChildren(Object element) {
> return ((String) element).startsWith("Group");
> }
>
> public Object[] getElements(Object inputElement) {
> return groups.toArray();
> }
>
> public void dispose() {
> }
>
> public void inputChanged(Viewer viewer, Object oldInput, Object
> newInput) {
> }
>
> public void addNewGroup() {
> List<String> items = new ArrayList<String>();
> for (int j = 0; j < NUM_ITEMS; j++) {
> items.add("Item " + (j + 1));
> }
> final String group = "Group " + (groups.size() + 1);
> itemsByGroup.put(group, items);
> groups.add(group);
> }
> }
>
> 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 SnippetGalleryViewerTester() {
> // Initialize the containing Shell
> final Display display = new Display();
> shell = new Shell(display);
> shell.setSize(WIDTH, HEIGHT);
> shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
> GridLayoutFactory.fillDefaults().applyTo(shell);
>
> final GalleryTreeViewer viewer = new GalleryTreeViewer(shell);
> GridDataFactory.fillDefaults().grab(true,
> true).applyTo(viewer.getGallery());
> final GalleryTestContentProvider contentProvider = new
> GalleryTestContentProvider();
> viewer.setContentProvider(contentProvider);
> viewer.setLabelProvider(new GalleryTestLabelProvider());
> viewer.setComparator(new ViewerComparator());
> // viewer.addFilter(new OddNumbersFilter());
> viewer.setInput(new Object());
>
> // Show the Shell
> shell.open();
> shell.layout();
>
> final Runnable runnable = new Runnable() {
> public void run() {
> contentProvider.addNewGroup();
> viewer.refresh();
> if (contentProvider.groups.size() < 7)
> display.timerExec(3000, this);
> }
> };
> display.timerExec(3000, runnable);
>
> // Run the event loop
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> new SnippetGalleryViewerTester();
> }
>
> }
>
>
>
Re: [GalleryTreeViewer] New groups added via refresh() appear collapsed [message #592354 is a reply to message #59391] Fri, 26 September 2008 09:30 Go to previous message
Justin Dolezy is currently offline Justin DolezyFriend
Messages: 68
Registered: July 2009
Member
Salut Nicolas,

Bug raised: https://bugs.eclipse.org/bugs/show_bug.cgi?id=248700

Cheers,
Justin


Nicolas Richeton wrote:

> Hi Justin,

> I'll take a look at your snippet as soon as I get some free time. Until
> then, please open a bug for this.

> There are many changes from Peter that I need to commit so maybe the
> problem is already solved.

> --
> Nicolas.
Previous Topic:[Grid] DefaultCellRenderer and wordwrap
Next Topic:gantt charts synchronize
Goto Forum:
  


Current Time: Wed Nov 06 03:12:18 GMT 2024

Powered by FUDForum. Page generated in 0.04796 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top