Java Code Examples for org.openide.nodes.CookieSet

The following examples show how to use org.openide.nodes.CookieSet. These examples are extracted from open source projects. 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 Project: netbeans   Source File: JShellDataObject.java    License: Apache License 2.0 6 votes vote down vote up
public JShellDataObject(FileObject fo, MultiFileLoader loader) throws DataObjectExistsException {
    super(fo, loader);
    CookieSet cks = getCookieSet();
    cks.add(new Class[] {
            OpenCookie.class,
            EditorCookie.Observable.class,
            CloseCookie.class,
            LineCookie.class,
            SimpleES.class,
        }, new CookieSet.Factory() {
        private CloneableEditorSupport supp;
        public <T extends Node.Cookie> T createCookie(Class<T> klass) {
            if (supp != null) {
                return klass.cast(supp);
            }
            return klass.cast(
                    /*
                    supp = DataEditorSupport.create(JShellDataObject.this, 
                            getPrimaryEntry(), getCookieSet(), 
                            () -> createPane())
                    );*/
                    supp = new SimpleES(JShellDataObject.this, getPrimaryEntry())
            );
        }
    });
}
 
Example 2
Source Project: netbeans   Source File: LayerDataObject.java    License: Apache License 2.0 6 votes vote down vote up
public LayerDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    final CookieSet cookies = getCookieSet();
    final Lookup baseLookup = cookies.getLookup();
    lkp = new ProxyLookup(baseLookup) {
        final AtomicBoolean checked = new AtomicBoolean();
        protected @Override void beforeLookup(Template<?> template) {
            if (template.getType() == LayerHandle.class && checked.compareAndSet(false, true)) {
                FileObject xml = getPrimaryFile();
                Project p = FileOwnerQuery.getOwner(xml);
                if (p != null) {
                    setLookups(baseLookup, Lookups.singleton(new LayerHandle(p, xml)));
                }
            }
        }
    };
    registerEditor("text/x-netbeans-layer+xml", true);
    cookies.add(new ValidateXMLSupport(DataObjectAdapters.inputSource(this)));
}
 
Example 3
Source Project: netbeans   Source File: XMLJ2eeDataObject.java    License: Apache License 2.0 6 votes vote down vote up
public XMLJ2eeDataObject(FileObject pf, MultiFileLoader loader)
    throws org.openide.loaders.DataObjectExistsException {
    super(pf,loader);
    
    CookieSet cs = getCookieSet();
    cs.add(XMLJ2eeEditorSupport.class, this);
    cs.add(EditCookie.class, this);
    cs.add(EditorCookie.class, this);
    cs.add(LineCookie.class, this);
    cs.add(PrintCookie.class, this);
    cs.add(CloseCookie.class, this);
    // added CheckXMLCookie
    InputSource in = DataObjectAdapters.inputSource(this);
    CheckXMLCookie checkCookie = new CheckXMLSupport(in);
    cs.add(checkCookie);
}
 
Example 4
public GlslGeometryShaderDataObject(FileObject pf, GlslGeometryShaderDataLoader loader) throws DataObjectExistsException, IOException {

        super(pf, loader);

        CookieSet cookies = getCookieSet();
        observer = new GlslShaderFileObserver(this);

        final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
        support.addPropertyChangeListener(new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent event) {
                if ("document".equals(event.getPropertyName())) {
                    if (event.getNewValue() != null) {
                        support.getDocument().addDocumentListener(observer);
                        observer.runCompileTask();
                    } else if (event.getOldValue() != null) {
                        // cylab: I think this is never called.
                        // But I don't know if unregistering the observer makes any difference...
                        ((Document) event.getOldValue()).removeDocumentListener(observer);
                    }
                }
            }
        });
        cookies.add((Node.Cookie) support);
    }
 
Example 5
Source Project: netbeans   Source File: DiffSidebar.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tries to obtain an {@code EditorCookie} representing the given file.
 * @param  fileObj  file to get an {@code EditorCookie} from
 * @return  {@code EditorCookie} representing the file, or {@code null}
 * @throws  java.io.IOException
 *          if there was some I/O error while reading the file's content
 */
