Bug 282114 - enable snippet view to work with objects not only strings
Summary: enable snippet view to work with objects not only strings
Status: RESOLVED FIXED
Alias: None
Product: WTP Common Tools
Classification: WebTools
Component: Snippets Framework (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 enhancement (vote)
Target Milestone: 3.2 M4   Edit
Assignee: Nitin Dahyabhai CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2009-07-01 04:12 EDT by Dimitar Giormov CLA
Modified: 2009-11-12 00:07 EST (History)
3 users (show)

See Also:


Attachments
overview diagram (4.20 KB, image/png)
2009-07-01 04:12 EDT, Dimitar Giormov CLA
no flags Details
initial version of the core funcionality (44.86 KB, patch)
2009-07-08 03:40 EDT, Dimitar Giormov CLA
no flags Details | Diff
some junit tests (25.13 KB, patch)
2009-07-08 03:42 EDT, Dimitar Giormov CLA
no flags Details | Diff
added support for import export and delete of complex snippets (65.39 KB, patch)
2009-08-18 09:48 EDT, Dimitar Giormov CLA
no flags Details | Diff
adds snippets support for faces config xml navigation view (16.36 KB, patch)
2009-08-18 09:55 EDT, Dimitar Giormov CLA
no flags Details | Diff
modified and combined patches (100.97 KB, patch)
2009-09-01 17:53 EDT, Nitin Dahyabhai CLA
no flags Details | Diff
polished - java doc, removed snippet transfer, exception handling improved (104.67 KB, text/plain)
2009-09-08 09:05 EDT, Dimitar Giormov CLA
no flags Details
javadoc and disable of variables for provider based snippets (100.89 KB, patch)
2009-10-01 08:18 EDT, Dimitar Giormov CLA
no flags Details | Diff
updated the faces config implementation according to the latest patch (21.38 KB, patch)
2009-10-01 08:19 EDT, Dimitar Giormov CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitar Giormov CLA 2009-07-01 04:12:02 EDT
Created attachment 140573 [details]
overview diagram

The goal is enabling the end user to store snippets that are not text based and have some complex logic behind them.
Some examples are storing common JPA model, JSPs, Configurations that can be reused in several projects.

Current implementation is based only on text snippets, but in my opinion can be easily extended so it can cover any scenario.
The implementation should be also extensible, so different vendors can benefit from the snippets view in their proprietary solutions.

I have made initial overview diagram of the idea.
Comment 1 Nitin Dahyabhai CLA 2009-07-07 07:49:48 EDT
An explanation of the concrete user and plug-in developer scenarios would be useful, as it's already possible to do this as a plug-in developer using a custom insertion class and your own transfer type.  Exactly how an end-user would construct snippets employing more complicated logic is something I'm curious about.
Comment 2 Dimitar Giormov CLA 2009-07-07 08:57:46 EDT
I will try to explain in use cases:

Developer/End User: want to draw a diagram using Custom/Vendor specific GEF Editor for example and JPA Entity model. And the user wants to save this model as a snippet, so she can reuse it later in another project.

I know about the insert mechanism, but in this case it is not enough, since it is missing logic for storing in this case the JPA Model and logic to reproduce it on insert.

My idea is to have the snippet framework extensible so vendors (plugin developers) can write "Providers" that are able to deal with certain object from certain editor, and provide insert and save action.


The plugin developer should enable the user to work on certain editor with the snippets view.

The plugin developer should specify enablement and provider class in extension point. Enablement is for on which editor the provider will work.

The provider class should implement in my opinion 2 methods: 

one that will save additional content something like: IStatus saveAdditionalContent(IPath path)
and one that returns ISnippetInsertion class: ISnippetInsertion getSnippetInstertion()

I am working on a prototype separates current Text based logic in a TextSnippetProvider and creating JPA Entitties Provider, I can record a short video of what I have done till now.

I am trying to do this easy for the plugin developers and trasparent for the end users. So the plugin developers should implement save and insert.
End users will work with the snippets view in the same way they use it in text editors.
Comment 3 Dimitar Giormov CLA 2009-07-08 03:40:46 EDT
Created attachment 141047 [details]
initial version of the core funcionality

what is in the patch:
1. New Extension point for registering snippet providers.
2. Text based logic for insert and add to snippets is moved in TextSnippetProvider
3. Some manager classes are created to deal with extension points and applicability for the providers.
4. Providers have priorities similar to the ModelProviders.
5. SnippetTransfer based on ByteArrayTransfer is added for drag and drop.
6. New property is saved in the user model (id of the provider) - I am thinking of removing that if possible
7. Fallback to TextSnippetProvider if other provider fails.

Some info about the extension point
It has provider class that in most cases should extend AbstractSnippetProvider (ISnippetProvider is for greater freedom)
Priority - if more then one Provider is applicable for certain editor, the one with lowest priority will be chosen.
Enablement - based on org.eclipse.expressions on which editor is the current provider active.
Comment 4 Dimitar Giormov CLA 2009-07-08 03:42:24 EDT
Created attachment 141048 [details]
some junit tests

here are some junit test that are added to test the new functionality.
Comment 5 David Williams CLA 2009-08-04 11:26:37 EDT
Dimitar, or others, I know you said you'd want this for "...Custom/Vendor specific GEF Editor ..." but I'm curious if anything in WTP could or should take advantage addition? 

I partially ask out of pure curiosity, but also because it's harder to provide an API if we (WTP) do not actually make use of it. If we don't really make use of it, perhaps a small "example use" could be provided for one of the Graphical editors in WTP? 

[And, sorry if how to do that is obvious to others, or already included in JUnit tests ... I've just scanned over this bugzilla and that question came to my mind.] 

Thanks. 
Comment 6 Dimitar Giormov CLA 2009-08-05 03:54:50 EDT
Hi David,
Providing meaningful example in eclipse is our next step :)
I am currently researching some graphical editors that can take advantage of this functionality. And hopefully will have some basic implementation soon.
Comment 7 Dimitar Giormov CLA 2009-08-18 09:48:43 EDT
Created attachment 144819 [details]
added support for import export and delete of complex snippets
Comment 8 Dimitar Giormov CLA 2009-08-18 09:55:07 EDT
Created attachment 144823 [details]
adds snippets support for faces config xml navigation view

This is an example how the new functionality could be used.

Here in faces config xml one can add to snippets part of the navigation along with the jsps (using context menu).
the jsps then can be inserted in any other project. The jsps will be inserted in the same place they were taken and the navigation rules will be added to the xml.

(I did not have enough time to add DnD)
Comment 9 Kaloyan Raev CLA 2009-08-31 06:23:54 EDT
Nitin, did you have the time to review this contribution?

We hoped to have this in the WTP December 2009 release, but because it was canceled, David mentioned that it could be included as exception in the Galileo SR1 release. Before we can discuss this we need to have the provided patches reviewed.
Comment 10 Nitin Dahyabhai CLA 2009-08-31 14:28:32 EDT
(In reply to comment #9)
> We hoped to have this in the WTP December 2009 release, but because it was
> canceled, David mentioned that it could be included as exception in the Galileo
> SR1 release. Before we can discuss this we need to have the provided patches
> reviewed.

I think that needs discussion regardless of the patches being reviewed.
Comment 11 Nitin Dahyabhai CLA 2009-09-01 17:53:18 EDT
Created attachment 146236 [details]
modified and combined patches

Most of it looks alright to me, but I have a few questions and observations.

There's already a SnippetTransfer class used for clipboard operations; having another with the same name for use with drag and drop is confusing.  And is there a reason to use this for drag and drop instead of org.eclipse.jface.util.LocalSelectionTransfer?  I've left this as-is pending your thoughts.

There are opportunities for optimizing class-loading and plug-in activation that could be done through ID strings.  Most problematic here, for me, is org.eclipse.wst.common.snippets.internal.SnippetContributor.getPrio()--allowing extensions to return priorities invites abuse.  Was 0 made the highest priority to try in an attempt to avoid this?

The SnippetProvider extension point uses "impl" instead of the somewhat standardized "class".  I changed it.

Additionally, are there any provisions for cleaning up the storage area?  If a snippet is no longer contributed in a future release, its metadata content should go away cleanly.  And the new SnippetManager#moveFilesInStorageFolder(IPath, IPath[], IProject) and SnippetManager#moveFilesInWorkspace(File[], IProject, IPath) aren't used in the snippets plug-in or tests; they are better placed in the JSF extension plug-in.

I also fixed a few typos, expanded some abbreviated method names (e.g. I favor getPriority() over getPrio()), and moved the snippet storage into a subdirectory of the plug-in's state location.  org.eclipse.wst.common.snippets.core.ISnippetProvider will need documenting, and I think ISnippetProvider#isActionEnabled(ISelection) could use a name better fitting to something in a core package.

I'd also like you to review the edit permissions in the customizer dialog for the snippets that come from the providers; it may need to do a item.setSourceType(ISnippetsEntry.SNIPPET_SOURCE_PLUGINS) in AbstractSnippetProvider#createSnippetMetadata(PaletteEntry) before returning.
Comment 12 Dimitar Giormov CLA 2009-09-02 03:04:45 EDT
thanks for the feedback.

SnippetTransfer - I will see what I can do to improve the situation there.

Prio - I have specifically done this to avoid plugin activation, that is why the initialization of SnippetContributor is done in 2 steps. the idea is to have maximum flexibility and the consumers to be able to override the default behavior, in my opinion this is nice to have, but not essential. I can remove it.

About the cleaning up - there is a mechanism that deletes the generated additional content on remove of the snippet.

SnippetManager#moveFilesInStorageFolder are purely helper methods for the providers, I am reusing them in 2 snippets that I have prototyped, one is SAP specific. I think if they are a little bit polished, they will be in great help for the contributors.

All interface methods and the extension point will be documented.

ISnippetProvider#isActionEnabled(ISelection) could use a name better fitting to something in a core package - Agree I will research.

about the edit permissions in the customizer dialog - I will check.


I will get back to you when I address at least some of the issues
Comment 13 Dimitar Giormov CLA 2009-09-08 09:05:12 EDT
Created attachment 146652 [details]
polished - java doc, removed snippet transfer, exception handling improved

SnippetTransfer - removed only one remains,

Prio - left it unchanged if you wish I will remove it.

Provided documentation and javadoc.

ISnippetProvider#isActionEnabled(ISelection) could not find better place for it, since it is provider specific, every provider should state that the add to snippet action will be available or not (for example there is no selection of text)

about the edit permissions in the customizer dialog - looks OK users should be able to add additional information like variables about the snippet, that can be really handy, the only thing is the code snippet area that is currently not needed in some cases.
Comment 14 Nitin Dahyabhai CLA 2009-09-14 03:16:23 EDT
(In reply to comment #13)
> about the edit permissions in the customizer dialog - looks OK users should be
> able to add additional information like variables about the snippet, that can
> be really handy, the only thing is the code snippet area that is currently not
> needed in some cases.

I have to emphasize your last point and ask that they be disabled for anything having a provider other than the text one--unless we want to enforce that all providers have to support the variables.
Comment 15 Dimitar Giormov CLA 2009-09-24 03:45:11 EDT
From what I have imagined and tested variables are stored correctly no matter of the provider.
However as you said there is not much sense in allowing the user to add variables since this is hard to be predicted by the provider. I think the provider should be able to add variables and maybe supply default values. 

Another approach is that the provider can say if it allows additional variables to be add by the user.

Which approach do you think will be best?
Comment 16 Nitin Dahyabhai CLA 2009-09-30 23:39:29 EDT
(In reply to comment #15)
> However as you said there is not much sense in allowing the user to add
> variables since this is hard to be predicted by the provider. I think the
> provider should be able to add variables and maybe supply default values. 
> 
> Another approach is that the provider can say if it allows additional variables
> to be add by the user.
> 
> Which approach do you think will be best?

I think it's out of place being something asked of a provider by the framework.  If support for variables is there at all, it is an internal detail of the provider.  I would lean toward that being something internal and specific to the text provider.

Any further thoughts on enabling the provider to supply a Control to be shown in the customizer dialog?
Comment 17 Dimitar Giormov CLA 2009-10-01 03:22:31 EDT
In the last day, while I was working on this I realized that may be the best approach is to provide possibility for the SnippetProvider to supply UI for customize dialog, I think in this way we will be open for enhancement. The text provider will provide the VariableItemEditor.

What do you think?

One more think the snippet text area in customize dialog has a label Template Pattern, which is a bit confusing. Maybe only Template will be more appropriate?
Comment 18 Dimitar Giormov CLA 2009-10-01 08:18:53 EDT
Created attachment 148521 [details]
javadoc and disable of variables for provider based snippets

somehow I have lost some changes and attached wrong patch for javadoc and the fixes.
Here is the original fix for java doc and snippets transfer + changes for customize dialog.
Comment 19 Dimitar Giormov CLA 2009-10-01 08:19:54 EDT
Created attachment 148523 [details]
updated the faces config implementation according to the latest patch
Comment 20 Nitin Dahyabhai CLA 2009-10-07 19:06:38 EDT
(In reply to comment #17)
> In the last day, while I was working on this I realized that may be the best
> approach is to provide possibility for the SnippetProvider to supply UI for
> customize dialog, I think in this way we will be open for enhancement. The text
> provider will provide the VariableItemEditor.
> 
> What do you think?

I think that'd work well.

> One more think the snippet text area in customize dialog has a label Template
> Pattern, which is a bit confusing. Maybe only Template will be more
> appropriate?

Depends on where that string comes from.  Parts of the UI are inherited from the GEF superclass.
Comment 21 Dimitar Giormov CLA 2009-10-08 03:08:16 EDT
It is in a property file in the snippets plugin.
Comment 22 Dimitar Giormov CLA 2009-10-20 04:45:19 EDT
Nitin do we have something more to improve here?
Comment 23 Nitin Dahyabhai CLA 2009-10-26 15:42:19 EDT
No, I think we're good here.  I'm a little nervous about putting it in this week, though.  Early M4 ok?
Comment 24 Dimitar Giormov CLA 2009-10-27 04:57:01 EDT
sounds good. We can test it more thoroughly then.
Comment 25 Nitin Dahyabhai CLA 2009-10-27 11:06:49 EDT
I'd swear I've added an M4 target milestone and field value to Common twice now, but it's still not there.
Comment 26 Nitin Dahyabhai CLA 2009-11-12 00:07:58 EST
Released with the following changes from attachment 148521 [details]:
-extension schema's "priority" attribute is optional
-SnippetContributor#priority defaults to 100 (lowest) instead of zero
-plug-in version bumped up to 1.2.0
-AddToSnippetsEditorActionDelegate restores several (now deprecated) methods for binary compatibility
-"Template Pattern:" label in customizer dialog is now just "Template:"
-SnippetCustomizerDialog#copyInputStream(InputStream, OutputStream) made package protected instead of public
-SnippetCustomizerDialog#unzip(ZipFile, String) made package protected instead of public
-ISnippetProvider#getCustomSnippetEditor() is now ISnippetProvider#getSnippetEditor()

Thanks for all your work, Dimitar.