Java Code Examples for org.netbeans.api.editor.mimelookup.MimeLookup#getMimeLookup()

The following examples show how to use org.netbeans.api.editor.mimelookup.MimeLookup#getMimeLookup() . 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: IssuesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 
 * Issues of changes in layer
 */
public void testForChangeInLayer() throws IOException{
    
    // issue #63338
    // http://www.netbeans.org/issues/show_bug.cgi?id=63338
    // Subj: deadlock during showing annotations
    // fix: deadlock occured in after inproper firing of lookup changed event.
    //      event was fired even in cases, the lookup listener should be quiet.
    MimeLookup lookup = MimeLookup.getMimeLookup("text/jsp"); //NOI18N
    Result result = lookup.lookup(new Template(TestLookupObject.class));
    result.allInstances().size(); // remove this line if issue #60010 is fixed
    LookupListener listener = new LookupListener(){
        public void resultChanged(LookupEvent ev){
            resultChangedCount[0]++;
        }
    };
    result.addLookupListener(listener);
    
    //simulate module installation, new file will be added
    createFile("Editors/text/jsp/testLookup/org-openide-actions-PasteAction.instance"); //NOI18N        

    checkResultChange(0);
    
    TestUtilities.deleteFile(getWorkDir(),
            "Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");

    checkResultChange(1);
    
    result.removeLookupListener(listener);
    resultChangedCount[0] = 0;
    // end of issue #63338 ------------------------------------------------
    
    
    
}
 
Example 2
Source File: IssuesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Issue #72873 
 *  MimeLookup duplicates objects from default mimetype folder
 */
public void testDoubleItems(){
    MimeLookup lookup = MimeLookup.getMimeLookup("text/x-java"); //NOI18N
    Result result = lookup.lookup(new Template(TestLookupObjectTwo.class));
    Collection col = result.allInstances();
    assertTrue(col.size() == 1);
    
    lookup = MimeLookup.getMimeLookup(""); //NOI18N
    result = lookup.lookup(new Template(TestLookupObjectTwo.class));
    col = result.allInstances();
    assertTrue(col.size() == 1);
    
}
 
Example 3
Source File: Depr_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
    MimeLookup lookup = MimeLookup.getMimeLookup("text/xml");
    checkLookupObject(lookup, StringBuffer.class, false);        
}
 
Example 4
Source File: Depr_MimeLookupTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 
 * Checking wheather the initialization of MimeLookup for appropriate
 * mime type will not instantiate lookup object
 */
public void testLazyLookupObjectInstantiation() throws IOException{
    MimeLookup lookup = MimeLookup.getMimeLookup("text/xml"); //NOI18N
    // lookup for some object in the mime lookup
    checkLookupObject(lookup, StringBuffer.class, false);
    // calling 
    // checkLookupObject(lookup, TestLookupObjectInstantiation.class, false);
    // should fail
}
 
Example 5
Source File: Depr_MimeLookupInheritanceTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Issue #61216: MimeLookup should support layer hidding
 */
public void testHidding(){
    MimeLookup lookup = MimeLookup.getMimeLookup("text/xml");
    checkLookupObject(lookup, CopyAction.class, true);
    checkLookupObject(lookup, ReplaceAction.class, true);
    checkLookupObject(lookup, PasteAction.class, false);
    lookup = MimeLookup.getMimeLookup("text/x-ant+xml");
    checkLookupObject(lookup, CutAction.class, true);
    checkLookupObject(lookup, CopyAction.class, false);
    checkLookupObject(lookup, PasteAction.class, true);
    checkLookupObject(lookup, ReplaceAction.class, false);
}
 
Example 6
Source File: Depr_MimeLookupInheritanceTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Issue #61245: Delegate application/*+xml -> text/xml
 */
public void test61245(){
    MimeLookup lookup = MimeLookup.getMimeLookup("application/xml");
    checkLookupObject(lookup, FindAction.class, true);
    lookup = MimeLookup.getMimeLookup("application/xhtml+xml");
    checkLookupObject(lookup, CutAction.class, true);
    checkLookupObject(lookup, FindAction.class, false);
    checkLookupObject(lookup, ReplaceAction.class, true);
}
 
Example 7
Source File: Depr_MimeLookupInheritanceTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAntXmlPopup(){
    MimeLookup lookup = MimeLookup.getMimeLookup("text/xml"); //NOI18N
    Class layerObjects[] = {CutAction.class, CopyAction.class, PasteAction.class, ReplaceAction.class};
    testPopupItems(lookup, layerObjects);
    lookup = MimeLookup.getMimeLookup("text/x-ant+xml"); //NOI18N
    Class layerObjects2[] = {CutAction.class, CopyAction.class, PasteAction.class, ReplaceAction.class, FindAction.class};
    testPopupItems(lookup, layerObjects2);
}
 
Example 8
Source File: MimeLookupInheritanceTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Issue #61245: Delegate application/*+xml -> text/xml
 */
