Home » Eclipse Projects » Advanced Scripting Environment (EASE) » Problems with the new EASE script metadata
Problems with the new EASE script metadata [message #1690013] |
Sun, 21 December 2014 05:14 |
Nicolas Rouquette Messages: 157 Registered: July 2009 |
Senior Member |
|
|
Due to recent refactoring of the EASE Core plugins, the EASE script metadata format has changed.
Before, we had something like this:
/*
* Menu: Examples > Modeling > UML > Show all classes (java)
* License: EDL 1.0
* VisibleWhen:[And {
* With activeEditor {
* Equal "org.eclipse.papyrus.infra.core.papyrusEditor"
* },
* With selection {
* Iterable {
* AdaptTo "org.eclipse.emf.ecore.EObject"{
* InstanceOf "org.eclipse.uml2.uml.Namespace"
* }
* }
* }
* }]
* Description: {This script finds and prints all the UML classes contained inside the selected element, directly or indirectly.}
*/
...
This old format is still used in the modeling examples.
The new format is different.
There is some description here: https://wiki.eclipse.org/EASE/Scripts
However, it seems that we've lost a couple of things in this refactoring:
1) we used to be able to specify a menu path with ">" as a path segment separator.
With the new code, it seems that the intention is to use something that
can be parsed as an Eclipse IPath -- i.e., using "/" as a path segment separator.
2) The old format used the Eclipse Expression XML syntax for specifying enabling logic. The wiki page only mentions "enableFor(<metaclass>)" as an example.
It is completely unclear to me what kind of things we can specify in the new tags,
particularly 'popup', 'toolbar' and 'menu'
For example, where is this "enableFor(...)" defined? I can't find it in the doc:
http://help.eclipse.org/luna/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/workbench_cmd_expressions.htm
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_core_expressions_definitions.html
I really liked the old mechanism where we could use any Eclipse XML Expression.
At least, there was documentation for what we can do we it but now, it's unclear.
I managed to restore the functionality of the menu paths (1) with the following patch.
diff --git a/plugins/org.eclipse.ease.ui/src/org/eclipse/ease/ui/scripts/repository/impl/ScriptContributionFactory.java b/plugins/org.eclipse.ease.ui/src/org/eclipse/ease/ui/scripts/repository/impl/ScriptContributionFactory.java
index 5faca4e..e0dbdee 100644
--- a/plugins/org.eclipse.ease.ui/src/org/eclipse/ease/ui/scripts/repository/impl/ScriptContributionFactory.java
+++ b/plugins/org.eclipse.ease.ui/src/org/eclipse/ease/ui/scripts/repository/impl/ScriptContributionFactory.java
@@ -11,9 +11,14 @@
package org.eclipse.ease.ui.scripts.repository.impl;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.ease.ui.repository.IScript;
+import org.eclipse.ease.ui.scripts.ui.ScriptPopup;
+import org.eclipse.ease.ui.scripts.ui.ScriptPopupMenu;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.MenuManager;
@@ -57,16 +62,51 @@ public class ScriptContributionFactory extends AbstractContributionFactory {
}
}
- if (getLocation().endsWith(UIIntegrationJob.POPUP_LOCATION)) {
- for (IScript script : fScripts)
- additions.addContributionItem(new ScriptContributionItem(script, script.getParameters().get("popup")), null);
+ // adapted from org.eclipse.ease.ui.scripts.ScriptContributionFactory.getContributionItems()
+ final Map<IPath, ScriptPopupMenu> dynamicMenus = new HashMap<IPath, ScriptPopupMenu>();
+ List<IContributionItem> rootItems = new ArrayList<IContributionItem>();
- } else {
- for (IScript script : fScripts)
- additions.addContributionItem(new ScriptContributionItem(script), null);
+ for (final IScript script : fScripts) {
+ final ScriptPopup popup = new ScriptPopup(script);
+
+ final IPath path = script.getPath().removeLastSegments(1);
+ if (path.lastSegment() == null) {
+ // script in root folder
+ rootItems.add(popup.getContribution(serviceLocator));
+
+ } else {
+ // script in sub menu
+ ScriptPopupMenu menu = registerPath(dynamicMenus, path);
+ menu.addItem(popup);
+ }
}
+
+ // add root menus to additions
+ for (IPath path : dynamicMenus.keySet()) {
+ if (path.segmentCount() == 1)
+ additions.addContributionItem(dynamicMenus.get(path).getContribution(serviceLocator), null);
+ }
+
+ // add root elements to additions
+ for (IContributionItem item : rootItems)
+ additions.addContributionItem(item, null);
}
+ // @see org.eclipse.ease.ui.scripts.ScriptContributionFactory.registerPath(Map<IPath, ScriptPopupMenu>, IPath)
+ private static ScriptPopupMenu registerPath(final Map<IPath, ScriptPopupMenu> dynamicMenus, final IPath path) {
+ if (!dynamicMenus.containsKey(path)) {
+ dynamicMenus.put(path, new ScriptPopupMenu(path.lastSegment()));
+
+ if (path.segmentCount() > 1) {
+ IPath parent = path.removeLastSegments(1);
+ ScriptPopupMenu parentMenu = registerPath(dynamicMenus, parent);
+ parentMenu.addItem(dynamicMenus.get(path));
+ }
+ }
+
+ return dynamicMenus.get(path);
+ }
+
public void addScript(final IScript script) {
fScripts.add(script);
}
At least, we can get popup menus in the right place. E.g:
/*
* name: OMG/Tool Infrastructure/Compute Package-extent xmi:IDs
* popup: enabledFor(org.eclipse.uml2.uml.Model)
* description: This script shows the computed XMI ID per OMG's Tool Infrastructure algorithm for all the elements in the scope of the selected Package.
*/
However, the 'enabledFor(...)' criteria is not effective.
In fact, this popup menu shows up everywhere.
Is the refactoring perhaps incomplete with respect to the enabling logic of EASE scripts and the configuration of menus (toolbar, popups, ..)?
- Nicolas.
|
|
|
Re: Problems with the new EASE script metadata [message #1690017 is a reply to message #1690013] |
Sun, 21 December 2014 20:48 |
Christian Pontesegger Messages: 250 Registered: July 2009 Location: Graz, Austria |
Senior Member |
|
|
Quote:
> 1) we used to be able to specify a menu path with ">" as a path segment separator.
>
> With the new code, it seems that the intention is to use something that
> can be parsed as an Eclipse IPath -- i.e., using "/" as a path segment separator.
You are right. Refactored this part, as it simpler to parse using IPath elements.
Quote:
> 2) The old format used the Eclipse Expression XML syntax for specifying enabling logic. The wiki page only mentions "enableFor(<metaclass>)" as an example.
There was an interesting discussion on this topic at the last eclipseCon. It seemed that there was no interest in extended expressions. Mostly because the way to define them was way too complicated for most users. So in the current implementation it got replaced by the much simpler enabledFor(class.name) expression. There is nothing else you could define here, so I see your point that this is too general for your usecase. I would love to continue this topic on the mailing list to get more feedback on the required functionality. We also will need a simpler way to define more complex expressions.
Quote:
> It is completely unclear to me what kind of things we can specify in the new tags,
> particularly 'popup', 'toolbar' and 'menu'
I guess you found out about popup: by yourself. toolbar: and menu: allow to add a dynamic toolbar or menu item to a dedicated view by providing either the viewID or the view title as a parameter. See http://codeandme.blogspot.co.at/2014/12/ease-scripts-conquer-ui.html for an example.
Quote:
> I managed to restore the functionality of the menu paths (1) with the following patch.
Thanks, could you provide it via gerrit? We are not allowed to accept patches in the forums.
Quote:
> Is the refactoring perhaps incomplete with respect to the enabling logic of EASE scripts and the configuration of menus (toolbar, popups, ..)?
The extension of the UI integration is not complete yet. For example I am not sure yet if a script using submenus in its name (like my/sub/folder/script) has to use the same structure when added to a popup or view menu. So eventually these keywords will allow for additional names.
In the future scripts should also allow to bind to the main menu. Here the naming will very likely be different to that of the 'name' keyword.
|
|
| |
Goto Forum:
Current Time: Mon Oct 07 20:32:19 GMT 2024
Powered by FUDForum. Page generated in 0.03007 seconds
|