gt:         node = mail; // saves last done evaluated
context: /**
   * Copyright (c) 2006-2015 Paco Avila & Josep Llort
   * 
   * No bytes were intentionally harmed during the development of this application.
   * 
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   * 
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU General Public License for more details.
   * 
   * You should have received a copy of the GNU General Public License along
   * with this program; if not, write to the Free Software Foundation, Inc.,
   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   */
  
  package com.openkm.frontend.client.widget.toolbar;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  
  import com.google.gwt.core.client.GWT;
  import com.google.gwt.event.dom.client.ClickEvent;
  import com.google.gwt.event.dom.client.ClickHandler;
  import com.google.gwt.event.dom.client.MouseOutEvent;
  import com.google.gwt.event.dom.client.MouseOutHandler;
  import com.google.gwt.event.dom.client.MouseOverEvent;
  import com.google.gwt.event.dom.client.MouseOverHandler;
  import com.google.gwt.user.client.rpc.AsyncCallback;
  import com.google.gwt.user.client.ui.Composite;
  import com.google.gwt.user.client.ui.FileUpload;
  import com.google.gwt.user.client.ui.HTML;
  import com.google.gwt.user.client.ui.HorizontalPanel;
  import com.google.gwt.user.client.ui.Image;
  import com.google.gwt.user.client.ui.RootPanel;
  import com.google.gwt.user.client.ui.Widget;
  import com.openkm.frontend.client.Main;
  import com.openkm.frontend.client.OKMException;
  import com.openkm.frontend.client.bean.FileToUpload;
  import com.openkm.frontend.client.bean.GWTDocument;
  import com.openkm.frontend.client.bean.GWTFolder;
  import com.openkm.frontend.client.bean.GWTMail;
  import com.openkm.frontend.client.bean.GWTPermission;
  import com.openkm.frontend.client.bean.GWTProfileToolbar;
  import com.openkm.frontend.client.bean.GWTPropertyGroup;
  import com.openkm.frontend.client.bean.ToolBarOption;
  import com.openkm.frontend.client.constants.service.ErrorCode;
  import com.openkm.frontend.client.constants.ui.UIDesktopConstants;
  import com.openkm.frontend.client.constants.ui.UIDockPanelConstants;
  import com.openkm.frontend.client.constants.ui.UIFileUploadConstants;
  import com.openkm.frontend.client.extension.event.HasToolBarEvent;
  import com.openkm.frontend.client.extension.event.handler.ToolBarHandlerExtension;
  import com.openkm.frontend.client.extension.event.hashandler.HasToolBarHandlerExtension;
  import com.openkm.frontend.client.extension.widget.toolbar.ToolBarButtonExtension;
  import com.openkm.frontend.client.service.OKMDocumentService;
  import com.openkm.frontend.client.service.OKMDocumentServiceAsync;
  import com.openkm.frontend.client.service.OKMFolderService;
  import com.openkm.frontend.client.service.OKMFolderServiceAsync;
  import com.openkm.frontend.client.service.OKMPropertyGroupService;
  import com.openkm.frontend.client.service.OKMPropertyGroupServiceAsync;
  import com.openkm.frontend.client.util.CommonUI;
  import com.openkm.frontend.client.util.OKMBundleResources;
  import com.openkm.frontend.client.util.Util;
  import com.openkm.frontend.client.widget.ConfirmPopup;
  import com.openkm.frontend.client.widget.OriginPanel;
  import com.openkm.frontend.client.widget.mainmenu.Bookmark;
  
  /**
   * ToolBar
   * 
   * @author jllort
   */
  public class ToolBar extends Composite implements OriginPanel, HasToolBarEvent, HasToolBarHandlerExtension {
      private final OKMDocumentServiceAsync documentService = (OKMDocumentServiceAsync) GWT.create(OKMDocumentService.class);
      private final OKMFolderServiceAsync folderService = (OKMFolderServiceAsync) GWT.create(OKMFolderService.class);
      private final OKMPropertyGroupServiceAsync propertyGroupService = (OKMPropertyGroupServiceAsync) GWT
              .create(OKMPropertyGroupService.class);
  
      private HorizontalPanel panel;
      private ToolBarButton createFolder;
      private ToolBarButton find;
      private ToolBarButton download;
      private ToolBarButton downloadPdf;
      private ToolBarButton print;
      private ToolBarButton lock;
      private ToolBarButton unlock;
      private ToolBarButton addDocument;
      private ToolBarButton checkout;
      private ToolBarButton checkin;
      private ToolBarButton cancelCheckout;
      private ToolBarButton delete;
      private ToolBarButton addPropertyGroup;
      private ToolBarButton removePropertyGroup;
      private ToolBarButton startWorkflow;
      private ToolBarButton addSubscription;
      private ToolBarButton removeSubscription;
      private ToolBarButton home;
      private ToolBarButton refresh;
      private ToolBarButton scanner;
      private ToolBarButton uploader;
      private ToolBarButton splitterResize;
      private Object node;
      private ResizeToolBarMenu resizeToolBarMenu;
      private FindToolBarMenu findToolBarMenu;
  
      private boolean enabled = true; // Indicates if toolbar is enabled or disabled
      private boolean propertyGroupEnabled = false; // Indicates if property group is enabled, used only on changing language
      private ToolBarOption toolBarOption;
      private int actualView;
      private HashMap<String, ToolBarOption> viewValues;
      private List<ToolBarButtonExtension> widgetExtensionList;
      private List<ToolBarHandlerExtension> toolBarHandlerExtensionList;
  
      // Used to store latest evaluation before massive actions selected
      private Object massiveObj1;
      private int massiveOriginPanel = 0;
      private boolean massiveOptions = false;
  
      private MouseOverHandler mouseOverHandler = new MouseOverHandler() {
          @Override
          public void onMouseOver(MouseOverEvent event) {
              Widget sender = (Widget) event.getSource();
              sender.addStyleName("okm-ToolBar-selected");
          }
      };
  
      private MouseOutHandler mouseOutHandler = new MouseOutHandler() {
          @Override
          public void onMouseOut(MouseOutEvent event) {
              Widget sender = (Widget) event.getSource();
              sender.removeStyleName("okm-ToolBar-selected");
          }
      };
  
      /**
       * Folder listener
       */
      ClickHandler createFolderHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.createFolderOption) {
                  executeFolderDirectory();
                  fireEvent(HasToolBarEvent.EXECUTE_CREATE_FOLDER);
              }
          }
      };
  
      /**
       * Execute create folder
       */
      public void executeFolderDirectory() {
          Main.get().activeFolderTree.addTmpFolderCreate();
      }
  
      /**
       * executeFindFolder
       */
      public void executeFindFolder() {
          Main.get().findFolderSelectPopup.show();
          fireEvent(HasToolBarEvent.EXECUTE_FIND_FOLDER);
      }
  
      /**
       * executeFindDocument
       */
      public void executeFindDocument() {
          Main.get().findDocumentSelectPopup.show();
          fireEvent(HasToolBarEvent.EXECUTE_FIND_DOCUMENT);
      }
  
      /**
       * executeFindDocument
       */
      public void executeFindSimilarDocument() {
          Main.get().findSimilarDocumentSelectPopup.show();
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isDocumentSelected()) {
              Main.get().findSimilarDocumentSelectPopup.find(Main.get().mainPanel.desktop.browser.fileBrowser.getDocument().getUuid());
          }
          fireEvent(HasToolBarEvent.EXECUTE_FIND_SIMILAR_DOCUMENT);
      }
  
      /**
       * Lock Handler
       */
      ClickHandler lockHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.lockOption) {
                  executeLock();
              }
          }
      };
  
      /**
       * Execute unlock
       */
      public void executeLock() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isMassive()) {
              Main.get().confirmPopup.setConfirm(ConfirmPopup.CONFIRM_LOCK_MASSIVE);
              Main.get().confirmPopup.center();
          } else {
              Main.get().mainPanel.desktop.browser.fileBrowser.lock();
          }
          fireEvent(HasToolBarEvent.EXECUTE_LOCK);
      }
  
      /**
       * Unlock Handler
       */
      ClickHandler unLockHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.unLockOption) {
                  executeUnlock();
              }
          }
      };
  
      /**
       * Execute lock
       */
      public void executeUnlock() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isMassive()) {
              Main.get().confirmPopup.setConfirm(ConfirmPopup.CONFIRM_UNLOCK_MASSIVE);
              Main.get().confirmPopup.center();
          } else {
              GWTDocument doc = Main.get().mainPanel.desktop.browser.fileBrowser.getDocument();
              if (doc.getLockInfo().getOwner().equals(Main.get().workspaceUserProperties.getUser().getId())) {
                  Main.get().mainPanel.desktop.browser.fileBrowser.unlock();
                  fireEvent(HasToolBarEvent.EXECUTE_UNLOCK);
              } else if (Main.get().workspaceUserProperties.getWorkspace().isAdminRole()) {
                  Main.get().confirmPopup.setConfirm(ConfirmPopup.CONFIRM_FORCE_UNLOCK);
                  Main.get().confirmPopup.show();
              }
          }
      }
  
      /**
       * Add document Handler
       */
      ClickHandler addDocumentHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.addDocumentOption) {
                  if (Main.get().mainPanel.bottomPanel.userInfo.isQuotaExceed()) {
                      Main.get().showError("UserQuotaExceed",
                              new OKMException("OKM-" + ErrorCode.ORIGIN_OKMBrowser + ErrorCode.CAUSE_QuotaExceed, ""));
                  } else {
                      executeAddDocument();
                  }
              }
          }
      };
  
      /**
       * Execute adds documents
       */
      public void executeAddDocument() {
          FileToUpload fileToUpload = new FileToUpload();
          fileToUpload.setFileUpload(new FileUpload());
          fileToUpload.setPath((String) Main.get().activeFolderTree.getActualPath());
          fileToUpload.setAction(UIFileUploadConstants.ACTION_INSERT);
          Main.get().fileUpload.addPendingFileToUpload(fileToUpload);
          fireEvent(HasToolBarEvent.EXECUTE_ADD_DOCUMENT);
      }
  
      /**
       * Delete Handler
       */
      ClickHandler deleteHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.deleteOption) {
                  executeDelete();
              }
          }
      };
  
      /**
       * Executes delete option
       */
      public void executeDelete() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isMassive()) {
              Main.get().confirmPopup.setConfirm(ConfirmPopup.CONFIRM_DELETE_MASSIVE);
              Main.get().confirmPopup.center();
          } else {
              if (Main.get().mainPanel.desktop.browser.fileBrowser.isPanelSelected()) {
                  Main.get().mainPanel.desktop.browser.fileBrowser.confirmDelete();
              } else if (Main.get().activeFolderTree.isPanelSelected()) {
                  Main.get().activeFolderTree.confirmDelete();
              }
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_DELETE);
      }
  
      /**
       * Executes delete option
       */
      public void executeCopy() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isMassive()) {
              Main.get().activeFolderTree.massiveCopy();
          } else if (Main.get().mainPanel.desktop.browser.fileBrowser.isPanelSelected()) {
              Main.get().mainPanel.desktop.browser.fileBrowser.copy();
          } else if (Main.get().activeFolderTree.isPanelSelected()) {
              Main.get().activeFolderTree.copy();
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_COPY);
      }
  
      /**
       * Executes move option
       */
      public void executeMove() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isMassive()) {
              Main.get().activeFolderTree.massiveMove();
          } else if (Main.get().mainPanel.desktop.browser.fileBrowser.isPanelSelected()) {
              Main.get().mainPanel.desktop.browser.fileBrowser.move();
          } else if (Main.get().activeFolderTree.isPanelSelected()) {
              Main.get().activeFolderTree.move();
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_MOVE);
      }
  
      /**
       * Executes rename option
       */
      public void executeRename() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isPanelSelected()) {
              Main.get().mainPanel.desktop.browser.fileBrowser.rename();
          } else if (Main.get().activeFolderTree.isPanelSelected()) {
              Main.get().activeFolderTree.rename();
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_RENAME);
      }
  
      /**
       * addNote
       */
      public void addNote() {
          Main.get().notesPopup.center();
          Main.get().notesPopup.richTextArea.setFocus(true); // Solves safari bug
      }
  
      /**
       * addNote
       */
      public void addCategory() {
          Main.get().categoriesPopup.reset();
          Main.get().categoriesPopup.center();
      }
  
      /**
       * addNote
       */
      public void addKeyword() {
          Main.get().keywordsPopup.reset();
          Main.get().keywordsPopup.center();
      }
  
      /**
       * addPropertyGroup
       */
      public void addPropertyGroup() {
          Main.get().propertyGroupPopup.reset();
          Main.get().propertyGroupPopup.center();
          fireEvent(HasToolBarEvent.EXECUTE_ADD_PROPERTY_GROUP);
      }
  
      /**
       * updatePropertyGroup
       */
      public void updatePropertyGroup() {
          if (toolBarOption.updatePropertyGroupOption) {
              Main.get().updatePropertyGroupPopup.reset();
              Main.get().updatePropertyGroupPopup.center();
          }
      }
  
      /**
       * mergePdf
       */
      public void mergePdf() {
          Main.get().pdfMergePopup.reset(Main.get().mainPanel.desktop.browser.fileBrowser.getAllSelectedPdfDocuments());
          Main.get().pdfMergePopup.center();
      }
  
      /**
       * Edit Handler
       */
      ClickHandler editHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.checkoutOption) {
                  executeCheckout();
              }
          }
      };
  
      /**
       * Execute check out
       */
      public void executeCheckout() {
          if (Main.get().mainPanel.bottomPanel.userInfo.isQuotaExceed()) {
              Main.get().showError("UserQuotaExceed",
                      new OKMException("OKM-" + ErrorCode.ORIGIN_OKMBrowser + ErrorCode.CAUSE_QuotaExceed, ""));
          } else {
              Main.get().mainPanel.desktop.browser.fileBrowser.checkout();
              fireEvent(HasToolBarEvent.EXECUTE_CHECKOUT);
          }
      }
  
      /**
       * Checkin Handler
       */
      ClickHandler checkinHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.checkinOption) {
                  executeCheckin();
              }
          }
      };
  
      /**
       * Execute checkin
       */
      public void executeCheckin() {
          Main.get().mainPanel.desktop.browser.fileBrowser.checkin();
          fireEvent(HasToolBarEvent.EXECUTE_CHECKIN);
      }
  
      /**
       * Checkout cancel Handler
       */
      ClickHandler cancelCheckoutHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.cancelCheckoutOption) {
                  executeCancelCheckout();
              }
          }
      };
  
      /**
       * Cancel the check out
       */
      public void executeCancelCheckout() {
          GWTDocument doc = Main.get().mainPanel.desktop.browser.fileBrowser.getDocument();
  
          if (doc.getLockInfo().getOwner().equals(Main.get().workspaceUserProperties.getUser().getId())) {
              Main.get().mainPanel.desktop.browser.fileBrowser.cancelCheckout();
              fireEvent(HasToolBarEvent.EXECUTE_CANCEL_CHECKOUT);
          } else if (Main.get().workspaceUserProperties.getWorkspace().isAdminRole()) {
              Main.get().confirmPopup.setConfirm(ConfirmPopup.CONFIRM_FORCE_CANCEL_CHECKOUT);
              Main.get().confirmPopup.show();
          }
      }
  
      /**
       * Download Handler
       */
      ClickHandler downloadHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.downloadOption) {
                  executeDownload();
              }
          }
      };
  
      /**
       * Download as PDF Handler
       */
      ClickHandler downloadPdfHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.downloadPdfOption) {
                  executeDownloadPdf();
              }
          }
      };
  
      /**
       * Print as PDF Handler
       */
      ClickHandler printHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.printOption) {
                  executePrint();
              }
          }
      };
  
      /**
       * Download document
       */
      public void executeDownload() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isMassive()) {
              Main.get().mainPanel.desktop.browser.fileBrowser.massiveDownload();
          } else {
              if (Main.get().mainPanel.desktop.browser.fileBrowser.isDocumentSelected()) {
                  Main.get().mainPanel.desktop.browser.fileBrowser.table.downloadDocument(false);
              } else if (Main.get().mainPanel.desktop.browser.fileBrowser.isMailSelected()) {
                  Main.get().mainPanel.desktop.browser.fileBrowser.table.downloadMail();
              }
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_DOWNLOAD_DOCUMENT);
      }
  
      /**
       * Download document as PDF
       */
      public void executeDownloadPdf() {
          Main.get().mainPanel.desktop.browser.fileBrowser.table.downloadDocumentPdf();
          fireEvent(HasToolBarEvent.EXECUTE_DOWNLOAD_PDF_DOCUMENT);
      }
  
      /**
       * Convert document
       */
      public void executeConvert() {
          if (toolBarOption.convertOption) {
              if (Main.get().mainPanel.desktop.browser.fileBrowser.isDocumentSelected()) {
                  Main.get().convertPopup.reset(Main.get().mainPanel.desktop.browser.fileBrowser.getDocument());
                  Main.get().convertPopup.center();
              }
          }
      }
  
      /**
       * executePrint
       */
      public void executePrint() {
          Main.get().mainPanel.desktop.browser.fileBrowser.table.print();
      }
  
      /**
       * Add property group Handler
       */
      ClickHandler addPropertyGroupHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.addPropertyGroupOption) {
                  addPropertyGroup();
              }
          }
      };
  
      /**
       * executeAddBookmark
       */
      public void executeAddBookmark() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isPanelSelected()) {
              if (Main.get().mainPanel.desktop.browser.fileBrowser.isDocumentSelected()) {
                  String path = Main.get().mainPanel.desktop.browser.fileBrowser.getDocument().getPath();
                  Main.get().mainPanel.topPanel.mainMenu.bookmarkPopup.show(path, path.substring(path.lastIndexOf("/") + 1));
              } else if (Main.get().mainPanel.desktop.browser.fileBrowser.isFolderSelected()) {
                  String path = Main.get().mainPanel.desktop.browser.fileBrowser.getFolder().getPath();
                  Main.get().mainPanel.topPanel.mainMenu.bookmarkPopup.show(path, path.substring(path.lastIndexOf("/") + 1));
              }
          } else if (Main.get().activeFolderTree.isPanelSelected()) {
              String path = Main.get().activeFolderTree.getActualPath();
              Main.get().mainPanel.topPanel.mainMenu.bookmarkPopup.show(path, path.substring(path.lastIndexOf("/") + 1));
          }
      }
  
      /**
       * Add workflowgroup
       */
      public void executeAddWorkflow() {
          Main.get().workflowPopup.show();
          fireEvent(HasToolBarEvent.EXECUTE_ADD_WORKFLOW);
      }
  
      /**
       * Remove property group Handler
       */
      ClickHandler removePropertyGroupHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.removePropertyGroupOption && toolBarOption.firedRemovePropertyGroupOption) {
                  executeRemovePropertyGroup();
              }
          }
      };
  
      /**
       * Add workflow Handler
       */
      ClickHandler startWorkflowHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.workflowOption) {
                  executeAddWorkflow();
              }
          }
      };
  
      /**
       * Execute remove property group
       */
      public void executeRemovePropertyGroup() {
          Main.get().confirmPopup.setConfirm(ConfirmPopup.CONFIRM_DELETE_PROPERTY_GROUP);
          Main.get().confirmPopup.show();
          fireEvent(HasToolBarEvent.EXECUTE_REMOVE_PROPERTY_GROUP);
      }
  
      /**
       * Add subscription
       */
      ClickHandler addSubscriptionHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.addSubscription) {
                  executeAddSubscription();
              }
          }
      };
  
      /**
       * Execute add subscription
       */
      public void executeAddSubscription() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isPanelSelected()) {
              Main.get().mainPanel.desktop.browser.fileBrowser.addSubscription();
          } else if (Main.get().activeFolderTree.isPanelSelected()) {
              Main.get().activeFolderTree.addSubscription();
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_ADD_SUBSCRIPTION);
      }
  
      /**
       * Remove subscription
       */
      ClickHandler removeSubscriptionHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.removeSubscription) {
                  executeRemoveSubscription();
              }
          }
      };
  
      /**
       * Execute remove property group
       */
      public void executeRemoveSubscription() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isPanelSelected()) {
              Main.get().mainPanel.desktop.browser.fileBrowser.removeSubscription();
          } else if (Main.get().activeFolderTree.isPanelSelected()) {
              Main.get().activeFolderTree.removeSubscription();
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_REMOVE_SUBSCRIPTION);
      }
  
      /**
       * Arrow rotate clock wise Handler
       */
      ClickHandler arrowRefreshHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.refreshOption) {
                  executeRefresh();
              }
          }
      };
  
      /**
       * Scanner Handler
       */
      ClickHandler scannerHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              executeScanner();
          }
      };
  
      /**
       * Upload Handler
       */
      ClickHandler uploaderHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              executeUploader();
          }
      };
  
      /**
       * executeScanner
       */
      public void executeScanner() {
          if (toolBarOption.scannerOption) {
              setScannerApplet(Main.get().workspaceUserProperties.getWorkspace().getSessionId(), Main.get().activeFolderTree.getActualPath());
              fireEvent(HasToolBarEvent.EXECUTE_SCANNER);
          }
      }
  
      /**
       * executeUploader
       */
      public void executeUploader() {
          if (toolBarOption.uploaderOption) {
              setUploaderApplet(Main.get().workspaceUserProperties.getWorkspace().getSessionId(), Main.get().activeFolderTree.getActualPath());
              fireEvent(HasToolBarEvent.EXECUTE_UPLOADER);
          }
  
      }
  
      /**
       * Refreshing workspace
       */
      public void executeRefresh() {
          Main.get().mainPanel.topPanel.mainMenu.refreshAvailableTemplates();
  
          switch (Main.get().mainPanel.topPanel.tabWorkspace.getSelectedWorkspace()) {
          case UIDockPanelConstants.DESKTOP:
              int actualView = Main.get().mainPanel.desktop.navigator.stackPanel.getStackIndex();
  
              switch (actualView) {
              case UIDesktopConstants.NAVIGATOR_TAXONOMY:
              case UIDesktopConstants.NAVIGATOR_CATEGORIES:
              case UIDesktopConstants.NAVIGATOR_METADATA:
              case UIDesktopConstants.NAVIGATOR_THESAURUS:
              case UIDesktopConstants.NAVIGATOR_TEMPLATES:
              case UIDesktopConstants.NAVIGATOR_PERSONAL:
              case UIDesktopConstants.NAVIGATOR_MAIL:
                  Main.get().activeFolderTree.refresh(false);
                  break;
  
              case UIDesktopConstants.NAVIGATOR_TRASH:
                  Main.get().activeFolderTree.refresh(false);
                  break;
              }
              break;
  
          case UIDockPanelConstants.SEARCH:
              break;
  
          case UIDockPanelConstants.DASHBOARD:
              Main.get().mainPanel.dashboard.refreshAll();
              break;
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_REFRESH);
      }
  
      /**
       * Arrow rotate clock wise Handler
       */
      ClickHandler arrowHomeHandler = new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              if (toolBarOption.homeOption) {
                  executeGoToUserHome();
              }
          }
      };
  
      /**
       * Goes home
       */
      public void executeGoToUserHome() {
          // First must validate path is correct
          if (Main.get().userHome != null && !Main.get().userHome.getHomePath().equals("")) {
              if (Main.get().userHome.getHomeType().equals(Bookmark.BOOKMARK_DOCUMENT)) {
                  documentService.isValid(Main.get().userHome.getHomePath(), new AsyncCallback<Boolean>() {
                      public void onSuccess(Boolean result) {
                          if (result.booleanValue()) {
                              String path = Main.get().userHome.getHomePath();
                              CommonUI.openPath(Util.getParent(path), path);
                          }
                      }
  
                      public void onFailure(Throwable caught) {
                          Main.get().showError("isValid", caught);
                      }
                  });
              } else if (Main.get().userHome.getHomeType().equals(Bookmark.BOOKMARK_FOLDER)) {
                  folderService.isValid(Main.get().userHome.getHomePath(), new AsyncCallback<Boolean>() {
                      public void onSuccess(Boolean result) {
                          if (result.booleanValue()) {
                              CommonUI.openPath(Util.getParent(Main.get().userHome.getHomePath()), "");
                          }
                      }
  
                      public void onFailure(Throwable caught) {
                          Main.get().showError("isValid", caught);
                      }
                  });
              }
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_GO_HOME);
      }
  
      /**
       * Execute add export
       */
      public void executeExport() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isPanelSelected()) {
              Main.get().mainPanel.desktop.browser.fileBrowser.exportFolderToFile();
          } else if (Main.get().activeFolderTree.isPanelSelected()) {
              Main.get().activeFolderTree.exportFolderToFile();
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_EXPORT_TO_ZIP);
      }
  
      /**
       * executePurge
       */
      public void executePurge() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isPanelSelected()) {
              Main.get().mainPanel.desktop.browser.fileBrowser.confirmPurge();
          } else if (Main.get().activeFolderTree.isPanelSelected()) {
              Main.get().confirmPopup.setConfirm(ConfirmPopup.CONFIRM_PURGE_FOLDER);
              Main.get().confirmPopup.show();
          }
      }
  
      /**
       * executeRestore
       */
      public void executeRestore() {
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isPanelSelected()) {
              Main.get().mainPanel.desktop.browser.fileBrowser.restore();
          } else if (Main.get().activeFolderTree.isPanelSelected()) {
              Main.get().activeFolderTree.restore();
          }
      }
  
      /**
       * executeCreateFromTemplate
       */
      public void executeCreateFromTemplate() {
          Main.get().mainPanel.desktop.browser.fileBrowser.createFromTemplate();
      }
  
      /**
       * executePurgeTrash
       */
      public void executePurgeTrash() {
          Main.get().confirmPopup.setConfirm(ConfirmPopup.CONFIRM_EMPTY_TRASH);
          Main.get().confirmPopup.show();
      }
  
      /**
       * Gets the HTML space code
       * 
       * @return Space tool bar code
       */
      private HTML space() {
          HTML space = new HTML(" ");
          space.setStyleName("okm-ToolBar-space");
          return space;
      }
  
      /**
       * Tool Bar
       */
      public ToolBar() {
          actualView = UIDesktopConstants.NAVIGATOR_TAXONOMY;
          viewValues = new HashMap<String, ToolBarOption>();
          toolBarOption = getDefaultRootToolBar();
          widgetExtensionList = new ArrayList<ToolBarButtonExtension>();
          toolBarHandlerExtensionList = new ArrayList<ToolBarHandlerExtension>();
  
          // ONLY TO DEVELOPMENT TESTING
          // enableAllToolBarForTestingPurpose();
          find = new ToolBarButton(new Image(OKMBundleResources.INSTANCE.find()), Main.i18n("general.menu.find"), new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {
                  if (toolBarOption.findOption) {
                      findToolBarMenu.setPopupPosition(find.getAbsoluteLeft() + 20, find.getAbsoluteTop() + 6);
                      findToolBarMenu.show();
                  }
              }
          });
  
          lock = new ToolBarButton(new Image(OKMBundleResources.INSTANCE.lockDisabled()), Main.i18n("general.menu.edit.lock"), lockHandler);
  
          unlock =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.lockDisabled()), Main.i18n("general.menu.edit.unlock"),
                          unLockHandler);
  
          createFolder =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.createFolder()), Main.i18n("tree.menu.directory.create"),
                          createFolderHandler);
  
          addDocument =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.addDocument()), Main.i18n("general.menu.file.add.document"),
                          addDocumentHandler);
  
          delete =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.deleteDisabled()), Main.i18n("general.menu.edit.delete"),
                          deleteHandler);
  
          checkout =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.checkoutDisabled()), Main.i18n("general.menu.edit.checkout"),
                          editHandler);
  
          checkin =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.checkinDisabled()), Main.i18n("general.menu.edit.checkin"),
                          checkinHandler);
  
          cancelCheckout =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.cancelCheckoutDisabled()),
                          Main.i18n("general.menu.edit.cancel.checkout"), cancelCheckoutHandler);
  
          download =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.downloadDisabled()),
                          Main.i18n("general.menu.file.download.document"), downloadHandler);
  
          downloadPdf =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.downloadPdfDisabled()),
                          Main.i18n("general.menu.file.download.document.pdf"), downloadPdfHandler);
  
          print =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.printDisabled()), Main.i18n("general.menu.file.print"),
                          printHandler);
  
          addPropertyGroup =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.addPropertyGroupDisabled()),
                          Main.i18n("general.menu.edit.add.property.group"), addPropertyGroupHandler);
  
          removePropertyGroup =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.removePropertyGroupDisabled()),
                          Main.i18n("general.menu.edit.remove.property.group"), removePropertyGroupHandler);
  
          startWorkflow =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.startWorkflowDisabled()),
                          Main.i18n("general.menu.file.start.workflow"), startWorkflowHandler);
  
          addSubscription =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.addSubscriptionDisabled()),
                          Main.i18n("general.menu.edit.add.subscription"), addSubscriptionHandler);
  
          removeSubscription =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.removeSubscriptionDisabled()),
                          Main.i18n("general.menu.edit.remove.subscription"), removeSubscriptionHandler);
  
          home = new ToolBarButton(new Image(OKMBundleResources.INSTANCE.home()), Main.i18n("general.menu.bookmark.home"), arrowHomeHandler);
  
          refresh =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.refresh()), Main.i18n("general.menu.file.refresh"),
                          arrowRefreshHandler);
  
          scanner =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.scanner()), Main.i18n("general.menu.file.scanner"), scannerHandler);
  
          uploader =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.uploader()), Main.i18n("general.menu.file.uploader"),
                          uploaderHandler);
  
          splitterResize =
                  new ToolBarButton(new Image(OKMBundleResources.INSTANCE.splitterResize()), Main.i18n("general.menu.splitter.resize"),
                          new ClickHandler() {
                              @Override
                              public void onClick(ClickEvent event) {
                                  if (toolBarOption.splitterResizeOption) {
                                      resizeToolBarMenu.setPopupPosition(splitterResize.getAbsoluteLeft() + 20,
                                              splitterResize.getAbsoluteTop() + 6);
                                      resizeToolBarMenu.show();
                                  }
                              }
                          });
  
          find.addMouseOverHandler(mouseOverHandler);
          find.addMouseOutHandler(mouseOutHandler);
          lock.addMouseOverHandler(mouseOverHandler);
          lock.addMouseOutHandler(mouseOutHandler);
          unlock.addMouseOverHandler(mouseOverHandler);
          unlock.addMouseOutHandler(mouseOutHandler);
          createFolder.addMouseOverHandler(mouseOverHandler);
          createFolder.addMouseOutHandler(mouseOutHandler);
          addDocument.addMouseOverHandler(mouseOverHandler);
          addDocument.addMouseOutHandler(mouseOutHandler);
          delete.addMouseOverHandler(mouseOverHandler);
          delete.addMouseOutHandler(mouseOutHandler);
          checkout.addMouseOverHandler(mouseOverHandler);
          checkout.addMouseOutHandler(mouseOutHandler);
          checkin.addMouseOverHandler(mouseOverHandler);
          checkin.addMouseOutHandler(mouseOutHandler);
          cancelCheckout.addMouseOverHandler(mouseOverHandler);
          cancelCheckout.addMouseOutHandler(mouseOutHandler);
          download.addMouseOverHandler(mouseOverHandler);
          download.addMouseOutHandler(mouseOutHandler);
          downloadPdf.addMouseOverHandler(mouseOverHandler);
          downloadPdf.addMouseOutHandler(mouseOutHandler);
          print.addMouseOverHandler(mouseOverHandler);
          print.addMouseOutHandler(mouseOutHandler);
          addPropertyGroup.addMouseOverHandler(mouseOverHandler);
          addPropertyGroup.addMouseOutHandler(mouseOutHandler);
          removePropertyGroup.addMouseOverHandler(mouseOverHandler);
          removePropertyGroup.addMouseOutHandler(mouseOutHandler);
          startWorkflow.addMouseOverHandler(mouseOverHandler);
          startWorkflow.addMouseOutHandler(mouseOutHandler);
          addSubscription.addMouseOverHandler(mouseOverHandler);
          addSubscription.addMouseOutHandler(mouseOutHandler);
          removeSubscription.addMouseOverHandler(mouseOverHandler);
          removeSubscription.addMouseOutHandler(mouseOutHandler);
          home.addMouseOverHandler(mouseOverHandler);
          home.addMouseOutHandler(mouseOutHandler);
          refresh.addMouseOverHandler(mouseOverHandler);
          refresh.addMouseOutHandler(mouseOutHandler);
          scanner.addMouseOverHandler(mouseOverHandler);
          scanner.addMouseOutHandler(mouseOutHandler);
          uploader.addMouseOverHandler(mouseOverHandler);
          uploader.addMouseOutHandler(mouseOutHandler);
          splitterResize.addMouseOverHandler(mouseOverHandler);
          splitterResize.addMouseOutHandler(mouseOutHandler);
  
          find.setStyleName("okm-ToolBar-button");
          lock.setStyleName("okm-ToolBar-button");
          unlock.setStyleName("okm-ToolBar-button");
          createFolder.setStyleName("okm-ToolBar-button");
          addDocument.setStyleName("okm-ToolBar-button");
          delete.setStyleName("okm-ToolBar-button-disabled");
          checkout.setStyleName("okm-ToolBar-button-disabled");
          checkin.setStyleName("okm-ToolBar-button-disabled");
          cancelCheckout.setStyleName("okm-ToolBar-button-disabled");
          download.setStyleName("okm-ToolBar-button-disabled");
          downloadPdf.setStyleName("okm-ToolBar-button-disabled");
          print.setStyleName("okm-ToolBar-button-disabled");
          addPropertyGroup.setStyleName("okm-ToolBar-button-disabled");
          removePropertyGroup.setStyleName("okm-ToolBar-button-disabled");
          startWorkflow.setStyleName("okm-ToolBar-button-disabled");
          addSubscription.setStyleName("okm-ToolBar-button-disabled");
          removeSubscription.setStyleName("okm-ToolBar-button-disabled");
          home.setStyleName("okm-ToolBar-button-disabled");
          refresh.setStyleName("okm-ToolBar-button-disabled");
          scanner.setStyleName("okm-ToolBar-button-disabled");
          uploader.setStyleName("okm-ToolBar-button-disabled");
          splitterResize.setStyleName("okm-ToolBar-button-disabled");
  
          panel = new HorizontalPanel();
          panel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
          panel.setHorizontalAlignment(HorizontalPanel.ALIGN_LEFT);
          panel.addStyleName("okm-ToolBar");
          panel.add(space());
          panel.add(find);
          panel.add(space());
          panel.add(download);
          panel.add(space());
          panel.add(downloadPdf);
          panel.add(space());
          panel.add(print);
          panel.add(space());
          panel.add(new Image(OKMBundleResources.INSTANCE.separator())); // pos 9
          panel.add(lock);
          panel.add(space());
          panel.add(unlock);
          panel.add(space());
          panel.add(new Image(OKMBundleResources.INSTANCE.separator()));
          panel.add(createFolder);
          panel.add(space());
          panel.add(addDocument);
          panel.add(space());
          panel.add(checkout);
          panel.add(space());
          panel.add(checkin);
          panel.add(space());
          panel.add(cancelCheckout);
          panel.add(space());
          panel.add(delete);
          panel.add(space());
          panel.add(new Image(OKMBundleResources.INSTANCE.separator()));
          panel.add(addPropertyGroup);
          panel.add(space());
          panel.add(removePropertyGroup);
          panel.add(space());
          panel.add(new Image(OKMBundleResources.INSTANCE.separator()));
          panel.add(startWorkflow);
          panel.add(space());
          panel.add(new Image(OKMBundleResources.INSTANCE.separator()));
          panel.add(addSubscription);
          panel.add(space());
          panel.add(removeSubscription);
          panel.add(space());
          panel.add(new Image(OKMBundleResources.INSTANCE.separator()));
          panel.add(refresh);
          panel.add(space());
          panel.add(home);
          panel.add(space());
          panel.add(new Image(OKMBundleResources.INSTANCE.separator()));
          panel.add(scanner);
          panel.add(space());
          panel.add(uploader);
          panel.add(space());
          panel.add(splitterResize);
          panel.add(space());
  
          // Hide all buttons at startup
          for (int i = 0; i < panel.getWidgetCount(); i++) {
              panel.getWidget(i).setVisible(false);
          }
  
          resizeToolBarMenu = new ResizeToolBarMenu();
          findToolBarMenu = new FindToolBarMenu();
  
          initWidget(panel);
      }
  
      /**
       * Checks permissions associated to folder and tool button enabled actions
       * 
       * @param folder The folder
       * @param folderParent the folder parent
       * @param origin The Origin panel
       */
      public void checkToolButtonPermissions(GWTFolder folder, GWTFolder folderParent, int originPanel) {
          node = folder; // saves last done evaluated
          this.massiveObj1 = folderParent;
          this.massiveOriginPanel = originPanel;
  
          // Disable all menu options
          disableAllOptions();
  
          // folderParent.setPermissions((byte)(GWTPermission.DELETE |
          // GWTPermission.READ | GWTPermission.SECURITY |
          // GWTPermission.WRITE));
          // Only if toolbar is enabled must change tools icons values
          boolean isRoot = Util.isRoot(folder.getPath());
  
          if (isEnabled()) {
              // Enable quick search
              if (Main.get().mainPanel.topPanel.tabWorkspace.getSelectedWorkspace() == UIDockPanelConstants.DESKTOP
                      && (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TAXONOMY
                              || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TEMPLATES
                              || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_PERSONAL
                              || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_MAIL || Main.get().mainPanel.desktop.navigator
                              .getStackIndex() == UIDesktopConstants.NAVIGATOR_TRASH)) {
                  toolBarOption.findOption = true;
                  toolBarOption.findFolderOption = true;
                  toolBarOption.findDocumentOption = true;
              }
  
              if (Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_THESAURUS
                      && Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_CATEGORIES
                      && Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_METADATA) {
                  toolBarOption.workflowOption = true;
              }
  
              // On folder parent don't enables subscription
              if (!isRoot) {
                  toolBarOption.exportOption = true;
                  if (folder.isSubscribed()) {
                      toolBarOption.removeSubscription = true;
                  } else {
                      toolBarOption.addSubscription = true;
                  }
              }
  
              // Enables or disables deleting ( in root is not enabled by default
              if (!isRoot
                      && ((folderParent.getPermissions() & GWTPermission.DELETE) == GWTPermission.DELETE)
                      && ((folder.getPermissions() & GWTPermission.DELETE) == GWTPermission.DELETE)
                      && (Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_THESAURUS && Main.get().mainPanel.desktop.navigator
                              .getStackIndex() != UIDesktopConstants.NAVIGATOR_METADATA)
                      && !((originPanel == OriginPanel.FILE_BROWSER) && Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_CATEGORIES)) {
                  toolBarOption.deleteOption = true;
              }
  
              if ((folder.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE) {
                  // Case segurity property group grant is not enabled
                  toolBarOption.addPropertyGroupOption = true;
                  toolBarOption.updatePropertyGroupOption = true;
                  toolBarOption.removePropertyGroupOption = true;
  
                  toolBarOption.addNoteOption = true;
                  toolBarOption.addCategoryOption = true;
                  toolBarOption.addKeywordOption = true;
                  // Evaluates special case root node that must not be deleted;
                  if (!isRoot) {
                      toolBarOption.renameOption = true;
                      toolBarOption.copyOption = true;
                      toolBarOption.moveOption = true;
                  }
  
                  // Enable uploading buttons
                  if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TAXONOMY
                          || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TEMPLATES
                          || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_PERSONAL
                          || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_MAIL
                          || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TRASH) {
                      toolBarOption.addDocumentOption = true;
                      toolBarOption.createFolderOption = true;
                      toolBarOption.scannerOption = true;
                      toolBarOption.uploaderOption = true;
                      toolBarOption.createFromTemplateOption = true;
                  } else if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_CATEGORIES) {
                      toolBarOption.createFolderOption = true;
                  }
              }
  
              // Enable property groups
              boolean getGroups = false;
              if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_THESAURUS
                      || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_CATEGORIES
                      || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_METADATA) {
                  // Evaluate real parent folder
                  getGroups = ((folder.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE);
              } else {
                  // Evalute real parent folder
                  getGroups =
                          ((folderParent.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE)
                                  && ((folder.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE);
              }
              if (getGroups) {
                  // Always enable it ( not controls button, only boolean value )
                  toolBarOption.removePropertyGroupOption = true;
                  // Evaluates enable or disable property group buttons
                  getAllGroups();
              }
  
              // Disables add document, delete and create directory from thesaurus
              // view
              if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_THESAURUS
                      || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_CATEGORIES
                      || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_METADATA) {
                  toolBarOption.addSubscription = false;
  
                  if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_THESAURUS
                          || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_METADATA) {
                      toolBarOption.deleteOption = false;
                  }
              }
  
              // The remove property group is special case depends on tab property
              // enabled, with this call we force to set
              // false
              evaluateRemovePropertyGroup(false);
  
              if (Main.get().mainPanel.topPanel.tabWorkspace.getSelectedWorkspace() == UIDockPanelConstants.DESKTOP) {
                  toolBarOption.refreshOption = true;
                  toolBarOption.homeOption = true;
                  toolBarOption.bookmarkOption = true;
                  toolBarOption.goOption = true;
                  toolBarOption.splitterResizeOption = true;
              } else if (Main.get().mainPanel.topPanel.tabWorkspace.getSelectedWorkspace() == UIDockPanelConstants.DASHBOARD) {
                  toolBarOption.refreshOption = true;
              }
  
              // Disable move & copy option in categories case
              if ((Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_CATEGORIES)) {
                  if (originPanel == OriginPanel.FILE_BROWSER) {
                      toolBarOption.moveOption = false;
                      toolBarOption.copyOption = false;
                  } else if (originPanel == OriginPanel.TREE_ROOT) {
                      toolBarOption.copyOption = false;
                      toolBarOption.addCategoryOption = false;
                      toolBarOption.addKeywordOption = false;
                      toolBarOption.addNoteOption = false;
                  }
              }
              // Disable move & copy option in metadata case
              if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_METADATA) {
                  toolBarOption.moveOption = false;
                  toolBarOption.copyOption = false;
              }
          } else if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TRASH) {
              toolBarOption.purgeTrash = true;
  
              if (isRoot) {
                  toolBarOption.purge = false;
                  toolBarOption.restore = false;
              } else {
                  toolBarOption.purge = true;
                  toolBarOption.restore = true;
              }
  
          }
  
          // Checking extension button
          for (Iterator<ToolBarButtonExtension> it = widgetExtensionList.iterator(); it.hasNext();) {
              it.next().checkPermissions(folder, folderParent, originPanel);
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_CHECK_FOLDER_PERMISSION);
  
          // Sets the permission to menus
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isMassive()) {
              enableMassiveView();
          } else {
              propagateToolBarOptions();
              evaluateShowIcons();
          }
      }
  
      /**
       * Checks permissions associated to document and tool button enabled actions
       * 
       * @param doc The document
       */
      public void checkToolButtonPermissions(GWTDocument doc, GWTFolder folder) {
          node = doc; // saves last done evaluated
          this.massiveObj1 = folder;
          this.massiveOriginPanel = 0;
  
          // Disable all menu options
          disableAllOptions();
  
          // Only if toolbar is enabled must change tools icons values
          if (isEnabled()) {
              // Enable quick search
              if (Main.get().mainPanel.topPanel.tabWorkspace.getSelectedWorkspace() == UIDockPanelConstants.DESKTOP
                      && (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TAXONOMY
                              || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TEMPLATES
                              || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_PERSONAL
                              || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_MAIL || Main.get().mainPanel.desktop.navigator
                              .getStackIndex() == UIDesktopConstants.NAVIGATOR_TRASH)) {
                  toolBarOption.findOption = true;
                  toolBarOption.findFolderOption = true;
                  toolBarOption.findDocumentOption = true;
                  toolBarOption.findSimilarDocumentOption = true;
              }
  
              boolean disable = false;
              String user = Main.get().workspaceUserProperties.getUser().getId();
  
              toolBarOption.downloadOption = true;
              if (Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_THESAURUS
                      && Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_CATEGORIES
                      && Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_METADATA) {
                  toolBarOption.workflowOption = true;
              }
  
              if (toolBarOption.downloadOption && doc.isConvertibleToPdf()) {
                  toolBarOption.downloadPdfOption = true;
                  toolBarOption.printOption = true;
              } else {
                  toolBarOption.downloadPdfOption = false;
                  if (doc.getMimeType().equals("application/pdf")) {
                      toolBarOption.printOption = true; // pdf files are printable
                  }
              }
  
              // Checking delete permissions
              if (((doc.getPermissions() & GWTPermission.DELETE) == GWTPermission.DELETE)
                      && ((folder.getPermissions() & GWTPermission.DELETE) == GWTPermission.DELETE) && !doc.isCheckedOut() && !doc.isLocked()
                      && Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_THESAURUS
                      && Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_CATEGORIES
                      && Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_METADATA) {
                  toolBarOption.deleteOption = true;
              }
  
              // Enable related with creation new documents
              if (((folder.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE)) {
                  if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TAXONOMY
                          || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TEMPLATES
                          || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_PERSONAL) {
                      toolBarOption.addDocumentOption = true;
                      toolBarOption.createFolderOption = true;
                      toolBarOption.scannerOption = true;
                      toolBarOption.uploaderOption = true;
  
                  } else if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_CATEGORIES
                          || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_MAIL) {
                      toolBarOption.createFolderOption = true;
                  }
  
                  // Conversion
                  if (doc.isConvertibleToPdf()
                          && (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TAXONOMY
                                  || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TEMPLATES
                                  || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_PERSONAL || Main
                                  .get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_MAIL)) {
                      toolBarOption.convertOption = true;
                  }
              }
  
              if ((doc.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE) {
                  if (!doc.isCheckedOut() && !doc.isLocked()) {
                      toolBarOption.checkoutOption = true;
                      toolBarOption.lockOption = true;
                      toolBarOption.checkinOption = false;
                      toolBarOption.cancelCheckoutOption = false;
                      toolBarOption.unLockOption = false;
                      toolBarOption.addNoteOption = true;
                      toolBarOption.addCategoryOption = true;
                      toolBarOption.addKeywordOption = true;
  
                      if (doc.isSubscribed()) {
                          toolBarOption.removeSubscription = true;
                      } else if (!doc.isLocked()) {
                          toolBarOption.addSubscription = true;
                      }
                  } else {
                      if (doc.isCheckedOut()) {
                          if (doc.getLockInfo().getOwner().equals(user) || Main.get().workspaceUserProperties.getWorkspace().isAdminRole()) {
                              if (doc.getLockInfo().getOwner().equals(user)) {
                                  toolBarOption.checkinOption = true;
                                  toolBarOption.addPropertyGroupOption = true;
                                  toolBarOption.updatePropertyGroupOption = true;
                                  toolBarOption.removePropertyGroupOption = true;
  
                                  toolBarOption.addNoteOption = true;
                                  toolBarOption.addCategoryOption = true;
                                  toolBarOption.addKeywordOption = true;
                              } else {
                                  toolBarOption.checkinOption = false;
                                  toolBarOption.addPropertyGroupOption = false;
                                  toolBarOption.updatePropertyGroupOption = false;
                                  toolBarOption.removePropertyGroupOption = false;
                                  toolBarOption.addNoteOption = false;
                                  toolBarOption.addCategoryOption = false;
                                  toolBarOption.addKeywordOption = false;
                              }
  
                              toolBarOption.cancelCheckoutOption = true;
                              toolBarOption.checkoutOption = false;
                              toolBarOption.lockOption = false;
                              toolBarOption.unLockOption = false;
                          } else {
                              disable = true;
                          }
                      } else {
                          if (doc.getLockInfo().getOwner().equals(user) || Main.get().workspaceUserProperties.getWorkspace().isAdminRole()) {
                              toolBarOption.unLockOption = true;
                              toolBarOption.checkinOption = false;
                              toolBarOption.cancelCheckoutOption = false;
                              toolBarOption.checkoutOption = false;
                              toolBarOption.lockOption = false;
  
                              toolBarOption.addPropertyGroupOption = true;
                              toolBarOption.updatePropertyGroupOption = true;
                              toolBarOption.removePropertyGroupOption = true;
  
                              toolBarOption.addNoteOption = true;
                              toolBarOption.addCategoryOption = true;
                              toolBarOption.addKeywordOption = false;
  
                              if (doc.isSubscribed()) {
                                  toolBarOption.removeSubscription = true;
                              } else if (!doc.isLocked()) {
                                  toolBarOption.addSubscription = true;
                              }
                          } else {
                              disable = true;
                          }
                      }
                  }
              } else {
                  disable = true;
              }
  
              // Enable property groups
              boolean getGroups = false;
              if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_THESAURUS
                      || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_CATEGORIES
                      || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_METADATA) {
                  // Evaluate real parent folder
                  getGroups = ((doc.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE);
              } else {
                  // Evalute real parent folder
                  getGroups =
                          ((doc.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE)
                                  && ((folder.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE);
              }
              if (getGroups) {
                  toolBarOption.renameOption = true;
                  toolBarOption.copyOption = true;
                  toolBarOption.moveOption = true;
                  // Always enable it ( not controls button, only boolean value )
                  toolBarOption.removePropertyGroupOption = true;
                  // Evaluates enable or disable property group buttons
                  getAllGroups();
              }
  
              if (disable) {
                  toolBarOption.lockOption = false;
                  toolBarOption.unLockOption = false;
                  toolBarOption.checkoutOption = false;
                  toolBarOption.checkinOption = false;
                  toolBarOption.cancelCheckoutOption = false;
                  toolBarOption.addPropertyGroupOption = false;
                  toolBarOption.updatePropertyGroupOption = false;
                  toolBarOption.removePropertyGroupOption = false;
              }
  
              // If not personal and trash can send mail
              if (Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_PERSONAL
                      && Main.get().mainPanel.desktop.navigator.getStackIndex() != UIDesktopConstants.NAVIGATOR_TRASH) {
                  toolBarOption.sendDocumentLinkOption = true;
                  toolBarOption.sendDocumentAttachmentOption = true;
              }
  
              // Create from template
              if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TEMPLATES) {
                  toolBarOption.createFromTemplateOption = true;
              } else if ((folder.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE
                      && (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TAXONOMY
                              || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TEMPLATES
                              || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_PERSONAL
                              || Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_MAIL || Main.get().mainPanel.desktop.navigator
                              .getStackIndex() == UIDesktopConstants.NAVIGATOR_TRASH)) {
                  toolBarOption.createFromTemplateOption = true;
              }
  
              if (Main.get().mainPanel.topPanel.tabWorkspace.getSelectedWorkspace() == UIDockPanelConstants.DESKTOP) {
                  toolBarOption.refreshOption = true;
                  toolBarOption.homeOption = true;
                  toolBarOption.bookmarkOption = true;
                  toolBarOption.goOption = true;
                  toolBarOption.splitterResizeOption = true;
              } else if (Main.get().mainPanel.topPanel.tabWorkspace.getSelectedWorkspace() == UIDockPanelConstants.DASHBOARD) {
                  toolBarOption.refreshOption = true;
              }
  
              // Disable move & copy option in categories and metadata case
              if ((Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_CATEGORIES || Main.get().mainPanel.desktop.navigator
                      .getStackIndex() == UIDesktopConstants.NAVIGATOR_METADATA)) {
                  toolBarOption.moveOption = false;
                  toolBarOption.copyOption = false;
              }
          } else if (Main.get().mainPanel.desktop.navigator.getStackIndex() == UIDesktopConstants.NAVIGATOR_TRASH) {
              toolBarOption.purgeTrash = true;
              toolBarOption.purge = true;
              toolBarOption.restore = true;
          }
  
          // Checking extension button
          for (Iterator<ToolBarButtonExtension> it = widgetExtensionList.iterator(); it.hasNext();) {
              it.next().checkPermissions(doc, folder);
          }
  
          fireEvent(HasToolBarEvent.EXECUTE_CHECK_DOCUMENT_PERMISSION);
  
          // Sets the permission to menus
          if (Main.get().mainPanel.desktop.browser.fileBrowser.isMassive()) {
              enableMassiveView();
          } else {
              propagateToolBarOptions();
              evaluateShowIcons();
          }
      }
  
      /**
       * Checks permissions associated to document and tool button enabled actions
       * 
       * @param mail The Mail
       */
      public void checkToolButtonPermissions(GWTMail mail, GWTFolder folder) {
  