@Override
        public final SafeHtml getValue(Snapshot snapshot) {
          // Get raw description string (ignore < and > characters).
          // Customize description style as needed.
          SafeHtml description = SafeHtmlUtils.fromString(snapshot.getDescription());
          String descriptionStr = description.asString();

          if (snapshot.getStatus() == SnapshotStatus.IN_PREVIEW) {
            List<String> previewedItems =
                new ArrayList<>(Arrays.asList(constants.vmConfiguration()));
            previewedItems.addAll(Linq.getDiskAliases(snapshot.getDiskImages()));
            descriptionStr =
                messages.snapshotPreviewing(
                    descriptionStr, StringUtils.join(previewedItems, ", ")); // $NON-NLS-1$
            description =
                templates.snapshotDescription("color:orange", descriptionStr); // $NON-NLS-1$
          } else if (snapshot.getType() == SnapshotType.STATELESS) {
            descriptionStr =
                descriptionStr
                    + " ("
                    + constants.readonlyLabel()
                    + ")"; //$NON-NLS-1$ //$NON-NLS-2$
            description =
                templates.snapshotDescription("font-style:italic", descriptionStr); // $NON-NLS-1$
          } else if (snapshot.getType() == SnapshotType.PREVIEW) {
            descriptionStr = constants.snapshotDescriptionActiveVmBeforePreview();
            description =
                templates.snapshotDescription("color:gray", descriptionStr); // $NON-NLS-1$
          } else if (snapshot.getType() == SnapshotType.ACTIVE) {
            descriptionStr = constants.snapshotDescriptionActiveVm();
            description =
                templates.snapshotDescription("color:gray", descriptionStr); // $NON-NLS-1$
          } else if (snapshot.getType() == SnapshotType.REGULAR
              && !snapshot.getDiskImages().isEmpty()) {
            descriptionStr =
                messages.snapshotPreviewing(
                    descriptionStr,
                    StringUtils.join(
                        Linq.getDiskAliases(snapshot.getDiskImages()), ", ")); // $NON-NLS-1$
            description =
                templates.snapshotDescription("color:gold", descriptionStr); // $NON-NLS-1$
          }

          return description;
        }
  @Override
  public void edit(final SnapshotModel model) {
    driver.edit(model);

    if (model.isShowMemorySnapshotWarning() && !model.isShowPartialSnapshotWarning()) {
      Style dialogStyle = getParent().getParent().getParent().getElement().getStyle();
      dialogStyle.setWidth(450, Style.Unit.PX);
      dialogStyle.setHeight(200, Style.Unit.PX);
    }

    partialSnapshotWarningPanel.setVisible(model.isShowPartialSnapshotWarning());
    memoryWarningPanel.setVisible(model.isShowMemorySnapshotWarning());
    horizontalSeparator.setVisible(
        model.isShowPartialSnapshotWarning() && model.isShowMemorySnapshotWarning());

    vmDisksLabel.setText(
        messages.vmDisksLabel(
            model.getVmDisks().size(),
            StringUtils.join(Linq.getDiskAliases(model.getVmDisks()), ", "))); // $NON-NLS-1$
    snapshotDisksLabel.setText(
        messages.snapshotDisksLabel(
            model.getDisks().size(),
            StringUtils.join(Linq.getDiskAliases(model.getDisks()), ", "))); // $NON-NLS-1$
  }
 @Override
 public void render(Context context, SafeHtmlBuilder sb) {
   if (!isEnabled()) {
     if (getValue()) {
       sb.append(INPUT_CHECKED_DISABLED);
     } else {
       sb.append(INPUT_UNCHECKED_DISABLED);
     }
     if (getLabel() != null && !StringUtils.isEmpty(getLabel())) {
       sb.append(SafeHtmlUtils.fromString(getLabel()));
     }
   } else {
     super.render(context, sb);
   }
 }
Esempio n. 4
0
 /**
  * Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
  *
  * <p>When encoding the line length and line separator are given in the constructor, and the
  * encoding table is STANDARD_ENCODE_TABLE.
  *
  * <p>Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4
  * in the encoded data.
  *
  * <p>When decoding all variants are supported.
  *
  * @param lineLength Each line of encoded data will be at most of the given length (rounded down
  *     to nearest multiple of 4). If lineLength <= 0, then the output will not be divided into
  *     lines (chunks). Ignored when decoding.
  * @param lineSeparator Each line of encoded data will end with this sequence of bytes.
  * @param urlSafe Instead of emitting '+' and '/' we emit '-' and '_' respectively. urlSafe is
  *     only applied to encode operations. Decoding seamlessly handles both modes.
  * @throws IllegalArgumentException The provided lineSeparator included some base64 characters.
  *     That's not going to work!
  * @since 1.4
  */
 public Base64(int lineLength, byte[] lineSeparator, boolean urlSafe) {
   if (lineSeparator == null) {
     lineLength = 0; // disable chunk-separating
     lineSeparator = CHUNK_SEPARATOR; // this just gets ignored
   }
   this.lineLength = lineLength > 0 ? (lineLength / 4) * 4 : 0;
   this.lineSeparator = new byte[lineSeparator.length];
   System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length);
   if (lineLength > 0) {
     this.encodeSize = 4 + lineSeparator.length;
   } else {
     this.encodeSize = 4;
   }
   this.decodeSize = this.encodeSize - 1;
   if (containsBase64Byte(lineSeparator)) {
     String sep = StringUtils.newStringUtf8(lineSeparator);
     throw new IllegalArgumentException(
         "lineSeperator must not contain base64 characters: [" + sep + "]");
   }
   this.encodeTable = urlSafe ? URL_SAFE_ENCODE_TABLE : STANDARD_ENCODE_TABLE;
 }
 /**
  * Checks if a String is not empty ("") and not null.
  *
  * <pre>
  * StringUtils.isNotEmpty(null)      = false
  * StringUtils.isNotEmpty("")        = false
  * StringUtils.isNotEmpty(" ")       = true
  * StringUtils.isNotEmpty("bob")     = true
  * StringUtils.isNotEmpty("  bob  ") = true
  * </pre>
  *
  * @param str the String to check, may be null
  * @return <code>true</code> if the String is not empty and not null
  */
 public static boolean isNotEmpty(String str) {
   return !StringUtils.isEmpty(str);
 }
Esempio n. 6
0
 /**
  * Encodes a byte[] containing binary data, into a String containing characters in the Base64
  * alphabet.
  *
  * @param pArray a byte array containing binary data
  * @return A String containing only Base64 character data
  * @since 1.4
  */
 public String encodeToString(byte[] pArray) {
   return StringUtils.newStringUtf8(encode(pArray));
 }
Esempio n. 7
0
 /**
  * Decodes a String containing containing characters in the Base64 alphabet.
  *
  * @param pArray A String containing Base64 character data
  * @return a byte array containing binary data
  * @since 1.4
  */
 public byte[] decode(String pArray) {
   return decode(StringUtils.getBytesUtf8(pArray));
 }
Esempio n. 8
0
 /**
  * Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the
  * output. The url-safe variation emits - and _ instead of + and / characters.
  *
  * @param binaryData binary data to encode
  * @return String containing Base64 characters
  * @since 1.4
  */
 public static String encodeBase64URLSafeString(byte[] binaryData) {
   return StringUtils.newStringUtf8(encodeBase64(binaryData, false, true));
 }