You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Will Hartung <wi...@gmail.com> on 2021/01/17 22:13:12 UTC

Updating text file in MultiView

I have a XMLMultiView from the generic New File Type wizard.

I'm creating the GUI form for the XML file.

How do I keep the XML file up to date after I make changes in the GUI?

Do I need to create a Saveable and put it in the lookup to mark it as
"dirty", or will that happen automatically when the XML file is updated?

Can I update the XML file only when the tabs are switched vs for every
change? In that case, I would have to add a Saveable since the XML may not
have changed yet.

Anyway, how does that workflow all work out?

Regards,

Will Hartung

Re: Updating text file in MultiView

Posted by Boris Heithecker <bo...@gmx.net>.
Hi,
use XMLDataObject.getDocument() to access the DOM. After modifying the DOM,
you can update the file like this:

        final FileObject file = getPrimaryFile();
        file.getFileSystem().runAtomicAction(() -> {
            final FileLock l = file.lock();
            try (final OutputStream os = file.getOutputStream(l)) {
                XMLUtil.write(doc, os, "utf-8");
                //Do something to unregister the Saveable
            } finally {
                l.releaseLock();
            }
        });

Hope it helps.
Boris

On Sun, 17 Jan 2021 at 23:13, Will Hartung <wi...@gmail.com> wrote:

> I have a XMLMultiView from the generic New File Type wizard.
>
> I'm creating the GUI form for the XML file.
>
> How do I keep the XML file up to date after I make changes in the GUI?
>
> Do I need to create a Saveable and put it in the lookup to mark it as
> "dirty", or will that happen automatically when the XML file is updated?
>
> Can I update the XML file only when the tabs are switched vs for every
> change? In that case, I would have to add a Saveable since the XML may not
> have changed yet.
>
> Anyway, how does that workflow all work out?
>
> Regards,
>
> Will Hartung
>
>

-- 
Boris Heithecker


Dr. Boris Heithecker
Lüneburger Str. 30
28870 Ottersberg
Festnetz: +49 4205 315834
Mobil: +49 170 6137015

Re: Updating text file in MultiView

Posted by Dragan Bjedov <dr...@gmail.com>.
I have created a similar plugin for CSV files.
Please take a look
https://bitbucket.org/draganbjedov/netbeans-csv-editor/src/master/
Hope it helps.

нед, 17. јан 2021. у 23:13 Will Hartung <wi...@gmail.com> је
написао/ла:

> I have a XMLMultiView from the generic New File Type wizard.
>
> I'm creating the GUI form for the XML file.
>
> How do I keep the XML file up to date after I make changes in the GUI?
>
> Do I need to create a Saveable and put it in the lookup to mark it as
> "dirty", or will that happen automatically when the XML file is updated?
>
> Can I update the XML file only when the tabs are switched vs for every
> change? In that case, I would have to add a Saveable since the XML may not
> have changed yet.
>
> Anyway, how does that workflow all work out?
>
> Regards,
>
> Will Hartung
>
>

-- 

MSc Dragan Bjedov