org.netbeans.api.editor.mimelookup.MimeLookup Java Examples

The following examples show how to use org.netbeans.api.editor.mimelookup.MimeLookup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LegacyFormattersProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Formatter getFormatter() {
    if (legacyFormatter == null) {
        EditorKit kit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
        if (kit != null) {
            try {
                Method createFormatterMethod = kit.getClass().getDeclaredMethod("createFormatter"); //NOI18N
                legacyFormatter = createFormatterMethod.invoke(kit);
            } catch (Exception e) {
                legacyFormatter = e;
            }
        } else {
            legacyFormatter = NO_FORMATTER;
        }
    }
    return legacyFormatter instanceof Formatter ? (Formatter) legacyFormatter : null;
}
 
Example #2
Source File: HintsUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void refresh(Document doc, int pos) {
    AnnotationHolder holder = getAnnotationHolder(doc);

    if (holder == null) {
        Logger.getLogger(HintsUI.class.getName()).log(Level.FINE, "No AnnotationHolder associated to: {0} (stream description property: {1})", new Object[] {doc, doc.getProperty(Document.StreamDescriptionProperty)});
        return ;
    }
    
    Context context = ContextAccessor.getDefault().newContext(pos, cancel);
    String mimeType = org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(doc);
    Lookup lookup = MimeLookup.getLookup(mimeType);
    Collection<? extends PositionRefresher> refreshers = lookup.lookupAll(PositionRefresher.class);
    //set errors from all available refreshers
    for (PositionRefresher ref : refreshers) {
        Map<String, List<ErrorDescription>> layer2Errs = ref.getErrorDescriptionsAt(context, doc);
        holder.setErrorsForLine(pos, layer2Errs);
    }
}
 
Example #3
Source File: EmbeddedSectionsHighlighting.java    From netbeans with Apache License 2.0 6 votes vote down vote up
EmbeddedSectionsHighlighting(Document document) {
    this.document = document;
    
    // load the background color for the embedding token
    AttributeSet jsAttribs = null;
    AttributeSet elAttribs = null;
    String mimeType = (String) document.getProperty("mimeType"); //NOI18N
    FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
    if (fcs != null) {
        Color jsBC = getColoring(fcs, JspTokenId.SCRIPTLET.primaryCategory());
        if (jsBC != null) {
            jsAttribs = AttributesUtilities.createImmutable(
                StyleConstants.Background, jsBC, 
                ATTR_EXTENDS_EOL, Boolean.TRUE);
        }
        Color elBC = getColoring(fcs, JspTokenId.EL.primaryCategory());
        if (elBC != null) {
            elAttribs = AttributesUtilities.createImmutable(
                StyleConstants.Background, elBC, 
                ATTR_EXTENDS_EOL, Boolean.TRUE);
        }
    }
    javascripletBackground = jsAttribs;
    expressionLanguageBackground = elAttribs;
}
 
Example #4
Source File: EmbeddedSectionsHighlighting.java    From netbeans with Apache License 2.0 6 votes vote down vote up
EmbeddedSectionsHighlighting(Document document) {
    this.document = document;
    
    // load the background color for the embedding token
    AttributeSet attribs = null;
    String mimeType = (String) document.getProperty("mimeType"); //NOI18N
    FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
    if (fcs != null) {
        Color jsBC = getColoring(fcs, GspTokenId.GSTRING_CONTENT.primaryCategory());
        if (jsBC != null) {
             attribs = AttributesUtilities.createImmutable(
                StyleConstants.Background, jsBC, 
                ATTR_EXTENDS_EOL, Boolean.TRUE);
        }
    }
    groovyBackground = attribs;
}
 
Example #5
Source File: IndexingSupportACIDTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testChangesVisibleAfterCommit() throws InterruptedException, IOException {

        assertTrue(GlobalPathRegistry.getDefault().getPaths(FOO_SOURCES).isEmpty());
        final RepositoryUpdaterTest.TestHandler handler = new RepositoryUpdaterTest.TestHandler();
        final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
        logger.setLevel (Level.FINEST);
        logger.addHandler(handler);

        globalPathRegistry_register(FOO_SOURCES,new ClassPath[]{cp1});
        assertTrue (handler.await());
        assertEquals(0, handler.getBinaries().size());
        assertEquals(1, handler.getSources().size());
        assertEquals(this.src1.toURL(), handler.getSources().get(0));
        assertTrue(MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).isSuccess());
        QuerySupport qs = QuerySupport.forRoots(FooIndexerFactory.NAME, FooIndexerFactory.VERSION, src1);
        final Collection<? extends IndexResult> res = qs.query("_sn", "", QuerySupport.Kind.PREFIX, (String[]) null);   //NOI18N
        assertEquals(1, res.size());
        assertEquals(file1, res.iterator().next().getFile());
    }
 
