Java Code Examples for org.openide.loaders.DataObject#isValid()
The following examples show how to use
org.openide.loaders.DataObject#isValid() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CatalogModelImpl.java From netbeans with Apache License 2.0 | 6 votes |
private Reader getFileStreamFromDocument(File resultFile) { FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(resultFile)); if(fo != null){ DataObject dobj = null; try { dobj = DataObject.find(fo); } catch (DataObjectNotFoundException ex) { return null; } if(dobj.isValid() && dobj.isModified()){ // DataObjectAdapters does not implement getByteStream // so calling this here will effectively return null return DataObjectAdapters.inputSource(dobj).getCharacterStream(); } else{ //return null so that the validator will use normal file path to access doc return null; } } return null; }
Example 2
Source File: JspUpToDateStatusProvider.java From netbeans with Apache License 2.0 | 6 votes |
/** Creates a new instance of AnnotationMarkProvider */ private JspUpToDateStatusProvider(Document document) { upToDate = UpToDateStatus.UP_TO_DATE_OK; document.addDocumentListener(this); //listen to parser results DataObject documentDO = NbEditorUtilities.getDataObject(document); if(documentDO != null && documentDO.isValid()) { JspColoringData jspcd = JspUtils.getJSPColoringData(documentDO.getPrimaryFile()); //jspcd.addPropertyChangeListener(this); if(jspcd != null) { jspcd.addPropertyChangeListener(WeakListeners.propertyChange(this, jspcd)); } else { //coloring data is null - weird, likely some parser problem or something in the file or project is broken //we will ignore the state, but the up-to-date status provider won't work for this file! upToDate = UpToDateStatus.UP_TO_DATE_DIRTY; Logger.getAnonymousLogger().info("JspUtils.getJSPColoringData(document, " + documentDO.getPrimaryFile() + ") returned null!"); } } }
Example 3
Source File: MatchingObjectNode.java From netbeans with Apache License 2.0 | 6 votes |
/** * Check whether the file object is valid and a valid data object can be * found for it. It should be checked after original node is destroyed. It * does not have to mean the the file was deleted, but also that a module * that contain data loader was enabled. In the letter case, the node should * be updated for new data object. */ private void checkFileObjectValid() { FileObject fo = matchingObject.getFileObject(); if (fo != null && fo.isValid()) { try { DataObject reloaded = DataObject.find(fo); matchingObject.updateDataObject(reloaded); valid = reloaded.isValid(); if (valid) { EventQueue.invokeLater(new Runnable() { @Override public void run() { resetValidOriginal(); } }); } } catch (DataObjectNotFoundException ex) { // still invalid, the file was probably really deleted } } }
Example 4
Source File: HelpCtxProcessor.java From netbeans with Apache License 2.0 | 6 votes |
/** Create a new presenter. * @param obj XML file describing it */ public ShortcutAction(DataObject obj, String helpID, boolean showmaster) { this.obj = obj; this.helpID = helpID; this.showmaster = showmaster; putValue("noIconInMenu", true); // NOI18N Installer.log.log(Level.FINE, "new ShortcutAction: {0} {1} showmaster={2}", new Object[] {obj, helpID, showmaster}); updateText(); updateIcon(); updateEnabled(); if (obj.isValid()) { Node n = obj.getNodeDelegate(); n.addNodeListener(org.openide.nodes.NodeOp.weakNodeListener (this, n)); } Help h = findHelp(); if (h != null) { h.addChangeListener(WeakListeners.change(this, h)); } }
Example 5
Source File: ActionPasteType.java From netbeans with Apache License 2.0 | 6 votes |
public Transferable paste() throws IOException { if (targetFolder != null) { for (Iterator iterator = sourceDataObjects.iterator(); iterator.hasNext();) { DataObject dataObject = (DataObject) iterator.next(); boolean isValid = dataObject != null && dataObject.isValid(); if (isValid && pasteOperation == LoaderTransfer.CLIPBOARD_COPY) { dataObject.createShadow(targetFolder); } if (isValid && pasteOperation == LoaderTransfer.CLIPBOARD_CUT) { dataObject.move(targetFolder); } } } return null; }
Example 6
Source File: CustomizationWSEditor.java From netbeans with Apache License 2.0 | 6 votes |
private boolean modelExists(final WSDLModel wsdlModel) { if (wsdlModels.size() == 0) { return false; } DataObject modelDobj = getDataObjectOfModel(wsdlModel); if (!modelDobj.isValid()) { return true; } Set<WSDLModel> wsdls = wsdlModels.keySet(); for (WSDLModel wsdl : wsdls) { DataObject dobj = getDataObjectOfModel(wsdl); if (!dobj.isValid()) { continue; } if (modelDobj.equals(dobj)) { return true; } } return false; }
Example 7
Source File: CustomizationWSEditor.java From netbeans with Apache License 2.0 | 6 votes |
private void populateAllModels(WSDLModel wsdlModel) throws CatalogModelException { if (modelExists(wsdlModel)) { return; } DataObject dobj = getDataObjectOfModel(wsdlModel); if (!dobj.isValid()) { return; } Definitions definitions = wsdlModel.getDefinitions(); if (definitions.getImports().size() == 0) { wsdlModels.put(wsdlModel, Boolean.valueOf(dobj.isModified())); return; } else { wsdlModels.put(wsdlModel, Boolean.valueOf(dobj.isModified())); Set<WSDLModel> modelSet = getImportedModels(definitions); for (WSDLModel wModel : modelSet) { populateAllModels(wModel); } } }
Example 8
Source File: CustomizationWSEditor.java From netbeans with Apache License 2.0 | 6 votes |
private boolean modelExists(final WSDLModel wsdlModel) { if (wsdlModels.size() == 0) { return false; } DataObject modelDobj = getDataObjectOfModel(wsdlModel); if (!modelDobj.isValid()) { return true; } Set<WSDLModel> wsdls = wsdlModels.keySet(); for (WSDLModel wsdl : wsdls) { DataObject dobj = getDataObjectOfModel(wsdl); if (!dobj.isValid()) { continue; } if (modelDobj.equals(dobj)) { return true; } } return false; }
Example 9
Source File: CustomizationWSEditor.java From netbeans with Apache License 2.0 | 6 votes |
private void populateAllModels(WSDLModel wsdlModel) throws Exception { if (modelExists(wsdlModel)) { return; } DataObject dobj = getDataObjectOfModel(wsdlModel); if (!dobj.isValid()) { return; } Definitions definitions = wsdlModel.getDefinitions(); if (definitions == null) { // invalid (broken) wsdl model return; } if (definitions.getImports().size() == 0) { wsdlModels.put(wsdlModel, Boolean.valueOf(dobj.isModified())); return; } else { wsdlModels.put(wsdlModel, Boolean.valueOf(dobj.isModified())); Set<WSDLModel> modelSet = getImportedModels(definitions); for (WSDLModel wModel : modelSet) { populateAllModels(wModel); } } }
Example 10
Source File: Utils.java From netbeans with Apache License 2.0 | 5 votes |
/** * Returns current editor component instance. * * @return current editor component instance */ private static EditorCookie getCurrentEditorCookie () { Node[] nodes = TopComponent.getRegistry ().getActivatedNodes (); if ((nodes == null) || (nodes.length != 1)) return null; Node node = nodes [0]; DataObject dob = node.getLookup().lookup (DataObject.class); if (dob != null && !dob.isValid()) { return null; } return node.getLookup().lookup (EditorCookie.class); }
Example 11
Source File: BugtrackingOwnerSupport.java From netbeans with Apache License 2.0 | 5 votes |
private static FileObject getOpenFileObj() { TopComponent activatedTopComponent = TopComponent.getRegistry() .getActivated(); if (activatedTopComponent == null) { return null; } DataObject dataObj = activatedTopComponent.getLookup() .lookup(DataObject.class); if ((dataObj == null) || !dataObj.isValid()) { return null; } return dataObj.getPrimaryFile(); }
Example 12
Source File: ExitDialog.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) // the list and the cell have the focus { final DataObject obj = (DataObject)value; if (!obj.isValid()) { // #17059: it might be invalid already. // #18886: but if so, remove it later, otherwise BasicListUI gets confused. SwingUtilities.invokeLater(new Runnable() { @Override public void run() { listModel.removeElement(obj); } }); setText(""); return this; } Node node = obj.getNodeDelegate(); ImageIcon icon = new ImageIcon(node.getIcon(BeanInfo.ICON_COLOR_16x16)); super.setIcon(icon); setText(node.getDisplayName()); if (isSelected){ this.setBackground(UIManager.getColor("List.selectionBackground")); // NOI18N this.setForeground(UIManager.getColor("List.selectionForeground")); // NOI18N } else { this.setBackground(list.getBackground()); this.setForeground(list.getForeground()); } this.setBorder(cellHasFocus ? hasFocusBorder : noFocusBorder); return this; }
Example 13
Source File: ServletEditor.java From netbeans with Apache License 2.0 | 5 votes |
/** Constructs message that should be used to name the editor component. * * @return name of the editor */ protected String messageName () { DataObject dobj = getServlet(); if (dobj == null) return "..."; // NOI18N if (! dobj.isValid()) return ""; // NOI18N if(DataNode.getShowFileExtensions()) { return dobj.getPrimaryFile().getNameExt(); } else { return dobj.getPrimaryFile().getName(); } }
Example 14
Source File: SourceMultiViewElement.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void componentShowing() { super.componentShowing(); DataObject dobj = getEditorSupport().getDataObject(); if (dobj == null || !dobj.isValid()) { setActivatedNodes(new Node[] {}); } else { setActivatedNodes(new Node[] {getEditorSupport().getDataObject().getNodeDelegate()}); } }
Example 15
Source File: AntNavigatorPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void display(Collection<? extends DataObject> selectedFiles) { // Show list of targets for selected file: if (selectedFiles.size() == 1) { DataObject d = selectedFiles.iterator().next(); if (d.isValid()) { // #145571 manager.setRootContext(d.getNodeDelegate()); return; } } // Fallback: manager.setRootContext(Node.EMPTY); }
Example 16
Source File: HtmlEditorSupport.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected boolean close(boolean ask) { boolean closed = super.close(ask); DataObject dobj = getDataObject(); if(closed && dobj.isValid()) { //set the original property sets HtmlDataNode nodeDelegate = (HtmlDataNode)dobj.getNodeDelegate(); nodeDelegate.setPropertySets(null); } return closed; }
Example 17
Source File: BIEditorSupport.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected Pane createPane() { DataObject dobj = getDataObject(); if (dobj == null || !dobj.isValid()) { return super.createPane(); } return (Pane) MultiViews.createCloneableMultiView(MIME_BEAN_INFO, getDataObject()); }
Example 18
Source File: FixActionProvider.java From netbeans with Apache License 2.0 | 5 votes |
/** * Returns the project that the active node's fileobject belongs to. * If this cannot be determined for some reason, returns the main project. * * @return the project that the active node's fileobject belongs to */ private Project getCurrentProject() { Node[] nodes = TopComponent.getRegistry ().getActivatedNodes (); if (nodes == null || nodes.length == 0) { return MainProjectManager.getDefault().getMainProject(); } DataObject dao = (DataObject) nodes[0].getLookup().lookup(DataObject.class); if (dao == null || !dao.isValid()) { return MainProjectManager.getDefault().getMainProject(); } return FileOwnerQuery.getOwner(dao.getPrimaryFile()); }
Example 19
Source File: J2SEProjectBuilder.java From netbeans with Apache License 2.0 | 4 votes |
private static void createMainClass( final @NonNull String mainClassName, final @NonNull FileObject srcFolder, @NullAllowed String mainClassTemplate) throws IOException { int lastDotIdx = mainClassName.lastIndexOf( '.' ); String mName, pName; if ( lastDotIdx == -1 ) { mName = mainClassName.trim(); pName = null; } else { mName = mainClassName.substring( lastDotIdx + 1 ).trim(); pName = mainClassName.substring( 0, lastDotIdx ).trim(); } if ( mName.length() == 0 ) { return; } if (mainClassTemplate == null) { mainClassTemplate = "Templates/Classes/Main.java"; //NOI18N } final FileObject mainTemplate = FileUtil.getConfigFile(mainClassTemplate); if ( mainTemplate == null ) { LOG.log( Level.WARNING, "Template {0} not found!", //NOI18N mainClassTemplate); return; // Don't know the template } DataObject mt = DataObject.find( mainTemplate ); FileObject pkgFolder = srcFolder; if ( pName != null ) { String fName = pName.replace( '.', '/' ); // NOI18N pkgFolder = FileUtil.createFolder( srcFolder, fName ); } DataFolder pDf = DataFolder.findFolder( pkgFolder ); DataObject res = mt.createFromTemplate( pDf, mName ); if (res == null || !res.isValid()) { LOG.log( Level.WARNING, "Template {0} created an invalid DataObject in folder {1}!", //NOI18N new Object[] { mainClassTemplate, FileUtil.getFileDisplayName(pkgFolder) }); } }
Example 20
Source File: SelectFileDialog.java From netbeans with Apache License 2.0 | 4 votes |
/** * Get file object that have user selected * @throws IOException if cancelled or invalid data entered */ public FileObject getFileObject () throws IOException { FileObject newFO = null; while ( newFO == null ) { DialogDisplayer.getDefault().notify(selectDD); if (selectDD.getValue() != NotifyDescriptor.OK_OPTION) { throw new UserCancelException(); } final String newName = selectDD.getInputText(); newFO = folder.getFileObject (newName, ext); if ( ( newFO == null ) || ( newFO.isVirtual() == true ) ) { FileSystem fs = folder.getFileSystem(); final FileObject tempFile = newFO; fs.runAtomicAction (new FileSystem.AtomicAction () { public void run () throws IOException { if ( ( tempFile != null ) && tempFile.isVirtual() ) { tempFile.delete(); } try { folder.createData (newName, ext); } catch (IOException exc) { NotifyDescriptor desc = new NotifyDescriptor.Message (NbBundle.getMessage(SelectFileDialog.class, "MSG_cannot_create_data", newName + "." + ext), NotifyDescriptor.WARNING_MESSAGE); DialogDisplayer.getDefault().notify (desc); //if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (exc); } } }); newFO = folder.getFileObject (newName, ext); } else if (newFO != null) { DataObject data = DataObject.find(newFO); if (data.isModified() || data.isValid() == false) { NotifyDescriptor message = new NotifyDescriptor.Message(NbBundle.getMessage(SelectFileDialog.class, "BK0001"), NotifyDescriptor.WARNING_MESSAGE); DialogDisplayer.getDefault().notify(message); throw new UserCancelException(); } else if (! GuiUtil.confirmAction (NbBundle.getMessage(SelectFileDialog.class, "PROP_replaceMsg", newName, ext ) )) { throw new UserCancelException(); } } } // while return newFO; }