本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
}
示例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();
}
}
}
}
示例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();
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}