private static EditorCookie getEditorCookie(FileObject fileObj) throws IOException {
    DataObject dao;
    try {
        dao = DataObject.find(fileObj);
    } catch (DataObjectNotFoundException ex) {
        return null;
    }

    if (dao instanceof MultiDataObject) {
        MultiDataObject.Entry entry = findEntryForFile((MultiDataObject) dao, fileObj);
        if ((entry != null) && (entry instanceof CookieSet.Factory)) {
            CookieSet.Factory factory = (CookieSet.Factory) entry;
            return factory.createCookie(EditorCookie.class);   //can be null
        }
    }

    return dao.getCookie(EditorCookie.class);                  //can be null
}
 
Example 6
Source Project: netbeans   Source File: PropertiesLocaleNode.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates a new PropertiesLocaleNode for the given locale-specific file */
public PropertiesLocaleNode (PropertiesFileEntry fe) {
    super(fe, fe.getChildren());
    setDisplayName(Util.getLocaleLabel(fe));

    setIconBaseWithExtension(LOCALE_ICON_BASE);        
    setShortDescription(messageToolTip());

    // the node uses lookup based on CookieSet from PropertiesFileEntry
    CookieSet cookieSet = fe.getCookieSet();
    cookieSet.add(PropertiesOpen.class, this);
    cookieSet.add(fe);
    cookieSet.add(fe.getDataObject());
    cookieSet.add(this);

    fsStatusListener = new FSListener();
    try {
        FileSystem fs = fe.getFile().getFileSystem();
        fs.addFileStatusListener(FileUtil.weakFileStatusListener(fsStatusListener, fs));
    } catch (FileStateInvalidException ex) {
    }
}
 
Example 7
Source Project: netbeans   Source File: PresentableFileEntry.java    License: Apache License 2.0 6 votes vote down vote up
/** Get the set of cookies.
 * If the set had been
 * previously set by {@link #setCookieSet}, that set
 * is returned. Otherwise an empty set is
 * returned.
 *
 * @return the cookie set (never <code>null</code>)
 */
protected final CookieSet getCookieSet () {
    CookieSet s = cookieSet;
    if (s != null) {
        return s;
    }
    synchronized (this) {
        if (cookieSet != null) {
            return cookieSet;
        }
        // sets an empty sheet and adds a listener to it
        setCookieSet (CookieSet.createGeneric(null));
        cookieSet.assign(FileObject.class, getFile());
        return cookieSet;
    }
}
 
Example 8
Source Project: netbeans   Source File: PresentableFileEntry.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Looks for a cookie in the current cookie set matching the requested class.
 *
 * @param type the class to look for
 * @return an instance of that class, or <code>null</code> if this class of cookie
 *    is not supported
 */
@SuppressWarnings("unchecked")
public <T extends Node.Cookie> T getCookie(Class<T> type) {
    CookieSet c = cookieSet;
    if (c != null) {
        T cookie = c.getCookie(type);
        if (cookie != null) {
            return cookie;
        }
    }
    
    if (type.isInstance (this)) {
        return (T) this;
    }
    return null;
}
 
Example 9
Source Project: netbeans   Source File: EntityDataObject.java    License: Apache License 2.0 6 votes vote down vote up
public EntityDataObject (final FileObject obj, final UniFileLoader loader) throws DataObjectExistsException {
        super (obj, loader);

        CookieSet set = getCookieSet();
        set.add (cookieManager = new DataObjectCookieManager (this, set));
        
        final TextEditorSupport.TextEditorSupportFactory editorFactory =
            new TextEditorSupport.TextEditorSupportFactory (this, MIME_TYPE);
        editorFactory.registerCookies (set);

//         CookieSet.Factory treeEditorFactory = new TreeEditorCookieImpl.CookieFactoryImpl (this);
//         set.add (TreeEditorCookie.class, treeEditorFactory);

        // add check cookie
        InputSource in = DataObjectAdapters.inputSource(this);
        set.add(new CheckXMLSupport(in, CheckXMLSupport.CHECK_ENTITY_MODE));
        
//         new CookieManager (this, set, EntityCookieFactoryCreator.class);
        //enable "Save As"
        set.assign( SaveAsCapable.class, new SaveAsCapable() {
            public void saveAs(FileObject folder, String fileName) throws IOException {
                editorFactory.createEditor().saveAs( folder, fileName );
            }
        });
    }
 
