From 3b812157cea7df82e268138d80eb8e109a098cb7 Mon Sep 17 00:00:00 2001 From: John Steele Date: Wed, 21 Jul 2021 16:54:39 -0700 Subject: [PATCH] Open rulesets w/in default xml editor. --- .../rules/OpenRuleDefinitionHandler.java | 2 +- .../ui/internal/rules/RuleRepositoryView.java | 7 ++-- .../ui/internal/rules/RulesetEditor.java | 2 + .../rules/xml/XMLRulesetModelUtil.java | 41 ++++++++++++++++++- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/OpenRuleDefinitionHandler.java b/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/OpenRuleDefinitionHandler.java index 3f129d5c..10f18a6b 100644 --- a/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/OpenRuleDefinitionHandler.java +++ b/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/OpenRuleDefinitionHandler.java @@ -56,7 +56,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { Pair pair = XMLRulesetModelUtil.findRuleProvider( ruleId, executionBuilder.getSystemRuleProviderRegistry(), modelService); if (pair != null) { - XMLRulesetModelUtil.openRuleInEditor(pair.getFirst(), pair.getSecond(), RulesetEditor.ID); + XMLRulesetModelUtil.openRuleInEditor(pair.getFirst(), pair.getSecond(), RulesetEditor.XML_EDITOR); } } catch (RemoteException e) { WindupUIPlugin.log(e); diff --git a/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/RuleRepositoryView.java b/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/RuleRepositoryView.java index 428ec08e..68f09f46 100644 --- a/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/RuleRepositoryView.java +++ b/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/RuleRepositoryView.java @@ -127,8 +127,8 @@ public void doubleClick(DoubleClickEvent event) { if (element instanceof RulesetFileNode) { RulesetFileNode node = (RulesetFileNode)element; if (node.getRuleProvider() != null) { -// XMLRulesetModelUtil.openRuleInEditor(node.getRuleProvider(), null, "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"); - XMLRulesetModelUtil.openRuleInEditor(node.getRuleProvider(), null, RulesetEditor.ID); + XMLRulesetModelUtil.openRuleInEditor(node.getRuleProvider(), null, RulesetEditor.XML_EDITOR); + // XMLRulesetModelUtil.openRuleInEditor(node.getRuleProvider(), null, RulesetEditor.ID); } /*IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(node.getFile().getParent())); fileStore = fileStore.getChild(node.getName()); @@ -149,7 +149,8 @@ else if (element instanceof Node) { Node node = (Node)element; Object provider = contentProvider.getProvider(node); if (provider != null) { - XMLRulesetModelUtil.openRuleInEditor(provider, node, RulesetEditor.ID); + XMLRulesetModelUtil.openRuleInEditor(provider, null, RulesetEditor.XML_EDITOR); + // XMLRulesetModelUtil.openRuleInEditor(provider, node, RulesetEditor.ID); } } } diff --git a/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/RulesetEditor.java b/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/RulesetEditor.java index a3f8e587..d1366ef2 100644 --- a/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/RulesetEditor.java +++ b/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/RulesetEditor.java @@ -48,6 +48,8 @@ public class RulesetEditor { private static final String SASH_LEFT = "weightLeft"; //$NON-NLS-1$ private static final String SASH_RIGHT = "weightRight"; //$NON-NLS-1$ + + public static final String XML_EDITOR = "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"; //$NON-NLS-1$ private static final int SASH_LEFT_DEFAULT = 238; private static final int SASH_RIGHT_DEFAULT = 685; diff --git a/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/xml/XMLRulesetModelUtil.java b/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/xml/XMLRulesetModelUtil.java index 7a8c929b..b485cd56 100644 --- a/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/xml/XMLRulesetModelUtil.java +++ b/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/xml/XMLRulesetModelUtil.java @@ -63,6 +63,7 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.jboss.tools.windup.ui.internal.rules.RulesetEditor; import com.google.common.base.Objects; import com.google.common.collect.Lists; @@ -105,6 +106,7 @@ public static IFile createLinkedResource(String location) { try { op1.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell)); } catch (final ExecutionException e) { + e.printStackTrace(); WindupUIPlugin.log(e); } }; @@ -217,17 +219,52 @@ public static IDOMModel getModel(IFile file, boolean edit) { return (IDOMModel) model; } } catch (IOException | CoreException e) { + e.printStackTrace(); WindupUIPlugin.log(e); } return null; } - public static void openRuleInEditor(Object provider, Node ruleNode) { + public static void openSystemRuleInEditor(Object provider, Node ruleNode) { IFile file = XMLRulesetModelUtil.getRuleset(provider); if (file != null && file.exists()) { try { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IEditorPart editor = IDE.openEditor(page, file); +// IEditorPart editor = IDE.openEditor(page, file); + IEditorPart editor = IDE.openEditor(page, file, RulesetEditor.XML_EDITOR); + if (editor != null && ruleNode != null) { + if (editor instanceof RulesetEditorWrapper) { + ((RulesetEditorWrapper)editor).selectAndReveal((Element)ruleNode); + } + else { + editor.getSite().getSelectionProvider().setSelection(new StructuredSelection(ruleNode)); + ITextEditor textEditor = editor.getAdapter(ITextEditor.class); + if (ruleNode instanceof IndexedRegion && textEditor != null) { + int start = ((IndexedRegion) ruleNode).getStartOffset(); + int length = ((IndexedRegion) ruleNode).getEndOffset() - start; + if ((start > -1) && (length > -1)) { + textEditor.selectAndReveal(start, length); + } + } + } + } + } catch (PartInitException e) { + WindupUIPlugin.log(e); + MessageDialog.openError( + Display.getDefault().getActiveShell(), + Messages.openRuleset, + Messages.errorOpeningRuleset); + } + } + } + + public static void openRuleInEditor(Object provider, Node ruleNode, String editorId) { + IFile file = XMLRulesetModelUtil.getRuleset(provider); + if (file != null && file.exists()) { + try { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); +// IEditorPart editor = IDE.openEditor(page, file); + IEditorPart editor = IDE.openEditor(page, file, editorId); if (editor != null && ruleNode != null) { if (editor instanceof RulesetEditorWrapper) { ((RulesetEditorWrapper)editor).selectAndReveal((Element)ruleNode);