Adding drag and drop support in a custom TreeView - visual-studio-code

I have successfully populated a TreeView via creating a TreeDataProvider and customized the icons and its collapse-able property. Now I want to be able to drag and drop its ViewItem(s) onto a WebView. There are unfortunately no samples for drag and drop. Reading through the TreeView source, ViewItem(s) are created in HeightMap.OnInsertItems() via the TreeView.createViewItem(), from the derived class.
The public TreeView.onInsertItem() would appear to be a great extension point, extending TreeView and onInsertItem() and capturing its ViewItem parameter. This Unfortunately, the creation of the concrete class, ExtHostTreeView, that is ultimately created, is buried in layers of private methods (createExtHostTreeViewer()).
Strangely, the ViewItem has a setter for draggable. However, how would you ever get a reference to the ViewItem to set it? If there is a way to do this please point me at an example. If there is not, I would be glad to fork and implement it. Leaving the existing onInsertItem and perhaps add an array of handlers to be added to with an addOnInsertItemListener() method? Or perhaps use RxJS?
There are so many places this could be used. You could drag template fragments into documents or code, DSL rules into a expert system, configuration file values into parameters or right hand values (generating the code to retrieve the value). Thank you for any assistance.

It seems that drag and drop in custom views is currently not supported. There's a (fairly popular) feature request for it here:
Add drag and drop for contributed tree views (#32592)

As of version 1.66 (March 2022) there is a TreeDragAndDropController which can be used for some drag & drop actions.
In April 2022, their sample focuses on drag & drop within a tree view: https://github.com/microsoft/vscode-extension-samples/blob/main/tree-view-sample/src/testViewDragAndDrop.ts
It is also possible to use the text/url-list type as described in the documentation to allow for dragging files to the editor panel: https://github.com/microsoft/vscode/blob/dc2f5d8dd1790ac4fc6054e11b44e36884caa4be/src/vscode-dts/vscode.d.ts#L9843-L9859
It is not clear to me yet whether it is possible to drag arbitrary data to webviews or to use standard HTML5 drag & drop API in a webview to allow dragging data to a custom tree view.

Related

How do I customize cursor in MRTK?

I'm struggling to find documentation on cursor customization in MRTK. Consider a plain simple scenario - I want custom cursor when I focus on certain object in the scene.
If you look into this official sample -- EyeTracking, the visual effects of the “cursor” when a user is looking at an object is simply switching the state of the background object (enable/disable). You may refer to the sample to customize the visual effects.
EyeTracking sample is not of much help, MRTK in fact does not provide available tools to customize cursor visuals. I see two options available:
Implement custom BaseCursor similarly to how e.g. AnimatedCursor is implemented and create your own context info class similarly to how CursorContextInfo is done. This is how MRTK modifies cursor when focusing on resize and scale handles.
Modify available pointer prefab, add your custom visuals into it and add a custom singleton script there. Use available focus on/off events on your content objects to modify cursor via singleton methods.

Drag & drop in custom tree view [duplicate]

I have successfully populated a TreeView via creating a TreeDataProvider and customized the icons and its collapse-able property. Now I want to be able to drag and drop its ViewItem(s) onto a WebView. There are unfortunately no samples for drag and drop. Reading through the TreeView source, ViewItem(s) are created in HeightMap.OnInsertItems() via the TreeView.createViewItem(), from the derived class.
The public TreeView.onInsertItem() would appear to be a great extension point, extending TreeView and onInsertItem() and capturing its ViewItem parameter. This Unfortunately, the creation of the concrete class, ExtHostTreeView, that is ultimately created, is buried in layers of private methods (createExtHostTreeViewer()).
Strangely, the ViewItem has a setter for draggable. However, how would you ever get a reference to the ViewItem to set it? If there is a way to do this please point me at an example. If there is not, I would be glad to fork and implement it. Leaving the existing onInsertItem and perhaps add an array of handlers to be added to with an addOnInsertItemListener() method? Or perhaps use RxJS?
There are so many places this could be used. You could drag template fragments into documents or code, DSL rules into a expert system, configuration file values into parameters or right hand values (generating the code to retrieve the value). Thank you for any assistance.
It seems that drag and drop in custom views is currently not supported. There's a (fairly popular) feature request for it here:
Add drag and drop for contributed tree views (#32592)
As of version 1.66 (March 2022) there is a TreeDragAndDropController which can be used for some drag & drop actions.
In April 2022, their sample focuses on drag & drop within a tree view: https://github.com/microsoft/vscode-extension-samples/blob/main/tree-view-sample/src/testViewDragAndDrop.ts
It is also possible to use the text/url-list type as described in the documentation to allow for dragging files to the editor panel: https://github.com/microsoft/vscode/blob/dc2f5d8dd1790ac4fc6054e11b44e36884caa4be/src/vscode-dts/vscode.d.ts#L9843-L9859
It is not clear to me yet whether it is possible to drag arbitrary data to webviews or to use standard HTML5 drag & drop API in a webview to allow dragging data to a custom tree view.

How to add an Eclipse CompareEditor inside a View?

How can I open an Eclipse CompareEditor inside a View?
More specifically, I want the view to contain a SashForm. In the left sash I put some information about the commit, and in the right sash I want to put a compare editor that compares the commit to its parent. Is there such a thing even possible?
I've succeeded in using a GitCompareEditorInput from eGit and the CompareUI class to open a separate compare editor or a dialog with the compare editor (that compares a certain commit to its parent). But now I am interested in putting that compare editor inside another view, as detailed above.
Thanks
Update:
I have tried CompareEditorInput.createContents(compositeParent) but I only get two empty rectangles.
The key to hosting a CompareEditorInput class appears to be providing a class which implements org.eclipse.compare.ICompareContainer. Once you have this you connect it to the input using CompareEditorInput.setContainer(container).
org.eclipse.compare.internal.CompareContainer provides a partial implementation of the container but this is internal so should only be used as a guide rather than used directly.

GWT Editors for readonly and edit mode

GWT's Editor framework is really handy and it can not only be used for editing POJOs but also for read-only display.
However I am not entirely sure what the best practice is for doing inline edits.
Let's assume I have a PersonProxy and I have one Presenter-View pair for displaying and editing the PersonProxy. This Presenter-View should by default display the PersonProxy in read-only mode and if the user presses on a edit button it should allow the user to edit the PersonProxy object.
The solution I came up with was to create two Editors (PersonEditEditor and PersonDisplayEditor) that both added via UiBinder to the View. The PersonEditEditor contains
ValueBoxEditorDecorators and the PersonDisplayEditor contains normal Labels.
Initially I display the PersonDisplayEditor and hide PersonEditEditor.
In the View I create two RequestFactoryEditorDriver for each Editor and make it accessable from the Presenter via the View interface. I also define a setState() method in the View interface.
When the Presenter is displayed for the first time I call PersonDisplayDriver.display() and setState(DISPLAYING).
When the user clicks on the Edit button I call PersonEditDriver.edit() and setState(EDITING) from my Presenter.
setState(EDITING) will hide the PersonDisplayEditor and make the PersonEditEditor visible.
I am not sure if this is the best approach. If not what's the recommended approach for doing inline edits? What's the best way to do unit-testing on the Editors?
If you can afford developing 2 distinct views, then go with it, it gives you the most flexibility.
What we did in our app, where we couldn't afford the cost of developing and maintaining two views, was to bake the two states down into our editors, e.g. a custom component that can be either a label or a text box (in most cases, we simply set the text box to read-only and applied some styling to hide the box borders).
To detect which mode we're in, because we use RequestFactoryEditorDriver (like you do), we have our editors implement HasRequestContext: receiving a null value here means the driver's display() method was used, so we're in read-only mode. An alternative would be to use an EditorVisitor along with some HasReadOnly interface (which BTW is exactly what RequestFactoryEditorDriver does to pass the RequestContext down to HasRequestContext editors).
Yes,Presenter-View pair should be. But Here two ways to achieve this feature if you like to go with:
1) Integrate Edit/View code design in one ui.xml i.e.Edit code in EDitHorizonatlPanel and View code in ViewHorizontalPanel.The panel has different id. By using id, show/hide panel with display method. if getView().setState() ==Displaying then show ViewHorizontalPanel and if getView().setState()==Editing then show EditHorizontalPanel.
2) Instead of using labels, Use textboxes only. set Enable property is false when you need it in view mode otherwise true
You have created two Presenter/view but I think if Edit/View function has similar code so no need to rewrite similar code again and again for view purpose.
If a big project has so many Edit/View function and you will create such type of multiple View/Presenter than your project size become so huge unnecessary.
I think that whatever I have suggest that might be not good approach but a way should be find out which help to avoid code replication.

