public void testColorPrefs() throws Exception {
    IPreferenceStore store = PreferenceConstants.getPreferenceStore();
    PreferenceConstants.initializeDefaultValues(store);

    // openTestEditor("");
    fail("Open test editor");

    IPreferenceStore prefs = testEditor.getPreferences();
    Display display = testEditor.getViewer().getTextWidget().getDisplay();
    Color ebg = DartUI.getEditorBackground(prefs, display);
    Color efg = DartUI.getEditorForeground(prefs, display);
    Color esbg = DartUI.getEditorSelectionBackground(prefs, display);
    Color esfg = DartUI.getEditorSelectionForeground(prefs, display);
    assertNull(ebg);
    assertNull(efg);
    assertNull(esbg);
    assertNull(esfg);
    // simulate changing theme
    store.putValue("AbstractTextEditor.Color.Foreground.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.Background.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.SelectionBackground.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.SelectionForeground.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.Foreground", "0,0,0");
    store.putValue("AbstractTextEditor.Color.Background", "1,1,1");
    store.putValue("AbstractTextEditor.Color.SelectionForeground", "10,10,10");
    store.putValue("AbstractTextEditor.Color.SelectionBackground", "11,11,11");
    ebg = DartUI.getEditorBackground(prefs, display);
    efg = DartUI.getEditorForeground(prefs, display);
    esbg = DartUI.getEditorSelectionBackground(prefs, display);
    esfg = DartUI.getEditorSelectionForeground(prefs, display);
    assertNotNull(ebg);
    assertNotNull(efg);
    assertNotNull(esbg);
    assertNotNull(esfg);
    // simulate restoring defaults
    store.setToDefault("AbstractTextEditor.Color.Foreground.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.Background.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.SelectionBackground.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.SelectionForeground.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.Foreground");
    store.setToDefault("AbstractTextEditor.Color.Background");
    store.setToDefault("AbstractTextEditor.Color.SelectionForeground");
    store.setToDefault("AbstractTextEditor.Color.SelectionBackground");
    ebg = DartUI.getEditorBackground(prefs, display);
    efg = DartUI.getEditorForeground(prefs, display);
    esbg = DartUI.getEditorSelectionBackground(prefs, display);
    esfg = DartUI.getEditorSelectionForeground(prefs, display);
    assertNull(ebg);
    assertNull(efg);
    assertNull(esbg);
    assertNull(esfg);
  }
 public static void setSpacesPerIndent(String tabWidth) {
   PreferenceConstants.getPreferenceStore()
       .setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH, tabWidth);
   EditorsPlugin.getDefault()
       .getPreferenceStore()
       .setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH, tabWidth);
 }
 public static void setInsertSpacesForTabs(boolean useSpaces) {
   PreferenceConstants.getPreferenceStore()
       .setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, useSpaces);
   EditorsPlugin.getDefault()
       .getPreferenceStore()
       .setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, useSpaces);
 }
  private void initFromPrefs() {
    IPreferenceStore editorPreferences = EditorsPlugin.getDefault().getPreferenceStore();
    IPreferenceStore toolsPreferences = PreferenceConstants.getPreferenceStore();

    lineNumbersCheck.setSelection(
        editorPreferences.getBoolean(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER));
    printMarginCheck.setSelection(DartFormatter.getMaxLineLengthEnabled());
    printMarginText.setText(DartFormatter.getMaxLineLength());
    printMarginText.setEnabled(printMarginCheck.getSelection());

    enableAutoCompletion.setSelection(
        toolsPreferences.getBoolean(PreferenceConstants.CODEASSIST_AUTOACTIVATION));
    if (!DartCoreDebug.ENABLE_ANALYSIS_SERVER) {
      enableFolding.setSelection(
          toolsPreferences.getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED));
    }
    removeTrailingWhitespaceCheck.setSelection(
        toolsPreferences.getBoolean(PreferenceConstants.EDITOR_REMOVE_TRAILING_WS));
    formatCheck.setSelection(
        toolsPreferences.getBoolean(PreferenceConstants.EDITOR_FORMAT_ON_SAVES));

    IEclipsePreferences prefs = DartCore.getPlugin().getPrefs();
    if (prefs != null) {
      runPubAutoCheck.setSelection(prefs.getBoolean(DartCore.PUB_AUTO_RUN_PREFERENCE, true));
      enableAnalysisServerButton.setSelection(
          prefs.getBoolean(DartCoreDebug.ENABLE_ANALYSIS_SERVER_PREF, true));
    }
  }
 /**
  * Creates the required type proposal.
  *
  * @param completionProposal the core completion proposal
  * @param invocationContext invocation context
  * @return the required type completion proposal
  */
 protected LazyDartCompletionProposal createRequiredTypeCompletionProposal(
     CompletionProposal completionProposal, DartContentAssistInvocationContext invocationContext) {
   if (PreferenceConstants.getPreferenceStore()
       .getBoolean(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES)) {
     return (LazyDartCompletionProposal)
         new FillArgumentNamesCompletionProposalCollector(invocationContext)
             .createDartCompletionProposal(completionProposal);
   } else {
     return new LazyDartTypeCompletionProposal(completionProposal, invocationContext);
   }
 }
 public void installColoredLabels(StructuredViewer viewer) {
   if (fManagedViewers.containsKey(viewer)) {
     return; // already installed
   }
   if (fManagedViewers.isEmpty()) {
     // first viewer installed
     PreferenceConstants.getPreferenceStore().addPropertyChangeListener(this);
     fColorRegisty.addListener(this);
   }
   fManagedViewers.put(viewer, new ManagedViewer(viewer));
 }
  public void uninstallColoredLabels(StructuredViewer viewer) {
    ManagedViewer mv = fManagedViewers.remove(viewer);
    if (mv == null) {
      return; // not installed
    }

    if (fManagedViewers.isEmpty()) {
      PreferenceConstants.getPreferenceStore().removePropertyChangeListener(this);
      fColorRegisty.removeListener(this);
      // last viewer uninstalled
    }
  }
 public static void setPerformTransforms(boolean performTransforms) {
   PreferenceConstants.getPreferenceStore()
       .setValue(PreferenceConstants.FORMATTER_PERFORM_TRANSFORMS, performTransforms);
 }
 public static String getSpacesPerIndent() {
   return PreferenceConstants.getPreferenceStore()
       .getString(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);
 }
 public static boolean getPerformTransforms() {
   return PreferenceConstants.getPreferenceStore()
       .getBoolean(PreferenceConstants.FORMATTER_PERFORM_TRANSFORMS);
 }
 public static boolean getInsertSpacesForTabs() {
   return PreferenceConstants.getPreferenceStore()
       .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS);
 }
  @Override
  public boolean performOk() {
    IPreferenceStore editorPreferences = EditorsPlugin.getDefault().getPreferenceStore();

    editorPreferences.setValue(
        AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER,
        lineNumbersCheck.getSelection());

    DartFormatter.setMaxLineLengthEnabled(printMarginCheck.getSelection());
    if (printMarginCheck.getSelection()) {
      DartFormatter.setMaxLineLength(printMarginText.getText());
    }

    IPreferenceStore toolsPreferenceStore = PreferenceConstants.getPreferenceStore();

    toolsPreferenceStore.setValue(
        PreferenceConstants.CODEASSIST_AUTOACTIVATION, enableAutoCompletion.getSelection());
    if (!DartCoreDebug.ENABLE_ANALYSIS_SERVER) {
      toolsPreferenceStore.setValue(
          PreferenceConstants.EDITOR_FOLDING_ENABLED, enableFolding.getSelection());
    }
    toolsPreferenceStore.setValue(
        PreferenceConstants.EDITOR_REMOVE_TRAILING_WS,
        removeTrailingWhitespaceCheck.getSelection());

    toolsPreferenceStore.setValue(
        PreferenceConstants.EDITOR_FORMAT_ON_SAVES, formatCheck.getSelection());

    handleSave(editorPreferences);
    handleSave(toolsPreferenceStore);

    IEclipsePreferences prefs = DartCore.getPlugin().getPrefs();
    if (prefs != null) {
      prefs.putBoolean(DartCore.PUB_AUTO_RUN_PREFERENCE, runPubAutoCheck.getSelection());
      try {
        DartCore.getPlugin().savePrefs();
      } catch (CoreException e) {
        DartToolsPlugin.log(e);
      }
      //
      // If the user has changed the preference to true,
      // then run pub on all pubspecs in the workspace
      //
      if (runPubChanged) {
        UIInstrumentationBuilder instrumentation = UIInstrumentation.builder(this.getClass());
        try {
          boolean autoRunPubEnabled = runPubAutoCheck.getSelection();
          instrumentation.metric("autoRunPubEnabled", autoRunPubEnabled);
          if (autoRunPubEnabled) {
            PlatformUI.getWorkbench()
                .getDisplay()
                .asyncExec(
                    new Runnable() {
                      @Override
                      public void run() {
                        runPubNow();
                      }
                    });
          }
        } catch (RuntimeException e) {
          instrumentation.record(e);
          throw e;
        } finally {
          instrumentation.log();
        }
      }
    }

    boolean serverChanged =
        setPrefBool(DartCoreDebug.ENABLE_ANALYSIS_SERVER_PREF, true, enableAnalysisServerButton);

    if (serverChanged) {
      MessageDialog.openInformation(
          getShell(),
          "Restart Required",
          "These changes will only take effect once the IDE has been restarted.");
    }

    return true;
  }
 public static boolean showColoredLabels() {
   String preference =
       PreferenceConstants.getPreference(AppearancePreferencePage.PREF_COLORED_LABELS, null);
   return preference != null && Boolean.valueOf(preference).booleanValue();
 }