Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-29-2008, 06:09 PM
xcallmejudasx's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Houston, TX & Flint, MI
Posts: 585
Rep Power: 2
xcallmejudasx is on a distinguished road
Send a message via AIM to xcallmejudasx
Default 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?
Code:
treeViewer.addSelectionChangedListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				IActionBars bars = getViewSite().getActionBars();
				   bars.getStatusLineManager().setMessage(treeViewer.getSelection().toString());
			}
		});
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-29-2008, 06:16 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-29-2008, 06:35 PM
xcallmejudasx's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Houston, TX & Flint, MI
Posts: 585
Rep Power: 2
xcallmejudasx is on a distinguished road
Send a message via AIM to xcallmejudasx
Default
It's from the IDE. Viewer is from
org.eclipse.jface.viewers.Viewer;

I changed the code to this
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");

			   
			       }
			   }
			});
This will not display Hello if nothing is selected but displays Test if anything is selected. I tried adding && instanceof Target but that didn't work so I tried event.getSource() instanceof Target but that also had no display.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-29-2008, 06:37 PM
xcallmejudasx's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Houston, TX & Flint, MI
Posts: 585
Rep Power: 2
xcallmejudasx is on a distinguished road
Send a message via AIM to xcallmejudasx
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-29-2008, 08:40 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
Sorry, I'm not familiar with your IDE or classes.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 10-29-2008, 10:32 PM
xcallmejudasx's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Houston, TX & Flint, MI
Posts: 585
Rep Power: 2
xcallmejudasx is on a distinguished road
Send a message via AIM to xcallmejudasx
Default
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.
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());
				   }
			   }
			});

Code:
defaultTarget1 = new Target("Dev","\\Home\\Default\\Dev");
defaultTarget2 = new Target("Stage", "\\Home\\Default\\Stage");
defaultTarget3 = new Target("Prod", "\\Home\\Default\\Prod");
The deepest objects are of type Target and each Target under a Server is given a display name and a directory. My issue is determining parent Server so that I can accurately get the directory attribute for the Target.

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)
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SelectionListener and DisposeListener Example Java Tip SWT 0 07-11-2008 05:47 PM
[SOLVED] Last line in JTextArea wont display Chris.Brown.SPE Advanced Java 5 04-11-2008 02:52 PM
Applet with scrolling status line Java Tip Java Tips 0 03-10-2008 03:53 PM
Display Line# and Column# in JSP loganathan.lakshmanan JavaServer Pages (JSP) and JSTL 3 01-17-2008 01:37 PM
Setting display in MIDlet Java Tip Java Tips 0 11-21-2007 12:49 PM


All times are GMT +2. The time now is 09:48 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org