Пример #1
0
    /**
     * Verifies if the file (which is currently selected) can be replaced with the document to be
     * saved.
     *
     * @return <code>JOptionPane.YES_OPTION</code> if the file is not Read-Only, not opened or can
     *     be replaced, <code>JOptionPane.NO_OPTION</code> if the document can't be saved because
     *     the selected file is Read-Only or the user said no to replace it, or <code>
     *     <code>JOptionPane.NO_OPTION</code></code> if the user does not want to replace the file
     *     and canceled the confirm dialog
     */
    private int canReplaceExistingFile() {
      File file = getSelectedFile();
      String applicationName =
          workbenchContext.getApplicationContext().getApplication().getShortProductName();

      // The file is actually opened
      if (isDocumentOpened(file)) {
        String message =
            resourceRepository()
                .getString("SAVE_AS_DIALOG_ALREADY_OPENED", applicationName, file, StringTools.CR);
        LabelArea label = new LabelArea(message);
        label.setPreferredWidth(800);

        JOptionPane.showMessageDialog(
            workbenchContext.getCurrentWindow(),
            label,
            applicationName,
            JOptionPane.WARNING_MESSAGE);

        return JOptionPane.NO_OPTION;
      }

      // The file exist but is marked as Read-Only, show we can't save it
      if (file.exists() && !file.canWrite()) {
        String message = resourceRepository().getString("SAVE_AS_DIALOG_CANT_SAVE", file);
        LabelArea label = new LabelArea(message);
        label.setPreferredWidth(800);

        JOptionPane.showMessageDialog(
            workbenchContext.getCurrentWindow(),
            label,
            applicationName,
            JOptionPane.WARNING_MESSAGE);

        return JOptionPane.NO_OPTION;
      }

      // The file exist and is not the file to save, ask to replace it
      if (file.exists() && !topLinkSessions().getPath().equals(file)) {
        String message =
            resourceRepository().getString("SAVE_AS_DIALOG_REPLACE", getSelectedFile().getPath());
        LabelArea label = new LabelArea(message);
        label.setPreferredWidth(800);

        return JOptionPane.showConfirmDialog(
            workbenchContext.getCurrentWindow(),
            label,
            applicationName,
            JOptionPane.YES_NO_CANCEL_OPTION);
      }

      return JOptionPane.YES_OPTION;
    }
  private void intializeLayout() {
    GridBagConstraints constraints = new GridBagConstraints();

    JPanel scrollPaneView = new JPanel(new GridBagLayout());

    JScrollPane scrollPane = new JScrollPane(scrollPaneView);
    scrollPane.getVerticalScrollBar().setBlockIncrement(20);
    scrollPane.setBorder(null);
    scrollPane.setViewportBorder(null);
    add(scrollPane, BorderLayout.CENTER);

    JPanel container = new JPanel(new GridBagLayout());
    container.setBorder(
        BorderFactory.createCompoundBorder(
            buildTitledBorder("PREFERENCES.MAPPINGS.CLASS.MAINTAIN_ZERO_ARGUMENT_CONSTRUCTOR"),
            BorderFactory.createEmptyBorder(0, 5, 5, 5)));

    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.PAGE_START;
    constraints.insets = new Insets(5, 5, 5, 5);
    scrollPaneView.add(container, constraints);

    // Message area
    LabelArea label =
        new LabelArea(
            resourceRepository()
                .getString(
                    "PREFERENCES.MAPPINGS.CLASS.MAINTAIN_ZERO_ARGUMENT_CONSTRUCTOR_EXPLANATION"));
    label.setScrollable(true);

    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.PAGE_START;
    constraints.insets = new Insets(0, 5, 0, 5);
    container.add(label, constraints);

    JRadioButton yesRadioButton =
        buildRadioButton(
            "PREFERENCES.MAPPINGS.CLASS.MAINTAIN_ZERO_ARGUMENT_CONSTRUCTOR_YES",
            buildRadioButtonModel(ZeroArgConstructorPreference.YES));
    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.LINE_START;
    constraints.insets = new Insets(5, 5, 0, 5);
    container.add(yesRadioButton, constraints);

    JRadioButton noRadioButton =
        buildRadioButton(
            "PREFERENCES.MAPPINGS.CLASS.MAINTAIN_ZERO_ARGUMENT_CONSTRUCTOR_NO",
            buildRadioButtonModel(ZeroArgConstructorPreference.NO));
    constraints.gridx = 0;
    constraints.gridy = 2;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.LINE_START;
    constraints.insets = new Insets(0, 5, 0, 5);
    container.add(noRadioButton, constraints);

    JRadioButton promptRadioButton =
        buildRadioButton(
            "PREFERENCES.MAPPINGS.CLASS.MAINTAIN_ZERO_ARGUMENT_CONSTRUCTOR_PROMPT",
            buildRadioButtonModel(ZeroArgConstructorPreference.PROMPT));
    constraints.gridx = 0;
    constraints.gridy = 3;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.LINE_START;
    constraints.insets = new Insets(0, 5, 5, 5);
    container.add(promptRadioButton, constraints);

    // last refresh
    JCheckBox lastRefreshCheckBox =
        this.buildCheckBox(
            "PREFERENCES.MAPPINGS.CLASS.PERSIST_LAST_REFRESH_TIMESTAMP",
            this.buildPersistLastRefreshModel());
    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.LINE_START;
    constraints.insets = new Insets(0, 0, 0, 0);
    add(lastRefreshCheckBox, BorderLayout.NORTH);

    addHelpTopicId(this, "preferences.class");
  }