Example 10
Source Project: netbeans   Source File: HtmlDataObject.java    License: Apache License 2.0 6 votes vote down vote up
/** New instance.
 * @param pf primary file object for this data object
 * @param loader the data loader creating it
 * @exception DataObjectExistsException if there was already a data object for it
 */
public HtmlDataObject(FileObject pf, UniFileLoader loader) throws DataObjectExistsException {
    super(pf, loader);
    CookieSet set = getCookieSet();
    set.add(HtmlEditorSupport.class, this);
    set.add(ViewSupport.class, this);
    set.assign(SaveAsCapable.class, new SaveAsCapable() {
        public void saveAs( FileObject folder, String fileName ) throws IOException {
            HtmlEditorSupport es = getCookie( HtmlEditorSupport.class );
            try {
                es.updateEncoding();
                es.saveAs( folder, fileName );
            } catch (UserCancelException e) {
                //ignore, just not save anything
            }
        }
    });

    set.assign(FileEncodingQueryImplementation.class, new FileEncodingQueryImpl());
            
    //add check/validate xml cookies
    InputSource in = DataObjectAdapters.inputSource(this);
    set.add(new ValidateXMLSupport(in));
    set.add(new CheckXMLSupport(in));
    
}
 
Example 11
Source Project: netbeans   Source File: SpringXMLConfigDataObject.java    License: Apache License 2.0 5 votes vote down vote up
public SpringXMLConfigDataObject(FileObject pf, SpringXMLConfigDataLoader loader) throws DataObjectExistsException {
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    InputSource in = DataObjectAdapters.inputSource(this);
    cookies.add(new CheckXMLSupport(in));
    cookies.add(new ValidateXMLSupport(in));
    cookies.assign(FileEncodingQueryImplementation.class, XmlFileEncodingQueryImpl.singleton());

    registerEditor(SpringConstants.CONFIG_MIME_TYPE, true);
}
 
Example 12
Source Project: netbeans   Source File: TestNGSuiteDataObject.java    License: Apache License 2.0 5 votes vote down vote up
public TestNGSuiteDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    cookies.add(new CheckXMLSupport(DataObjectAdapters.inputSource(this)));
    cookies.add(new ValidateXMLSupport(DataObjectAdapters.inputSource(this)));
    registerEditor(MIME_TYPE, true);
}
 
Example 13
Source Project: netbeans   Source File: JnlpDataObject.java    License: Apache License 2.0 5 votes vote down vote up
public JnlpDataObject(FileObject pf, JnlpDataLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    registerEditor(JnlpDataLoader.REQUIRED_MIME, true);
    CookieSet cookies = getCookieSet();
    InputSource in = DataObjectAdapters.inputSource(this);
    CheckXMLSupport checkCookieImpl = new CheckXMLSupport(in);
    ValidateXMLSupport validateCookieImpl = new ValidateXMLSupport(in);
    cookies.add(checkCookieImpl);
    cookies.add(validateCookieImpl);
}
 
Example 14
Source Project: netbeans   Source File: AntProjectDataObject.java    License: Apache License 2.0 5 votes vote down vote up
public AntProjectDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    cookies.add (new AntProjectDataEditor (this));
    FileObject prim = getPrimaryFile ();
    AntProjectCookie proj = new AntProjectSupport (prim);
    cookies.add (proj);
    if (proj.getFile () != null) {
        cookies.add (new AntActionInstance (proj));
    }
    cookies.add(new CheckXMLSupport(DataObjectAdapters.inputSource(this)));
    addPropertyChangeListener (this);
}
 
Example 15
public GlslVertexShaderDataObject(FileObject pf, GlslVertexShaderDataLoader loader) throws DataObjectExistsException, IOException {
    
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    observer= new GlslShaderFileObserver(this);
    
    final CloneableEditorSupport support= DataEditorSupport.create(this, getPrimaryEntry(), cookies);
    support.addPropertyChangeListener(
        new PropertyChangeListener(){
            public void propertyChange(PropertyChangeEvent event) {
                if("document".equals(event.getPropertyName())){
                    if(event.getNewValue()!=null)
                    {
                        support.getDocument().addDocumentListener(observer);
                        observer.runCompileTask();
                    }
                    else if(event.getOldValue()!=null)
                    {
                        // cylab: I think this is never called.
                        // But I don't know if unregistering the observer makes any difference...
                        ((Document)event.getOldValue()).removeDocumentListener(observer);
                    }
                }
            }
        }
    );
    cookies.add((Node.Cookie) support);
}
 
