Esempio n. 1
0
 @Action
 public void portInputDidEndEditing(final NSNotification sender) {
   try {
     host.setPort(portField.intValue());
   } catch (NumberFormatException e) {
     host.setPort(-1);
   }
   this.itemChanged();
   this.init();
   this.reachable();
 }
Esempio n. 2
0
 public void pkSelectionPanelDidEnd_returnCode_contextInfo(
     NSOpenPanel sheet, int returncode, ID contextInfo) {
   log.debug("pkSelectionPanelDidEnd");
   if (returncode == NSPanel.NSOKButton) {
     NSArray selected = sheet.filenames();
     NSEnumerator enumerator = selected.objectEnumerator();
     NSObject next;
     while (((next = enumerator.nextObject()) != null)) {
       host.getCredentials().setIdentity(LocalFactory.createLocal(next.toString()));
     }
   }
   if (returncode == NSPanel.NSCancelButton) {
     host.getCredentials().setIdentity(null);
   }
   this.init();
   this.itemChanged();
 }
Esempio n. 3
0
 @Override
 public void collectionItemRemoved(Host item) {
   if (item.equals(host)) {
     final NSWindow window = window();
     if (null != window) {
       window.close();
     }
   }
 }
Esempio n. 4
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();
 }
Esempio n. 5
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);
    }
  }
Esempio n. 6
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());
   }
 }
Esempio n. 7
0
 @Action
 public void commentInputDidChange(final NSNotification sender) {
   host.setComment(commentField.textStorage().string());
   this.itemChanged();
 }
Esempio n. 8
0
 @Action
 public void webURLInputDidChange(final NSNotification sender) {
   host.setWebURL(webURLField.stringValue());
   this.updateFavicon();
   this.itemChanged();
 }
Esempio n. 9
0
 @Action
 public void usernameInputDidChange(final NSNotification sender) {
   host.getCredentials().setUsername(usernameField.stringValue());
   this.itemChanged();
   this.init();
 }
Esempio n. 10
0
 @Action
 public void nicknameInputDidChange(final NSNotification sender) {
   host.setNickname(nicknameField.stringValue());
   this.itemChanged();
   this.init();
 }
Esempio n. 11
0
 @Action
 public void pathInputDidChange(final NSNotification sender) {
   host.setDefaultPath(pathField.stringValue());
   this.itemChanged();
   this.init();
 }
Esempio n. 12
0
 @Action
 public void hostFieldDidChange(final NSNotification sender) {
   String input = hostField.stringValue();
   if (ProtocolFactory.isURL(input)) {
     final Host parsed = Host.parse(input);
     host.setProtocol(parsed.getProtocol());
     host.setPort(parsed.getPort());
     host.setHostname(parsed.getHostname());
     host.setDefaultPath(parsed.getDefaultPath());
   } else {
     host.setHostname(input);
   }
   this.itemChanged();
   this.init();
   this.reachable();
 }
Esempio n. 13
0
 /**
  * Parses URL in the format ftp://username:pass@hostname:portnumber/path/to/file
  *
  * @param url URL
  * @return Bookmark
  */
 public static Host parse(final String url) {
   final String input = url.trim();
   int begin = 0;
   int cut;
   Protocol protocol = null;
   if (input.indexOf("://", begin) != -1) {
     cut = input.indexOf("://", begin);
     protocol = ProtocolFactory.forScheme(input.substring(begin, cut));
     if (null != protocol) {
       begin += cut - begin + 3;
     }
   }
   if (null == protocol) {
     protocol =
         ProtocolFactory.forName(
             Preferences.instance().getProperty("connection.protocol.default"));
   }
   String username;
   String password = null;
   if (protocol.isAnonymousConfigurable()) {
     username = Preferences.instance().getProperty("connection.login.anon.name");
   } else {
     username = Preferences.instance().getProperty("connection.login.name");
   }
   if (input.lastIndexOf('@') != -1) {
     if (input.indexOf(':', begin) != -1 && input.lastIndexOf('@') > input.indexOf(':', begin)) {
       // ':' is not for the port number but username:pass seperator
       cut = input.indexOf(':', begin);
       username = input.substring(begin, cut);
       begin += username.length() + 1;
       cut = input.lastIndexOf('@');
       password = input.substring(begin, cut);
       begin += password.length() + 1;
     } else {
       // no password given
       cut = input.lastIndexOf('@');
       username = input.substring(begin, cut);
       begin += username.length() + 1;
     }
   }
   String hostname = Preferences.instance().getProperty("connection.hostname.default");
   if (StringUtils.isNotBlank(input)) {
     hostname = input.substring(begin, input.length());
   }
   String path = null;
   int port = protocol.getDefaultPort();
   if (input.indexOf(':', begin) != -1) {
     cut = input.indexOf(':', begin);
     hostname = input.substring(begin, cut);
     begin += hostname.length() + 1;
     try {
       String portString;
       if (input.indexOf(Path.DELIMITER, begin) != -1) {
         portString = input.substring(begin, input.indexOf(Path.DELIMITER, begin));
         begin += portString.length();
         try {
           path = URLDecoder.decode(input.substring(begin, input.length()), "UTF-8");
         } catch (UnsupportedEncodingException e) {
           log.error(e.getMessage(), e);
         }
       } else {
         portString = input.substring(begin, input.length());
       }
       port = Integer.parseInt(portString);
     } catch (NumberFormatException e) {
       log.warn("Invalid port number given");
     }
   } else if (input.indexOf(Path.DELIMITER, begin) != -1) {
     cut = input.indexOf(Path.DELIMITER, begin);
     hostname = input.substring(begin, cut);
     begin += hostname.length();
     try {
       path = URLDecoder.decode(input.substring(begin, input.length()), "UTF-8");
     } catch (UnsupportedEncodingException e) {
       log.error(e.getMessage(), e);
     }
   }
   final Host h = new Host(protocol, hostname, port, path);
   h.setCredentials(username, password);
   return h;
 }