@Override
 public void selectionChanged(ITextSelection selection) {
   try {
     if (editor.getModule() != null) {
       this.node = editor.getModule().getNodeAtPosition(selection.getOffset());
     } else {
       this.node = null;
     }
   } catch (YangModelException e) {
     this.node = null;
   }
   setEnabled(node != null && (node instanceof GroupingDefinition || node instanceof UsesNode));
 }
Beispiel #2
0
  @Override
  public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
    @SuppressWarnings("deprecation")
    String info = super.getHoverInfo(textViewer, hoverRegion);
    if (info != null) {
      return HelpCompositionUtils.wrapHtmlText(info, null);
    }

    String hoverInfo = null;
    YangEditor editor = (YangEditor) getEditor();
    if (editor != null) {
      try {
        Module module = editor.getModule();
        if (module != null) {
          ASTNode node = module.getNodeAtPosition(hoverRegion.getOffset());
          hoverInfo = HelpCompositionUtils.getNodeHelp(node);
        }
      } catch (YangModelException e) {
        YangCorePlugin.log(e);
      }
    }
    return hoverInfo;
  }
  @Override
  public void run(ITextSelection selection) {
    if (node != null && (node instanceof GroupingDefinition || node instanceof UsesNode)) {
      IFile file = ((IFileEditorInput) editor.getEditorInput()).getFile();
      InlineGroupingRefactoring refactoring =
          new InlineGroupingRefactoring(file, (ASTNamedNode) node);
      InlineGroupingRefactoringWizard wizard = new InlineGroupingRefactoringWizard(refactoring);

      RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
      try {
        op.run(getShell(), "Inline Grouping");
      } catch (InterruptedException e) {
        // do nothing
      }
    } else {
      MessageDialog.openInformation(
          getShell(),
          "Inline",
          "Operation unavailable on the current selection.\nSelect a grouping or uses element.");
    }
  }
 public InlineGroupingAction(YangEditor editor) {
   this(editor.getSite());
   this.editor = editor;
 }