Example 16
public FXKitDataObject(FileObject ffo, FileObject jfo, FXKitDataLoader loader) throws DataObjectExistsException, IOException
{
    super(jfo, loader);
    formEntry = (FileEntry)registerEntry(ffo);

    CookieSet cookies = getCookieSet();
    //cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
}
 
Example 17
Source Project: netbeans   Source File: FightWithWrongOrderInPathsTest.java    License: Apache License 2.0 5 votes vote down vote up
public FormKitDataObject(FileObject ffo, FileObject jfo, FormKitDataLoader loader) throws DataObjectExistsException, IOException
{
    super(jfo, loader);
    formEntry = (FileEntry)registerEntry(ffo);

    CookieSet cookies = getCookieSet();
    //cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
}
 
Example 18
Source Project: netbeans   Source File: AntProjectDataObjectProblemTest.java    License: Apache License 2.0 5 votes vote down vote up
public AntProjectDataObject(
            FileObject pf, MultiFileLoader loader
        ) throws DataObjectExistsException, IOException {
            super(pf, loader);
            CookieSet cookies = getCookieSet();
            cookies.add (new AntProjectDataEditor (this));
            FileObject prim = getPrimaryFile ();
            AntProjectCookie proj = new AntProjectSupport (prim);
            cookies.add (proj);
            if (proj.getFile () != null) {
                cookies.add (new AntActionInstance (proj));
            }
//            cookies.add(new CheckXMLSupport(DataObjectAdapters.inputSource(this)));
            addPropertyChangeListener (this);
        }
 
Example 19
Source Project: netbeans   Source File: CookieActionTest.java    License: Apache License 2.0 5 votes vote down vote up
public NodeWithDefaultLookup() {
    super(Children.LEAF);
    getCookieSet().add(OpenCookie.class, new CookieSet.Factory() {
        public Node.Cookie createCookie(Class clazz) {
            if(clazz.isAssignableFrom(OpenCookie.class)) {
                synchronized(NodeWithDefaultLookup.this) {
                    NodeWithDefaultLookup.this.cookieCreated = true;
                }
                return new Open();
            }
            return null;
        }
    });
}
 
Example 20
Source Project: netbeans   Source File: EjbJarMultiViewDataObject.java    License: Apache License 2.0 5 votes vote down vote up
public EjbJarMultiViewDataObject(FileObject pf, EjbJarDataLoader loader) throws DataObjectExistsException {
    super(pf, loader);
    
    // added ValidateXMLCookie
    InputSource in = DataObjectAdapters.inputSource(this);
    ValidateXMLCookie validateCookie = new ValidateXMLSupport(in);
    CookieSet set = getCookieSet();
    set.add(validateCookie);
    CookieSet.Factory viewCookieFactory = new ViewCookieFactory();
    set.add(ViewCookie.class, viewCookieFactory);

    // initialize srcRoots
    refreshSourcesTask.schedule(0);

    RP.submit(new Runnable() {
        @Override
        public void run() {
            Project project = getProject();
            if (project != null) {
                Sources sources = ProjectUtils.getSources(project);
                sources.addChangeListener(EjbJarMultiViewDataObject.this);
            }
            // refresh srcRoots if any change happened in the meantime
            refreshSourcesTask.schedule(0);
        }
    });
}
 
Example 21
Source Project: netbeans   Source File: JSFConfigDataObject.java    License: Apache License 2.0 5 votes vote down vote up
private void init() {
    CookieSet cookies = getCookieSet();

    cookies.add(JSFConfigEditorSupport.class, this);

    //Lookup JSFConfigEditorContext for Page Flow Editor multiview
    cookies.assign(JSFConfigEditorContext.class, new JSFConfigEditorContextImpl(this));

    // Creates Check XML and Validate XML context actions
    InputSource in = DataObjectAdapters.inputSource(this);
    cookies.add(new CheckXMLSupport(in));
    cookies.add(new ValidateXMLSupport(in));
    cookies.assign(FileEncodingQueryImplementation.class, XmlFileEncodingQueryImpl.singleton());
}
 
