Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-06-2008, 06:54 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 using instanceof to get Object type and parent type?
Is it possible to somehow && instanceof to check if the selected object is of type Target and is a child of type Asset. The issue is I have 2 editors for the same Object based on what type their parent is. Here is my listener
Code:
treeViewer.addOpenListener(new IOpenListener() {
			public void open(final OpenEvent event) {
				Object firstElement = ((IStructuredSelection)event.getSelection()).getFirstElement();
				if (firstElement instanceof Target){
					try {
						PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("NOVLayout.edittargetview");
					} catch (PartInitException e) {
						e.printStackTrace();
					}
					System.out.println("Open target editor");
				}
)};
I want it to be something along the lines of firstElement instanceof Target && firstElement.getParent() instanceof Asset
I'm not sure if I can do this though. Does the selected object have a way to know what type of node its parent is?
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-06-2008, 07:11 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
First try compiling it. Does it compile? Copy and post error message here. You will have to cast the Object to the type you want.
The compound if (a && b) should work. The shortcuted operand will skip the second test if the first one fails.
Otherwise break the statement up into multiple parts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-06-2008, 07:24 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 guess I don't need to worry about traveling the tree to get its parent. Just had to create 2 methods within my Target class that would return the server parent or the asset parent. Some casting and it works.
Code:
if (firstElement instanceof Target && (( (Target) firstElement).getAssetParent() instanceof Asset))

Eh that's what I get for over complicating things.
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
[SOLVED] Cast string type to int type GilaMonster New To Java 9 09-17-2008 11:43 AM
List views, a type of object Leprechaun New To Java 2 02-06-2008 04:07 AM
Need help with creating array of type object riz618 New To Java 3 01-29-2008 07:14 AM
Getting object type gapper New To Java 1 01-20-2008 09:49 AM
Creating object of Type Object class venkatv New To Java 3 07-17-2007 04:33 PM


All times are GMT +2. The time now is 03:32 PM.



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