Results 1 to 6 of 6
  1. #1
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    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?
    Java Code:
    treeViewer.addSelectionChangedListener(new SelectionAdapter() {
    			public void widgetSelected(SelectionEvent event) {
    				IActionBars bars = getViewSite().getActionBars();
    				   bars.getStatusLineManager().setMessage(treeViewer.getSelection().toString());
    			}
    		});

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    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.

  3. #3
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    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");
    
    			   
    			       }
    			   }
    			});
    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.

  4. #4
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    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.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    Sorry, I'm not familiar with your IDE or classes.

  6. #6
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    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.
    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");
    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)

Similar Threads

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •