Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3b81215

Browse files
committedJul 21, 2021
Open rulesets w/in default xml editor.
1 parent 8f4ce91 commit 3b81215

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed
 

‎plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/OpenRuleDefinitionHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
5656
Pair<Object, Node> pair = XMLRulesetModelUtil.findRuleProvider(
5757
ruleId, executionBuilder.getSystemRuleProviderRegistry(), modelService);
5858
if (pair != null) {
59-
XMLRulesetModelUtil.openRuleInEditor(pair.getFirst(), pair.getSecond(), RulesetEditor.ID);
59+
XMLRulesetModelUtil.openRuleInEditor(pair.getFirst(), pair.getSecond(), RulesetEditor.XML_EDITOR);
6060
}
6161
} catch (RemoteException e) {
6262
WindupUIPlugin.log(e);

‎plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/RuleRepositoryView.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ public void doubleClick(DoubleClickEvent event) {
127127
if (element instanceof RulesetFileNode) {
128128
RulesetFileNode node = (RulesetFileNode)element;
129129
if (node.getRuleProvider() != null) {
130-
// XMLRulesetModelUtil.openRuleInEditor(node.getRuleProvider(), null, "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart");
131-
XMLRulesetModelUtil.openRuleInEditor(node.getRuleProvider(), null, RulesetEditor.ID);
130+
XMLRulesetModelUtil.openRuleInEditor(node.getRuleProvider(), null, RulesetEditor.XML_EDITOR);
131+
// XMLRulesetModelUtil.openRuleInEditor(node.getRuleProvider(), null, RulesetEditor.ID);
132132
}
133133
/*IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(node.getFile().getParent()));
134134
fileStore = fileStore.getChild(node.getName());
@@ -149,7 +149,8 @@ else if (element instanceof Node) {
149149
Node node = (Node)element;
150150
Object provider = contentProvider.getProvider(node);
151151
if (provider != null) {
152-
XMLRulesetModelUtil.openRuleInEditor(provider, node, RulesetEditor.ID);
152+
XMLRulesetModelUtil.openRuleInEditor(provider, null, RulesetEditor.XML_EDITOR);
153+
// XMLRulesetModelUtil.openRuleInEditor(provider, node, RulesetEditor.ID);
153154
}
154155
}
155156
}

‎plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/RulesetEditor.java

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class RulesetEditor {
4848

4949
private static final String SASH_LEFT = "weightLeft"; //$NON-NLS-1$
5050
private static final String SASH_RIGHT = "weightRight"; //$NON-NLS-1$
51+
52+
public static final String XML_EDITOR = "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"; //$NON-NLS-1$
5153

5254
private static final int SASH_LEFT_DEFAULT = 238;
5355
private static final int SASH_RIGHT_DEFAULT = 685;

‎plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/rules/xml/XMLRulesetModelUtil.java

+39-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.w3c.dom.NamedNodeMap;
6464
import org.w3c.dom.Node;
6565
import org.w3c.dom.NodeList;
66+
import org.jboss.tools.windup.ui.internal.rules.RulesetEditor;
6667

6768
import com.google.common.base.Objects;
6869
import com.google.common.collect.Lists;
@@ -105,6 +106,7 @@ public static IFile createLinkedResource(String location) {
105106
try {
106107
op1.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell));
107108
} catch (final ExecutionException e) {
109+
e.printStackTrace();
108110
WindupUIPlugin.log(e);
109111
}
110112
};
@@ -217,17 +219,52 @@ public static IDOMModel getModel(IFile file, boolean edit) {
217219
return (IDOMModel) model;
218220
}
219221
} catch (IOException | CoreException e) {
222+
e.printStackTrace();
220223
WindupUIPlugin.log(e);
221224
}
222225
return null;
223226
}
224227

225-
public static void openRuleInEditor(Object provider, Node ruleNode) {
228+
public static void openSystemRuleInEditor(Object provider, Node ruleNode) {
226229
IFile file = XMLRulesetModelUtil.getRuleset(provider);
227230
if (file != null && file.exists()) {
228231
try {
229232
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
230-
IEditorPart editor = IDE.openEditor(page, file);
233+
// IEditorPart editor = IDE.openEditor(page, file);
234+
IEditorPart editor = IDE.openEditor(page, file, RulesetEditor.XML_EDITOR);
235+
if (editor != null && ruleNode != null) {
236+
if (editor instanceof RulesetEditorWrapper) {
237+
((RulesetEditorWrapper)editor).selectAndReveal((Element)ruleNode);
238+
}
239+
else {
240+
editor.getSite().getSelectionProvider().setSelection(new StructuredSelection(ruleNode));
241+
ITextEditor textEditor = editor.getAdapter(ITextEditor.class);
242+
if (ruleNode instanceof IndexedRegion && textEditor != null) {
243+
int start = ((IndexedRegion) ruleNode).getStartOffset();
244+
int length = ((IndexedRegion) ruleNode).getEndOffset() - start;
245+
if ((start > -1) && (length > -1)) {
246+
textEditor.selectAndReveal(start, length);
247+
}
248+
}
249+
}
250+
}
251+
} catch (PartInitException e) {
252+
WindupUIPlugin.log(e);
253+
MessageDialog.openError(
254+
Display.getDefault().getActiveShell(),
255+
Messages.openRuleset,
256+
Messages.errorOpeningRuleset);
257+
}
258+
}
259+
}
260+
261+
public static void openRuleInEditor(Object provider, Node ruleNode, String editorId) {
262+
IFile file = XMLRulesetModelUtil.getRuleset(provider);
263+
if (file != null && file.exists()) {
264+
try {
265+
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
266+
// IEditorPart editor = IDE.openEditor(page, file);
267+
IEditorPart editor = IDE.openEditor(page, file, editorId);
231268
if (editor != null && ruleNode != null) {
232269
if (editor instanceof RulesetEditorWrapper) {
233270
((RulesetEditorWrapper)editor).selectAndReveal((Element)ruleNode);

0 commit comments

Comments
 (0)
Please sign in to comment.