Eclipse Plug-in / View Question

I have a plugin which contains class A that brings up a view defined in class B via the following line of code:
(VideoLogView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("Videolog.VideoLogView");
What I need to do in the createPartControl() method of the view (class B object) is access a method in the class A object.
How can this be done?
Thanks.
Look like you are facing the classic issue of "how do I pass arguments to my view" ?
This thread illustrates it best:
I was facing the same problem at the beggining of my RCP project. I was getting weird about the fact that there was no way to pass an argument to a view as the viewed model.
Why? Because (emphasis mine):
You are on an opened, pluggable platform.
You contribute to existing developments, others should be able to contribute to yours.
Therefore you will not "pass" arguments to a view, this would lock the whole thing into a non-opened design.
Instead, your view will ask the platform (or will listen to the platform) to determine which information to manage.
Other views (from other plugins that don't yet exist) might also want to manage the same information on the same event.
What you should do then is to ask the workbench for the current selection. I guess your view is opening on a double click action or simple selection so the object you want to manage in your view will be currently selected.
This is how you could retrieve the workbench selection from your view :
ISelection s = this.getSite().getWorkbenchWindow().getSelectionService().getSelection();
where "this" is a ViewPart.
Then you have to make your initial view (the one initiating the view creation from a given event like DoubleClick) a selection provider. A JFace viewer is a selection provider, so you can use it if you're using jface, or you can implement the ISelectionProvider interface when you're using custom SWT controls (that was my case).
The article "Eclipse Workbench: Using the Selection Service" can also give you some pointers.