Handling Save As

Save As requires the plug-in to implement the interface SaveAsRequestor. The following example uses an inner class:

  if (saveAsAdapter == null) {
  saveAsAdapter = new SaveAsAdapter();
  }
  SaveAsDialog.showDialog(resources.getString("exportTitle"), (SaveAsRequestor) saveAsAdapter);
  
}

The initSaveAsDialog is called to allow the dialog/frame to initialize the SaveAsDialog as it needs to. By default a file system chooser is added to mainPanel at index 0. A plug-in can add other panels to save to other places in this method.

When an object is selected from any panel, then the saveAsObject method is called with the selected object. If the file system panel is selected the object will be a File if the plug-in adds a panel of their own it they will have to perform the steps to save the object.

private class SaveAsAdapter implements SaveAsRequestor {
  public void initSaveAsDialogComponents(JTabbedPane mainPanel) {
    String xmlString = ResourceUtilities.getStringSafely(resources, XML_FILES);
    DefaultFileFilter xmlFilter =  new DefaultFileFilter(xmlString, "xml", resultAction);
    JFileChooser jfc = (JFileChooser) mainPanel.getComponentAt(0);
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (jfc.isAcceptAllFileFilterUsed() == true)
      jfc.setAcceptAllFileFilterUsed(false);
    jfc.setFileFilter(xmlFilter);
  }
  
  public void initExtraComponents(JPanel extraPanel) {
  }
  
   public boolean saveAsObject(Object saveObject) {
    boolean saved = false;
    if (saveObject instanceof File) {
      File file = (File) saveObject;
      String exportFile = file.getPath();
      if (exportFile != null) {
        String msg = "";
        if (AdminServerPropertiesHelper.requestExportDB(exportFile))
        {
          msg = resources.getString("sucEXDBMsg");
          StandardMessages.showMessage(resources, "exportTitle", msg,           JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
          saved = true;
        }
        else
        {
          msg = resources.getString("failEXDBMsg");
          StandardMessages.showMessage(resources, "exportTitle", msg,           JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
        }
      }
    }
    return saved;
  }
  public void setFocusComponent() {
  }
}