public void focusOnLines(ILocation range) {
   if (range instanceof ILineLocation) {
     ILineLocation lineLocation = (ILineLocation) range;
     // editors count lines from 0, Crucible counts from 1
     final int startLine = lineLocation.getRangeMin() - 1;
     final int endLine = lineLocation.getRangeMax() - 1;
     if (sourceViewer != null) {
       IDocument document = sourceViewer.getDocument();
       if (document != null) {
         try {
           int offset = document.getLineOffset(startLine);
           int length = document.getLineOffset(endLine) - offset;
           StyledText widget = sourceViewer.getTextWidget();
           try {
             widget.setRedraw(false);
             // sourceViewer.revealRange(offset, length);
             // sourceViewer.setSelectedRange(offset, 0);
             sourceViewer.setSelection(new TextSelection(offset, length), true);
           } finally {
             widget.setRedraw(true);
           }
         } catch (BadLocationException e) {
           StatusHandler.log(
               new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, e.getMessage(), e));
         }
       }
     }
   }
 }
  public void forceCustomAnnotationHover() throws NoSuchFieldException, IllegalAccessException {
    Class<SourceViewer> sourceViewerClazz = SourceViewer.class;
    sourceViewer.setAnnotationHover(new CommentAnnotationHover(null));

    // hack for Eclipse 3.5
    try {
      Field hoverControlCreator = TextViewer.class.getDeclaredField("fHoverControlCreator");
      hoverControlCreator.setAccessible(true);
      hoverControlCreator.set(sourceViewer, new CommentInformationControlCreator());
    } catch (Throwable t) {
      // ignore as it may not exist in other versions
    }

    // hack for Eclipse 3.5
    try {
      Method ensureMethod =
          sourceViewerClazz.getDeclaredMethod("ensureAnnotationHoverManagerInstalled");
      ensureMethod.setAccessible(true);
      ensureMethod.invoke(sourceViewer);
    } catch (Throwable t) {
      // ignore as it may not exist in other versions
    }

    Field hoverManager = SourceViewer.class.getDeclaredField("fVerticalRulerHoveringController");
    hoverManager.setAccessible(true);
    AnnotationBarHoverManager manager = (AnnotationBarHoverManager) hoverManager.get(sourceViewer);
    if (manager != null) {
      Field annotationHover = AnnotationBarHoverManager.class.getDeclaredField("fAnnotationHover");
      annotationHover.setAccessible(true);
      IAnnotationHover hover = (IAnnotationHover) annotationHover.get(manager);
      annotationHover.set(manager, new CommentAnnotationHover(hover));
    }
    sourceViewer.showAnnotations(true);
    sourceViewer.showAnnotationsOverview(true);
  }
Ejemplo n.º 3
0
    protected SourceViewer createViewer(Composite parent) {

      SourceViewer viewer =
          new SourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
      SourceViewerConfiguration configuration = new YEditSourceViewerConfiguration();
      viewer.configure(configuration);

      return viewer;
    }
  /*
   * @see IInformationControl#setInformation(String)
   */
  public void setInformation(String content) {
    if (content == null) {
      fViewer.setInput(null);
      return;
    }

    IDocument doc = new Document(content);
    fViewer.setInput(doc);
  }
 @Override
 public void createControl(Composite parent) {
   super.createControl(parent);
   final SourceViewer viewer = getSourceViewer();
   viewer.unconfigure();
   IPreferenceStore store = DartToolsPlugin.getDefault().getCombinedPreferenceStore();
   viewer.configure(
       new DartSourceViewerConfiguration(
           DartToolsPlugin.getDefault().getDartTextTools().getColorManager(), store, null, null));
   viewer.getControl().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT));
 }
Ejemplo n.º 6
0
  /*
   * @see org.eclipse.ui.texteditor.templates.TemplatePreferencePage#updateViewerInput()
   */
  protected void updateViewerInput() {
    IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
    SourceViewer viewer = getViewer();

    if (selection.size() == 1 && selection.getFirstElement() instanceof TemplatePersistenceData) {
      TemplatePersistenceData data = (TemplatePersistenceData) selection.getFirstElement();
      Template template = data.getTemplate();
      viewer.getDocument().set(template.getPattern());

    } else {
      viewer.getDocument().set("");
    }
  }
