Attaching Properties view to a custom XML Editor - eclipse

I have created a custom editor in eclipse plugin which shows a XML in Tree-Table(TreeViewer) format with couple of its attributes. For showing remaining attributes I am trying to tie it up with "Properties View", but not really able to make progress on it.
I went through similar question on SO like
How to handle property sheet from customized editor in eclipse plugin development? where it talk about make your viewer contribute to workbench selection and implementing an IPropertySource on object which is selected in editor.
In my case I am directly setting an document object in treeviewer input like below.
IFileEditorInput editorInput = (IFileEditorInput) getEditorInput();
IFile inputIFile = editorInput.getFile();
File f = new File(inputIFile.getLocation().toString());
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(f);
}
catch (SAXException | IOException | ParserConfigurationException e) {
e.printStackTrace();
}
//setting root element of doc as input
treeViewer.setInput(doc.getDocumentElement());
Now on what object should I implement an IPropertySource interface to contribute properties?
Let me know if I am going in right direction or missing something or doing it completely wrong.
Hope this make sense !!

When your selection provider fires a selection changed event the properties page will look at the new selection. If you are using a tree viewer as the provider the selection will be the current object from your tree content provider.
The properties view will try to get an IPropertySourceProvider from the selection. Your object can implement IPropertySourceProvider directly, or provide it view the IAdaptable interface or by using IAdapterFactory.
Once the view has the IPropertySourceProvier it will call the getPropertySource method. Your code must return an IPropertySource object - it is up to you to write this class.

Related

Visual Studio Code: How to add checkbox in view container

