本文整理汇总了Java中org.openide.loaders.DataObject.getPrimaryFile方法的典型用法代码示例。如果您正苦于以下问题:Java DataObject.getPrimaryFile方法的具体用法?Java DataObject.getPrimaryFile怎么用?Java DataObject.getPrimaryFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.loaders.DataObject
的用法示例。
在下文中一共展示了DataObject.getPrimaryFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSchemaFileName
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
public String getSchemaFileName(){
DataObject dobj = (DataObject) getLookup().lookup(DataObject.class);
if (dobj != null) {
FileObject fobj = dobj.getPrimaryFile();
File file = FileUtil.toFile(fobj);
String uri = file.getPath();
if (uri != null) {
try {
// escape the non-ASCII characters
uri = new URI(uri).toASCIIString();
} catch (URISyntaxException e) {
// the specified uri is not valid, it is too late to fix it now
}
}
return uri;
}
return null;
}
示例2: runTaskWithinContext
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
@Override
public void runTaskWithinContext(Lookup context, Task task) {
JTextComponent component = context.lookup(JTextComponent.class);
if (component != null) {
DataObject dobj = NbEditorUtilities.getDataObject(component.getDocument());
if (dobj != null) {
FileObject fo = dobj.getPrimaryFile();
ModelSource ms = Utilities.createModelSource(fo);
if (ms.isEditable()) {
POMModel model = POMModelFactory.getDefault().getModel(ms);
if (model != null) {
Lookup newContext = new ProxyLookup(context, Lookups.fixed(model));
task.run(newContext);
return;
}
}
}
}
task.run(context);
}
示例3: getText
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
@Override
public String getText( TabData tab ) {
if( !settings.isShowFolderName() )
return null;
if( tab.getComponent() instanceof TopComponent ) {
TopComponent tc = ( TopComponent ) tab.getComponent();
DataObject dob = tc.getLookup().lookup( DataObject.class );
if( null != dob ) {
FileObject fo = dob.getPrimaryFile();
if( fo.isData() ) {
FileObject folder = fo.getParent();
if( null != folder ) {
String folderName = folder.getNameExt() + pathSeparator;
String defaultText = tab.getText();
return merge( folderName, defaultText );
}
}
}
}
return null;
}
示例4: enable
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
protected boolean enable(Node[] node) {
if (node.length == 0) {
return false;
}
DataObject dobj = (DataObject) node[0].getLookup().lookup(DataObject.class);
if (dobj == null) {
return false;
}
FileObject fo = dobj.getPrimaryFile();
Project project = FileOwnerQuery.getOwner(fo);
if(project == null)
return false;
Sources sources = ProjectUtils.getSources(project);
SourceGroup[] srcGrps = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
if (srcGrps == null || srcGrps.length == 0) {
return false;
} else {
return true;
}
}
示例5: getFilesFromLookup
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
/** In given lookup will find all FileObjects owned by given project
* with given command supported.
*/
public static FileObject[] getFilesFromLookup( Lookup lookup, Project project ) {
HashSet<FileObject> result = new HashSet<FileObject>();
for (DataObject dObj : lookup.lookupAll(DataObject.class)) {
FileObject fObj = dObj.getPrimaryFile();
Project p = FileOwnerQuery.getOwner(fObj);
if ( p != null && p.equals( project ) ) {
result.add( fObj );
}
}
FileObject[] fos = new FileObject[ result.size() ];
result.toArray( fos );
return fos;
}
示例6: actionPerformed
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
public void actionPerformed( ActionEvent e ) {
String command = e.getActionCommand();
if ( COMMAND_SELECT.equals( command ) ) {
Node selection[] = browsePanel.getExplorerManager().getSelectedNodes();
if ( selection != null && selection.length > 0 ) {
DataObject dobj = (DataObject)selection[0].getLookup().
lookup( DataObject.class );
if (dobj!=null && dobj.getClass().isAssignableFrom(target)) {
result = dobj.getPrimaryFile();
}
/*
if ( dobj != null ) {
FileObject fo = dobj.getPrimaryFile();
if ( fo.isFolder() ) {
result = fo;
}
}
*/
}
}
}
示例7: updateDataObject
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
/**
* Update data object. Can be called when a module is enabled and new data
* loader produces new data object.
*/
public void updateDataObject(DataObject updatedDataObject) {
FileObject updatedPF = updatedDataObject.getPrimaryFile();
if (dataObject == null
|| dataObject.getPrimaryFile().equals(updatedPF)) {
if (updatedPF.isValid()) {
this.invalidityStatus = null;
if (fileListener == null) {
this.fileListener = new FileListener();
updatedPF.addFileChangeListener(fileListener);
} else if (updatedPF != dataObject.getPrimaryFile()) {
dataObject.getPrimaryFile().removeFileChangeListener(
fileListener);
updatedPF.addFileChangeListener(fileListener);
}
this.dataObject = updatedDataObject;
this.nodeDelegate = updatedDataObject.getNodeDelegate();
this.valid = true;
for (TextDetail td : textDetails) {
td.updateDataObject(updatedDataObject);
}
}
} else {
throw new IllegalArgumentException(
"Expected data object for the same file"); //NOI18N
}
}
示例8: fileForDocument
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
private FileObject fileForDocument(Document doc) {
DataObject dobj = (DataObject) doc.getProperty(Document.StreamDescriptionProperty);
LOG.log(Level.FINEST, "document {0} returns {1} for property=" + Document.StreamDescriptionProperty, new Object[] {doc, dobj});
if (dobj == null) return null;
LOG.log(Level.FINER, "looking up file for {0}", dobj);
if (dobj instanceof MultiDataObject) {
return fileForDataobject(doc, (MultiDataObject) dobj);
} else if (dobj != null) {
return dobj.getPrimaryFile();
} else {
return null;
}
}
示例9: discardChanges
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
/** Discards all changes in modified files of given project. */
private static void discardChanges(Project project) {
// discard all changes in modified files
Iterator iter = DataObject.getRegistry().getModifiedSet().iterator();
while (iter.hasNext()) {
DataObject dobj = (DataObject) iter.next();
if (dobj != null) {
FileObject fobj = dobj.getPrimaryFile();
Project owner = FileOwnerQuery.getOwner(fobj);
if(owner == project) {
dobj.setModified(false);
}
}
}
}
示例10: run
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
public void run() {
List<FileObject> fileObjects = new ArrayList<FileObject>(nodes.size());
for (Node node : nodes) {
DataObject dataObject = node.getLookup().lookup(DataObject.class);
if (dataObject != null) {
FileObject primaryFileObject = dataObject.getPrimaryFile();
if (primaryFileObject != null) {
fileObjects.add(primaryFileObject);
}
}
}
UI.openRefactoringUI(createRefactoringUI(fileObjects.toArray(new FileObject[fileObjects.size()])));
}
示例11: getCurrentFile
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
/**
* Gets a the file related to the document
*
* @return the file related to the document, <code>null</code> if none
* exists.
*/
File getCurrentFile() {
File result = referencedFile;
if (result == null) {
DataObject dobj = (DataObject) doc.getProperty(Document.StreamDescriptionProperty);
if (dobj != null) {
FileObject fo = dobj.getPrimaryFile();
result = FileUtil.toFile(fo);
}
}
return result;
}
示例12: canRemove
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
private boolean canRemove(final JavaPlatform platform, final DataObject dobj) {
if (isDefaultPlatform(platform)) {
return false;
}
if (dobj != null) {
final FileObject fo = dobj.getPrimaryFile();
Object attr = fo.getAttribute(ATTR_CAN_REMOVE); //NOI18N
if (attr instanceof Boolean && ((Boolean)attr) == Boolean.FALSE) {
return false;
}
}
return true;
}
示例13: getShortDescription
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
@Override
public String getShortDescription() {
final DataObject dobj = getLookup().lookup(DataObject.class);
FileObject pf;
if (dobj != null && (pf = dobj.getPrimaryFile()) != null) {
return FileUtil.getFileDisplayName(pf);
} else {
return super.getShortDescription();
}
}
示例14: DataObjectListener
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
@SuppressWarnings("LeakingThisInConstructor")
public DataObjectListener(final DataObject dobj) {
this.dobj = dobj;
this.fobj = dobj.getPrimaryFile();
wlistener = WeakListeners.propertyChange(this, dobj);
this.dobj.addPropertyChangeListener(wlistener);
}
示例15: canBePasted
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
private static boolean canBePasted(final DataObject[] dataObjects, final DataFolder targetFolder, final int operation) throws FileStateInvalidException {
final Set<DataObject> pasteableDataObjects = new HashSet<DataObject> ();
final FileObject folder = targetFolder.getPrimaryFile();
DataObject[] folderChildren = targetFolder.getChildren();
for (int j = 0; j < dataObjects.length; j++) {
final DataObject dataObject = dataObjects[j];
final FileObject fo = dataObject.getPrimaryFile ();
if (!isAction(dataObject) || !fo.getFileSystem().isDefault()) {
break;
}
final boolean isCopyPaste = operation == LoaderTransfer.CLIPBOARD_COPY && dataObject.isCopyAllowed();
final boolean isCutPaste = operation == LoaderTransfer.CLIPBOARD_CUT && dataObject.isMoveAllowed() &&
!(fo.getParent() == folder);//prevents from cutting into the same folder where it was
if (isCopyPaste || isCutPaste) {
boolean isDuplicate = false;
for( int i=0; i<folderChildren.length; i++ ) {
if( 0 == folderChildren[i].getName().compareTo( dataObject.getName() ) ) {
isDuplicate = true;
break;
}
}
if( !isDuplicate )
pasteableDataObjects.add(dataObject);
}
}
return (pasteableDataObjects.size() == dataObjects.length);
}