cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Closing the active document via java code

unknown1
1-Newbie

Closing the active document via java code

Does anyone know how to "close" the active document being edited in the Arbortext Editor using java code?
Here's what I have tried:

ADocument doc = (ADocument)Application.getActiveDocument();
adoc.save();
adoc.close();

But this doesn't seem to actually close out the file. The Edit Window goes blank, but the Document Map window still shows the tag structure of the document. And the file being edited hasn't been fully released; for example, if I go outside the editor and try and delete the file from the local disk, the Windows OS says the file is still "in use".
Any ideas/ suggestions?
Thanks,
Gary
3 REPLIES 3

Gary,

What version of Arbortext are you using? In 5.1, close works fine for us. Instead of using the getActiveDocument method, we actually loop through all windows to ensure we're closing the right one, but it should work the same. In the following example the "briefcase" is a list of files we are currently monitoring.


This example will loop through all open documents. When it finds the correct one, it verifies that the document has first been saved before losing changes. The only notable thing I can see is that we explicitly set the modified flag to false at the end so that it does not again prompt for saves.


String targetPath = this.briefcase.getDocumentPath(targetId);

NodeList docs = Application.getDocuments();

ADocument curNode = null;

for (int i=0; i<docs.getlength(); i++)=" {<br="/>
curNode = (ADocument)docs.item(i);


String openDocPath = curNode.getDirectory() + File.separator + curNode.getName();

if (openDocPath.equals(targetPath)) {

if (curNode.getModified()) {

//Ask user if they want to save, and handle accordingly.


int result = Application.messageBox("The document has been modified since last save. Save before checking in?",3,"Document still open...");

if (result == 1) {

// Yes
curNode.save();
}
if (result == 3) {
// Cancel
return;
}

}

break;


}

// If not found, set this to null so later operations do not fail.
curNode = null;
}

if (curNode != null) {
Acl.execute("window_set(window_id(), 'title', '')");

curNode.setModified(false);
curNode.close();
}


Keith Berard
XML Systems Analyst
Milliman Care Guidelines LLC, A Milliman Company
719 Second Avenue, Suite 300
Seattle, WA 98104
Tel +1 206
381.8166
keith.berard@milliman.com
http://www.careguidelines.com/

Delivering evidence-based knowledge at the point of care


On 5/7/07, Gary Ouzts <gary.r.ouzts@boeing.com> wrote:
Does anyone know how to "close" the active document being edited in the Arbortext Editor using java code?

Here's what I have tried:

ADocument doc = (ADocument)Application.getActiveDocument();

adoc.save();

adoc.close();

But this doesn't seem to actually close out the file. The Edit Window goes blank, but the Document Map window still shows the tag structure of the document. And the file being edited hasn't been fully released; for example, if I go outside the editor and try and delete the file from the local disk, the Windows OS says the file is still "in use".


Any ideas/ suggestions?

Thanks,

Gary

We're using Arbortext Editor version 5.3 M010

Gary,

I tried the same thing on my machine (Editor 5.3 M020) with the same
results. However, I don't think there is a problem here. Since you
evidently have both the edit view and docmap view opened, there are
apparently 2 document "views" open as well. Your code only closes one
of the views. The following code seems to work for me, although I
haven't thoroughly tested it:

Acl.execute("set viewmode=edit;");
ADocument adoc = (ADocument)Application.getActiveDocument();
adoc.setModified(false); // or adoc.save();
adoc.close();

The first line has the effect of removing the docmap view, so there is
only one view of the document you want to close. There are probably
better ways of closing both views, but this seems to be the quickest. It
is possible (I haven't tested it) that both views of the document are
listed in the NodeList returned by Application.getDocuments(). If so you
could first get the ACL docid of the active document and then loop
through this NodeList, checking the docid of each against that of the
active document. Call ADocument's close method on all that match.


--
Brian Jensen

Kyoshinsha Co. Ltd.
brian@kik.co.jp
2-9-5 Morinomiya-chuo Chuo-ku
Osaka 540-0003 Japan
Tel: 81-6-6941-8881
Fax: 81-6-6941-1053


Gary Ouzts wrote:
> Does anyone know how to "close" the active document being edited in the
> Arbortext Editor using java code?
> Here's what I have tried:
>
> ADocument doc = (ADocument)Application.getActiveDocument();
> adoc.save();
> adoc.close();
>
> But this doesn't seem to actually close out the file. The Edit Window goes
> blank, but the Document Map window still shows the tag structure of the
> document. And the file being edited hasn't been fully released; for example, if
> I go outside the editor and try and delete the file from the local disk, the
> Windows OS says the file is still "in use".
> Any ideas/ suggestions?
> Thanks,
> Gary >> To unsubscribe from the list, send an email to
> listmanager@maillist.arbortext.com with the following in the body: unsubscribe
> adepters - For additional information on the adepters list (how to subscribe or
> unsubscribe etc), send an email to: listmanager@maillist.arbortext.com with the
> following in the body: info Adepters - You may also go to forums.arbortext.com,
> enter the Adepters folder and change your subscription options and preferences.>>
Announcements