Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » ListViewer only instantiated once visible on perspective
ListViewer only instantiated once visible on perspective [message #431333] Wed, 10 March 2004 19:56
Ross is currently offline RossFriend
Messages: 14
Registered: July 2009
Junior Member

I have created an editor, two views and a perspective plugin. The user can
choose to add something to the ListViewer, which is on one of the views.
My two view are part of a folder in the perspective. The problem is when
the view with the ListViewer is at the back, when the user chooses to add
something to it, the viewer is null. However, if the viewer is visible. It
works fine. How do I instantiate the ListViewer without having to have it
visible? Heres my code:

* Created on 19-Nov-2003
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
package org.eclipse.view.crm;

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.SelectionChangedEvent;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.ui.part.ViewPart;

import java.util.StringTokenizer;

* @author res
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
public class crmView extends ViewPart implements ISelectionChangedListener
static ListViewer viewer;
Display display = Display.getCurrent();
Image pictureImage;

public crmView() {

public void createPartControl(Composite parent) {
Label label = new Label(parent, SWT.WRAP);
label.setText("Campaign Trail: ");

viewer = new ListViewer(parent);
viewer.setLabelProvider(new LabelProvider());

public static void addToViewer(String file, String selectedPath) {
viewer.setData(file, selectedPath);

public void getSelection(String selection) {
StringTokenizer tokens = new StringTokenizer(selection, "[]"); //
tokenize selection [ selected ]
String select = tokens.nextToken(); // get the first token
String data = (String) viewer.getData(select); // gets the full
path for the image


* @param data
private void setImage(String data) {
// TODO Auto-generated method stub
final Image image = new Image(display, data);

Shell shell = new Shell(display);
shell.setText("CRM Developer - Campaign Link");
shell.setLayout(new FillLayout());
//Image crmImage = new Image(display, "CRMInfo.gif");

Group group = new Group(shell, SWT.NONE);
group.setLayout(new FillLayout());
group.setText("Campaign Link");

Canvas canvas = new Canvas(group, SWT.NONE);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.drawImage(image, 0, 0);

Rectangle shellRect = shell.getBounds();
Rectangle displayRect = display.getBounds();
int x = (displayRect.width - shellRect.width) / 2;
int y = (displayRect.height - shellRect.height) / 2;
shell.setSize(640, 450);
shell.setLocation(x, y); // sets the location centrally;

public void setFocus() {
// set focus to my widget. For a label, this doesn't
// make much sense, but for more complex sets of widgets
// you would decide which one gets the focus.

/* (non-Javadoc)
* @see
org.eclipse.jface.viewers.ISelectionChangedListener#selectio nChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
public void selectionChanged(SelectionChangedEvent e) {
String selection = viewer.getSelection().toString();

/*public static void deleteViewer() {
// TODO Auto-generated method stub

Thanks in advance,

Previous Topic:ListViewer only instantiated once visible on perspective
Next Topic:ListViewer only instantiated once visible on perspective
Goto Forum:

Current Time: Thu Jun 21 16:42:33 GMT 2018

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

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

Back to the top