Skip to content

Commit bb3fcae

Browse files
committed
Open rulesets w/in default xml editor.
1 parent 8f4ce91 commit bb3fcae

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public static IFile createLinkedResource(String location) {
105105
try {
106106
op1.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell));
107107
} catch (final ExecutionException e) {
108+
e.printStackTrace();
108109
WindupUIPlugin.log(e);
109110
}
110111
};
@@ -217,17 +218,52 @@ public static IDOMModel getModel(IFile file, boolean edit) {
217218
return (IDOMModel) model;
218219
}
219220
} catch (IOException | CoreException e) {
221+
e.printStackTrace();
220222
WindupUIPlugin.log(e);
221223
}
222224
return null;
223225
}
224226

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

0 commit comments

Comments
 (0)