Home » Eclipse Projects » Nebula » [GalleryTreeViewer] Now groups added via refresh() appear collapsed
| |
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 message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Justin Dolezy![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=justin.dolezy%40digital-software-technology.co.uk) 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 message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Nicolas Richeton![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=nicolas.richeton%40gmail.com) 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 message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Nicolas Richeton![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=nicolas.richeton%40gmail.com) 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 #592259 is a reply to message #59181] |
Fri, 19 September 2008 09:32 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Justin Dolezy![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=justin.dolezy%40digital-software-technology.co.uk) 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 Go to previous message](theme/Solstice/images/up.png) |
Nicolas Richeton![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=nicolas.richeton%40gmail.com) 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 Go to previous message](theme/Solstice/images/up.png) |
Nicolas Richeton![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=nicolas.richeton%40gmail.com) 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();
> }
>
> }
>
>
>
|
|
| |
Goto Forum:
Current Time: Wed Aug 28 02:35:06 GMT 2024
Powered by FUDForum. Page generated in 0.06246 seconds
|