Results 1 to 6 of 6
- 10-29-2008, 05:09 PM #1
Setting up a selectionListener to display to a status line
I have this listener that I want to display the name of the object selected from the treeviewer and display it on the status line. It keeps saying
The method addSelectionChangedListener(ISelectionChangedListe ner) in the type Viewer is not applicable for the arguments (new SelectionAdapater(){})
and gives me the option to change the method to addPostSelectionChangedListener.
If I change it to that I get the same error except for type StructuredListener instead of Viewer. Eventually I'm going to have it display an attribute of the deepest object within the tree if it's selected and not display anything for higher tiered objects but if I can get this working I don't see a problem with doing that.
How can I get this code(or new code if this is wrong) to register my selection and display it?
Java Code:treeViewer.addSelectionChangedListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { IActionBars bars = getViewSite().getActionBars(); bars.getStatusLineManager().setMessage(treeViewer.getSelection().toString()); } });
- 10-29-2008, 05:16 PM #2
When you get error messages from the compiler, please copy and paste all of them without editting.
Or is that from your IDE?
What class libraries are you using? I don't see the class Viewer in the java API doc.
- 10-29-2008, 05:35 PM #3
It's from the IDE. Viewer is from
org.eclipse.jface.viewers.Viewer;
I changed the code to this
Java Code:final IActionBars bars = getViewSite().getActionBars(); // treeViewer.addSelectionChangedListener(new SelectionAdapter() { // public void widgetSelected(SelectionEvent event) { // bars.getStatusLineManager().setMessage(treeViewer.getSelection().toString()); // } // }); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if(event.getSelection().isEmpty()) { bars.getStatusLineManager().setMessage("Hello"); return; } if(event.getSelection() instanceof IStructuredSelection) { bars.getStatusLineManager().setMessage("Test"); } } });
- 10-29-2008, 05:37 PM #4
import org.eclipse.jface.viewers.ISelectionChangedListene r;
import org.eclipse.jface.viewers.IStructuredContentProvid er;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.Model;
import org.eclipse.ui.part.ViewPart;
those are all the libraries being used.
- 10-29-2008, 07:40 PM #5
Sorry, I'm not familiar with your IDE or classes.
- 10-29-2008, 09:32 PM #6
I've updated it and sorta cheated my way to get it to display my selection within the status line. I have "working" code that will display an attribute of the deepest object when selected. The issue is that it displays the default directory from the last Server object created from the initial setup. This is the code for that.
Java Code:treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { String testString = event.getSelection().toString().replace("[", "").replace("]",""); bars.getStatusLineManager().setMessage(testString); if(event.getSelection().isEmpty()){ bars.getStatusLineManager().setMessage("Empty"); } if(testString.equals(groups.Server.target1.getName())){ bars.getStatusLineManager().setMessage(groups.Server.target1.getDirectory()); System.out.println("Testing "+groups.Server.target1.getName()); } if(testString.equals(groups.Server.target2.getName())){ bars.getStatusLineManager().setMessage(groups.Server.target2.getDirectory()); System.out.println("Testing "+groups.Server.target2.getName()); } if(testString.equals(groups.Server.target3.getName())){ bars.getStatusLineManager().setMessage(groups.Server.target3.getDirectory()); System.out.println("Testing "+groups.Server.target3.getName()); } if(testString.equals(defaultTarget1.getName())){ bars.getStatusLineManager().setMessage(defaultTarget1.getDirectory()); } if(testString.equals(defaultTarget2.getName())){ bars.getStatusLineManager().setMessage(defaultTarget2.getDirectory()); } if(testString.equals(defaultTarget3.getName())){ bars.getStatusLineManager().setMessage(defaultTarget3.getDirectory()); } } });
Java Code:defaultTarget1 = new Target("Dev","\\Home\\Default\\Dev"); defaultTarget2 = new Target("Stage", "\\Home\\Default\\Stage"); defaultTarget3 = new Target("Prod", "\\Home\\Default\\Prod");
Sorry my questions are confusing I don't really know what to ask since I'm not sure exactly what I'm supposed to do to achieve the output(which I do know)
Similar Threads
-
SelectionListener and DisposeListener Example
By Java Tip in forum SWT TipsReplies: 0Last Post: 07-11-2008, 04:47 PM -
[SOLVED] Last line in JTextArea wont display
By Chris.Brown.SPE in forum Advanced JavaReplies: 5Last Post: 04-11-2008, 01:52 PM -
Applet with scrolling status line
By Java Tip in forum Java TipReplies: 0Last Post: 03-10-2008, 02:53 PM -
Display Line# and Column# in JSP
By loganathan.lakshmanan in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 01-17-2008, 12:37 PM -
Setting display in MIDlet
By Java Tip in forum Java TipReplies: 0Last Post: 11-21-2007, 11:49 AM
Bookmarks