@Override
  public Resource getValue() {
    if (_immutableValue != null) {
      return _immutableValue;
    }

    String path;
    String resourceType = _resourceTypeComboBox.getSelectedItem();
    if ("file".equals(resourceType)) {
      path = _filenameField.getFilename();
    } else {
      path = _otherPathTextField.getText();
    }

    if (StringUtils.isNullOrEmpty(path)) {
      return null;
    }

    final String resourceString = resourceType + "://" + path;
    try {
      Resource resource = getResourceConverter().fromString(Resource.class, resourceString);
      return resource;
    } catch (Exception e) {
      // sometimes an exception can occur because the path is not valid (a
      // URL with a wrong pattern or so).
      if (logger.isDebugEnabled()) {
        logger.debug("Could not create resource from string: " + resourceString, e);
      }
      return null;
    }
  }
Beispiel #2
0
 public DCCheckBox(String text, boolean selected) {
   super(text, selected);
   if (!StringUtils.isNullOrEmpty(text)) {
     setBorder(REGULAR_BORDER);
     setBorderPainted(true);
     addMouseListener(this);
   }
   super.addItemListener(this);
 }
 private static String getDescription(Datastore datastore) {
   if (datastore.getDescription() != null) {
     return datastore.getDescription();
   }
   if (datastore instanceof FileDatastore) {
     return ((FileDatastore) datastore).getFilename();
   } else if (datastore instanceof JdbcDatastore) {
     JdbcDatastore jdbcDatastore = (JdbcDatastore) datastore;
     String jdbcUrl = jdbcDatastore.getJdbcUrl();
     String datasourceJndiUrl = jdbcDatastore.getDatasourceJndiUrl();
     if (StringUtils.isNullOrEmpty(datasourceJndiUrl)) {
       return jdbcUrl;
     }
     return datasourceJndiUrl;
   } else if (datastore instanceof MongoDbDatastore) {
     MongoDbDatastore mongoDbDatastore = (MongoDbDatastore) datastore;
     return mongoDbDatastore.getHostname()
         + ":"
         + mongoDbDatastore.getPort()
         + " - "
         + mongoDbDatastore.getDatabaseName();
   } else if (datastore instanceof CouchDbDatastore) {
     CouchDbDatastore couchDbDatastore = (CouchDbDatastore) datastore;
     return (couchDbDatastore.isSslEnabled() ? "https://" : "http://")
         + couchDbDatastore.getHostname()
         + ":"
         + couchDbDatastore.getPort();
   } else if (datastore instanceof PojoDatastore) {
     return "In-memory collection of records.";
   } else if (datastore instanceof CompositeDatastore) {
     List<? extends Datastore> datastores = ((CompositeDatastore) datastore).getDatastores();
     StringBuilder sb = new StringBuilder();
     for (Datastore ds : datastores) {
       if (sb.length() != 0) {
         sb.append(", ");
       }
       sb.append(ds.getName());
     }
     return sb.toString();
   }
   return "";
 }