Example usage for org.eclipse.jface.preference IPreferenceStore contains

List of usage examples for org.eclipse.jface.preference IPreferenceStore contains

Introduction

In this page you can find the example usage for org.eclipse.jface.preference IPreferenceStore contains.

Prototype

boolean contains(String name);

Source Link

Document

Returns whether the named preference is known to this preference store.

Usage

From source file:net.certiv.fluentmark.editor.FluentSourceViewer.java

License:Open Source License

/**
 * Creates a color from the information stored in the given preference delta. Returns
 * <code>null</code> if there is no such information available. TODO: move or fix store.getColor
 *
 * @param delta the delta to read from/*w  ww .ja  va 2  s  .  com*/
 * @param key the key used for the lookup in the preference delta
 * @param display the display used create the color
 * @return the created color according to the specification in the preference delta
 */
public Color createColor(IPreferenceStore store, String key, Display display) {
    RGB rgb = null;
    if (store.contains(key)) {
        if (store.isDefault(key)) {
            rgb = PreferenceConverter.getDefaultColor(store, key);
        } else {
            rgb = PreferenceConverter.getColor(store, key);
        }
        if (rgb != null)
            return new Color(display, rgb);
    }
    return null;
}

From source file:net.sf.eclipse.tomcat.TomcatLauncherPlugin.java

License:Open Source License

public List readProjectsInSourcePathFromPref() {
    IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
    if (!(pref.contains(TOMCAT_PREF_PROJECTSINSOURCEPATH_KEY))) {
        // Compute source path for a new workspace
        pref.setValue(TOMCAT_PREF_COMPUTESOURCEPATH_KEY, true);
        return computeProjectsInSourcePath();
    } else {/*from w  w  w . ja v a2 s .  c om*/
        return TomcatLauncherPlugin.readProjectsFromPreferenceStore(TOMCAT_PREF_PROJECTSINSOURCEPATH_KEY);
    }
}

From source file:net.sf.eclipsensis.editor.text.NSISTextUtility.java

License:Open Source License

private static Color createColor(Map<String, Color> map, IPreferenceStore store, String key, String defaultKey,
        Display display) {/*from w  w  w  . j a  va  2  s . com*/
    if (!store.getBoolean(defaultKey)) {
        if (store.contains(key)) {
            RGB rgb = null;
            if (store.isDefault(key)) {
                rgb = PreferenceConverter.getDefaultColor(store, key);
            } else {
                rgb = PreferenceConverter.getColor(store, key);
            }
            Color color = new Color(display, rgb);
            Color oldColor = map.put(key, color);
            if (oldColor != null) {
                oldColor.dispose();
            }
            return color;
        }
    }

    return null;
}

From source file:net.sf.eclipsensis.installoptions.dialogs.InstallOptionsPreferencePage.java

License:Open Source License

private <T> void loadPreference(Map<String, ? super T> map, String name, TypeConverter<T> converter,
        T defaultValue) {//from w w  w. jav a 2s  . c  om
    T o = null;
    try {
        IPreferenceStore store = getPreferenceStore();
        if (store.contains(name) || store.isDefault(name)) {
            o = converter.asType(store.getString(name));
        }
    } catch (Exception ex) {
        o = null;
    }
    if (o == null) {
        o = converter.makeCopy(defaultValue);
    }
    map.put(name, o);
}

From source file:net.sf.eclipsensis.installoptions.InstallOptionsPlugin.java

License:Open Source License

private void initializePreference(IPreferenceStore store, String name, String defaultValue) {
    store.setDefault(name, defaultValue);
    if (!store.contains(name)) {
        store.setToDefault(name);//  w w w  .j av  a 2  s .c  o m
    }
}

From source file:net.sf.eclipsensis.installoptions.InstallOptionsPlugin.java

License:Open Source License

