當前位置: 首頁>>代碼示例>>Java>>正文


Java DataObject.find方法代碼示例

本文整理匯總了Java中org.openide.loaders.DataObject.find方法的典型用法代碼示例。如果您正苦於以下問題:Java DataObject.find方法的具體用法?Java DataObject.find怎麽用?Java DataObject.find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openide.loaders.DataObject的用法示例。


在下文中一共展示了DataObject.find方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: openFile

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
private JavaSource openFile(String name) throws DataObjectNotFoundException, IOException, InterruptedException, InvocationTargetException {
    String dataDir = getDataDir().getAbsoluteFile().getPath();
    File sample = new File(dataDir+"/projects/java_editor_test/src/markOccurrences",name);
    assertTrue("file "+sample.getAbsolutePath()+" does not exist",sample.exists());
    
    fileObject = FileUtil.toFileObject(sample);
    dataObject = DataObject.find(fileObject);
    JavaSource js = JavaSource.forFileObject(fileObject);                
    final EditorCookie ec = dataObject.getCookie(EditorCookie.class);
    ec.openDocument();
    ec.open();
            
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            JEditorPane[] panes = ec.getOpenedPanes();
            editorPane = panes[0];
            
        }
    });
    return js;
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:MarkOccurrencesTest.java

示例2: setUp

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
protected void setUp() throws Exception {
    Object lookup = Lookup.getDefault().getClass ();
    assertEquals ("Our lookup registered", Lkp.class, lookup);
    
    // register Env as a handler for PublicIDs "-//NetBeans//Test//EN" which
    // is will contain the settings file we create
    FileObject root = FileUtil.getConfigRoot();
    FileObject register = FileUtil.createData (root, "/xml/lookups/NetBeans/Test.instance");
    register.setAttribute("instanceCreate", Env.INSTANCE);
    assertTrue (register.getAttribute("instanceCreate") instanceof Environment.Provider);
    
    
    // prepare an object to ask him for cookie
    FileObject fo = createSettings (root, "x.settings");
    ComplexPair.obj = DataObject.find (fo);

    assertNotNull ("correct resolver is registered", Lookup.getDefault().lookup (Environment.Provider.class));
    assertEquals ("correct resolver is registered", FileEntityResolver.class, Lookup.getDefault().lookup (Environment.Provider.class).getClass ());
    
    Lookup l = org.openide.loaders.Environment.find (DataObject.find (fo.getParent()));
    assertNotNull ("Previous call is done just to initialize the Environment.getProviders()", l);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:FileEntityResolverDeadlock54971Test.java

示例3: initialize

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
@Override
public boolean initialize(Lookup context, AtomicBoolean cancel) {
    FileObject file = context.lookup(FileObject.class);
    if (file == null || file.isFolder()) {
        return false;
    }

    DataObject currentFileDo = null;
    try {
        currentFileDo = DataObject.find(file);
    } catch (DataObjectNotFoundException ex) {
    } // Not important, only for Icon.
    icon = currentFileDo != null ? new ImageIcon(currentFileDo.getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16)) : null;
    detail = file.getNameExt();
    scope = Scope.create(null, null, Arrays.asList(file));

    return true;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:CurrentFileScopeProvider.java

示例4: get

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
public static synchronized AnnotationsHolder get(FileObject file) {
    try {
        DataObject od = DataObject.find(file);
        AnnotationsHolder a = file2Annotations.get(od);

        if (a != null) {
            return a;
        }

        EditorCookie.Observable ec = od.getLookup().lookup(EditorCookie.Observable.class);
        
        if (ec == null) {
            return null;
        }
        
        file2Annotations.put(od, a = new AnnotationsHolder(od, ec));
        
        return a;
    } catch (IOException ex) {
        LOGGER.log(Level.INFO, null, ex);
        
        return null;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:AnnotationsHolder.java

示例5: actionPerformed

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
@Override public void actionPerformed(ActionEvent e) {
    for (NbMavenProjectImpl project : projects) {
        FileObject pom = FileUtil.toFileObject(project.getPOMFile());
        if (pom != null) {
            DataObject d;
            try {
                d = DataObject.find(pom);
            } catch (DataObjectNotFoundException x) {
                continue;
            }
            Openable o = d.getLookup().lookup(Openable.class);
            if (o != null) {
                o.open();
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:OpenPOMAction.java

示例6: testLineSeparator

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
public void testLineSeparator() throws Exception {
    File file = File.createTempFile("lineSeparator", ".txt", getWorkDir());
    file.deleteOnExit();
    FileObject fileObject = FileUtil.toFileObject(file);
    fileObject.setAttribute(FileObject.DEFAULT_LINE_SEPARATOR_ATTR, "\r");
    DataObject dataObject = DataObject.find(fileObject);
    EditorCookie editor = dataObject.getLookup().lookup(org.openide.cookies.EditorCookie.class);
    final StyledDocument doc = editor.openDocument();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            try {
                doc.insertString(doc.getLength(), ".\n", null);
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    });
    
    editor.saveDocument();
    InputStream inputStream = fileObject.getInputStream();
    assertEquals('.',inputStream.read());
    assertEquals('\r',inputStream.read());
    inputStream.close();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:LineSeparatorDataEditorSupportTest.java

示例7: getJavaFieldOccurPlaces

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
private static List<OccurrenceItem> getJavaFieldOccurPlaces(FileObject mappingFile, String className, String fieldName) {
    List<OccurrenceItem> foundPlaces = new ArrayList<OccurrenceItem>();
    try {
        // Get the document for this file
        DataObject dataObject = DataObject.find(mappingFile);
        EditorCookie result = dataObject.getCookie(EditorCookie.class);
        if (result == null) {
            throw new IllegalStateException("File " + mappingFile + " does not have an EditorCookie.");
        }

        CloneableEditorSupport editor = (CloneableEditorSupport) result;
        Document document = editor.openDocument();
        XMLSyntaxSupport syntaxSupport = XMLSyntaxSupport.getSyntaxSupport(document);
        if (syntaxSupport == null) {
            return foundPlaces;
        }
        foundPlaces = syntaxSupport.runWithSequence(0, 
                (TokenSequence ts) -> {
            int start = document.getStartPosition().getOffset();
            return getJavaFieldOccurPlacesLocked(syntaxSupport, ts, start, editor, className, fieldName);
        });
    } catch (IOException  | BadLocationException ex) {
        ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex);
    }
    return foundPlaces;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:HibernateRefactoringUtil.java

示例8: getLastResource2

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
/** Getter for last resource property. */
public DataObject getLastResource2(DataObject srcDataObject) {
    String path = getPreferences().get(PROP_LAST_RESOURCE2,null);
    if(path == null) {
        return null;
    }
    FileObject f = (srcDataObject != null) ? findFileObject(srcDataObject, path) : findFileObject(path);
    if ((f != null) && !f.isFolder() && f.isValid()) {
        try {
            return DataObject.find(f);
        } catch (DataObjectNotFoundException e) {
            /* The file was probably deleted or moved. */
            getPreferences().remove(PROP_LAST_RESOURCE2);
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:I18nOptions.java

示例9: XtestCreateFromTemplateDocumentCreated

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
public void XtestCreateFromTemplateDocumentCreated() throws Exception {
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo = FileUtil.createData(root, "simpleObject.txt");
    OutputStream os = fo.getOutputStream();
    os.write("test".getBytes());
    os.close();
    fo.setAttribute ("template", Boolean.TRUE);
    fo.setAttribute("javax.script.ScriptEngine", "freemarker");

    MockServices.setServices(MockMimeLookup.class);
    MockMimeLookup.setInstances(MimePath.parse("content/unknown"), new TestEditorKit());
    
    DataObject obj = DataObject.find(fo);
    DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
    
    assertFalse(TestEditorKit.createDefaultDocumentCalled);
    DataObject inst = obj.createFromTemplate(folder, "test");
    assertTrue(TestEditorKit.createDefaultDocumentCalled);
    
    String exp = "test";
    assertEquals(exp, inst.getPrimaryFile().asText());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:ScriptingCreateFromTemplateTest.java

示例10: open

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
public boolean open (FileObject fo) {
    Project owner = FileOwnerQuery.getOwner (fo);
    if (!urls4project.containsKey (owner)) {
      // add project
        urls4project.put(owner, new TreeSet<String>());
    }
    URL url = null;
    DataObject dobj = null;
    try {
        dobj = DataObject.find (fo);
        url = dobj.getPrimaryFile ().toURL ();
        urls4project.get(owner).add(url.toExternalForm());
        openFiles.add (fo.toURL ().toExternalForm ());
    } catch (DataObjectNotFoundException donfe) {
        fail ("DataObjectNotFoundException on " + fo);
    }
    return true;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:OpenProjectListTest.java

示例11: instantiate

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
@Override
public Set<DataObject> instantiate () throws IOException/*, IllegalStateException*/ {
    // Here is the default plain behavior. Simply takes the selected
    // template (you need to have included the standard second panel
    // in createPanels(), or at least set the properties targetName and
    // targetFolder correctly), instantiates it in the provided
    // position, and returns the result.
    // More advanced wizards can create multiple objects from template
    // (return them all in the result of this method), populate file
    // contents on the fly, etc.
   
    org.openide.filesystems.FileObject dir = Templates.getTargetFolder( wiz );
    DataFolder df = DataFolder.findFolder( dir );
    
    FileObject template = Templates.getTemplate( wiz );
    
    DataObject dTemplate = DataObject.find( template );                
    final DataObject dobj = dTemplate.createFromTemplate( df, Templates.getTargetName( wiz )  );

    //this part might be turned pluggable once we have also ant based osgi projects. if..
    Project project = Templates.getProject( wiz );
    ClassPath cp = ClassPath.getClassPath(dobj.getPrimaryFile(), ClassPath.SOURCE);
    final String path = cp.getResourceName(dobj.getPrimaryFile(), '.', false);

    final NbMavenProject prj = project.getLookup().lookup(NbMavenProject.class);
    if (prj != null) {
        Utilities.performPOMModelOperations(project.getProjectDirectory().getFileObject("pom.xml"),
                Collections.<ModelOperation<POMModel>>singletonList(
                    new ModelOperation<POMModel>() {
            @Override
                       public void performOperation(POMModel model) {
                           addActivator(prj, model, path);
                       }
                }
        ));
    }

    return Collections.singleton(dobj);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:40,代碼來源:ActivatorIterator.java

示例12: handleCopyRename

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
@Override
protected DataObject handleCopyRename(DataFolder df, String name, String ext) throws IOException {
    FileObject fo = getPrimaryEntry ().copyRename (df.getPrimaryFile (), name, ext);
    DataObject dob = DataObject.find( fo );
    //TODO invoke refactoring here (if needed)
    return dob;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:GsfDataObject.java

示例13: support

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
DES support () throws Exception {
    DataObject tmpObj = DataObject.find (fileObject);
    
    assertEquals ("My object was created", MyDataObject.class, tmpObj.getClass ());
    Object cookie = tmpObj.getCookie (org.openide.cookies.OpenCookie.class);
    assertNotNull ("Our object has this cookie", cookie);
    assertEquals ("It is my cookie", DES.class, cookie.getClass ());
    
    return (DES)cookie;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:DataEditorSupportTest.java

示例14: setUp

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    dir = FileUtil.toFileObject(getWorkDir());
    f1 = dir.createData("f1.java");
    f2 = dir.createData("f2.java");
    f3 = dir.createData("f3.properties");
    f4 = dir.createData("f4.xml");          
    d1 = DataObject.find(f1);
    d2 = DataObject.find(f2);
    d3 = DataObject.find(f3);
    d4 = DataObject.find(f4);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:LookupSensitiveActionTest.java

示例15: getIcon

import org.openide.loaders.DataObject; //導入方法依賴的package包/類
@Override
protected ImageIcon getIcon() {
    if (insertText.endsWith("/")) { // NOI18N
        return ImageUtilities.loadImageIcon(ICON_FOLDER, false);
    } else if (fileResource != null) {
        return ImageUtilities.loadImageIcon(fileResource, true);
    } else if (icon != null) {
        return icon;
    } else {
        Path p = basePath.resolve(insertText);
        if (p != null) {
            FileObject f = FileUtil.toFileObject(p.toFile());
            if (f != null) {
                Node n;
                
                try {
                    DataObject d = DataObject.find(f);
                    n = d.getNodeDelegate();
                } catch (DataObjectNotFoundException ex) {
                    n = f.getLookup().lookup(Node.class);
                }
                if (n != null) {
                    return (ImageIcon)ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
                }
            }
        }
        return icon = ImageUtilities.loadImageIcon(ICON_FILE, false);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:CommandCompletionProvider.java


注:本文中的org.openide.loaders.DataObject.find方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。