public void test61245(){
    MimeLookup lookup = MimeLookup.getMimeLookup("application/xml");
    checkLookupObject(lookup, FindAction.class, true);
    lookup = MimeLookup.getMimeLookup("application/xhtml+xml");
    checkLookupObject(lookup, CutAction.class, true);
    checkLookupObject(lookup, FindAction.class, false);
    checkLookupObject(lookup, ReplaceAction.class, true);
}
 
Example 9
Source File: MimeLookupInheritanceTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAntXmlPopup(){
    MimeLookup lookup = MimeLookup.getMimeLookup("text/xml"); //NOI18N
    Class layerObjects[] = {CutAction.class, CopyAction.class, PasteAction.class, ReplaceAction.class};
    testPopupItems(lookup, layerObjects);
    lookup = MimeLookup.getMimeLookup("text/x-ant+xml"); //NOI18N
    Class layerObjects2[] = {CutAction.class, CopyAction.class, PasteAction.class, ReplaceAction.class, FindAction.class};
    testPopupItems(lookup, layerObjects2);
}
 
Example 10
Source File: Depr_MimeLookupInheritanceTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Testing Base level popup items lookup and sorting */
public void testBaseLevelPopups(){
    MimeLookup lookup = MimeLookup.getMimeLookup(""); //NOI18N
    Class layerObjects[] = {CutAction.class, CopyAction.class, PasteAction.class};
    testPopupItems(lookup, layerObjects);
}
 
Example 11
Source File: MimeLookupInheritanceTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Testing Base level popup items lookup and sorting */
public void testBaseLevelPopups(){
    MimeLookup lookup = MimeLookup.getMimeLookup(""); //NOI18N
    Class layerObjects[] = {CutAction.class, CopyAction.class, PasteAction.class};
    testPopupItems(lookup, layerObjects);
}
 
Example 12
Source File: Depr_MimeLookupPopupItemsChangeTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Testing Base level popup items lookup and sorting */
@RandomlyFails // NB-Core-Build #3718
public void testDynamicChangeInPopupFolders() throws IOException{
    final int resultChangedCount[] = new int[1];
    resultChangedCount[0] = 0;

    MimeLookup lookup = MimeLookup.getMimeLookup("text/x-java").childLookup("text/xml"). //NOI18N
            childLookup("text/html"); //NOI18N
    Lookup.Result result = lookup.lookup(new Template(PopupActions.class));
    result.allInstances(); // remove this line if issue #60010 is fixed
    LookupListener listener = new LookupListener(){
        public void resultChanged(LookupEvent ev){
            resultChangedCount[0]++;
        }
    };
    result.addLookupListener(listener);
    PopupActions actions = (PopupActions) lookup.lookup(PopupActions.class);
    assertTrue("PopupActions should be found", actions != null);
    List popupActions = actions.getPopupActions();
    int size = popupActions.size();
    assertTrue("Number of PopupActions found:"+size+" and should be:"+fsstruct.length, size == fsstruct.length);

    //delete RenameAction
    TestUtilities.deleteFile(getWorkDir(),
            "Editors/text/html/Popup/org-openide-actions-RenameAction.instance");
    checkPopupItemPresence(lookup, RenameAction.class, false);

    // check firing the change
    assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of 1"),resultChangedCount[0] == 1);
    resultChangedCount[0] = 0;
    
    //delete base CutAction
    TestUtilities.deleteFile(getWorkDir(),
            "Editors/Popup/org-openide-actions-CutAction.instance");

    checkPopupItemPresence(lookup, CutAction.class, false);

    // check firing the change
    assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of 1"),resultChangedCount[0] == 1);
    resultChangedCount[0] = 0;
    
    //simulate module installation, new action will be added
    TestUtilities.createFile(getWorkDir(), 
            "Editors/Popup/org-openide-actions-FindAction.instance"); //NOI18N      

    checkPopupItemPresence(lookup, FindAction.class, true);

    // check firing the change
    assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of 1"),resultChangedCount[0] == 1);
    resultChangedCount[0] = 0;
    
    //simulate module installation, new action will be added
    TestUtilities.createFile(getWorkDir(), 
            "Editors/text/x-java/text/xml/text/html/Popup/org-openide-actions-ReplaceAction.instance"); //NOI18N      

    checkPopupItemPresence(lookup, ReplaceAction.class, true);
    
    //ReplaceAction was created in the uppermost folder
    // let's try it is missing in the lower lookup
    lookup = MimeLookup.getMimeLookup("text/x-java").childLookup("text/xml"); //NOI18N
    checkPopupItemPresence(lookup, ReplaceAction.class, false);        
    checkPopupItemPresence(lookup, FindAction.class, true);
    
    // lookup for ReplaceAction in the folder that doesn't exist
    lookup = MimeLookup.getMimeLookup("text/html"); //NOI18N
    checkPopupItemPresence(lookup, ReplaceAction.class, false); 
    // create folder with ReplaceAction
    TestUtilities.createFile(getWorkDir(), 
            "Editors/text/html/Popup/org-openide-actions-ReplaceAction.instance"); //NOI18N

    checkPopupItemPresence(lookup, ReplaceAction.class, true);
    
}