Example #6
Source File: Model.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean getParameter(String parameterName, boolean defaultValue) {
    Set<String> mimeTypes = EditorSettings.getDefault().getAllMimeTypes();
    List<String> list = new ArrayList<String>(PRIVILEDGED_MIME_TYPES);
    list.addAll(mimeTypes);
    
    for(String mimeType : list) {
        Preferences prefs = MimeLookup.getLookup(mimeType).lookup(Preferences.class);
        
        String value = prefs.get(parameterName, null);
        if (value != null) {
            return prefs.getBoolean(parameterName, false);
        }
    }
    
    return defaultValue;
}
 
Example #7
Source File: TinyTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Map<String, String> alterSettings(String... settings) throws Exception {
    //XXX: hack, need to initialize the HintTest's lookup before setting the
    //formatting preferences
    HintTest.create();
    
    Map<String, String> adjustPreferences = new HashMap<String, String>();
    for (int i = 0; i < settings.length; i += 2) {
        adjustPreferences.put(settings[i], settings[i + 1]);
    }
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    Map<String, String> origValues = new HashMap<String, String>();
    for (String key : adjustPreferences.keySet()) {
        origValues.put(key, preferences.get(key, null));
    }
    setValues(preferences, adjustPreferences);
    return origValues;
}
 
Example #8
Source File: PHPTokenListProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public TokenList findTokenList(Document doc) {
    String mimeType = NbEditorUtilities.getMimeType(doc);
    if (FileUtils.PHP_MIME_TYPE.equals(mimeType)
            && doc instanceof BaseDocument) {
        for (TokenListProvider p : MimeLookup.getLookup(MimePath.get("text/html")).lookupAll(TokenListProvider.class)) { // NOI18N
            TokenList l = p.findTokenList(doc);
            if (l != null) {
                List<TokenList> tokens = new ArrayList<>(2);
                tokens.add(new PHPTokenList(doc));
                tokens.add(l);
                return MultiTokenList.create(tokens);
            }
        }
    }
    return null;
}
 
Example #9
Source File: NbEditorToolBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public NbEditorToolBar(JTextComponent component) {
        this.componentRef = new WeakReference(component);
        
        setFloatable(false);
        //mkleint - instead of here, assign the border in CloneableEditor and MultiView module.
//        // special border installed by core or no border if not available
//        Border b = (Border)UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N
//        setBorder(b);
        addMouseListener(sharedMouseListener);

        installModulesInstallationListener();
        installNoOpActionMappings();
        
        lookupResult = MimeLookup.getLookup(DocumentUtilities.getMimeType(component)).lookupResult(KeyBindingSettings.class);
        lookupResult.addLookupListener(WeakListeners.create(LookupListener.class, keybindingsTracker, lookupResult));
        
        String mimeType = DocumentUtilities.getMimeType(component);
        preferences = MimeLookup.getLookup(mimeType == null ? MimePath.EMPTY : MimePath.parse(mimeType)).lookup(Preferences.class);
        preferences.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefsTracker, preferences));
        
        refreshToolbarButtons();
        setBorderPainted(true);
    }
 
Example #10
Source File: TypingCompletionUnitTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCommentBlockCompletionTwoComments () {
    Preferences prefs = MimeLookup.getLookup(JavaKit.JAVA_MIME_TYPE).lookup(Preferences.class);
    try {
        prefs.putBoolean("enableBlockCommentFormatting", true);
        Context ctx = new Context(new JavaKit(),
                "/*|\n" +
                "/*\n" +
                " */"
        );
        ctx.typeChar('\n');
        ctx.assertDocumentTextEquals(
                "/*\n" +
                " * |\n" +
                " */\n" +
                "/*\n" +
                " */"
        );
    } finally {
        prefs.remove("enableBlockCommentFormatting");
    }
}
 
