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 Ross
Messages: 14
Registered: July 2009
Junior Member
Hi,

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.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
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());
viewer.addSelectionChangedListener(this);
}

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

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

setImage(data);
}

/**
* @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");
//shell.setImage(crmImage);

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
shell.open();
}

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.
viewer.getControl().setFocus();
}

/* (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();
getSelection(selection);
}

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

Thanks in advance,

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


Current Time: Mon Sep 15 02:14:02 GMT 2014

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

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