diff options
author | Benoit Maggi | 2014-11-03 13:48:16 +0000 |
---|---|---|
committer | Benoit Maggi | 2014-11-06 09:18:18 +0000 |
commit | 6932fa267f6caabd97fdeb4c46d0f15816552e2a (patch) | |
tree | a9ba1e5d1e54b7de7e93c8d06d5d9765c20a28b3 | |
parent | 8237c87ab58c3811e6e056effabd24203f815d10 (diff) | |
download | org.eclipse.papyrus-6932fa267f6caabd97fdeb4c46d0f15816552e2a.tar.gz org.eclipse.papyrus-6932fa267f6caabd97fdeb4c46d0f15816552e2a.tar.xz org.eclipse.papyrus-6932fa267f6caabd97fdeb4c46d0f15816552e2a.zip |
Bug 449770 - [Palette Customization] cannot customize a palette for a
sysML Diagram
- fix the filtering mechanism so the custom palette waits for the
refid to be defineded to be loaded
Change-Id: I257cd3321e9a5ccf59465356c44a73e34df582e9
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
(cherry picked from commit 26ba32317e8f9d4411b1db117bc08b74f4bbb79d)
-rwxr-xr-x | plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/FilteringPaletteProvider.java | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/FilteringPaletteProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/FilteringPaletteProvider.java index 0d8ef98b01e..1644a7f6e9e 100755 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/FilteringPaletteProvider.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/FilteringPaletteProvider.java @@ -79,8 +79,19 @@ public class FilteringPaletteProvider implements IPaletteProvider { * Retrieve all elements of a palette contribution * */ - private static class WalkerPaletteContribution implements IPapyrusPaletteConstant { + private class WalkerPaletteContributionHelper implements IPapyrusPaletteConstant { + protected String field; + + /** + * Init the Helper with the field you want to extract the values. + * + */ + public WalkerPaletteContributionHelper(String field) { + this.field = field; + } + + /** * Retrieve all elements ID of the palette contributions * @@ -88,7 +99,7 @@ public class FilteringPaletteProvider implements IPaletteProvider { * the palette contributions * @return the list of palette nodes ID */ - public static List<String> getAllPaletteNodesID(NodeList contributions) { + public List<String> getAllPaletteNodesID(NodeList contributions) { List<String> paletteNodesID = new ArrayList<String>(); for (int i = 0; i < contributions.getLength(); i++) { Node node = contributions.item(i); @@ -106,7 +117,7 @@ public class FilteringPaletteProvider implements IPaletteProvider { * the node to parse * @return the list of palette nodes ID */ - private static List<String> walkDefinition(Node paletteDefinitionNode) { + private List<String> walkDefinition(Node paletteDefinitionNode) { List<String> paletteNodesID = new ArrayList<String>(); NodeList nodes = paletteDefinitionNode.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { @@ -125,40 +136,17 @@ public class FilteringPaletteProvider implements IPaletteProvider { * the node to parse * @return the list of palette nodes ID */ - private static List<String> walkContentNode(Node paletteContentNode) { + private List<String> walkContentNode(Node paletteContentNode) { List<String> paletteNodesID = new ArrayList<String>(); NodeList nodes = paletteContentNode.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); String name = node.getNodeName(); - String nodeID = null; - if (DRAWER.equals(name)) { - nodeID = node.getAttributes().getNamedItem(ID).getNodeValue(); - paletteNodesID.add(nodeID); - if (node.getChildNodes().getLength() > 0) { - paletteNodesID.addAll(walkContentNode(node)); - } - } else if (STACK.equals(name)) { - nodeID = node.getAttributes().getNamedItem(ID).getNodeValue(); - paletteNodesID.add(nodeID); - if (node.getChildNodes().getLength() > 0) { - paletteNodesID.addAll(walkContentNode(node)); - } - } else if (SEPARATOR.equals(name)) { - nodeID = node.getAttributes().getNamedItem(ID).getNodeValue(); - paletteNodesID.add(nodeID); - if (node.getChildNodes().getLength() > 0) { - paletteNodesID.addAll(walkContentNode(node)); + if (DRAWER.equals(name)|| STACK.equals(name) || SEPARATOR.equals(name) || TOOL.equals(name) || ASPECT_TOOL.equals(name)) { + Node namedItem = node.getAttributes().getNamedItem(field); + if (namedItem!= null){ + paletteNodesID.add(namedItem.getNodeValue()); } - } else if (TOOL.equals(name)) { - nodeID = node.getAttributes().getNamedItem(ID).getNodeValue(); - paletteNodesID.add(nodeID); - if (node.getChildNodes().getLength() > 0) { - paletteNodesID.addAll(walkContentNode(node)); - } - } else if (ASPECT_TOOL.equals(name)) { - nodeID = node.getAttributes().getNamedItem(ID).getNodeValue(); - paletteNodesID.add(nodeID); if (node.getChildNodes().getLength() > 0) { paletteNodesID.addAll(walkContentNode(node)); } @@ -267,11 +255,14 @@ public class FilteringPaletteProvider implements IPaletteProvider { CustomPaletteProvider provider = new CustomPaletteProvider(); provider.setContributions(paletteURI); contributions = provider.getContributions(); - List<String> nodesID = WalkerPaletteContribution.getAllPaletteNodesID(contributions); - + List<String> nodesID = (new WalkerPaletteContributionHelper(IPapyrusPaletteConstant.ID)).getAllPaletteNodesID(contributions); // verify if the elements (nodes) from the custom palette already contributed if (!isCustomPaletteContributed(predefinedEntries, nodesID)) { - provider.contributeToPalette(editor, content, root, predefinedEntries); + // verify if the extended elements (refids) from the custom palette are already contributed + List<String> refToolsID = (new WalkerPaletteContributionHelper(IPapyrusPaletteConstant.REF_TOOL_ID)).getAllPaletteNodesID(contributions); + if (isCustomPaletteContributed(predefinedEntries, refToolsID)){ + provider.contributeToPalette(editor, content, root, predefinedEntries); + } } } } |