Ejemplo n.º 7
0
 @Override
 public void initWithArgument(final Object param) {
   if (param instanceof String) {
     queryViewer.getDocument().set((String) param);
     executeAction.run();
   } else if (param instanceof QueryResult) {
     QueryResult queryResult = (QueryResult) param;
     initQueryResult(queryResult, null);
   } else if (param instanceof PaneState) {
     queryViewer.getDocument().set(((PaneState) param).getIdentifier());
     new ExecuteQueryAction((PaneState) param).run();
   }
 }
Ejemplo n.º 8
0
 /** {@inheritDoc} */
 public void run() {
   IDocument document = viewer.getDocument();
   ISelection selection = viewer.getSelection();
   TextSelection textSelection;
   if (selection instanceof TextSelection) {
     textSelection = (TextSelection) selection;
     boolean isCommented = isCommented(document, textSelection);
     if (isCommented) {
       viewer.doOperation(ITextOperationTarget.STRIP_PREFIX);
     } else {
       viewer.doOperation(ITextOperationTarget.PREFIX);
     }
   }
 }
Ejemplo n.º 9
0
    @Execute
    public void openDeclaration(final @Named(ISources.ACTIVE_EDITOR_NAME) RobotFormEditor editor) {
      final SourceViewer viewer = editor.getSourceEditor().getViewer();

      final IRegion hyperlinkRegion = new Region(viewer.getTextWidget().getCaretOffset(), 0);

      final SourceViewerConfiguration configuration =
          editor.getSourceEditor().getViewerConfiguration();
      final IHyperlinkDetector[] detectors = configuration.getHyperlinkDetectors(viewer);

      final Optional<IHyperlink> hyperlink = getHyperlink(viewer, hyperlinkRegion, detectors);
      if (hyperlink.isPresent()) {
        hyperlink.get().open();
      }
    }
 @Override
 public void performDefaults() {
   super.performDefaults();
   fOverlayStore.loadDefaults();
   handleSyntaxColorListSelection();
   fPreviewViewer.invalidateTextPresentation();
 }
Ejemplo n.º 11
0
  private void initQueryResult(QueryResult queryResult, PaneState state) {
    IOQLQuery.Result subject = (IOQLQuery.Result) (queryResult).getSubject();
    queryViewer.getDocument().set(subject.getOQLQuery());

    AbstractEditorPane pane = EditorPaneRegistry.instance().createNewPane(subject, this.getClass());

    if (state == null) {
      for (PaneState child : getPaneState().getChildren()) {
        if (queryString.getText().equals(child.getIdentifier())) {
          state = child;
          break;
        }
      }

      if (state == null) {
        state =
            new PaneState(PaneType.COMPOSITE_CHILD, getPaneState(), queryString.getText(), true);
        state.setImage(getTitleImage());
      }
    }

    pane.setPaneState(state);

    createResultPane(pane, queryResult);
  }
 private void createHighlighting(Class<SourceViewer> sourceViewerClazz)
     throws IllegalArgumentException, IllegalAccessException, SecurityException,
         NoSuchFieldException {
   // TODO this could use some performance tweaks
   final StyledText styledText = sourceViewer.getTextWidget();
   styledText.addLineBackgroundListener(new ColoringLineBackgroundListener(styledText));
 }
 SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) {
   SourceViewer viewer = null;
   String contentTypeID = ContentTypeIdForHTML.ContentTypeID_HTML;
   viewer =
       new StructuredTextViewer(
           parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
   viewer
       .getTextWidget()
       .setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); // $NON-NLS-1$
   IStructuredModel scratchModel =
       StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(contentTypeID);
   IDocument document = scratchModel.getStructuredDocument();
   viewer.configure(viewerConfiguration);
   viewer.setDocument(document);
   return viewer;
 }
 public LineRange getSelection() {
   if (sourceViewer != null) {
     TextSelection selection = (TextSelection) sourceViewer.getSelection();
     return new LineRange(
         selection.getStartLine() + 1, selection.getEndLine() - selection.getStartLine());
   }
   return null;
 }
