本文整理匯總了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);
}