Example 22
Source Project: netbeans   Source File: StrutsConfigDataObject.java    License: Apache License 2.0 5 votes vote down vote up
private void init() {
    CookieSet cookies = getCookieSet();

    cookies.add(StrutsConfigEditorSupport.class, this);
    cookies.assign(FileEncodingQueryImplementation.class, XmlFileEncodingQueryImpl.singleton());
    // Creates Check XML and Validate XML context actions
    InputSource in = DataObjectAdapters.inputSource(this);
    cookies.add(new CheckXMLSupport(in));
    cookies.add(new ValidateXMLSupport(in));
}
 
Example 23
Source Project: netbeans   Source File: SunDescriptorDataObject.java    License: Apache License 2.0 5 votes vote down vote up
public SunDescriptorDataObject(FileObject pf, SunDescriptorDataLoader loader) throws DataObjectExistsException {
    super(pf, loader);
    
    descriptorType = DDType.getDDType(pf.getNameExt());
    
    // XML Validation cookies
    InputSource in = DataObjectAdapters.inputSource(this);
    CheckXMLCookie checkCookie = new CheckXMLSupport(in);
    getCookieSet().add(checkCookie);
    ValidateXMLCookie validateCookie = new ValidateXMLSupport(in);
    CookieSet set = getCookieSet();
    set.add(validateCookie);
    if (null == descriptorType) {
        xmlIndex = 0;
    } else if (descriptorType.equals(DDType.DD_GF_WEB_APP) || 
            descriptorType.equals(DDType.DD_SUN_WEB_APP)) {
        xmlIndex = 6;
    } else if (descriptorType.equals(DDType.DD_GF_APPLICATION) || 
            descriptorType.equals(DDType.DD_SUN_APPLICATION)) {
        xmlIndex = 1;
    } else if (descriptorType.equals(DDType.DD_GF_EJB_JAR) || 
            descriptorType.equals(DDType.DD_SUN_EJB_JAR)) {
        xmlIndex = 5;
    } else if (descriptorType.equals(DDType.DD_GF_APP_CLIENT) || 
            descriptorType.equals(DDType.DD_SUN_APP_CLIENT)) {
        xmlIndex = 4;
    } else {
        xmlIndex = 0;
    }
}
 
Example 24
Source Project: netbeans   Source File: DiffStreamSource.java    License: Apache License 2.0 5 votes vote down vote up
private static EditorCookie.Observable getEditableCookie (File file) {
    EditorCookie.Observable editorCookie = null;
    if (file == null) {
        return null;
    }
    FileObject fileObj = FileUtil.toFileObject(file);
    if (fileObj != null) {
        try {
            DataObject dao = DataObject.find(fileObj);
            if (dao instanceof MultiDataObject) {
                MultiDataObject mdao = (MultiDataObject) dao;
                for (MultiDataObject.Entry entry : mdao.secondaryEntries()) {
                    if (fileObj == entry.getFile() && entry instanceof CookieSet.Factory) {
                        CookieSet.Factory factory = (CookieSet.Factory) entry;
                        EditorCookie ec = factory.createCookie(EditorCookie.class);
                        if (ec instanceof EditorCookie.Observable) {
                            editorCookie = (EditorCookie.Observable) ec;
                        }
                    }
                }
            }
            if (editorCookie == null) {
                EditorCookie cookie = dao.getCookie(EditorCookie.class);
                if (cookie instanceof EditorCookie.Observable) {
                    editorCookie = (EditorCookie.Observable) cookie;
                }
            }
        } catch (DataObjectNotFoundException ex) {
        }
    }
    return editorCookie;
}
 
Example 25
Source Project: netbeans   Source File: DiffUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @since 1.9.1
 */
public static EditorCookie getEditorCookie(Document doc) {
    if (doc == null) {
        return null;
    }

    DataObject dataObj = (DataObject) doc.getProperty(
                                        Document.StreamDescriptionProperty);
    if (dataObj == null) {
        return null;
    }

    EditorCookie plain = null;

    if (dataObj instanceof MultiDataObject) {
        MultiDataObject multiDataObj = (MultiDataObject) dataObj;
        for (MultiDataObject.Entry entry : multiDataObj.secondaryEntries()) {
            if (entry instanceof CookieSet.Factory) {
                CookieSet.Factory factory = (CookieSet.Factory) entry;
                EditorCookie ec = factory.createCookie(EditorCookie.class);
                if (ec.getDocument() == doc) {
                    if (ec instanceof EditorCookie.Observable) {
                        return (EditorCookie.Observable) ec;
                    }

                    if (plain == null) {
                        plain = ec;
                    }
                }
            }
        }
    }

    return chooseBetterEditorCookie(getEditorCookie(dataObj, false), plain);
}
 
