private void loadColors() {
   fColors = new HashMap<TokenHighlight, HighlightStyle>();
   for (final TokenHighlight th : TokenHighlight.values()) {
     final HighlightStyle data = new HighlightStyle();
     data.load(COLORS_QUALIFIER + th.getName(), th.getDefaultData());
     fColors.put(th, data);
   }
 }
Example #2
0
  private void loadDefaultEditorColors() {
    final IPreferenceStore rootStore = getPreferenceStore();

    for (final TokenHighlight th : TokenHighlight.values()) {
      final HighlightStyle data = th.getDefaultStyle();
      rootStore.setDefault(th.getColorKey(), StringConverter.asString(data.getColor()));
      rootStore.setDefault(th.getStylesKey(), data.getStyles());
    }
  }
  /** @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) */
  @Override
  public void init(final IWorkbench workbench) {
    fColorManager = new ColorManager();
    fOverlayStore =
        new OverlayPreferenceStore(
            ErlideUIPlugin.getDefault().getPreferenceStore(),
            new OverlayPreferenceStore.OverlayKey[] {});
    fOverlayStore.addKeys(createOverlayStoreKeys());
    fOverlayStore.load();
    fOverlayStore.start();

    for (final TokenHighlight th : TokenHighlight.values()) {
      fColors.put(th, null);
    }
  }
 private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
   final List<OverlayPreferenceStore.OverlayKey> overlayKeys = Lists.newArrayList();
   for (final TokenHighlight item : TokenHighlight.values()) {
     overlayKeys.add(
         new OverlayPreferenceStore.OverlayKey(
             OverlayPreferenceStore.TypeDescriptor.STRING, item.getColorKey()));
     overlayKeys.add(
         new OverlayPreferenceStore.OverlayKey(
             OverlayPreferenceStore.TypeDescriptor.INT, item.getStylesKey()));
   }
   final OverlayPreferenceStore.OverlayKey[] keys =
       new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
   overlayKeys.toArray(keys);
   return keys;
 }
  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;
  }