public void init(PanelProvider provider) throws Exception {
   super.init(provider);
   addParameter(new BooleanParameter(provider, PARAMETER_USE_DEFAULTS, false, true));
   String[] methodsForEditMode = new String[] {"actionChangeEditingLanguage", "actionSaveChanges"};
   for (int i = 0; i < methodsForEditMode.length; i++) {
     String method = methodsForEditMode[i];
     addMethodPermission(method, PanelPermission.class, PanelPermission.ACTION_EDIT);
   }
 }
  protected void beforePanelInstanceRemove(final PanelInstance instance) throws Exception {
    super.beforePanelInstanceRemove(instance);

    new HibernateTxFragment() {
      protected void txFragment(Session session) throws Exception {
        HTMLText htmlText = load(instance);
        if (htmlText != null) htmlText.delete();
      }
    }.execute();
  }
  /**
   * Replicates panel data.
   *
   * @param src Source PanelInstance
   * @param dest Destinaton PanelInstance
   */
  public void replicateData(final PanelInstance src, PanelInstance dest) throws Exception {
    super.replicateData(src, dest);
    log.debug(
        "HTMLDriver replicating Data from PanelInstance "
            + src.getDbid()
            + " to "
            + dest.getDbid()
            + ").");
    if (src.equals(dest)) {
      log.debug("Ignoring replication, panel instance is the same.");
      return;
    }

    final HTMLText[] textArray = new HTMLText[1];
    try {
      new HibernateTxFragment() {
        protected void txFragment(Session session) throws Exception {
          log.debug("Getting text to duplicate for instance " + src.getDbid());
          FlushMode oldMode = session.getFlushMode();
          session.setFlushMode(
              FlushMode
                  .COMMIT); // Avoids flushing, as we know the text was not modified in this
                            // transaction.
          textArray[0] = load(src);
          session.setFlushMode(oldMode);
          log.debug("Got text to duplicate for instance " + src.getDbid());
        }
      }.execute();
    } catch (Exception e) {
      log.error("Error loading text for instance. ", e);
    }
    HTMLText text = textArray[0];
    if (text == null) {
      log.debug(
          "Nothing to replicate from PanelInstance " + src.getDbid() + " to " + dest.getDbid());
      return;
    }
    Map htmlSrc = text.getText();

    log.debug("htmlCode to replicate = " + htmlSrc);
    HTMLText htmlDest = new HTMLText();
    htmlDest.setPanelInstance(dest.getInstance());
    for (Iterator it = htmlSrc.keySet().iterator(); it.hasNext(); ) {
      String key = (String) it.next();
      String val = (String) htmlSrc.get(key);
      htmlDest.setText(key, val);
    }
    try {
      log.debug("Updating HTMLText: IDText " + htmlDest.getDbid() + " Text " + htmlDest.getText());
      htmlDest.save();
    } catch (Exception e) {
      log.error("Replicating panel data", e);
    }
  }
 /** Defines the action to be taken when activating edit mode */
 public void activateNormalMode(Panel panel, CommandRequest request) throws Exception {
   super.activateNormalMode(panel, request);
   SessionManager.getPanelSession(panel).removeAttribute(ATTR_TEXT);
   SessionManager.getPanelSession(panel).removeAttribute(ATTR_EDITING_LANGUAGE);
 }
 /** Defines the action to be taken when activating edit mode */
 public void activateEditMode(Panel panel, CommandRequest request) throws Exception {
   super.activateEditMode(panel, request);
   HTMLText text = load(panel.getInstance());
   SessionManager.getPanelSession(panel).setAttribute(ATTR_TEXT, toEditableObject(text));
 }