private void initializePaletteViewerPreferences(IPreferenceStore store) {
    //This should be done just once.
    if (!store.getBoolean(PREFERENCE_PALETTE_VIEWER_PREFS_INIT)) {
        String[] properties = { PaletteViewerPreferences.PREFERENCE_LAYOUT,
                PaletteViewerPreferences.PREFERENCE_AUTO_COLLAPSE,
                PaletteViewerPreferences.PREFERENCE_COLUMNS_ICON_SIZE,
                PaletteViewerPreferences.PREFERENCE_LIST_ICON_SIZE,
                PaletteViewerPreferences.PREFERENCE_ICONS_ICON_SIZE,
                PaletteViewerPreferences.PREFERENCE_DETAILS_ICON_SIZE,
                PaletteViewerPreferences.PREFERENCE_FONT };
        Bundle bundle = Platform.getBundle(GEF_BUNDLE_ID);
        if (bundle != null) {
            IPreferencesService preferencesService = Platform.getPreferencesService();
            IScopeContext[] contexts = { new InstanceScope() };
            for (int i = 0; i < properties.length; i++) {
                if (!store.contains(properties[i])) {
                    String val = preferencesService.getString(GEF_BUNDLE_ID, properties[i], "", contexts); //$NON-NLS-1$
                    if (!Common.isEmpty(val)) {
                        store.setValue(properties[i], val);
                    }//from  www  .  j av  a 2s .  c o  m
                }
            }
        }
        store.setValue(PREFERENCE_PALETTE_VIEWER_PREFS_INIT, true);
    }
}

From source file:net.sf.eclipsensis.startup.FileAssociationChecker.java

License:Open Source License

private void initializePreference(String associationId, boolean enablement, String bundleId,
        String enablementPref) {//  ww w  . ja  va  2 s . c om
    if (!PREFERENCES.contains(associationId)) {
        boolean enablement2 = enablement;
        if (enablementPref != null) {
            Bundle bundle = Platform.getBundle(bundleId);
            if (bundle != null) {
                IPreferenceStore prefs = new ScopedPreferenceStore(new InstanceScope(),
                        bundle.getSymbolicName());
                if (prefs.contains(enablementPref)) {
                    enablement2 = prefs.getBoolean(enablementPref);
                }
            }
        }
        PREFERENCES.setValue(associationId, Boolean.toString(enablement2));
    }
}

From source file:net.sf.eclipsensis.util.HTMLExporter.java

License:Open Source License

/**
 * @throws UnsupportedEncodingException/*  ww  w  .  j a  va 2s . c o  m*/
 * @throws FileNotFoundException
 * @throws IOException
 */