Example #11
Source File: GuardedBlockSuppressLayer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private AttributeSet getAttribs(String coloringName, boolean extendsEol, boolean extendsEmptyLine) {
    FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
    AttributeSet attribs = fcs.getFontColors(coloringName);
    
    if (attribs == null) {
        attribs = SimpleAttributeSet.EMPTY;
    } else if (extendsEol || extendsEmptyLine) {
        attribs = AttributesUtilities.createImmutable(
            attribs, 
            AttributesUtilities.createImmutable(
                ATTR_EXTENDS_EOL, Boolean.valueOf(extendsEol),
                ATTR_EXTENDS_EMPTY_LINE, Boolean.valueOf(extendsEmptyLine))
        );
    }
    
    return attribs;
}
 
Example #12
Source File: TrailingWhitespaceRemove.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void performTask() {
    Preferences prefs = MimeLookup.getLookup(DocumentUtilities.getMimeType(doc)).lookup(Preferences.class);
    if (prefs.getBoolean(SimpleValueNames.ON_SAVE_USE_GLOBAL_SETTINGS, Boolean.TRUE)) {
        prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
    }
    String policy = prefs.get(SimpleValueNames.ON_SAVE_REMOVE_TRAILING_WHITESPACE, "never"); //NOI18N
    if (!"never".equals(policy)) { //NOI18N
        ModRootElement modRootElement = ModRootElement.get(doc);
        if (modRootElement != null) {
            boolean origEnabled = modRootElement.isEnabled();
            modRootElement.setEnabled(false);
            try {
                new TrailingWhitespaceRemoveProcessor(doc, "modified-lines".equals(policy), canceled).removeWhitespace(); //NOI18N
            } finally {
                modRootElement.setEnabled(origEnabled);
            }
        }
    }
}
 
Example #13
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNewLineIndentationBeforeHalfIndentedTryBlock() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performNewLineIndentationTest("package t;\npublic class T {\n    public void op() {\n        try| {\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\n        try\n          {\n    }\n}\n");
    } finally {
        preferences.remove("otherBracePlacement");
    }
}
 
Example #14
Source File: CodeCompletionOptionsPanelController.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void applyChanges() {
    boolean fire;

    synchronized (this) {
        LOG.fine("applyChanges"); //NOI18N

        pf.applyChanges();

        // Make sure that completions settings that are only accessible for
        // 'all languages' are not overriden by particular languages (mime types)
        for(String mimeType : EditorSettings.getDefault().getAllMimeTypes()) {
            LOG.fine("Cleaning up '" + mimeType + "' preferences"); //NOI18N
            Preferences prefs = MimeLookup.getLookup(mimeType).lookup(Preferences.class);
            prefs.remove(SimpleValueNames.COMPLETION_PAIR_CHARACTERS); //NOI18N
            prefs.remove(SimpleValueNames.COMPLETION_AUTO_POPUP);
            prefs.remove(SimpleValueNames.JAVADOC_AUTO_POPUP);
            prefs.remove(SimpleValueNames.JAVADOC_POPUP_NEXT_TO_CC);
            prefs.remove(SimpleValueNames.SHOW_DEPRECATED_MEMBERS);
            prefs.remove(SimpleValueNames.COMPLETION_INSTANT_SUBSTITUTION);
            prefs.remove(SimpleValueNames.COMPLETION_CASE_SENSITIVE);
        }

        pf.destroy();
        pf = null;
        panel.setSelector(null);
        selector = null;

        fire = changed;
        changed = false;
    }

    if (fire) {
        pcs.firePropertyChange(PROP_CHANGED, true, false);
    }
}
 
Example #15
Source File: EditorUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Update various properties of the component in AWT thread.
 */
void updateComponentProperties() {

    // Refresh rendering hints
    String mimeType = org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(component);
    FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
    renderingHints = (Map<?, ?>) fcs.getFontColors(FontColorNames.DEFAULT_COLORING).getAttribute(EditorStyleConstants.RenderingHints);
    
    // Set the margin
    String value = prefs.get(SimpleValueNames.MARGIN, null);
    Insets margin = value != null ? SettingsConversions.parseInsets(value) : null;
    component.setMargin(margin != null ? margin : NULL_INSETS);

    lineNumberDigitWidth = computeLineNumberDigitWidth();

    // Update line height
    updateLineHeight(getComponent());

    // Update space width of the default coloring's font
    FontMetricsCache.Info fmcInfo = FontMetricsCache.getInfo(getDefaultColoring().getFont());
    defaultSpaceWidth = fmcInfo.getSpaceWidth(component);

    updateLineNumberWidth(0);

    // update glyph gutter colors and fonts
    if (isGlyphGutterVisible()) {
        glyphGutter.update();
        updateScrollPaneCornerColor();
    }
}
 
