コード例 #1
0
 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;
 }
コード例 #2
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;
  }
コード例 #3
0
ファイル: SourceViewer.java プロジェクト: neelance/jface4ruby
 /*
  * @see ISourceViewer#setDocument(IDocument, IAnnotationModel)
  */
 public void setDocument(IDocument document, IAnnotationModel annotationModel) {
   setDocument(document, annotationModel, -1, -1);
 }
コード例 #4
0
ファイル: SourceViewer.java プロジェクト: neelance/jface4ruby
 /*
  * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
  */
 public void setDocument(IDocument document, int visibleRegionOffset, int visibleRegionLength) {
   setDocument(document, null, visibleRegionOffset, visibleRegionLength);
 }
コード例 #5
0
ファイル: SourceViewer.java プロジェクト: neelance/jface4ruby
 /*
  * @see ISourceViewer#setDocument(IDocument, IAnnotationModel)
  */
 public void setDocument(IDocument document) {
   setDocument(document, null, -1, -1);
 }
コード例 #6
0
  @Test
  public void testGetDocumentation() throws Exception {

    File actual =
        new File(
            project
                .getFile(
                    new Path("actual")
                        .append(file.getProjectRelativePath().removeFirstSegments(1))
                        .removeFileExtension()
                        .addFileExtension("txt"))
                .getLocation()
                .toPortableString());

    actual.getParentFile().mkdirs();

    FileChannel fchan = new FileOutputStream(actual).getChannel();
    BufferedWriter bf = new BufferedWriter(Channels.newWriter(fchan, "UTF-8"));

    try {
      for (int offset = 0; offset < editor.document.getLength(); offset++) {

        Point loc = editor.getLocation(offset);

        Shell shell = new Shell();

        SourceViewer viewer = new SourceViewer(shell, null, 0);
        IAnnotationModel model = new AnnotationModel();
        model.connect(editor.document);
        viewer.setDocument(editor.document, model);
        String doc = hh.getHoverHelpAt(editor.parseController, viewer, offset);

        if (doc != null && doc.length() > 0) {
          loc = editor.getLocation(offset);
          bf.write("" + loc.x + "," + loc.y + ": ");
          bf.write(doc);
          bf.newLine();
        }
      }

    } finally {
      bf.close();
      fchan.close();
    }
    File expected =
        new File(
            project
                .getFile(
                    new Path("expected")
                        .append(file.getProjectRelativePath().removeFirstSegments(1))
                        .removeFileExtension()
                        .addFileExtension("txt"))
                .getLocation()
                .toPortableString());

    Assert.assertTrue(
        "The data file containing the expected results for "
            + file.getLocation()
            + " does not exist.  If you just added this file to the test suite be sure to verify the contents of "
            + actual.getPath()
            + " and copy it into the expected folder in the test suite.",
        expected.exists());
    int result = FileUtils.compareLinesOf(actual, expected);
    Assert.assertTrue("Actual differs from expected at line " + result, result == -1);
  }
