Results 1 to 3 of 3
- 11-06-2008, 05:54 PM #1
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
I want it to be something along the lines of firstElement instanceof Target && firstElement.getParent() instanceof AssetJava 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'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?
- 11-06-2008, 06:11 PM #2
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.
- 11-06-2008, 06:24 PM #3
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.
Java Code:if (firstElement instanceof Target && (( (Target) firstElement).getAssetParent() instanceof Asset))
Eh that's what I get for over complicating things.
Similar Threads
-
[SOLVED] Cast string type to int type
By GilaMonster in forum New To JavaReplies: 9Last Post: 09-17-2008, 10:43 AM -
List views, a type of object
By Leprechaun in forum New To JavaReplies: 2Last Post: 02-06-2008, 03:07 AM -
Need help with creating array of type object
By riz618 in forum New To JavaReplies: 3Last Post: 01-29-2008, 06:14 AM -
Getting object type
By gapper in forum New To JavaReplies: 1Last Post: 01-20-2008, 08:49 AM -
Creating object of Type Object class
By venkatv in forum New To JavaReplies: 3Last Post: 07-17-2007, 03:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks