@Override public boolean isValid() { return data.isValid(); }
private DataObject getValidDataObject() { if (!removed.get() && dao.isValid()) { return dao; } return null; }
/** Test whether the support is in valid state or not. * It could be invalid after deserialization when the object it * referenced to does not exist anymore. * * @return true or false depending on its state */ public boolean isValid () { return getDataObject ().isValid (); }
/** Setter that allows to destroy this data object. Because such * operation can be dangerous and not always possible (if the data object * is opened in editor) it can be vetoed. Either by this data object * or by any vetoable listener attached to this object (like editor support) * * @param valid should be false * @exception PropertyVetoException if the invalidation has been vetoed */ public void setValid (boolean valid) throws PropertyVetoException { if (!valid && isValid ()) { markInvalid0 (); } }
@Override public void propertyChange(PropertyChangeEvent pce) { DataObject invalidDO = (DataObject) pce.getSource(); if (invalidDO != dobj) return; final String propName = pce.getPropertyName(); if (DataObject.PROP_VALID.equals(propName)) { handleInvalidDataObject(invalidDO); } else if (pce.getPropertyName() == null && !dobj.isValid()) { handleInvalidDataObject(invalidDO); } }
private static DataObject getDataObject() { TopComponent tc = getActiveEditorSafe(); if (tc == null) return null; DataObject dobj = tc.getLookup().lookup(DataObject.class); if (dobj != null && dobj.isValid()) { return dobj; } else { return null; } }
/** Handle for location of given data object. * @return handle that remembers the data object. */ public Handle getHandle () { return new ObjectHandle(obj, obj.isValid() ? (this != obj.getNodeDelegate()) : /* to be safe */ true); }
protected String documentID() { if (! obj.isValid()) return ""; // NOI18N return obj.getPrimaryFile().getName(); }
public static Collection<NativeProject> getNativeProjects(DataObject dobj) { Collection<NativeProject> out = new ArrayList<>(); if (dobj != null && dobj.isValid()) { NativeFileItemSet set = dobj.getLookup().lookup(NativeFileItemSet.class); if (set != null && !set.isEmpty()) { for (NativeFileItem item : set.getItems()) { out.add(item.getNativeProject()); } } } return out; }
@Override public Image getIcon (int type) { if (dobj != null && dobj.isValid()) { return dobj.getNodeDelegate().getIcon(type); } else { return super.getIcon(type); } }
private void originalChanged () { DataObject ori = obj.getOriginal(); if (ori.isValid()) { changeOriginal (ori.getNodeDelegate(), true); } else { updateShadowOriginal(obj); } }
public static File getFile(Document bDoc) { DataObject dobj = NbEditorUtilities.getDataObject(bDoc); if (dobj != null && dobj.isValid()) { FileObject fo = dobj.getPrimaryFile(); if (fo != null) { File file = FileUtil.toFile(fo); return file; } } return null; }
@Override protected Node createNodeForKey(DataObject key) { if (!key.isValid()) { return null; } return key instanceof DataFolder ? new PackageFilterNode((DataFolder) key, folder, filter, g) : key.getNodeDelegate().cloneNode(); }
@Override protected String documentID() { DataObject dataObject = getDataObject(); if (dataObject != null && dataObject.isValid()) { // Netbeans use primitive names for top components id and use file name for editor top component id // So let differ threads TC and editor TC for threads.h // But best solution is use full file name for TC id return dataObject.getPrimaryFile().getNameExt(); } return ""; // NOI18N }
/** Creates menu item associated with the data object. * May be null if there is no ExecCookie. */ public static JMenuItem createMenuItem (org.openide.loaders.DataObject obj) { if (!obj.isValid()) return null; Node n = obj.getNodeDelegate (); Class c = getExecCookieClass(); if (c == null || n.getCookie(c) == null) return null; JMenuItem item = new JMenuItem (); new ExecBridge (n, item); return item; }
/** Creates toolbar component associated with the object. * May be null if there is no ExecCookie. */ public static JButton createButton (org.openide.loaders.DataObject obj) { if (!obj.isValid()) return null; Node n = obj.getNodeDelegate (); Class c = getExecCookieClass(); if (c == null || n.getCookie(c) == null) return null; JButton item = new JButton (); new ExecBridge (n, item); return item; }
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(); }
public static String getDocumentName(Document bDoc) { DataObject dobj = NbEditorUtilities.getDataObject(bDoc); if (dobj != null && dobj.isValid()) { FileObject fo = dobj.getPrimaryFile(); return fo.getNameExt(); } Object title = bDoc.getProperty(Document.TitleProperty); if (title instanceof String) { return (String)title; } return "MacroView"; // NOI18N } /**
/** 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(); } }
/** Overrides superclass method. Initializes editor component. */ protected void initializeCloneableEditor (CloneableEditor editor) { DataObject obj = getDataObject(); if(obj.isValid()) { org.openide.nodes.Node ourNode = obj.getNodeDelegate(); editor.setActivatedNodes(new org.openide.nodes.Node[] {ourNode}); editor.setIcon(ourNode.getIcon (java.beans.BeanInfo.ICON_COLOR_16x16)); NodeListener nl = new DataNodeListener(editor); ourNode.addNodeListener(org.openide.nodes.NodeOp.weakNodeListener (nl, ourNode)); nodeL = nl; } }