Example #16
Source File: OptionsUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void lazyInit() {
    if (INITED.compareAndSet(false, true)) {
        preferences = MimeLookup.getLookup(SQLLanguageConfig.mimeType).lookup(Preferences.class);
        preferences.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, PREFERENCES_TRACKER, preferences));
        PREFERENCES_TRACKER.preferenceChange(null);
    }
}
 
Example #17
Source File: RemoveSurroundingCodeAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public RemoveSurroundingCodeAction(){
    // retrieve colors from fonts color settings
    Lookup lookup = MimeLookup.getLookup(JavaKit.JAVA_MIME_TYPE);
    result = lookup.lookupResult(FontColorSettings.class);
    result.addLookupListener(WeakListeners.create(LookupListener.class, this, result));
    resultChanged(null); // initial retrieval
}
 
Example #18
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNewLineIndentationBeforeHalfIndentedElseBlock() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performNewLineIndentationTest("package t;\npublic class T {\n    public void op() {\n        if (true) {\n        } else| {\n        }\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\n        if (true) {\n        } else\n          {\n        }\n    }\n}\n");
    } finally {
        preferences.remove("otherBracePlacement");
    }
}
 
Example #19
Source File: FontColorSettingsImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void checkSingleAttribute(MimePath mimePath, String coloringName, Object attributeKey, Object attributeValue) {
    Lookup lookup = MimeLookup.getLookup(mimePath);
    
    FontColorSettings fcs = lookup.lookup(FontColorSettings.class);
    assertNotNull("Can't find FontColorSettings", fcs);
    
    AttributeSet attribs = fcs.getTokenFontColors(coloringName);
    assertNotNull("Can't find " + coloringName + " coloring", attribs);
    assertEquals("Wrong value of '" + attributeKey + "'", attributeValue, attribs.getAttribute(attributeKey));
}
 
Example #20
Source File: OverrideEditorActions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static EditorKit   getBaseEditorKit() {
    Reference<EditorKit> r = plainKitRef;
    EditorKit ek = r.get();
    if (ek != null) {
        return ek;
    }
    ek = MimeLookup.getLookup(MimePath.parse("text/plain")).lookup(EditorKit.class);
    synchronized (OverrideEditorActions.class) {
        if (r == plainKitRef) {
            plainKitRef = new WeakReference<>(ek);
        }
    }
    return ek;
}
 
Example #21
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testLineIndentationBeforeAbsolutLabeledStatement() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.putBoolean("absoluteLabelIndent", true);
    try {
        performLineIndentationTest("package t;\npublic class T {\n    public void op() {\n|        mylabel:\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\nmylabel:\n    }\n}\n");
    } finally {
        preferences.remove("absoluteLabelIndent");
    }
}
 
Example #22
Source File: MainMenuAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected @Override void setMenu(){
    super.setMenu();
    JTextComponent c = getComponent();
    MimePath mimePath = c == null ? MimePath.EMPTY : MimePath.parse(DocumentUtilities.getMimeType(c));
    Preferences prefs = MimeLookup.getLookup(mimePath).lookup(Preferences.class);
    boolean visible = prefs.getBoolean(SimpleValueNames.TOOLBAR_VISIBLE_PROP, EditorPreferencesDefaults.defaultToolbarVisible);
    SHOW_TOOLBAR_MENU.setState(visible);
}
 
Example #23
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNewLineIndentationBeforeHalfIndentedSwitchEnd() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performNewLineIndentationTest("package t;\npublic class T {\n    public void op() {\n        switch(get())\n          {\n            case 1:\n                break;|}\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\n        switch(get())\n          {\n            case 1:\n                break;\n          }\n    }\n}\n");
    } finally {
        preferences.remove("otherBracePlacement");
    }
}
 
Example #24
Source File: MimeLookupTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 
 * FolderLookup behaves recursively by default. It is not ideal as for MimeLookup,
 * that should operate only on the mime-type-folder
 * see issue #58991
 * Testing if the MimeLookup is not recursive
 */