Ejemplo n.º 15
0
 private StyleRange getStyleRange(final int x, final int y) {
   final StyledText t = sourceViewer.getTextWidget();
   final int offset;
   try {
     offset = t.getOffsetAtLocation(new Point(x, y));
   } catch (IllegalArgumentException e) {
     return null;
   }
   if (offset < t.getCharCount()) return t.getStyleRangeAtOffset(offset);
   else return null;
 }
  private void addProposals(final SubMenuManager quickFixMenu) {
    IAnnotationModel sourceModel = sourceViewer.getAnnotationModel();
    Iterator annotationIterator = sourceModel.getAnnotationIterator();
    while (annotationIterator.hasNext()) {
      Annotation annotation = (Annotation) annotationIterator.next();
      boolean isDeleted = annotation.isMarkedDeleted();
      boolean isIncluded =
          includes(sourceModel.getPosition(annotation), getTextWidget().getCaretOffset());
      boolean isFixable = sourceViewer.getQuickAssistAssistant().canFix(annotation);
      if (!isDeleted && isIncluded && isFixable) {
        IQuickAssistProcessor processor =
            sourceViewer.getQuickAssistAssistant().getQuickAssistProcessor();
        IQuickAssistInvocationContext context = sourceViewer.getQuickAssistInvocationContext();
        ICompletionProposal[] proposals = processor.computeQuickAssistProposals(context);

        for (ICompletionProposal proposal : proposals)
          quickFixMenu.add(createQuickFixAction(proposal));
      }
    }
  }
 @Override
 public void dispose() {
   if (!disposed) {
     selector.dispose();
     viewer.removeSelectionChangedListener(this);
     replaceAnnotations(getAnnotations(), NO_ANNOTAIONS);
     getBlock().dispose();
     disposed = true;
   }
   inited = false;
 }
  /*
   * @see IInformationControl#setSize(int, int)
   */
  public void setSize(int width, int height) {

    if (fStatusField != null) {
      GridData gd = (GridData) fViewer.getTextWidget().getLayoutData();
      Point statusSize = fStatusField.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
      Point separatorSize = fSeparator.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
      gd.heightHint = height - statusSize.y - separatorSize.y;
    }
    fShell.setSize(width, height);

    if (fStatusField != null) fShell.pack(true);
  }
  @Override
  protected void updateIndentationSettings(SourceViewer sourceViewer, String property) {
    super.updateIndentationSettings(sourceViewer, property);

    if (CodeFormatterConstants.FORMATTER_INDENTATION_SPACES_SIZE.key.equals(property)
        || CodeFormatterConstants.FORMATTER_INDENT_MODE.key.equals(property)) {

      for (String contentType : getConfiguredContentTypes(sourceViewer)) {
        String[] prefixes = getIndentPrefixes(sourceViewer, contentType);
        sourceViewer.setIndentPrefixes(prefixes, contentType);
      }
    }
  }
 @Override
 public void init() {
   if (inited) {
     return;
   }
   inited = true;
   if (selector != null) {
     selector.dispose();
     select(null);
   }
   selector = new ViewerSelector(viewer);
   viewer.addSelectionChangedListener(this);
 }
  public void registerContextMenu() {
    addLineCommentAction = new AddLineCommentToFileAction(this);
    //				addLineCommentAction.setImageDescriptor(CrucibleImages.ADD_COMMENT);
    //				addGeneralCommentAction = new
    // AddGeneralCommentToFileAction(crucibleAnnotationModel.getCrucibleFile());

    if (sourceViewer != null) {
      sourceViewer.addSelectionChangedListener(addLineCommentAction);
      //					sourceViewer.addSelectionChangedListener(addGeneralCommentAction);
    }
    mergeSourceViewer.addTextAction(addLineCommentAction);
    //				mergeSourceViewer.addTextAction(addGeneralCommentAction);
  }
 private void replaceAnnotations(Annotation[] remove, Map<Annotation, Position> add) {
   final IAnnotationModel model = viewer.getAnnotationModel();
   if (model instanceof IAnnotationModelExtension) {
     final IAnnotationModelExtension eModel = (IAnnotationModelExtension) model;
     eModel.replaceAnnotations(remove, add);
   } else {
     for (final Annotation annotation : remove) {
       model.removeAnnotation(annotation);
     }
     for (final Annotation annotation : add.keySet()) {
       model.addAnnotation(annotation, add.get(annotation));
     }
   }
 }
