Exemplo n.º 1
0
 @Action
 public void anonymousCheckboxClicked(final NSButton sender) {
   if (sender.state() == NSCell.NSOnState) {
     host.getCredentials()
         .setUsername(Preferences.instance().getProperty("connection.login.anon.name"));
   }
   if (sender.state() == NSCell.NSOffState) {
     if (Preferences.instance()
         .getProperty("connection.login.name")
         .equals(Preferences.instance().getProperty("connection.login.anon.name"))) {
       host.getCredentials().setUsername(StringUtils.EMPTY);
     } else {
       host.getCredentials()
           .setUsername(Preferences.instance().getProperty("connection.login.name"));
     }
   }
   this.itemChanged();
   this.init();
 }
Exemplo n.º 2
0
  private void reachable() {
    if (StringUtils.isNotBlank(host.getHostname())) {
      this.background(
          new AbstractBackgroundAction<Void>() {
            boolean reachable = false;

            @Override
            public void run() {
              reachable = ReachabilityFactory.get().isReachable(host);
            }

            @Override
            public void cleanup() {
              alertIcon.setEnabled(!reachable);
              alertIcon.setImage(reachable ? null : IconCache.iconNamed("alert.tiff"));
            }
          });
    } else {
      alertIcon.setImage(IconCache.iconNamed("alert.tiff"));
      alertIcon.setEnabled(false);
    }
  }
Exemplo n.º 3
0
 @Action
 public void pkCheckboxSelectionChanged(final NSButton sender) {
   log.debug("pkCheckboxSelectionChanged");
   if (sender.state() == NSCell.NSOnState) {
     publicKeyPanel = NSOpenPanel.openPanel();
     publicKeyPanel.setCanChooseDirectories(false);
     publicKeyPanel.setCanChooseFiles(true);
     publicKeyPanel.setAllowsMultipleSelection(false);
     publicKeyPanel.setMessage(
         Locale.localizedString("Select the private key in PEM or PuTTY format", "Credentials"));
     publicKeyPanel.setPrompt(Locale.localizedString("Choose"));
     publicKeyPanel.beginSheetForDirectory(
         LocalFactory.createLocal("~/.ssh").getAbsolute(),
         null,
         this.window(),
         this.id(),
         Foundation.selector("pkSelectionPanelDidEnd:returnCode:contextInfo:"),
         null);
   } else {
     this.pkSelectionPanelDidEnd_returnCode_contextInfo(
         publicKeyPanel, NSPanel.NSCancelButton, null);
   }
 }
Exemplo n.º 4
0
 private void init() {
   window.setTitle(host.getNickname());
   this.updateField(hostField, host.getHostname());
   hostField.setEnabled(host.getProtocol().isHostnameConfigurable());
   hostField.cell().setPlaceholderString(host.getProtocol().getDefaultHostname());
   this.updateField(nicknameField, host.getNickname());
   final String url;
   if (StringUtils.isNotBlank(host.getDefaultPath())) {
     url = host.toURL() + Path.normalize(host.getDefaultPath());
   } else {
     url = host.toURL();
   }
   urlField.setAttributedStringValue(HyperlinkAttributedStringFactory.create(url));
   this.updateField(portField, String.valueOf(host.getPort()));
   portField.setEnabled(host.getProtocol().isPortConfigurable());
   this.updateField(pathField, host.getDefaultPath());
   this.updateField(usernameField, host.getCredentials().getUsername());
   usernameField.cell().setPlaceholderString(host.getProtocol().getUsernamePlaceholder());
   usernameField.setEnabled(!host.getCredentials().isAnonymousLogin());
   anonymousCheckbox.setEnabled(host.getProtocol().isAnonymousConfigurable());
   anonymousCheckbox.setState(
       host.getCredentials().isAnonymousLogin() ? NSCell.NSOnState : NSCell.NSOffState);
   protocolPopup.selectItemAtIndex(
       protocolPopup.indexOfItemWithRepresentedObject(
           String.valueOf(host.getProtocol().hashCode())));
   if (null == host.getMaxConnections()) {
     transferPopup.selectItemWithTitle(DEFAULT);
   } else {
     transferPopup.selectItemWithTitle(
         host.getMaxConnections() == 1 ? TRANSFER_BROWSERCONNECTION : TRANSFER_NEWCONNECTION);
   }
   encodingPopup.setEnabled(host.getProtocol().isEncodingConfigurable());
   connectmodePopup.setEnabled(host.getProtocol().isConnectModeConfigurable());
   if (host.getProtocol().isConnectModeConfigurable()) {
     if (null == host.getFTPConnectMode()) {
       connectmodePopup.selectItemWithTitle(DEFAULT);
     } else if (host.getFTPConnectMode().equals(FTPConnectMode.PASV)) {
       connectmodePopup.selectItemWithTitle(CONNECTMODE_PASSIVE);
     } else if (host.getFTPConnectMode().equals(FTPConnectMode.PORT)) {
       connectmodePopup.selectItemWithTitle(CONNECTMODE_ACTIVE);
     }
   }
   pkCheckbox.setEnabled(host.getProtocol().equals(Protocol.SFTP));
   if (host.getCredentials().isPublicKeyAuthentication()) {
     pkCheckbox.setState(NSCell.NSOnState);
     this.updateField(pkLabel, host.getCredentials().getIdentity().getAbbreviatedPath());
     pkLabel.setTextColor(NSColor.textColor());
   } else {
     pkCheckbox.setState(NSCell.NSOffState);
     pkLabel.setStringValue(Locale.localizedString("No private key selected"));
     pkLabel.setTextColor(NSColor.disabledControlTextColor());
   }
   webURLField.setEnabled(host.getProtocol().isWebUrlConfigurable());
   final String webURL = host.getWebURL();
   webUrlImage.setToolTip(webURL);
   this.updateField(webURLField, host.getDefaultWebURL().equals(webURL) ? null : webURL);
   this.updateField(commentField, host.getComment());
   this.timezonePopup.setEnabled(!host.getProtocol().isUTCTimezone());
   if (null == host.getTimezone()) {
     if (host.getProtocol().isUTCTimezone()) {
       this.timezonePopup.setTitle(UTC.getID());
     } else {
       if (Preferences.instance().getBoolean("ftp.timezone.auto")) {
         this.timezonePopup.setTitle(AUTO);
       } else {
         this.timezonePopup.setTitle(
             TimeZone.getTimeZone(Preferences.instance().getProperty("ftp.timezone.default"))
                 .getID());
       }
     }
   } else {
     this.timezonePopup.setTitle(host.getTimezone().getID());
   }
 }