private void writeHead(File file) throws UnsupportedEncodingException, FileNotFoundException, IOException {
    String charset = null;
    IDocumentProvider provider = mEditor.getDocumentProvider();
    if (provider instanceof IStorageDocumentProvider) {
        charset = ((IStorageDocumentProvider) provider).getEncoding(mEditor.getEditorInput());
        if (charset == null) {
            charset = ((IStorageDocumentProvider) provider).getDefaultEncoding();
        }
    }
    if (charset == null) {
        charset = System.getProperty("file.encoding"); //$NON-NLS-1$
    }
    if (charset != null) {
        mWriter = new PrintWriter(
                new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)));
    } else {
        mWriter = new PrintWriter(new BufferedWriter(new FileWriter(file)));
    }

    mWriter.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); //$NON-NLS-1$
    mWriter.println("<html>"); //$NON-NLS-1$
    mWriter.println("<head>"); //$NON-NLS-1$
    mWriter.print("<title>"); //$NON-NLS-1$
    mWriter.print(NSISEditorUtilities.getPathEditorInput(mEditor).getPath().toOSString());
    mWriter.println("</title>"); //$NON-NLS-1$
    mWriter.print("<meta http-equiv=\"Content-Type\" content=\"text/html"); //$NON-NLS-1$
    if (charset != null) {
        mWriter.print("; charset="); //$NON-NLS-1$
        mWriter.print(charset);
    }
    mWriter.println("\">"); //$NON-NLS-1$
    mWriter.println("<meta http-equiv=\"Content-Style-Type\" content=\"text/css\">"); //$NON-NLS-1$
    mWriter.println("<style type=\"text/css\">"); //$NON-NLS-1$
    mWriter.print("body { background-color: #"); //$NON-NLS-1$
    mWriter.print(ColorManager.rgbToHex(mStyledText.getBackground().getRGB()));
    mWriter.println("}"); //$NON-NLS-1$
    mWriter.println("pre { display: inline }"); //$NON-NLS-1$
    mWriter.println("a { color: #567599; text-decoration: none; }"); //$NON-NLS-1$
    mWriter.println("a:hover { background-color: #F4F4F4; color: #303030; text-decoration: underline}"); //$NON-NLS-1$
    if (mProjectionEnabled) {
        mWriter.println(
                "table.expand { float:right; border: 1px solid #567599; font-size: 1px; cursor: pointer; cursor: hand; }"); //$NON-NLS-1$
        mWriter.println("table.expand td { height: 4px; width: 4px; }"); //$NON-NLS-1$
        mWriter.println("table.expand td.top { border-bottom: 1px solid #567599; }"); //$NON-NLS-1$
        mWriter.println("table.expand  td.right { width: 4px; border-left: 1px solid #567599; }"); //$NON-NLS-1$
        mWriter.println(
                "table.collapse { float:right; border: 1px solid #567599; font-size: 1px; cursor: pointer; cursor: hand; }"); //$NON-NLS-1$
        mWriter.println("table.collapse td { height: 4px; width: 4px; }"); //$NON-NLS-1$
        mWriter.println("table.collapse td.top { border-bottom: 1px solid #567599; }"); //$NON-NLS-1$
        mWriter.println(".hiddenRow { display:none; }"); //$NON-NLS-1$
        mWriter.println(
                "#lineDiv { font-size: 1px; display: none; position: absolute; color: #567599; border-left: solid 1px; border-bottom: solid 1px; width: 1px; height: 1px; }"); //$NON-NLS-1$
    }
    if (mLineNumbersVisible) {
        StringBuffer buf = new StringBuffer("text-align: right; color: #"); //$NON-NLS-1$
        RGB rgb = null;
        // foreground color
        IPreferenceStore store = EditorsUI.getPreferenceStore();
        String pref = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR;
        if (store.contains(pref)) {
            if (store.isDefault(pref)) {
                rgb = PreferenceConverter.getDefaultColor(store, pref);
            } else {
                rgb = PreferenceConverter.getColor(store, pref);
            }
        }
        if (rgb == null) {
            rgb = new RGB(0, 0, 0);
        }
        buf.append(ColorManager.rgbToHex(rgb));
        mWriter.print(".lineNum { "); //$NON-NLS-1$
        mWriter.print(buf.toString());
        mWriter.println(" }"); //$NON-NLS-1$
    }
    mWriter.print(".ruler { background-color: #FFFFFF; text-align: right; border-right: 2px solid #"); //$NON-NLS-1$
    mWriter.print(
            ColorManager.rgbToHex(mShell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).getRGB()));
    mWriter.println(" }"); //$NON-NLS-1$
    mWriter.println("</style>"); //$NON-NLS-1$
    if (mProjectionEnabled) {
        mWriter.println("<script type=\"text/javascript\" language=\"javascript\">"); //$NON-NLS-1$
        mWriter.println("<!--"); //$NON-NLS-1$
        mWriter.println("document.write(\"<style type='text/css'>\");"); //$NON-NLS-1$
        mWriter.println("if(navigator.userAgent.toLowerCase().indexOf(\"netscape6\") >= 0) {"); //$NON-NLS-1$
        mWriter.println("  document.write(\"table.collapse td.right { width: 4px; }\")"); //$NON-NLS-1$
        mWriter.println("}"); //$NON-NLS-1$
        mWriter.println("else {"); //$NON-NLS-1$
        mWriter.println("  document.write(\"table.collapse td.right { width: 5px; }\")"); //$NON-NLS-1$
        mWriter.println("}"); //$NON-NLS-1$
        mWriter.println("document.write(\"</style>\");"); //$NON-NLS-1$
        mWriter.println("if (!String.prototype.endsWith) {"); //$NON-NLS-1$
        mWriter.println("  String.prototype.endsWith = function(suffix) {"); //$NON-NLS-1$
        mWriter.println("    var startPos = this.length - suffix.length;"); //$NON-NLS-1$
        mWriter.println("    if (startPos < 0) {"); //$NON-NLS-1$
        mWriter.println("      return false;"); //$NON-NLS-1$
        mWriter.println("    }"); //$NON-NLS-1$
        mWriter.println("    return (this.lastIndexOf(suffix, startPos) == startPos);"); //$NON-NLS-1$
        mWriter.println("  };"); //$NON-NLS-1$
        mWriter.println("}"); //$NON-NLS-1$
        mWriter.println("function getObject(name)"); //$NON-NLS-1$
        mWriter.println("{"); //$NON-NLS-1$
        mWriter.println("  if(document.all) {"); //$NON-NLS-1$
        mWriter.println("    return document.all[name];"); //$NON-NLS-1$
        mWriter.println("  }"); //$NON-NLS-1$
        mWriter.println("  else {"); //$NON-NLS-1$
        mWriter.println("    return document.getElementById(name);"); //$NON-NLS-1$
        mWriter.println("  }"); //$NON-NLS-1$
        mWriter.println("}"); //$NON-NLS-1$
        mWriter.println("function showLine(trigger,end)"); //$NON-NLS-1$
        mWriter.println("{"); //$NON-NLS-1$
        mWriter.println("  if(trigger.className != \"expand\") {"); //$NON-NLS-1$
        mWriter.println("    var lineDiv = getObject(\"lineDiv\");"); //$NON-NLS-1$
        mWriter.println("    var sec = getObject(\"line\"+end);"); //$NON-NLS-1$
        mWriter.println("    if(sec && lineDiv) {"); //$NON-NLS-1$
        mWriter.println("      var triggerPos = getElementPosition(trigger);"); //$NON-NLS-1$
        mWriter.println("      var secPos = getElementPosition(sec);"); //$NON-NLS-1$
        mWriter.println("      if(secPos && triggerPos) {"); //$NON-NLS-1$
        mWriter.println("        lineDiv.style.left = triggerPos.left+triggerPos.width/2;"); //$NON-NLS-1$
        mWriter.println("        lineDiv.style.top = triggerPos.top+triggerPos.height;"); //$NON-NLS-1$
        mWriter.println("        lineDiv.style.width = triggerPos.width/2;"); //$NON-NLS-1$
        mWriter.println(
                "        lineDiv.style.height = secPos.top+secPos.height/2-(triggerPos.top+triggerPos.height);"); //$NON-NLS-1$
        mWriter.println("        lineDiv.style.display = \"block\";"); //$NON-NLS-1$
        mWriter.println("      }"); //$NON-NLS-1$
        mWriter.println("    }"); //$NON-NLS-1$
        mWriter.println("  }"); //$NON-NLS-1$
        mWriter.println("}"); //$NON-NLS-1$
        mWriter.println("function hideLine()"); //$NON-NLS-1$
        mWriter.println("{"); //$NON-NLS-1$
        mWriter.println("  var lineDiv = getObject(\"lineDiv\");"); //$NON-NLS-1$
        mWriter.println("  if(lineDiv) {"); //$NON-NLS-1$
        mWriter.println("    lineDiv.style.display = \"none\";"); //$NON-NLS-1$
        mWriter.println("  }"); //$NON-NLS-1$
        mWriter.println("}"); //$NON-NLS-1$
        mWriter.println("function toggle(trigger,start,end) "); //$NON-NLS-1$
        mWriter.println("{"); //$NON-NLS-1$
        mWriter.println("  if(trigger) {"); //$NON-NLS-1$
        mWriter.println("    var i;"); //$NON-NLS-1$
        mWriter.println("    var sec;"); //$NON-NLS-1$
        mWriter.println("    var expand;"); //$NON-NLS-1$
        mWriter.println("    hideLine();"); //$NON-NLS-1$
        mWriter.println("    if(trigger.className == \"expand\") {"); //$NON-NLS-1$
        mWriter.println("      expand = true;"); //$NON-NLS-1$
        mWriter.println("      trigger.className = \"collapse\";"); //$NON-NLS-1$
        mWriter.println("    }"); //$NON-NLS-1$
        mWriter.println("    else {"); //$NON-NLS-1$
        mWriter.println("      expand = false;"); //$NON-NLS-1$
        mWriter.println("      trigger.className = \"expand\";"); //$NON-NLS-1$
        mWriter.println("    }"); //$NON-NLS-1$
        mWriter.println("    for(i=start; i<= end; i++) {"); //$NON-NLS-1$
        mWriter.println("      sec = getObject(\"line\"+i);"); //$NON-NLS-1$
        mWriter.println("      if(sec) {"); //$NON-NLS-1$
        mWriter.println("        if(expand) {"); //$NON-NLS-1$
        mWriter.println("          if(sec.className == \"hiddenRow\") {"); //$NON-NLS-1$
        mWriter.println("            sec.className = \"\";"); //$NON-NLS-1$
        mWriter.println("          }"); //$NON-NLS-1$
        mWriter.println("          else if(sec.className.endsWith(\" hiddenRow\")) {"); //$NON-NLS-1$
        mWriter.println(
                "            sec.className = sec.className.substr(0,sec.className.length-\" hiddenRow\".length);"); //$NON-NLS-1$
        mWriter.println("          }"); //$NON-NLS-1$
        mWriter.println("        }"); //$NON-NLS-1$
        mWriter.println("        else {"); //$NON-NLS-1$
        mWriter.println("          if(sec.className == \"\") {"); //$NON-NLS-1$
        mWriter.println("            sec.className = \"hiddenRow\";"); //$NON-NLS-1$
        mWriter.println("          }"); //$NON-NLS-1$
        mWriter.println("          else {"); //$NON-NLS-1$
        mWriter.println("            sec.className = sec.className + \" hiddenRow\";"); //$NON-NLS-1$
        mWriter.println("          }"); //$NON-NLS-1$
        mWriter.println("        }"); //$NON-NLS-1$
        mWriter.println("      }"); //$NON-NLS-1$
        mWriter.println("    }"); //$NON-NLS-1$
        mWriter.println("  }"); //$NON-NLS-1$
        mWriter.println("}"); //$NON-NLS-1$
        mWriter.println("function getElementPosition(elem){"); //$NON-NLS-1$
        mWriter.println("  var offsetLeft = 0;"); //$NON-NLS-1$
        mWriter.println("  var offsetTop =0;"); //$NON-NLS-1$
        mWriter.println("  var width = elem.offsetWidth;"); //$NON-NLS-1$
        mWriter.println("  var height = elem.offsetHeight;"); //$NON-NLS-1$
        mWriter.println("  while (elem){"); //$NON-NLS-1$
        mWriter.println("    offsetLeft += elem.offsetLeft;"); //$NON-NLS-1$
        mWriter.println("    offsetTop += elem.offsetTop;"); //$NON-NLS-1$
        mWriter.println("    elem = elem.offsetParent;"); //$NON-NLS-1$
        mWriter.println("  }"); //$NON-NLS-1$
        mWriter.println(
                "  if (navigator.userAgent.indexOf('Mac') != -1 && typeof(document.body.leftMargin) !='undefined'){"); //$NON-NLS-1$
        mWriter.println("    offsetLeft += document.body.leftMargin;"); //$NON-NLS-1$
        mWriter.println("    offsetTop += document.body.topMargin;"); //$NON-NLS-1$
        mWriter.println("  }"); //$NON-NLS-1$
        mWriter.println("  return {left:offsetLeft,top:offsetTop, width:width, height: height};"); //$NON-NLS-1$
        mWriter.println("}"); //$NON-NLS-1$
        mWriter.println("//-->"); //$NON-NLS-1$
        mWriter.println("</script>"); //$NON-NLS-1$
    }
    mWriter.println("</head>"); //$NON-NLS-1$
}

