Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [ve-dev] Accessing Selected object in VE


Hi Rashmi,

The usual reason for the error you've got is that you're trying to do something that accesses the SWT subsystem and it isn't running on the display thread.  The way to usually code around this is to do something like

public void widgetSelected(SelectionEvent e){
  // This has to be in the Display thread because it's an SWT callback
  Display.getCurrent().asyncExec(new Runnable()){
    public void run(){
      // Do stuff here
    }
  }
}

The Display.asyncExec(Runnable) posts the runnable to run asynchronously on the Display thread, and syncExec does it synchronously.  Almost all of the time it's async exec you want.  

The VE has a nice helper that called EditPartRunnable that is useful because when you're doing stuff with edit parts (like selecting them) there is the possibility that things get de-activated between the time you post your request and it gets run, which will create some kind of race condition exception.  The code for EditPartRunnable is along the lines.

CDEUtilities.displayExec(getHost(), "KEY ONLY I USE" , new EditPartRunnable(getHost()) { //$NON-NLS-1$
  protected void doRun() {
    // Do stuff here
  }
});

The getHost() is the model object from the edit part (the IJavaInstance), and the String "KEY ONLY I USE" is just a unique identifier that means that if multiple requests are queued for the same model object and the same key then only one is executed.  This allows requests to be collapsed.

Best regards,

Joe Winchester

Please respond to Discussions people developing code for the Visual Editor project <ve-dev@xxxxxxxxxxx>

Sent by:        ve-dev-bounces@xxxxxxxxxxx

To:        "Discussions people developing code for the Visual Editor project" <ve-dev@xxxxxxxxxxx>
cc:        
Subject:        RE: [ve-dev] Accessing Selected object in VE


hi All,
  I have built a JTree(Swing )  to represent the uicomponent of Visual Editor using the EditParts retrived from TreeViewer of JavaVisualEditorPart .This tree is embedded in to a view.  On click of the tree node, I am retrieving the editpart stored in the tree node and trying to select the same on the JavaVisualEditorPart's TreeViewer. This event is raising the following exception.

org.eclipse.swt.SWTException: Invalid thread access
Can somebody help me in solving this?
Thanks and Regards
Rashmi H.Ramachandra

 



From: ve-dev-bounces@xxxxxxxxxxx [mailto:ve-dev-bounces@xxxxxxxxxxx] On Behalf Of H Ramachandra, Rashmi
Sent:
Thursday, 29 December 2005 12:09 PM
To:
Discussions people developing code for the Visual Editor project
Subject:
RE: [ve-dev] Accessing Selected object in VE


Hi Srimanth,
    Thanks for the input. I was able to assign a selection listener to the JavaVisualEditor. Its working fine. I can display the kind of object that is being selected by doing toString() to the selection object. Casting it to IJavaInstance provides with further functionalities. But I am unable to get the edit domain for the JavaVisualEditorPart as the required method ' getEditDomain()' does not seem to exist.
I want to loop through all the components from the root model to get to the component which i want it to be selected.
 
Can you please help me out.
 
Thank You and Regards
Rashmi H.Ramachandra
 
 


From: ve-dev-bounces@xxxxxxxxxxx [mailto:ve-dev-bounces@xxxxxxxxxxx] On Behalf Of Srimanth Gunturi
Sent:
Tuesday, 27 December 2005 10:54 PM
To:
Discussions people developing code for the Visual Editor project
Subject:
Re: [ve-dev] Accessing Selected object in VE



Hi Rashmi,


> how do I get the selected component on the visual editor canvas?

If you can get the EditorPart (JavaVisualEditorPart), you can add a listener to its site's page's selection provider -
       getSite().getPage().addSelectionListener(new ISelectionListener(){

               public void selectionChanged(IWorkbenchPart part, ISelection selection) {

                       System.out.println("Selection Changed!");

               }

       });


>
How do I get access to the root model
'JavaVisualEditorPart.getEditDomain().getDiagramData()' will give you the root model. You can cast it to the 'BeanSubclassComposition' class to access the this type, the components etc.

Or if you are coming from Codegen's model, 'IBeanDeclModel.getCompositionModel().getModelRoot()' should give you the 'BeanSubclassComposition' also.


> and the IJAvaInstance of the selected object.

When you get the GEF EditPart of the selected object as described above, just do a 'getModel()' on the EditPart to get the IJavaInstance.


Regards,

Sri.



"H Ramachandra, Rashmi" <rashmi.h.ramachandra@xxxxxxx>
Sent by: ve-dev-bounces@xxxxxxxxxxx

12/26/2005 11:40 PM

Please respond to
Discussions people developing code for the Visual Editor project


To
<ve-dev@xxxxxxxxxxx>
cc
Subject
[ve-dev] Accessing Selected object in VE







hi all,

how do I get the selected component on the visual editor canvas?

How do I get access to the root model and the IJAvaInstance of the selected object.
I have tried to go through source code of 'org.eclipse.ve.internal.java.codegen.editorpart.BeansList'

and 'org.eclipse.ve.internal.java.codegen.editorpart.JavaVisualEditorPart'. I am not able to find any entry point for accessing selected objects.

My requirement is to build a tree that partially replicates the JavaBean View to show both visual and non-visual components present in the java file in the form of a tree.Is there any API provided for developers to access the components in the visual editor. I have tried going through the current API and the source code available for tracking the JavaBean View components, but it has not been fruitful

Can anybody please help.
-rashmi
_______________________________________________
ve-dev mailing list
ve-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ve-dev_______________________________________________
ve-dev mailing list
ve-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ve-dev


Back to the top