本文整理汇总了Java中org.openide.loaders.DataFolder类的典型用法代码示例。如果您正苦于以下问题:Java DataFolder类的具体用法?Java DataFolder怎么用?Java DataFolder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataFolder类属于org.openide.loaders包,在下文中一共展示了DataFolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveKeymap
import org.openide.loaders.DataFolder; //导入依赖的package包/类
@Override
public void saveKeymap (String profile, Map<ShortcutAction, Set<String>> actionToShortcuts) {
// discard our cached copy first
keymaps.remove(profile);
keymapDefaults.remove(profile);
// 1) get / create Keymaps/Profile folder
DataFolder defaultFolder = getRootFolder(SHORTCUTS_FOLDER, null);
DataFolder folder = getRootFolder (KEYMAPS_FOLDER, profile);
if (folder == null) {
folder = getRootFolder (KEYMAPS_FOLDER, null);
try {
folder = DataFolder.create (folder, profile);
} catch (IOException ex) {
ErrorManager.getDefault ().notify (ex);
return;
}
}
saveKeymap (defaultFolder, folder, actionToShortcuts);
}
示例2: AnnotationTypesFolder
import org.openide.loaders.DataFolder; //导入依赖的package包/类
/** Creates new AnnotationTypesFolder */
private AnnotationTypesFolder(FileObject fo, DataFolder fld) {
super(fld);
recreate();
instanceFinished();
// add listener on changes in annotation types folder
fo.addFileChangeListener(new FileChangeAdapter() {
public void fileDeleted(FileEvent fe) {
AnnotationType type;
for (Iterator it = AnnotationTypes.getTypes().getAnnotationTypeNames(); it.hasNext(); ) {
type = AnnotationTypes.getTypes().getType((String)it.next());
if ( type != null && ((FileObject)type.getProp(AnnotationType.PROP_FILE)).equals(fe.getFile()) ) {
AnnotationTypes.getTypes().removeType(type.getName());
break;
}
}
}
});
}
示例3: doRefactoringBypass
import org.openide.loaders.DataFolder; //导入依赖的package包/类
@Override
public void doRefactoringBypass() throws IOException {
RequestProcessor.getDefault().post(new Runnable() {
@Override
public void run() {
try {
//Transferable t = paste.paste();
FileObject source = refactoring.getRefactoringSource().lookup(FileObject.class);
if (source != null) {
DataObject sourceDo = DataObject.find(source);
DataFolder targetDataFolder = DataFolder.findFolder(targetFolder);
sourceDo.copy(targetDataFolder).rename(panel.getNewName());
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
});
}
示例4: instantiate
import org.openide.loaders.DataFolder; //导入依赖的package包/类
/**
* This is where, the schema gets instantiated from the template.
*/
public Set instantiate (TemplateWizard wizard) throws IOException {
FileObject dir = Templates.getTargetFolder( wizard );
DataFolder df = DataFolder.findFolder( dir );
FileObject template = Templates.getTemplate( wizard );
DataObject dTemplate = DataObject.find( template );
DataObject dobj = dTemplate.createFromTemplate(df, Templates.getTargetName(wizard));
if (dobj == null)
return Collections.emptySet();
encoding = EncodingUtil.getProjectEncoding(df.getPrimaryFile());
if(!EncodingUtil.isValidEncoding(encoding))
encoding = "UTF-8"; //NOI18N
EditCookie edit = dobj.getCookie(EditCookie.class);
if (edit != null) {
EditorCookie editorCookie = dobj.getCookie(EditorCookie.class);
Document doc = (Document)editorCookie.openDocument();
fixEncoding(doc, encoding);
SaveCookie save = dobj.getCookie(SaveCookie.class);
if (save!=null) save.save();
}
return Collections.singleton(dobj.getPrimaryFile());
}
示例5: getTargetFolder
import org.openide.loaders.DataFolder; //导入依赖的package包/类
static private DataFolder getTargetFolder (Node [] nodes) {
DataFolder folder;
if (nodes == null || nodes.length == 0) {
folder = DataFolder.findFolder (getTemplatesRoot ());
} else {
// try if has a data folder (alert: leaf node can be a empty folder)
folder = nodes[0].getLookup ().lookup (DataFolder.class);
// if not this node then try its parent
if (folder == null && nodes [0].isLeaf ()) {
Node parent = nodes [0].getParentNode ();
folder = parent.getLookup ().lookup (DataFolder.class);
}
}
return folder;
}
示例6: getDataFolderNodeDelegate
import org.openide.loaders.DataFolder; //导入依赖的package包/类
private Node getDataFolderNodeDelegate() {
DataFolder df = getLookup().lookup(DataFolder.class);
try {
if (df.isValid()) {
return df.getNodeDelegate();
}
} catch (IllegalStateException e) {
//The data systems API is not thread save,
//the DataObject may become invalid after isValid call and before
//getNodeDelegate call, we have to catch the ISE. When the DataObject
//is valid - other cause rethrow it otherwise return leaf node.
//todo: The DataObject.getNodedelegate should throw specialized exception type.
if (df.isValid()) {
throw e;
}
}
return new AbstractNode(Children.LEAF);
}
示例7: testCreateFromTemplateUsingFreemarker
import org.openide.loaders.DataFolder; //导入依赖的package包/类
public void testCreateFromTemplateUsingFreemarker() throws Exception {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
FileObject fo = FileUtil.createData(root, "simpleObject.txt");
OutputStream os = fo.getOutputStream();
String txt = "<html><h1>${title}</h1></html>";
os.write(txt.getBytes());
os.close();
fo.setAttribute("javax.script.ScriptEngine", "freemarker");
DataObject obj = DataObject.find(fo);
DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
Map<String,String> parameters = Collections.singletonMap("title", "Nazdar");
DataObject n = obj.createFromTemplate(folder, "complex", parameters);
assertEquals("Created in right place", folder, n.getFolder());
assertEquals("Created with right name", "complex.txt", n.getName());
String exp = ">lmth/<>1h/<radzaN>1h<>lmth<";
assertEquals(exp, readFile(n.getPrimaryFile()));
}
示例8: createTemplateFromFile
import org.openide.loaders.DataFolder; //导入依赖的package包/类
static DataObject createTemplateFromFile(File file, DataFolder preferred) {
if (file == null) {
throw new IllegalArgumentException("Argument file cannot be null!"); // NOI18N
}
FileObject sourceFO = FileUtil.toFileObject(FileUtil.normalizeFile(file));
assert sourceFO != null : "FileObject found for file " + file;
DataObject sourceDO = null;
try {
sourceDO = DataObject.find(sourceFO);
} catch (DataObjectNotFoundException donfe) {
Logger.getLogger(CatalogPanel.class.getName()).log(Level.WARNING, null, donfe);
}
assert sourceDO != null : "DataObject found for FileObject " + sourceFO;
DataFolder folder = preferred == null ? DataFolder.findFolder(getCatalogRoot()) : preferred;
DataObject template = null;
try {
template = sourceDO.copy(folder);
template.setTemplate(true);
} catch (IOException ioe) {
Logger.getLogger(CatalogPanel.class.getName()).log(Level.WARNING, null, ioe);
}
return template;
}
示例9: createShadows
import org.openide.loaders.DataFolder; //导入依赖的package包/类
static DataObject createShadows(final DataFolder favourities, final List<DataObject> dos, final List<DataObject> listAdd) {
DataObject createdDO = null;
for (DataObject obj : dos) {
try {
DataShadow added = findShadow(favourities, obj);
if (added != null) {
if (createdDO == null) {
createdDO = added;
}
} else {
if (createdDO == null) {
// Select only first node in array added to favorites
createdDO = obj.createShadow(favourities);
listAdd.add(createdDO);
} else {
listAdd.add(obj.createShadow(favourities));
}
}
} catch (IOException ex) {
LOG.log(Level.WARNING, null, ex);
}
}
return createdDO;
}
示例10: attributesFor
import org.openide.loaders.DataFolder; //导入依赖的package包/类
@Override
public Map<String, ?> attributesFor(DataObject template, DataFolder target, String name) {
Project project = FileOwnerQuery.getOwner(target.getPrimaryFile());
HtmlVersion version;
if(project == null) {
version = HtmlVersion.getDefaultVersion();
} else {
String mimeType = template.getPrimaryFile().getMIMEType();
boolean xhtml = "text/xhtml".equals(mimeType); //NOI18N
version = ProjectDefaultHtmlSourceVersionController.getDefaultHtmlVersion(project, xhtml);
if(version == null) {
version = xhtml ? HtmlVersion.getDefaultXhtmlVersion() : HtmlVersion.getDefaultVersion();
}
}
return Collections.singletonMap(DOCTYPE_TEMPLATE_PROPERTY_NAME, version.getDoctypeDeclaration());
}
示例11: initActions
import org.openide.loaders.DataFolder; //导入依赖的package包/类
private void initActions (String folder, String category) {
if (loadedFromFolders != null) {
for (FileObject f : loadedFromFolders) {
f.removeFileChangeListener(weakFolderL);
}
}
FileObject fo = FileUtil.getConfigFile(folder);
if (fo == null) return;
DataFolder root = DataFolder.findFolder (fo);
if (loadedFromFolders == null) {
// the root must exist all the time, attach just once:
root.getPrimaryFile().addFileChangeListener(weakFolderL);
}
Enumeration<DataObject> en = root.children ();
Collection<FileObject> newFolders = new ArrayList<>(7);
while (en.hasMoreElements ()) {
DataObject dataObject = en.nextElement ();
if (dataObject instanceof DataFolder) {
initActions ((DataFolder) dataObject, null, category, newFolders);
}
}
this.loadedFromFolders = newFolders;
}
示例12: isFolderOfTemplates
import org.openide.loaders.DataFolder; //导入依赖的package包/类
private boolean isFolderOfTemplates(DataObject d) {
if (d instanceof DataFolder && !isTemplate((DataFolder)d)) {
Object o = d.getPrimaryFile().getAttribute("simple"); // NOI18N
if (o == null || Boolean.TRUE.equals(o)) {
boolean hasChildren = hasChildren((Project) projectsComboBox.getSelectedItem(), d);
if (hasChildren)
return hasChildren;
else {
for (DataObject child : ((DataFolder) d).getChildren()) {
return isFolderOfTemplates(child);
}
}
}
}
return false;
}
示例13: findPath
import org.openide.loaders.DataFolder; //导入依赖的package包/类
@Override
public Node findPath(Node root, Object target) {
Node result = null;
if (delegate != null && target instanceof FileObject) {
FileObject binRoot = root.getLookup().lookup(FileObject.class);
if (binRoot == null) {
final DataFolder dobj = root.getLookup().lookup(DataFolder.class);
binRoot = dobj == null ? null : dobj.getPrimaryFile();
}
if (binRoot != null) {
FileObject newTarget = rebase(binRoot, (FileObject) target);
if (newTarget != null) {
result = delegate.findPath(root, newTarget);
}
}
}
return result;
}
示例14: getPasteType
import org.openide.loaders.DataFolder; //导入依赖的package包/类
/**
*
*/
static PasteType getPasteType(final DataFolder targetFolder, final Transferable transfer) {
final FileObject folder = targetFolder.getPrimaryFile();
PasteType retVal = null;
try {
/*Copy/Cut/Paste is allowed just on SystemFileSystem*/
if (folder.getFileSystem().isDefault()) {
final int[] pasteOperations = new int[]{LoaderTransfer.CLIPBOARD_COPY, LoaderTransfer.CLIPBOARD_CUT};
for (int i = 0; i < pasteOperations.length; i++) {
final DataObject[] dataObjects = LoaderTransfer.getDataObjects(transfer, pasteOperations[i]);
if (dataObjects != null) {
if (canBePasted(dataObjects, targetFolder, pasteOperations[i])) {
retVal = new PasteTypeImpl(Arrays.asList(dataObjects), targetFolder, pasteOperations[i]);
break;
}
}
}
}
} catch (FileStateInvalidException e) {/*just null is returned if folder.getFileSystem fires ISE*/}
return retVal;
}
示例15: testReadWrite
import org.openide.loaders.DataFolder; //导入依赖的package包/类
public void testReadWrite() throws Exception {
AnnoFoo foo = new AnnoFoo();
foo.setName("xxx");
DataFolder test = DataFolder.findFolder(FileUtil.getConfigRoot());
DataObject obj = InstanceDataObject.create(test, null, foo, null);
final FileObject pf = obj.getPrimaryFile();
final String content = pf.asText();
if (content.indexOf("<string>xxx</string>") == -1) {
fail(content);
}
obj.setValid(false);
DataObject newObj = DataObject.find(pf);
if (newObj == obj) {
fail("Strange, objects shall differ");
}
InstanceCookie ic = newObj.getLookup().lookup(InstanceCookie.class);
assertNotNull("Instance cookie found", ic);
Object read = ic.instanceCreate();
assertNotNull("Instance created", read);
assertEquals("Correct class", AnnoFoo.class, read.getClass());
AnnoFoo readFoo = (AnnoFoo)read;
assertEquals("property changed", "xxx", readFoo.getName());
}