public void testLookupFolderRecursivity(){
    //StringBuffer.instance is declared 
    // in "Editors/text/xml/text/html/java-lang-StringBuffer.instance"
    // it shouldn't be found in text/xml parent folder
    Lookup lookup = MimeLookup.getLookup("text/xml");
    checkLookupObject(lookup, StringBuffer.class, false);        
}
 
Example #25
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNewLineIndentationInsideMultilineCommentWithTabIndents() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.putBoolean("expand-tabs", false);
    preferences.putInt("tab-size", 4);
    preferences.putBoolean("enableBlockCommentFormatting", true);
    try {
        performNewLineIndentationTest("package t;\npublic class T {\n\t/*|\n\t */\n\tpublic void op() {\n\t}\n}\n",
                "package t;\npublic class T {\n\t/*\n\t * \n\t */\n\tpublic void op() {\n\t}\n}\n");
    } finally {
        preferences.remove("enableBlockCommentFormatting");
        preferences.remove("tab-size");
        preferences.remove("expand-tabs");
    }
}
 
Example #26
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testLineIndentationBeforeHalfIndentedNewArrayInit() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performLineIndentationTest("package t;\npublic class T {\n    public void op() {\n        int[] arr = new int[]\n|                {\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\n        int[] arr = new int[]\n          {\n    }\n}\n");
    } finally {
        preferences.remove("otherBracePlacement");
    }
}
 
Example #27
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNewLineIndentationBeforeEmptyHalfIndentedArrayInitEnd() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
    try {
        performNewLineIndentationTest("package t;\npublic class T {\n    public void op() {\n        int[] arr =\n          {|}\n    }\n}\n",
                "package t;\npublic class T {\n    public void op() {\n        int[] arr =\n          {\n          }\n    }\n}\n");
    } finally {
        preferences.remove("otherBracePlacement");
    }
}
 
Example #28
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testLineIndentationAtMultilineCommentStartWithTabIndents() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.putBoolean("expand-tabs", false);
    preferences.putInt("tab-size", 4);
    preferences.putBoolean("enableBlockCommentFormatting", true);
    try {
        performLineIndentationTest("package t;\npublic class T {\n\t/*\n|\n\tpublic void op() {\n\t}\n}\n",
                "package t;\npublic class T {\n\t/*\n\t * \n\tpublic void op() {\n\t}\n}\n");
    } finally {
        preferences.remove("enableBlockCommentFormatting");
        preferences.remove("tab-size");
        preferences.remove("expand-tabs");
    }
}
 
Example #29
Source File: PreferencesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@RandomlyFails
public void testEvents142723() throws Exception {
    Preferences prefsA = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
    Preferences prefsB = MimeLookup.getLookup(MimePath.parse("text/x-testA")).lookup(Preferences.class);

    String key1 = "all-lang-key-" + getName();
    prefsA.put(key1, "xyz");
    assertEquals("'" + key1 + "' has wrong value", "xyz", prefsA.get(key1, null));

    // attach listeners
    L listenerA = new L();
    prefsA.addPreferenceChangeListener(listenerA);
    L listenerB = new L();
    prefsB.addPreferenceChangeListener(listenerB);
    
    // putting the same value again should not fire an event
    prefsA.put(key1, "xyz");
    assertEquals("'" + key1 + "' has wrong value", "xyz", prefsA.get(key1, null));
    assertEquals("There should be no events from prefsA", 0, listenerA.count);

    assertEquals("'" + key1 + "' should inherit the value", "xyz", prefsB.get(key1, null));
    assertEquals("There should be no events from prefsB", 0, listenerB.count);

    // putting the same value again should not fire an event
    prefsB.put(key1, "xyz");
    assertEquals("'" + key1 + "' has wrong value in prefsB", "xyz", prefsB.get(key1, null));
    assertEquals("There should still be no events from prefsB", 0, listenerB.count);
}
 
Example #30
Source File: TextEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Detects whether XML source editor is registered: must start with 'xml.text'. If
 * a module registers such multiview, it's responsible for displaying source in this
 * pane.
 *
 * @return true, if multiview source editor is available and multiview pane should be created
 */
boolean hasMultiTextEditor() {
    Collection<? extends MultiViewDescription> all = MimeLookup.getLookup(mimeType).lookupAll(MultiViewDescription.class);
    for (MultiViewDescription d : all) {
        if (d.preferredID().startsWith("xml.text")) {
            return true;
        }
    }
    return false;
}