/** Helper method. Adds save cookie to the data object. */
  private void addSaveCookie() {
    StrutsConfigDataObject obj = (StrutsConfigDataObject) getDataObject();

    // Adds save cookie to the data object.
    if (obj.getCookie(SaveCookie.class) == null) {
      obj.getCookieSet0().add(saveCookie);
      obj.setModified(true);
    }
  }
  /** Helper method. Removes save cookie from the data object. */
  private void removeSaveCookie() {
    StrutsConfigDataObject obj = (StrutsConfigDataObject) getDataObject();

    // Remove save cookie from the data object.
    Cookie cookie = obj.getCookie(SaveCookie.class);

    if (cookie != null && cookie.equals(saveCookie)) {
      obj.getCookieSet0().remove(saveCookie);
      obj.setModified(false);
    }
  }
 /** Implements <code>SaveCookie</code> interface. */
 public void save() throws java.io.IOException {
   StrutsConfigDataObject obj = (StrutsConfigDataObject) getDataObject();
   // invoke parsing before save
   restartTimer();
   obj.parsingDocument();
   if (obj.isDocumentValid()) {
     saveDocument();
   } else {
     DialogDescriptor dialog =
         new DialogDescriptor(
             NbBundle.getMessage(
                 StrutsConfigEditorSupport.class, "MSG_invalidXmlWarning"), // NOI18N
             NbBundle.getMessage(
                 StrutsConfigEditorSupport.class, "TTL_invalidXmlWarning")); // NOI18N
     java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog);
     d.setVisible(true);
     if (dialog.getValue() == org.openide.DialogDescriptor.OK_OPTION) {
       saveDocument();
     }
   }
 }
 /**
  * Restart the timer which starts the parser after the specified delay.
  *
  * @param onlyIfRunning Restarts the timer only if it is already running
  */
 public void restartTimer() {
   if (parsingDocumentTask == null
       || parsingDocumentTask.isFinished()
       || parsingDocumentTask.cancel()) {
     dataObject.setDocumentDirty(true);
     Runnable r =
         new Runnable() {
           public void run() {
             dataObject.parsingDocument();
           }
         };
     if (parsingDocumentTask != null)
       parsingDocumentTask = RequestProcessor.getDefault().post(r, AUTO_PARSING_DELAY);
     else parsingDocumentTask = RequestProcessor.getDefault().post(r, 100);
   }
 }