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());
     }
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see com.google.gwt.user.client.Command#execute()
   */
  @Override
  public void execute() {
    final SolutionFileActionEvent event = new SolutionFileActionEvent();
    event.setAction(this.getClass().getName());
    String temp = "";

    if (repositoryFiles != null) {
      for (RepositoryFile repoFile : repositoryFiles) {
        temp += repoFile.getId() + ","; // $NON-NLS-1$
      }
    }

    // Add file names from js
    temp = temp + fileList;

    // remove trailing ","
    temp = temp.substring(0, temp.length() - 1);

    final String filesList = temp;

    String deleteFilesURL = contextURL + "api/repo/files/restore"; // $NON-NLS-1$
    RequestBuilder deleteFilesRequestBuilder =
        new RequestBuilder(RequestBuilder.PUT, deleteFilesURL);
    deleteFilesRequestBuilder.setHeader("Content-Type", "text/plain"); // $NON-NLS-1$//$NON-NLS-2$
    deleteFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
      deleteFilesRequestBuilder.sendRequest(
          filesList,
          new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
              MessageDialogBox dialogBox =
                  new MessageDialogBox(
                      Messages.getString("cannotRestore"),
                      Messages.getString("couldNotRestoreItem", type), // $NON-NLS-1$ //$NON-NLS-2$
                      false,
                      false,
                      true);
              dialogBox.center();
              event.setMessage("cannotRestore");
              EventBusUtil.EVENT_BUS.fireEvent(event);
            }

            @Override
            public void onResponseReceived(final Request request, final Response response) {
              if (response.getStatusCode() == Response.SC_OK) {
                new RefreshRepositoryCommand().execute(false);
                event.setMessage("Success");
                EventBusUtil.EVENT_BUS.fireEvent(event);
              } else if (response.getStatusCode() == Response.SC_CONFLICT
                  || response.getStatusCode() == Response.SC_TEMPORARY_REDIRECT) {
                final int restoreResponseStatusCode = response.getStatusCode();

                final String userHomeDirUrl =
                    GWT.getHostPageBaseURL() + "api/session/userWorkspaceDir";

                final RequestBuilder builder =
                    new RequestBuilder(RequestBuilder.GET, userHomeDirUrl);
                try {
                  // Get user home folder string
                  builder.sendRequest(
                      "",
                      new RequestCallback() {
                        @Override
                        public void onResponseReceived(
                            final Request request, final Response response) {
                          if (response.getStatusCode() == 200) {
                            // API returns /user/home_folder/workspace
                            String userHomeFolderPath =
                                response.getText().replaceAll("/workspace", "");
                            performRestoreToHomeFolder(
                                filesList, restoreResponseStatusCode, userHomeFolderPath, event);
                          }
                        }

                        @Override
                        public void onError(Request request, Throwable exception) {
                          showErrorDialogBox(event);
                        }
                      });
                } catch (RequestException e) {
                  showErrorDialogBox(event);
                }
              } else {
                MessageDialogBox dialogBox =
                    new MessageDialogBox(
                        Messages.getString("cannotRestore"),
                        Messages.getString(
                            "couldNotRestoreItem", type), // $NON-NLS-1$ //$NON-NLS-2$
                        false,
                        false,
                        true,
                        Messages.getString("close"));
                dialogBox.center();
                event.setMessage("Success");
                FileChooserDialog.setIsDirty(Boolean.TRUE);
                setBrowseRepoDirty(Boolean.TRUE);
                EventBusUtil.EVENT_BUS.fireEvent(event);
              }
            }
          });
    } catch (RequestException e) {
      showErrorDialogBox(event);
    }
  }
