public void editFile() {
    if (filesListPanel.getSelectedFileItems() == null
        || filesListPanel.getSelectedFileItems().size() != 1) {
      return;
    }

    RepositoryFile file = filesListPanel.getSelectedFileItems().get(0).getRepositoryFile();
    if (file.getName().endsWith(".analysisview.xaction")) { // $NON-NLS-1$
      openFile(file, COMMAND.RUN);
    } else {
      // check to see if a plugin supports editing
      ContentTypePlugin plugin = PluginOptionsHelper.getContentTypePlugin(file.getName());
      if (plugin != null && plugin.hasCommand(COMMAND.EDIT)) {
        // load the editor for this plugin
        String editUrl =
            getPath()
                + "api/repos/"
                + pathToId(file.getPath())
                + "/"
                + (plugin != null && (plugin.getCommandPerspective(COMMAND.EDIT) != null)
                    ? plugin.getCommandPerspective(COMMAND.EDIT)
                    : "editor"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        // See if it's already loaded
        for (int i = 0; i < contentTabPanel.getTabCount(); i++) {
          Widget w = contentTabPanel.getTab(i).getContent();
          if (w instanceof IFrameTabPanel && ((IFrameTabPanel) w).getUrl().endsWith(editUrl)) {
            // Already up, select and exit
            contentTabPanel.selectTab(i);
            return;
          }
        }

        contentTabPanel.showNewURLTab(
            Messages.getString("editingColon") + file.getTitle(),
            Messages.getString("editingColon") + file.getTitle(),
            editUrl,
            true); //$NON-NLS-1$ //$NON-NLS-2$

        // Store representation of file in the frame for reference later when
        // save is called
        contentTabPanel.getCurrentFrame().setFileInfo(filesListPanel.getSelectedFileItems().get(0));

      } else {
        MessageDialogBox dialogBox =
            new MessageDialogBox(
                Messages.getString("error"), // $NON-NLS-1$
                Messages.getString("cannotEditFileType"), // $NON-NLS-1$
                true,
                false,
                true);
        dialogBox.center();
      }
    }
  }
 public void openFile(final RepositoryFile repositoryFile, final FileCommand.COMMAND mode) {
   PerspectiveManager.getInstance().setPerspective(PerspectiveManager.OPENED_PERSPECTIVE);
   String fileNameWithPath = repositoryFile.getPath();
   if (mode == FileCommand.COMMAND.EDIT) {
     editFile();
   } else if (mode == FileCommand.COMMAND.SCHEDULE_NEW) {
     ScheduleHelper.createSchedule(repositoryFile);
   } else if (mode == FileCommand.COMMAND.SHARE) {
     (new ShareFileCommand()).execute();
   } else {
     String url = null;
     String extension = ""; // $NON-NLS-1$
     if (fileNameWithPath.lastIndexOf(".") > 0) { // $NON-NLS-1$
       extension =
           fileNameWithPath.substring(fileNameWithPath.lastIndexOf(".") + 1); // $NON-NLS-1$
     }
     if (!executableFileExtensions.contains(extension)) {
       url =
           getPath()
               + "api/repos/"
               + pathToId(fileNameWithPath)
               + "/content"; //$NON-NLS-1$ //$NON-NLS-2$
     } else {
       ContentTypePlugin plugin = PluginOptionsHelper.getContentTypePlugin(fileNameWithPath);
       url =
           getPath()
               + "api/repos/"
               + pathToId(fileNameWithPath)
               + "/"
               + (plugin != null && (plugin.getCommandPerspective(mode) != null)
                   ? plugin.getCommandPerspective(mode)
                   : "generatedContent"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
     }
     if (mode == FileCommand.COMMAND.NEWWINDOW) {
       Window.open(
           url,
           "_blank",
           "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no"); //$NON-NLS-1$
       // //$NON-NLS-2$
     } else {
       contentTabPanel.showNewURLTab(
           repositoryFile.getTitle(), repositoryFile.getTitle(), url, true);
       addRecent(fileNameWithPath, repositoryFile.getTitle());
     }
   }
 }
  @SuppressWarnings("unchecked")
  public void populateFilesList(
      SolutionBrowserPerspective perspective, SolutionTree solutionTree, TreeItem item) {
    filesList.clear();
    ArrayList<Element> files = (ArrayList<Element>) item.getUserObject();
    // let's sort this list based on localized name
    Collections.sort(
        files,
        new Comparator<Element>() {
          public int compare(Element o1, Element o2) {
            String name1 = o1.getAttribute("localized-name"); // $NON-NLS-1$
            String name2 = o2.getAttribute("localized-name"); // $NON-NLS-1$
            return name1.compareTo(name2);
          }
        });
    if (files != null) {
      int rowCounter = 0;
      for (int i = 0; i < files.size(); i++) {
        Element fileElement = files.get(i);
        if ("false".equals(fileElement.getAttribute("isDirectory"))) { // $NON-NLS-1$ //$NON-NLS-2$
          String name = fileElement.getAttribute("name"); // $NON-NLS-1$
          String solution = solutionTree.getSolution();
          String path = solutionTree.getPath();
          String lastModifiedDateStr = fileElement.getAttribute("lastModifiedDate"); // $NON-NLS-1$
          String url = fileElement.getAttribute("url"); // $NON-NLS-1$
          ContentTypePlugin plugin = PluginOptionsHelper.getContentTypePlugin(name);
          String icon = null;
          if (plugin != null) {
            icon = plugin.getFileIcon();
          }
          String localizedName = fileElement.getAttribute("localized-name");
          String description = fileElement.getAttribute("description");
          String tooltip = localizedName;
          if (solutionTree.isUseDescriptionsForTooltip() && !StringUtils.isEmpty(description)) {
            tooltip = description;
          }
          final FileItem fileLabel =
              new FileItem(
                  name,
                  localizedName,
                  tooltip,
                  solution,
                  path, //$NON-NLS-1$
                  lastModifiedDateStr,
                  url,
                  this,
                  PluginOptionsHelper.getEnabledOptions(name),
                  toolbar.getSupportsACLs(),
                  icon);
          // BISERVER-2317: Request for more IDs for Mantle UI elements
          // set element id as the filename
          fileLabel.getElement().setId("file-" + name); // $NON-NLS-1$
          fileLabel.addFileSelectionChangedListener(toolbar);
          fileLabel.setWidth("100%"); // $NON-NLS-1$
          try {
            perspective.getDragController().makeDraggable(fileLabel);
          } catch (Exception e) {
            Throwable throwable = e;
            String text = "Uncaught exception: ";
            while (throwable != null) {
              StackTraceElement[] stackTraceElements = throwable.getStackTrace();
              text += throwable.toString() + "\n";
              for (int ii = 0; ii < stackTraceElements.length; ii++) {
                text += "    at " + stackTraceElements[ii] + "\n";
              }
              throwable = throwable.getCause();
              if (throwable != null) {
                text += "Caused by: ";
              }
            }
            DialogBox dialogBox = new DialogBox(true);
            DOM.setStyleAttribute(dialogBox.getElement(), "backgroundColor", "#ABCDEF");
            System.err.print(text);
            text = text.replaceAll(" ", "&nbsp;");
            dialogBox.setHTML("<pre>" + text + "</pre>");
            dialogBox.center();
          }
          filesList.setWidget(rowCounter++, 0, fileLabel);

          if (selectedFileItem != null
              && selectedFileItem.getFullPath().equals(fileLabel.getFullPath())) {
            fileLabel.setStyleName("fileLabelSelected"); // $NON-NLS-1$
            selectedFileItem = fileLabel;
          } else {
            fileLabel.setStyleName("fileLabel"); // $NON-NLS-1$
          }
        }
      }
    }
  }