コード例 #7
0
  /**
   * @param parent
   * @param initialText
   * @param readOnly
   * @param styles
   */
  public SpellcheckableMessageArea(
      Composite parent, String initialText, boolean readOnly, int styles) {
    super(parent, styles);
    setLayout(new FillLayout());

    AnnotationModel annotationModel = new AnnotationModel();
    sourceViewer =
        new HyperlinkSourceViewer(this, null, null, true, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
    getTextWidget().setAlwaysShowScrollBars(false);
    getTextWidget().setFont(UIUtils.getFont(UIPreferences.THEME_CommitMessageEditorFont));

    int endSpacing = 2;
    int textWidth = getCharWidth() * MAX_LINE_WIDTH + endSpacing;
    int textHeight = getLineHeight() * 7;
    Point size = getTextWidget().computeSize(textWidth, textHeight);
    getTextWidget().setSize(size);

    computeBrokenBidiPlatformTextWidth(size.x);

    getTextWidget().setEditable(!readOnly);

    createMarginPainter();

    configureHardWrap();
    final IPropertyChangeListener propertyChangeListener =
        new IPropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent event) {
            if (UIPreferences.COMMIT_DIALOG_HARD_WRAP_MESSAGE.equals(event.getProperty())) {
              getDisplay()
                  .asyncExec(
                      new Runnable() {
                        @Override
                        public void run() {
                          configureHardWrap();
                          if (brokenBidiPlatformTextWidth != -1) {
                            layout();
                          }
                        }
                      });
            }
          }
        };
    Activator.getDefault().getPreferenceStore().addPropertyChangeListener(propertyChangeListener);
    final IPropertyChangeListener syntaxColoringChangeListener =
        new IPropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent event) {
            if (JFacePreferences.HYPERLINK_COLOR.equals(event.getProperty())) {
              getDisplay()
                  .asyncExec(
                      new Runnable() {
                        @Override
                        public void run() {
                          if (!isDisposed()) {
                            sourceViewer.refresh();
                          }
                        }
                      });
            }
          }
        };
    JFacePreferences.getPreferenceStore().addPropertyChangeListener(syntaxColoringChangeListener);
    final SourceViewerDecorationSupport support = configureAnnotationPreferences();
    if (isEditable(sourceViewer)) {
      quickFixActionHandler = createQuickFixActionHandler(sourceViewer);
    }

    Document document = new Document(initialText);

    configuration =
        new HyperlinkSourceViewer.Configuration(EditorsUI.getPreferenceStore()) {

          @Override
          public int getHyperlinkStateMask(ISourceViewer targetViewer) {
            if (!targetViewer.isEditable()) {
              return SWT.NONE;
            }
            return super.getHyperlinkStateMask(targetViewer);
          }

          @Override
          protected Map getHyperlinkDetectorTargets(ISourceViewer targetViewer) {
            return getHyperlinkTargets();
          }

          @Override
          public IReconciler getReconciler(ISourceViewer viewer) {
            if (!isEditable(viewer)) return null;
            return super.getReconciler(sourceViewer);
          }

          @Override
          public IContentAssistant getContentAssistant(ISourceViewer viewer) {
            if (!viewer.isEditable()) return null;
            IContentAssistant assistant = createContentAssistant(viewer);
            // Add content assist proposal handler if assistant exists
            if (assistant != null)
              contentAssistActionHandler = createContentAssistActionHandler(sourceViewer);
            return assistant;
          }

          @Override
          public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) {
            PresentationReconciler reconciler = new PresentationReconciler();
            reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(viewer));
            DefaultDamagerRepairer hyperlinkDamagerRepairer =
                new DefaultDamagerRepairer(new HyperlinkTokenScanner(this, viewer));
            reconciler.setDamager(hyperlinkDamagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
            reconciler.setRepairer(hyperlinkDamagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
            return reconciler;
          }
        };

    sourceViewer.configure(configuration);
    sourceViewer.setDocument(document, annotationModel);

    configureContextMenu();

    getTextWidget()
        .addDisposeListener(
            new DisposeListener() {
              @Override
              public void widgetDisposed(DisposeEvent disposeEvent) {
                support.uninstall();
                Activator.getDefault()
                    .getPreferenceStore()
                    .removePropertyChangeListener(propertyChangeListener);
                JFacePreferences.getPreferenceStore()
                    .removePropertyChangeListener(syntaxColoringChangeListener);
              }
            });
  }