Ejemplo n.º 23
0
  /*
   * @see TextMergeViewer#configureTextViewer()
   */
  protected void configureTextViewer(TextViewer textViewer) {
    XMLPlugin plugin = XMLPlugin.getDefault();

    preferenceStore = plugin.getPreferenceStore();
    if (preferenceStore != null) {
      propertyChangeListener =
          new IPropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent event) {
              handlePreferenceStoreChanged(event);
            }
          };
      preferenceStore.addPropertyChangeListener(propertyChangeListener);
    }

    textTools = plugin.getXMLTextTools();

    if (textViewer instanceof SourceViewer) {
      SourceViewer sourceViewer = (SourceViewer) textViewer;
      sourceViewer.configure(new XMLConfiguration(textTools));
    }

    updateBackgroundColor();
  }
  public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
    if (oldInput != null) {
      annotationModel.disconnect(oldInput);
    }
    if (newInput != null && sourceViewer != null) {
      IAnnotationModel originalAnnotationModel = sourceViewer.getAnnotationModel();
      if (originalAnnotationModel instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension annotationModelExtension =
            (IAnnotationModelExtension) originalAnnotationModel;
        annotationModelExtension.addAnnotationModel(
            ReviewsUiPlugin.PLUGIN_ID, originalAnnotationModel);
      } else {
        try {
          Class<SourceViewer> sourceViewerClazz = SourceViewer.class;
          Field declaredField2 = sourceViewerClazz.getDeclaredField("fVisualAnnotationModel");
          declaredField2.setAccessible(true);
          Method declaredMethod =
              sourceViewerClazz.getDeclaredMethod(
                  "createVisualAnnotationModel", IAnnotationModel.class);
          declaredMethod.setAccessible(true);
          originalAnnotationModel =
              (IAnnotationModel) declaredMethod.invoke(sourceViewer, annotationModel);
          declaredField2.set(sourceViewer, originalAnnotationModel);
          originalAnnotationModel.connect(newInput);
          sourceViewer.showAnnotations(true);

          createVerticalRuler(newInput, sourceViewerClazz);
          createOverviewRuler(newInput, sourceViewerClazz);
          createHighlighting(sourceViewerClazz);
        } catch (Throwable t) {
          StatusHandler.log(
              new Status(
                  IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, "Error attaching annotation model", t));
        }
      }
    }
  }
Ejemplo n.º 25
0
 /**
  * Registers a source preview updater for the given viewer, configuration and preference store.
  *
  * @param viewer the viewer
  * @param configuration the configuration
  * @param preferenceStore the preference store
  */
 public static void registerPreviewer(
     final SourceViewer viewer,
     final CSourceViewerConfiguration configuration,
     final IPreferenceStore preferenceStore) {
   Assert.isNotNull(viewer);
   Assert.isNotNull(configuration);
   Assert.isNotNull(preferenceStore);
   final IPropertyChangeListener fontChangeListener =
       new IPropertyChangeListener() {
         /*
          * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
          */
         @Override
         public void propertyChange(PropertyChangeEvent event) {
           if (event.getProperty().equals(PreferenceConstants.EDITOR_TEXT_FONT)) {
             Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
             viewer.getTextWidget().setFont(font);
           }
         }
       };
   final IPropertyChangeListener propertyChangeListener =
       new IPropertyChangeListener() {
         /*
          * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
          */
         @Override
         public void propertyChange(PropertyChangeEvent event) {
           if (configuration.affectsTextPresentation(event)) {
             configuration.handlePropertyChangeEvent(event);
             viewer.invalidateTextPresentation();
           }
         }
       };
   viewer
       .getTextWidget()
       .addDisposeListener(
           new DisposeListener() {
             /*
              * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
              */
             @Override
             public void widgetDisposed(DisposeEvent e) {
               preferenceStore.removePropertyChangeListener(propertyChangeListener);
               JFaceResources.getFontRegistry().removeListener(fontChangeListener);
             }
           });
   JFaceResources.getFontRegistry().addListener(fontChangeListener);
   preferenceStore.addPropertyChangeListener(propertyChangeListener);
 }
 private Annotation[] getAnnotations(final boolean selected) {
   final String type = selected ? SELECTED_ANNOTATION_TYPE : ANNOTATION_TYPE;
   final IAnnotationModel model = viewer.getAnnotationModel();
   final List<Annotation> annotations = new ArrayList<Annotation>();
   if (model != null) {
     final Iterator<?> it = model.getAnnotationIterator();
     while (it.hasNext()) {
       final Annotation annotation = (Annotation) it.next();
       if (type.equals(annotation.getType())) {
         annotations.add(annotation);
       }
     }
   }
   return annotations.toArray(new Annotation[annotations.size()]);
 }