From source file:net.sf.solareclipse.xml.internal.ui.preferences.CSSSyntaxPreferencePage.java

License:Open Source License

/**
 * Creates a color from the information stored in the given preference store.
 * Returns <code>null</code> if there is no such information available.
 *///from  w ww .j  ava 2  s  . com
private Color createColor(IPreferenceStore store, String key, Display display) {
    RGB rgb = null;

    if (store.contains(key)) {
        if (store.isDefault(key)) {
            rgb = PreferenceConverter.getDefaultColor(store, key);
        } else {
            rgb = PreferenceConverter.getColor(store, key);
        }

        if (rgb != null) {
            return new Color(display, rgb);
        }
    }

    return null;
}

From source file:net.tourbook.colors.ColorDefinition.java

License:Open Source License

/**
 * Sets the color for the default, current and changes
 * /*from w w  w. j  a v  a 2s  .c  o  m*/
 * @param prefName
 *            preference name
 * @param visibleName
 *            visible name
 * @param defaultGradientBright
 *            default bright gradient color
 * @param defaultGradientDark
 *            default dark gradient color
 * @param defaultLineColor
 *            default line color
 * @param defaultLegendColor
 *            legend color configuration or <code>null</code> when legend is not available
 */
protected ColorDefinition(final String prefName, final String visibleName, final RGB defaultGradientBright,
        final RGB defaultGradientDark, final RGB defaultLineColor, final LegendColor defaultLegendColor) {

    _prefName = prefName;
    _visibleName = visibleName;

    _defaultGradientBright = defaultGradientBright;
    _defaultGradientDark = defaultGradientDark;
    _defaultLineColor = defaultLineColor;

    _defaultLegendColor = defaultLegendColor;

    final IPreferenceStore prefStore = TourbookPlugin.getDefault().getPreferenceStore();
    final String graphPrefName = getGraphPrefName();

    /*
     * set gradient bright from pref store or default
     */
    final String prefColorGradientBright = graphPrefName + GraphColorProvider.PREF_COLOR_BRIGHT;
    if (prefStore.contains(prefColorGradientBright)) {
        _gradientBright = PreferenceConverter.getColor(prefStore, prefColorGradientBright);
    } else {
        _gradientBright = _defaultGradientBright;
    }
    _newGradientBright = _gradientBright;

    /*
     * gradient dark
     */
    final String prefColorGradientDark = graphPrefName + GraphColorProvider.PREF_COLOR_DARK;
    if (prefStore.contains(prefColorGradientDark)) {
        _gradientDark = PreferenceConverter.getColor(prefStore, prefColorGradientDark);
    } else {
        _gradientDark = _defaultGradientDark;
    }
    _newGradientDark = _gradientDark;

    /*
     * line color
     */
    final String prefColorLine = graphPrefName + GraphColorProvider.PREF_COLOR_LINE;
    if (prefStore.contains(prefColorLine)) {
        _lineColor = PreferenceConverter.getColor(prefStore, prefColorLine);
    } else {
        _lineColor = _defaultLineColor;
    }
    _newLineColor = _lineColor;
}