Esempio n. 4
0
  /** @param repositoryFile */
  public ImportDialog(RepositoryFile repositoryFile, boolean allowAdvancedDialog) {
    super(
        Messages.getString("import"),
        Messages.getString("ok"),
        Messages.getString("cancel"),
        false,
        true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    form = new FormPanel();
    form.addSubmitHandler(
        new SubmitHandler() {
          @Override
          public void onSubmit(SubmitEvent se) {
            // if no file is selected then do not proceed
            okButton.setEnabled(false);
            cancelButton.setEnabled(false);
            MantleApplication.showBusyIndicator(
                Messages.getString("pleaseWait"), Messages.getString("importInProgress"));
          }
        });
    form.addSubmitCompleteHandler(
        new SubmitCompleteHandler() {
          @Override
          public void onSubmitComplete(SubmitCompleteEvent sce) {
            MantleApplication.hideBusyIndicator();
            okButton.setEnabled(false);
            cancelButton.setEnabled(true);
            ImportDialog.this.hide();
            String result = sce.getResults();
            if (result.length() > 5) {
              HTML messageTextBox = null;
              if (result.contains("INVALID_MIME_TYPE") == true) {
                messageTextBox =
                    new HTML(Messages.getString("uploadInvalidFileTypeQuestion", result));
              } else {
                logWindow(result, Messages.getString("importLogWindowTitle"));
              }

              if (messageTextBox != null) {
                PromptDialogBox dialogBox =
                    new PromptDialogBox(
                        Messages.getString("uploadUnsuccessful"),
                        Messages.getString("close"),
                        null,
                        true,
                        true);
                dialogBox.setContent(messageTextBox);
                dialogBox.center();
              }
            }

            // if mantle_isBrowseRepoDirty=true: do getChildren call
            // if mantle_isBrowseRepoDirty=false: use stored fileBrowserModel in
            // myself.get("cachedData")
            setBrowseRepoDirty(Boolean.TRUE);

            // BISERVER-9319 Refresh browse perspective after import
            final GenericEvent event = new GenericEvent();
            event.setEventSubType("ImportDialogEvent");
            EventBusUtil.EVENT_BUS.fireEvent(event);
          }
        });

    VerticalPanel rootPanel = new VerticalPanel();

    VerticalPanel spacer = new VerticalPanel();
    spacer.setHeight("10px");
    rootPanel.add(spacer);

    Label fileLabel = new Label(Messages.getString("file") + ":");
    final TextBox importDir = new TextBox();
    rootPanel.add(fileLabel);

    okButton.setEnabled(false);

    final TextBox fileTextBox = new TextBox();
    fileTextBox.setHeight("26px");
    fileTextBox.setEnabled(false);

    // We use an fileNameOverride because FileUpload can only handle US character set reliably.
    final Hidden fileNameOverride = new Hidden("fileNameOverride");

    final FileUpload upload = new FileUpload();
    upload.setName("fileUpload");
    ChangeHandler fileUploadHandler =
        new ChangeHandler() {
          @Override
          public void onChange(ChangeEvent event) {
            fileTextBox.setText(upload.getFilename());
            if (!"".equals(importDir.getValue())) {
              // Set the fileNameOverride because the fileUpload object can only reliably transmit
              // US-ASCII
              // character set.  See RFC283 section 2.3 for details
              String fileNameValue = upload.getFilename().replaceAll("\\\\", "/");
              fileNameValue = fileNameValue.substring(fileNameValue.lastIndexOf("/") + 1);
              fileNameOverride.setValue(fileNameValue);
              okButton.setEnabled(true);
            } else {
              okButton.setEnabled(false);
            }
          }
        };
    upload.addChangeHandler(fileUploadHandler);
    upload.setVisible(false);

    HorizontalPanel fileUploadPanel = new HorizontalPanel();
    fileUploadPanel.add(fileTextBox);
    fileUploadPanel.add(new HTML("&nbsp;"));

    Button browseButton = new Button(Messages.getString("browse") + "...");
    browseButton.setStyleName("pentaho-button");
    fileUploadPanel.add(browseButton);
    browseButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            setRetainOwnershipState();
            jsClickUpload(upload.getElement());
          }
        });

    rootPanel.add(fileUploadPanel);
    rootPanel.add(upload);

    applyAclPermissions.setName("applyAclPermissions");
    applyAclPermissions.setValue(Boolean.FALSE);
    applyAclPermissions.setFormValue("false");
    applyAclPermissions.setEnabled(true);
    applyAclPermissions.setVisible(false);

    final CheckBox overwriteAclPermissions =
        new CheckBox(Messages.getString("overwriteAclPermissions"), true);
    overwriteAclPermissions.setName("overwriteAclPermissions");
    applyAclPermissions.setValue(Boolean.FALSE);
    applyAclPermissions.setFormValue("false");
    overwriteAclPermissions.setEnabled(true);
    overwriteAclPermissions.setVisible(false);

    final Hidden overwriteFile = new Hidden("overwriteFile");
    overwriteFile.setValue("true");

    final Hidden logLevel = new Hidden("logLevel");
    logLevel.setValue("ERROR");

    final Hidden retainOwnership = new Hidden("retainOwnership");
    retainOwnership.setValue("true");

    rootPanel.add(applyAclPermissions);
    rootPanel.add(overwriteAclPermissions);
    rootPanel.add(overwriteFile);
    rootPanel.add(logLevel);
    rootPanel.add(retainOwnership);
    rootPanel.add(fileNameOverride);

    spacer = new VerticalPanel();
    spacer.setHeight("4px");
    rootPanel.add(spacer);

    DisclosurePanel disclosurePanel = new DisclosurePanel(Messages.getString("advancedOptions"));
    disclosurePanel.getHeader().setStyleName("gwt-Label");
    disclosurePanel.setVisible(allowAdvancedDialog);
    HorizontalPanel mainPanel = new HorizontalPanel();
    mainPanel.add(new HTML("&nbsp;"));
    VerticalPanel disclosureContent = new VerticalPanel();

    HTML replaceLabel = new HTML(Messages.getString("fileExists"));
    replaceLabel.setStyleName("gwt-Label");
    disclosureContent.add(replaceLabel);

    final CustomListBox overwriteFileDropDown = new CustomListBox();
    final CustomListBox filePermissionsDropDown = new CustomListBox();

    DefaultListItem replaceListItem = new DefaultListItem(Messages.getString("replaceFile"));
    replaceListItem.setValue("true");
    overwriteFileDropDown.addItem(replaceListItem);
    DefaultListItem doNotImportListItem = new DefaultListItem(Messages.getString("doNotImport"));
    doNotImportListItem.setValue("false");
    overwriteFileDropDown.addItem(doNotImportListItem);
    overwriteFileDropDown.setVisibleRowCount(1);
    disclosureContent.add(overwriteFileDropDown);

    spacer = new VerticalPanel();
    spacer.setHeight("4px");
    disclosureContent.add(spacer);

    HTML filePermissionsLabel = new HTML(Messages.getString("filePermissions"));
    filePermissionsLabel.setStyleName("gwt-Label");
    disclosureContent.add(filePermissionsLabel);

    DefaultListItem usePermissionsListItem =
        new DefaultListItem(Messages.getString("usePermissions"));
    usePermissionsListItem.setValue("false");
    filePermissionsDropDown.addItem(
        usePermissionsListItem); // If selected set "overwriteAclPermissions" to
    // false.
    DefaultListItem retainPermissionsListItem =
        new DefaultListItem(Messages.getString("retainPermissions"));
    retainPermissionsListItem.setValue("true");
    filePermissionsDropDown.addItem(
        retainPermissionsListItem); // If selected set "overwriteAclPermissions" to
    // true.

    final ChangeListener filePermissionsHandler =
        new ChangeListener() {
          @Override
          public void onChange(Widget sender) {
            String value = filePermissionsDropDown.getSelectedItem().getValue().toString();

            applyAclPermissions.setValue(Boolean.valueOf(value));
            applyAclPermissions.setFormValue(value);
            overwriteAclPermissions.setFormValue(value);
            overwriteAclPermissions.setValue(Boolean.valueOf(value));
            setRetainOwnershipState();
          }
        };
    filePermissionsDropDown.addChangeListener(filePermissionsHandler);
    filePermissionsDropDown.setVisibleRowCount(1);
    disclosureContent.add(filePermissionsDropDown);

    spacer = new VerticalPanel();
    spacer.setHeight("4px");
    disclosureContent.add(spacer);

    HTML fileOwnershipLabel = new HTML(Messages.getString("fileOwnership"));
    fileOwnershipLabel.setStyleName("gwt-Label");
    disclosureContent.add(fileOwnershipLabel);

    retainOwnershipDropDown.addChangeListener(
        new ChangeListener() {
          @Override
          public void onChange(Widget sender) {
            String value = retainOwnershipDropDown.getSelectedItem().getValue().toString();
            retainOwnership.setValue(value);
          }
        });
    DefaultListItem keepOwnershipListItem =
        new DefaultListItem(Messages.getString("keepOwnership"));
    keepOwnershipListItem.setValue("true");
    retainOwnershipDropDown.addItem(keepOwnershipListItem);
    DefaultListItem assignOwnershipListItem =
        new DefaultListItem(Messages.getString("assignOwnership"));
    assignOwnershipListItem.setValue("false");
    retainOwnershipDropDown.addItem(assignOwnershipListItem);

    retainOwnershipDropDown.setVisibleRowCount(1);
    disclosureContent.add(retainOwnershipDropDown);

    spacer = new VerticalPanel();
    spacer.setHeight("4px");
    disclosureContent.add(spacer);

    ChangeListener overwriteFileHandler =
        new ChangeListener() {
          @Override
          public void onChange(Widget sender) {
            String value = overwriteFileDropDown.getSelectedItem().getValue().toString();
            overwriteFile.setValue(value);
          }
        };
    overwriteFileDropDown.addChangeListener(overwriteFileHandler);

    HTML loggingLabel = new HTML(Messages.getString("logging"));
    loggingLabel.setStyleName("gwt-Label");
    disclosureContent.add(loggingLabel);

    final CustomListBox loggingDropDown = new CustomListBox();
    loggingDropDown.addChangeListener(
        new ChangeListener() {
          public void onChange(Widget sender) {
            String value = loggingDropDown.getSelectedItem().getValue().toString();
            logLevel.setValue(value);
          }
        });
    DefaultListItem noneListItem = new DefaultListItem(Messages.getString("none"));
    noneListItem.setValue("ERROR");
    loggingDropDown.addItem(noneListItem);
    DefaultListItem shortListItem = new DefaultListItem(Messages.getString("short"));
    shortListItem.setValue("WARN");
    loggingDropDown.addItem(shortListItem);
    DefaultListItem debugListItem = new DefaultListItem(Messages.getString("verbose"));
    debugListItem.setValue("TRACE");
    loggingDropDown.addItem(debugListItem);
    loggingDropDown.setVisibleRowCount(1);
    disclosureContent.add(loggingDropDown);

    mainPanel.add(disclosureContent);
    disclosurePanel.setContent(mainPanel);
    rootPanel.add(disclosurePanel);

    importDir.setName("importDir");
    importDir.setText(repositoryFile.getPath());
    importDir.setVisible(false);

    rootPanel.add(importDir);

    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

    setFormAction();

    form.add(rootPanel);

    setContent(form);
  }