Example 26
Source Project: netbeans   Source File: DiffSidebarManager.java    License: Apache License 2.0 5 votes vote down vote up
private FileObject fileForDataobject(Document doc, MultiDataObject dobj) {
    for (MultiDataObject.Entry entry : dobj.secondaryEntries()) {
        if (entry instanceof CookieSet.Factory) {
            CookieSet.Factory factory = (CookieSet.Factory) entry;
            EditorCookie ec = factory.createCookie(EditorCookie.class);
            Document entryDocument = ec.getDocument();
            if (entryDocument == doc) {
                return entry.getFile();
            }
        }
    }
    return dobj.getPrimaryFile();
}
 
Example 27
Source Project: netbeans   Source File: PresentableFileEntry.java    License: Apache License 2.0 5 votes vote down vote up
/** Set the set of cookies.
 * To the provided cookie set a listener is attached,
 * and any change to the set is propagated by
 * firing a change on {@link #PROP_COOKIE}.
 *
 * @param s the cookie set to use
 * @deprecated
 */
protected final synchronized void setCookieSet (CookieSet s) {
    if (cookieSet != null) {
        cookieSet.removeChangeListener (cookieL);
}

    s.addChangeListener (cookieL);
    cookieSet = s;

    firePropertyChange (Node.PROP_COOKIE, null, null);
}
 
Example 28
Source Project: netbeans   Source File: CookieManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 */
public CookieManager (DataObject dataObject, CookieSet cookieSet, Class clazz) {        
    if ( CookieFactoryCreator.class.isAssignableFrom (clazz) == false ) {
        throw new IllegalArgumentException ("Parameter class must extend CookieFactoryCreator class.");
    }

    this.dataObject = dataObject;
    this.cookieSet  = cookieSet;
    this.factoryMap = new HashMap<CookieFactoryCreator, CookieFactory>();

    register (clazz);

    addedToResult (getResult());
}
 
Example 29
Source Project: netbeans   Source File: SQLDataObject.java    License: Apache License 2.0 5 votes vote down vote up
public SQLDataObject(FileObject primaryFile, MultiFileLoader loader) throws DataObjectExistsException {
    super(primaryFile, loader);
    CookieSet cookies = getCookieSet();
    final SQLEditorSupport sqlEditorSupport = new SQLEditorSupport(this);
    cookies.add(sqlEditorSupport);
    cookies.assign( SaveAsCapable.class, new SaveAsCapable() {
        @Override
        public void saveAs(FileObject folder, String fileName) throws IOException {
            sqlEditorSupport.saveAs( folder, fileName );
        }
    });
}
 
Example 30
Source Project: netbeans   Source File: DiffStreamSource.java    License: Apache License 2.0 5 votes vote down vote up
private static EditorCookie.Observable getEditableCookie (File file) {
    EditorCookie.Observable editorCookie = null;
    if (file == null) {
        return null;
    }
    FileObject fileObj = FileUtil.toFileObject(file);
    if (fileObj != null) {
        try {
            DataObject dao = DataObject.find(fileObj);
            if (dao instanceof MultiDataObject) {
                MultiDataObject mdao = (MultiDataObject) dao;
                for (MultiDataObject.Entry entry : mdao.secondaryEntries()) {
                    if (fileObj == entry.getFile() && entry instanceof CookieSet.Factory) {
                        CookieSet.Factory factory = (CookieSet.Factory) entry;
                        EditorCookie ec = factory.createCookie(EditorCookie.class);
                        if (ec instanceof EditorCookie.Observable) {
                            editorCookie = (EditorCookie.Observable) ec;
                        }
                    }
                }
            }
            if (editorCookie == null) {
                EditorCookie cookie = dao.getCookie(EditorCookie.class);
                if (cookie instanceof EditorCookie.Observable) {
                    editorCookie = (EditorCookie.Observable) cookie;
                }
            }
        } catch (DataObjectNotFoundException ex) {
        }
    }
    return editorCookie;
}