Skip to content

Commit

Permalink
Open rulesets w/in default xml editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsteele committed Jul 21, 2021
1 parent 8f4ce91 commit bb3fcae
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
Pair<Object, Node> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public static IFile createLinkedResource(String location) {
try {
op1.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell));
} catch (final ExecutionException e) {
e.printStackTrace();
WindupUIPlugin.log(e);
}
};
Expand Down Expand Up @@ -217,17 +218,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);
Expand Down

0 comments on commit bb3fcae

Please sign in to comment.