Ejemplo n.º 27
0
  private void textEditorContextMenuAboutToShow(IMenuManager manager) {
    if (queryString != null) {
      undo.setEnabled(queryViewer.getUndoManager().undoable());
      redo.setEnabled(queryViewer.getUndoManager().redoable());
      manager.add(undo);
      manager.add(redo);
      manager.add(new Separator());

      manager.add(getAction(ActionFactory.CUT.getId()));
      manager.add(getAction(ActionFactory.COPY.getId()));
      manager.add(getAction(ActionFactory.PASTE.getId()));
      manager.add(new Separator());
      manager.add(getAction(ActionFactory.DELETE.getId()));
      manager.add(getAction(ActionFactory.SELECT_ALL.getId()));
    }
  }
    @Override
    public void widgetSelected(final SelectionEvent event) {
      final TexCommand command = (TexCommand) event.widget.getData();

      final IEditorPart editor = UIAccess.getActiveWorkbenchPage(true).getActiveEditor();
      if (editor instanceof ILtxEditor) {
        final ILtxEditor texEditor = (ILtxEditor) editor;
        if (!texEditor.isEditable(true)) {
          return;
        }
        final SourceViewer viewer = ((ILtxEditor) editor).getViewer();
        Point selection = viewer.getSelectedRange();
        if (selection == null || selection.x < 0) {
          return;
        }
        try {
          final String contentType =
              TextUtils.getContentType(
                  viewer.getDocument(),
                  texEditor.getDocumentContentInfo(),
                  selection.x,
                  selection.y == 0);

          final LtxAssistInvocationContext context =
              new LtxAssistInvocationContext(
                  texEditor, selection.x, contentType, true, new NullProgressMonitor());
          final LtxCommandCompletionProposal proposal =
              new LtxCommandCompletionProposal(context, context.getInvocationOffset(), command);
          proposal.apply(viewer, (char) 0, 1, context.getInvocationOffset());
          selection = proposal.getSelection(viewer.getDocument());
          if (selection != null) {
            viewer.setSelectedRange(selection.x, selection.y);
            viewer.revealRange(selection.x, selection.y);
          } else {
            viewer.revealRange(context.getInvocationOffset(), 0);
          }
        } catch (final Exception e) {
          StatusManager.getManager()
              .handle(
                  new Status(
                      IStatus.ERROR,
                      TexUI.PLUGIN_ID,
                      0,
                      "An error occurred when inserting LaTeX symbol.",
                      e));
        }
      }
    }
Ejemplo n.º 29
0
  public static SourceViewer createErlangPreviewer(
      final Composite parent,
      IColorManager colorManager,
      Map<TokenHighlight, HighlightStyle> colors,
      final String content) {
    // TODO we should move this method, to a utility class (or maybe create
    // an ErlangPreviewSourceViewer class)
    if (colorManager == null) {
      colorManager = new ColorManager();
    }
    if (colors == null) {
      colors = new HashMap<TokenHighlight, HighlightStyle>();
      for (final TokenHighlight th : TokenHighlight.values()) {
        colors.put(th, th.getDefaultData());
      }
    }

    final IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
    final IPreferenceStore store =
        new ChainedPreferenceStore(
            new IPreferenceStore[] {
              ErlideUIPlugin.getDefault().getPreferenceStore(), generalTextStore
            });

    final SourceViewer viewer =
        new SourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    final IDocument document = new Document(content);
    viewer.setDocument(document);

    final ErlangDocumentSetupParticipant setupParticipant = new ErlangDocumentSetupParticipant();
    setupParticipant.setup(document);

    final TextSourceViewerConfiguration configuration =
        new SyntaxColorPreviewEditorConfiguration(store, colorManager, colors);
    viewer.configure(configuration);

    final Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
    viewer.getTextWidget().setFont(font);
    new ErlangSourceViewerUpdater(viewer, configuration, store);
    viewer.setEditable(false);

    final Cursor arrowCursor =
        viewer.getTextWidget().getDisplay().getSystemCursor(SWT.CURSOR_ARROW);
    viewer.getTextWidget().setCursor(arrowCursor);

    return viewer;
  }
 @Override
 public SourceSelection getSelection() {
   final Point selection = viewer.getSelectedRange();
   return new SourceSelection(getBlock(), selection.x, selection.y);
 }