I've been searching non-stop for this on the documentation but haven't been able to find any sort of information. I would like to know how to add checkboxes in my custom view container, similar to the breakpoints' checkboxes.
You can simulate the checkbox by playing with the icon, create a new TreeItem with a different icon when clicked.
Somehow they have knowledge on where on the TreeItem you click.
Looking with the dev tools, it is an <input type="checkbox"/>.
This means that you can do more with TreeItems than the docs explain.
Looking at the source code the BreakpointView is not implemented with a TreeItemProvider, it extends the ViewPane class and uses some kind of templates to render an item. Beside a checkbox it is also possible to have a combobox (SelectBox class).
I have added a feature request (101175) to extend the vscode API so extension developers can write Views with ViewItems that have additional UI-Elements like the Breakpoint view.
You can do this in the proposed api: treeItemCheckbox in Insiders v1.72 now and since it is a fairly simple new api I suspect it will be released with Stable 1.72.
You can play with this now, see using the proposed apis.
Instead of extending TreeItem you will extend TreeItem2 (which extends TreeItem) if you want to use checkboxes. Here is some sample code I put together:
export class TreeTab extends vscode.TreeItem2 {
...
if (tab.isActive) {
this.iconPath = new vscode.ThemeIcon("arrow-small-right", new vscode.ThemeColor("tab.unfocusedActiveBackground"));
this.checkboxState = vscode.TreeItemCheckboxState.Checked;
// this.checkboxState = {state: vscode.TreeItemCheckboxState.Checked, tooltip: "my nifty checkbox tooltip"};
}
...
and elsewhere in your code if you want to detect when that checkbox is clicked/unclicked:
// use your TreeView variable instead of 'tabView'
// from this.tabView = vscode.window.createTreeView(...);
const checkBoxListener = this.tabView.onDidChangeCheckboxState(async event => {
// event = {item: Array(n)}, which TreeItem's checkbox was clicked and its state after clicking:0/1 = on/off
console.log(event);
});

Use eclipse GMF to create read only diagram

I followed the file system example http://gmfsamples.tuxfamily.org/wiki/doku.php?id=gmf_tutorial1
what I wanted to do is not using the generated editor with its palette.
I created a new plugin with one view and I wanted to create a diagram programatically inside this view to show for instance 2 objects connected with link
I came across this answer GMF display diagram example
but it didn't help me a lot.
in createPartControl of my view I did
#Override
public void createPartControl(Composite parent) {
DiagramGraphicalViewer viewer = new DiagramGraphicalViewer();
viewer.createControl(parent);
RootEditPart root = EditPartService.getInstance().createRootEditPart(diagram);
viewer.setRootEditPart(root);
viewer.setEditPartFactory(new EcoreEditPartProvider());
viewer.getControl().setBackground(ColorConstants.listBackground);
viewer.setContents(diagram);
}
as in the answer but I didn't know how to get that "diagram" variable
The easiest would be use the same GraphicalViewer for your view and the same diagram as well. Just get your DiagramEditPart from the viewer and call disableEditMode() on it. (Do the appropriate type casting if necessary).

Single select Tag in Touch UI

OOTB Tag has multi select functionality, Is it possible to create single select Tag in Touch UI? If yes, can you point me which js file I need to modify?
The cq:tags property is rendered by CUI.TagList widget that can be found within /etc/clientlibs/granite/coralui2/js/coral.js script.
Reading it you can learn that the widget raises itemadded event which might be helpful for you to handle the singular tag handling. An example function that can catch the event might be placed in any clientlibs that will be attached to the admin interface such as cq.authoring.dialog clientlib.
$('*[data-fieldname="./cq:tags"]').on('itemadded', function(ev, value) {
var el = $(ev.target),
div = el.siblings('div'),
input = div.find('input'),
button = div.find('button');
input.prop('disabled', true);
button.remove();
}
To have the fully functional flow you need to handle the itemremoved event as well and make the input field enabled again as well as add the button back to the widget.

How to get user's input from WicketStuff's TinyMCE

Pretty straight-forward question, but I can't find this anywhere. I'm using WicketStuff's TinyMCE to make a Rich Text Editor in my application, and can't find anywhere how to get the input from the text area. For brevity's sake, the following is a simplified version of the code I'm using.
private String input;
...
TinyMCESettings settings = new TinyMCESettings(TinyMCESettings.Theme.simple);
TextArea<String> textArea = new TextArea<String>("editor", new PropertyModel<String>(this, "input"));
textArea.add(new TinyMceBehavior(settings));
form.add(textArea);
Using this, I would expect the usual manner to simply use my String 'input' since it's set as the model. This always results in null as the model isn't being updated.
I tried using the auto-save plugin in case it was expecting the save button to be clicked (which doesn't update the model either), and neither worked. The only thing I've been able to do to get the user's input is to add a HiddenField, with a new model, and make a JavaScript call like
document.getElementById('hiddenField').value = tinyMCE.get('editor').getContent();
but this has led to other problems with trying to call the JS in the desired place and to get it to work properly. I feel this shouldn't be necessary anyways, as surely someone must have implemented a method to get the contents of the text area being used.
Any help would be greatly appreciated.
Thanks to a blog post at Nevermind Solutions, the way to get the model updated is to add the following JavaScript to the form's submitting button:
onclick="tinyMCE.triggerSave(true,true);"
My text area is inside a panel with the button outside of the panel, so it doesn't directly work for me. The trick was to add the JavaScript call to the button's onSubmit, move the logic into the onAfterSubmit, and to make the button MultiPart so that it could call the save trigger before doing the other logic associated to the model.
Hope this might help some others in the future.
You have to add a modifier to the submit button so that the model can update.
AjaxButton btnSubmit = new AjaxButton("btnSubmit", new Model()) {
#Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
doSomething();
}
};
btnSubmit.add(new TinyMceAjaxSubmitModifier());
Have a look here for more info

How to provide a custom component in the existing Web page Editor Palette

I want to add a new custom component in the Web page Editor Palete named "myHTMLComponent".
So, as soon as user opens any html page with WPE, myHTMLComponentM should be present there.
How can I do the needful, moreover this component will as well need to generate the code changes accordingly. How to achieve the desired result.
Is there any input I can get for this.
I already created standardmetadata tag, but what next!
Finally, I found the solution of the problem.
For adding new categories in the palette, we need to use pagedesignerextension in plugin.xml as following -
<extension
point="org.eclipse.jst.pagedesigner.pageDesignerExtension">
<paletteFactory
class="com.comp.myeditor.palette.CustomEditorPaletteFactory">
</paletteFactory>
</extension>
Where CustomEditorPaletteFactory will be extending AbstractPaletteFactory. Here in createPaletteRoot(), we can add our category.
public PaletteRoot createPaletteRoot(IEditorInput editorInput){
PaletteRoot paletteRoot = new PaletteRoot();
paletteRoot.add(createStandardComponents());
return paletteRoot;
//return null;
}
private static PaletteContainer createStandardComponents() {
PaletteDrawer componentsDrawer = new PaletteDrawer("CustomHTMLComponent");
TagToolPaletteEntry paletteEntry = new TagToolPaletteEntry(
new FormPaletteComponent(".....);
componentsDrawer.add(paletteEntry);
return componentsDrawer;
}
This will create the component category in the palette and we can add as many components as needed using the componentsdrawer.
For adding a new category in the existing one -
Add this in the constructor -
super();
this._paletteContext = PaletteItemManager.createPaletteContext(file);
this._manager = PaletteItemManager.getInstance(_paletteContext);
Then use Palette Grouping like this -
PaletteGroup controls = new PaletteGroup("CUST HTML");
super.add(controls);
ToolEntry tool = new SelectionToolEntry("CUST Cursor",
"Cursor DESCRIPTION");
controls.add(tool);
setDefaultEntry(tool);
//Custom Marquee
controls.add(new MarqueeToolEntry("Marquee", "Marquee Desc"));
controls.add(new PaletteSeparator());
//This class maintins or load all categories features
controls.add(new CustomComponentToolEntry("Custom Component", "Custom Component Descrition",
This really is a good start but I can't find any tutorial or book that get deeper in this matter. For instance, I don't want to replace the default palette but this code does with "new PaletteRoot()" and I lost my HTML tags. Also I want that my new custom components behave as HTML Tags using Drag and Drop, but I don't know how?????????
More Info:
I discovered this code, that was very helpful, whereas file come from ((FileEditorInput)editorInput).getFile()
PaletteRoot paletteRoot = DesignerPaletteRootFactory.createPaletteRoot(file);
This is very interesting topic and I think we are pioneer documenting this feature of eclipse. Here other good point, I want to personalize the tag... e.g. something similiar what I want to achieve is add a tag like "MY TRUEFALSE TAG" and then when is selected and place it in the HTML Designer, I want to become something like <select><option>YES</option><option>NO</option></select> and I guess that I can achieve it by doing something with the tagTransformOperation extension... if you know how to implement it, please let me know. also there is others extensions(tagConverterFactory, elValueResolver). I am guessing here! please I would like your help.
<extension point="org.eclipse.jst.pagedesigner.pageDesignerExtension">
<paletteFactory ...>
<tagTransformOperation id="plugin.tagTransformOperation1XXXXXX">...
SOLUTION?? (Chinese) -solved with tagConverterFactory
http://www.blogjava.net/reloadcn/archive/2007/11/08/webeditor1.html