コード例 #8
0
  /**
   * @param parent
   * @param initialText
   * @param readOnly
   * @param styles
   */
  public SpellcheckableMessageArea(
      Composite parent, String initialText, boolean readOnly, int styles) {
    super(parent, styles);
    setLayout(new FillLayout());

    AnnotationModel annotationModel = new AnnotationModel();
    sourceViewer = new SourceViewer(this, null, null, true, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
    getTextWidget().setAlwaysShowScrollBars(false);
    getTextWidget().setFont(UIUtils.getFont(UIPreferences.THEME_CommitMessageEditorFont));

    sys_normalCursor = sourceViewer.getTextWidget().getCursor();
    int endSpacing = 2;
    int textWidth = getCharWidth() * MAX_LINE_WIDTH + endSpacing;
    int textHeight = getLineHeight() * 7;
    Point size = getTextWidget().computeSize(textWidth, textHeight);
    getTextWidget().setSize(size);

    computeBrokenBidiPlatformTextWidth(size.x);

    getTextWidget().setEditable(!readOnly);

    createMarginPainter();

    configureHardWrap();
    final IPropertyChangeListener propertyChangeListener =
        new IPropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent event) {
            if (UIPreferences.COMMIT_DIALOG_HARD_WRAP_MESSAGE.equals(event.getProperty())) {
              getDisplay()
                  .asyncExec(
                      new Runnable() {
                        public void run() {
                          configureHardWrap();
                          if (brokenBidiPlatformTextWidth != -1) {
                            layout();
                          }
                        }
                      });
            }
          }
        };
    Activator.getDefault().getPreferenceStore().addPropertyChangeListener(propertyChangeListener);

    final SourceViewerDecorationSupport support = configureAnnotationPreferences();
    if (isEditable(sourceViewer)) {
      quickFixActionHandler = createQuickFixActionHandler(sourceViewer);
    }

    Document document = new Document(initialText);

    configuration =
        new TextSourceViewerConfiguration(EditorsUI.getPreferenceStore()) {

          public int getHyperlinkStateMask(ISourceViewer targetViewer) {
            return SWT.NONE;
          }

          protected Map getHyperlinkDetectorTargets(ISourceViewer targetViewer) {
            return getHyperlinkTargets();
          }

          @Override
          public IHyperlinkPresenter getHyperlinkPresenter(ISourceViewer targetViewer) {
            return new MultipleHyperlinkPresenter(
                PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_BLUE).getRGB()) {

              @Override
              public void hideHyperlinks() {
                // We want links to always show.
              }
            };
          }

          public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer targetViewer) {
            return getRegisteredHyperlinkDetectors(sourceViewer);
          }

          @Override
          public IReconciler getReconciler(ISourceViewer viewer) {
            if (!isEditable(viewer)) return null;
            return super.getReconciler(sourceViewer);
          }

          public IContentAssistant getContentAssistant(ISourceViewer viewer) {
            if (!viewer.isEditable()) return null;
            IContentAssistant assistant = createContentAssistant(viewer);
            // Add content assist proposal handler if assistant exists
            if (assistant != null)
              contentAssistActionHandler = createContentAssistActionHandler(sourceViewer);
            return assistant;
          }
        };

    sourceViewer.configure(configuration);
    sourceViewer.setDocument(document, annotationModel);

    StyleRange[] styleRanges =
        UIUtils.getHyperlinkDetectorStyleRanges(
            sourceViewer, configuration.getHyperlinkDetectors(sourceViewer));
    sourceViewer.getTextWidget().setStyleRanges(styleRanges);

    configureContextMenu();

    getTextWidget()
        .addDisposeListener(
            new DisposeListener() {
              public void widgetDisposed(DisposeEvent disposeEvent) {
                support.uninstall();
                Activator.getDefault()
                    .getPreferenceStore()
                    .removePropertyChangeListener(propertyChangeListener);
              }
            });
  }
コード例 #9
0
ファイル: OQLPane.java プロジェクト: blasd/org.eclipse.mat
  public void createPartControl(Composite parent) {
    SashForm sash = new SashForm(parent, SWT.VERTICAL | SWT.SMOOTH);

    queryViewer = new SourceViewer(sash, null, SWT.MULTI | SWT.WRAP);
    queryString = queryViewer.getTextWidget();
    queryString.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
    Color background = queryString.getBackground();
    IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
    ITheme current = themeManager.getCurrentTheme();
    ColorRegistry colorRegistry = current.getColorRegistry();
    commentCol = colorRegistry.get(ColorProvider.COMMENT_COLOR_PREF);
    keywordCol = colorRegistry.get(ColorProvider.KEYWORD_COLOR_PREF);
    IDocument d = createDocument();
    d.set(Messages.OQLPane_F1ForHelp);

    queryViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          public void selectionChanged(SelectionChangedEvent event) {
            updateActions();
          }
        });

    queryViewer.setDocument(d);
    queryViewer.configure(new OQLTextViewerConfiguration(getSnapshot(), commentCol, keywordCol));
    // Eclipse 4 seems to need this otherwise in high contrast mode the background is white
    queryString.setBackground(background);
    queryString.selectAll();

    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(queryString, "org.eclipse.mat.ui.help.oql"); // $NON-NLS-1$
    queryString.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (e.keyCode == '\r' && (e.stateMask & SWT.MOD1) != 0) {
              executeAction.run();
              e.doit = false;
            } else if (e.keyCode == ' ' && (e.stateMask & SWT.CTRL) != 0) {
              // ctrl space combination for content assist
              contentAssistAction.run();
            } else if (e.keyCode == SWT.F5) {
              executeAction.run();
              e.doit = false;
            }
          }
        });

    queryString.addFocusListener(
        new FocusListener() {

          public void focusGained(FocusEvent e) {
            IActionBars actionBars = getEditor().getEditorSite().getActionBars();
            actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyQueryStringAction);
            actionBars.updateActionBars();
          }

          public void focusLost(FocusEvent e) {}
        });
    queryString.setFocus();

    createContainer(sash);

    sash.setWeights(new int[] {1, 4});

    makeActions();
    hookContextMenu();
  }