Example usage for com.google.gwt.i18n.shared DateTimeFormat getFormat

List of usage examples for com.google.gwt.i18n.shared DateTimeFormat getFormat

Introduction

In this page you can find the example usage for com.google.gwt.i18n.shared DateTimeFormat getFormat.

Prototype

public static DateTimeFormat getFormat(String pattern) 

Source Link

Document

Returns a DateTimeFormat object using the specified pattern.

Usage

From source file:ch.gbrain.gwtstorage.manager.StorageManager.java

License:Apache License

/**
 * Write the items Date/Time store value to html5 storage for later usage in
 * relation to the cache time/*from   w  ww. j a  v a 2s .com*/
 * 
 * @param item The storage time for the given item (ID) is written to the
 *          key-value HTML5 storage.
 * @return false if the read operation failed or nothing is found.
 */
private void writeStorageItemStorageTimeToLocalStorage(StorageItem item) {
    if (item == null || item.getStorageItemTimeKey() == null)
        return;
    try {
        String saveTime = DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_FULL).format(new Date());
        getLocalStorage().setItem(item.getStorageItemTimeKey(), saveTime);
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Exception local writeStorageItem time" + item.getLogId(), ex);
    }
}

From source file:ch.gbrain.gwtstorage.manager.StorageManager.java

License:Apache License

/**
 * Read the items Date/Time store value from html5 storage.
 * //ww  w  .  j  av a2s  .c o m
 * @param item The time when a certain StorageItem was written to the HTML5
 *          key-value storage is read.
 * @return null if the read operation failed or nothing is found.
 */
private Date readStorageItemStorageTimeFromLocalStorage(StorageItem item) {
    if (item == null || item.getStorageItemTimeKey() == null)
        return null;
    try {
        String val = getLocalStorage().getItem(item.getStorageItemTimeKey());
        if (val != null) {
            return DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_FULL).parse(val);
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Exception local readStorageItem time" + item.getLogId(), ex);
    }
    return null;
}

From source file:com.achow101.bctalkaccountpricer.client.Bitcointalk_Account_Pricer.java

License:Open Source License

/**
 * This is the entry point method./*www . j  a  v a  2s . c  o m*/
 */
public void onModuleLoad() {

    // Add Gui stuff      
    final Button sendButton = new Button("Estimate Price");
    final TextBox nameField = new TextBox();
    nameField.setText("User ID/Token");
    final Label errorLabel = new Label();
    final Label uidLabel = new Label();
    final Label usernameLabel = new Label();
    final Label postsLabel = new Label();
    final Label activityLabel = new Label();
    final Label potActivityLabel = new Label();
    final Label postQualityLabel = new Label();
    final Label trustLabel = new Label();
    final Label priceLabel = new Label();
    final Label loadingLabel = new Label();
    final Label tokenLabel = new Label();
    final InlineHTML estimateShareLabel = new InlineHTML();
    final InlineHTML reportTimeStamp = new InlineHTML();
    final RadioButton radioNormal = new RadioButton("merch", "Normal");
    final RadioButton radioMerchant = new RadioButton("merch", "Merchant");

    // We can add style names to widgets
    sendButton.addStyleName("sendButton");
    radioNormal.setValue(true);
    radioMerchant.setValue(false);

    // Add the nameField and sendButton to the RootPanel
    // Use RootPanel.get() to get the entire body element
    RootPanel.get("nameFieldContainer").add(nameField);
    RootPanel.get("sendButtonContainer").add(sendButton);
    RootPanel.get("errorLabelContainer").add(errorLabel);
    RootPanel.get("uidLabelContainer").add(uidLabel);
    RootPanel.get("usernameLabelContainer").add(usernameLabel);
    RootPanel.get("postsLabelContainer").add(postsLabel);
    RootPanel.get("activityLabelContainer").add(activityLabel);
    RootPanel.get("potActivityLabelContainer").add(potActivityLabel);
    RootPanel.get("postQualityLabelContainer").add(postQualityLabel);
    RootPanel.get("trustLabelContainer").add(trustLabel);
    RootPanel.get("priceLabelContainer").add(priceLabel);
    RootPanel.get("loadingLabelContainer").add(loadingLabel);
    RootPanel.get("tokenLabelContainer").add(tokenLabel);
    RootPanel.get("tokenShareLabelContainer").add(estimateShareLabel);
    RootPanel.get("radioNormalContainer").add(radioNormal);
    RootPanel.get("radioMerchantContainer").add(radioMerchant);
    RootPanel.get("reportTimeStamp").add(reportTimeStamp);

    // Create activity breakdown panel
    final VerticalPanel actPanel = new VerticalPanel();
    final FlexTable actTable = new FlexTable();
    actPanel.add(actTable);
    RootPanel.get("activityBreakdown").add(actPanel);

    // Create posts breakdown panel
    final VerticalPanel postsPanel = new VerticalPanel();
    final FlexTable postsTable = new FlexTable();
    postsPanel.add(postsTable);
    RootPanel.get("postsBreakdown").add(postsPanel);

    // Create addresses breakdown panel
    final VerticalPanel addrPanel = new VerticalPanel();
    final FlexTable addrTable = new FlexTable();
    postsPanel.add(addrTable);
    RootPanel.get("addrBreakdown").add(addrTable);

    // Focus the cursor on the name field when the app loads
    nameField.setFocus(true);
    nameField.selectAll();

    // Create a handler for the sendButton and nameField
    class MyHandler implements ClickHandler, KeyUpHandler {
        /**
         * Fired when the user clicks on the sendButton.
         */
        public void onClick(ClickEvent event) {

            // Add request to queue
            addToQueue();
        }

        /**
         * Fired when the user types in the nameField.
         */
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                addToQueue();
            }
        }

        // Adds the request to server queue
        private void addToQueue() {

            // Clear previous output
            uidLabel.setText("");
            usernameLabel.setText("");
            postsLabel.setText("");
            activityLabel.setText("");
            potActivityLabel.setText("");
            postQualityLabel.setText("");
            trustLabel.setText("");
            priceLabel.setText("");
            sendButton.setEnabled(false);
            errorLabel.setText("");
            loadingLabel.setText("");
            tokenLabel.setText("");
            estimateShareLabel.setText("");
            reportTimeStamp.setText("");
            actTable.removeAllRows();
            postsTable.removeAllRows();
            addrTable.removeAllRows();

            // Create and add request
            request = new QueueRequest();
            request.setMerchant(radioMerchant.getValue());
            if (nameField.getText().matches("^[0-9]+$"))
                request.setUid(Integer.parseInt(escapeHtml(nameField.getText())));
            else {
                request.setToken(escapeHtml(nameField.getText()));
                request.setOldReq();
            }

            final String urlPath = com.google.gwt.user.client.Window.Location.getPath();
            final String host = com.google.gwt.user.client.Window.Location.getHost();
            final String protocol = com.google.gwt.user.client.Window.Location.getProtocol();
            final String url = protocol + "//" + host + urlPath + "?token=";

            // Request check loop
            Timer requestTimer = new Timer() {
                public void run() {
                    // send request to server
                    pricingService.queueServer(request, new AsyncCallback<QueueRequest>() {
                        @Override
                        public void onFailure(Throwable caught) {
                            errorLabel.setText("Request Queuing failed. Please try again.");
                            sendButton.setEnabled(true);
                            pricingService.removeRequest(request, null);
                            cancel();
                        }

                        @Override
                        public void onSuccess(QueueRequest result) {

                            if (result.getQueuePos() == -3) {
                                loadingLabel.setText(
                                        "Please wait for your previous request to finish and try again");
                                sendButton.setEnabled(true);
                                cancel();
                            }

                            else if (result.getQueuePos() == -2) {
                                loadingLabel.setText("Please wait 2 minutes before requesting again.");
                                sendButton.setEnabled(true);
                                cancel();
                            }

                            else if (result.getQueuePos() == -4) {
                                loadingLabel.setText("Invalid token");
                                sendButton.setEnabled(true);
                                cancel();
                            }

                            else {
                                tokenLabel.setText("Your token is " + result.getToken());
                                estimateShareLabel.setHTML("Share this estimate: <a href=\"" + url
                                        + result.getToken() + "\">" + url + result.getToken() + "</a>");
                                if (!result.isProcessing() && !result.isDone()) {
                                    loadingLabel.setText("Please wait. You are number " + result.getQueuePos()
                                            + " in the queue.");
                                }
                                if (result.isProcessing()) {
                                    loadingLabel.setText("Request is processing. Please wait.");
                                }
                                if (result.isDone()) {
                                    // Clear other messages
                                    errorLabel.setText("");
                                    loadingLabel.setText("");

                                    // Output results
                                    uidLabel.setText(result.getResult()[0]);
                                    usernameLabel.setText(result.getResult()[1]);
                                    postsLabel.setText(result.getResult()[2]);
                                    activityLabel.setText(result.getResult()[3]);
                                    potActivityLabel.setText(result.getResult()[4]);
                                    postQualityLabel.setText(result.getResult()[5]);
                                    trustLabel.setText(result.getResult()[6]);
                                    priceLabel.setText(result.getResult()[7]);
                                    int indexOfLastAct = 0;
                                    int startAddrIndex = 0;
                                    for (int i = 8; i < result.getResult().length; i++) {
                                        if (result.getResult()[i].equals("<b>Post Sections Breakdown</b>")) {
                                            indexOfLastAct = i;
                                            break;
                                        }
                                        actTable.setHTML(i - 8, 0, result.getResult()[i]);
                                    }
                                    for (int i = indexOfLastAct; i < result.getResult().length; i++) {
                                        if (result.getResult()[i]
                                                .contains("<b>Addresses posted in non-quoted text</b>")) {
                                            startAddrIndex = i;
                                            break;
                                        }
                                        postsTable.setHTML(i - indexOfLastAct, 0, result.getResult()[i]);
                                    }
                                    if (!result.isMerchant()) {
                                        for (int i = startAddrIndex; i < result.getResult().length; i++) {
                                            addrTable.setHTML(i - startAddrIndex, 0, result.getResult()[i]);
                                        }
                                    }

                                    // Set the right radio
                                    radioMerchant.setValue(result.isMerchant());
                                    radioNormal.setValue(!result.isMerchant());

                                    // Report the time stamp
                                    DateTimeFormat fmt = DateTimeFormat.getFormat("MMMM dd, yyyy, hh:mm:ss a");
                                    Date completedDate = new Date(1000L * result.getCompletedTime());
                                    Date expireDate = new Date(
                                            1000L * (result.getCompletedTime() + result.getExpirationTime()));
                                    reportTimeStamp
                                            .setHTML("<i>Report generated at " + fmt.format(completedDate)
                                                    + " and expires at " + fmt.format(expireDate) + "</i>");

                                    // Kill the timer after everything is done
                                    cancel();
                                }
                                request = result;
                                request.setPoll(true);
                                sendButton.setEnabled(true);
                            }
                        }
                    });
                }
            };
            requestTimer.scheduleRepeating(2000);

        }
    }

    // Add a handler to send the name to the server
    MyHandler handler = new MyHandler();
    sendButton.addClickHandler(handler);
    nameField.addKeyUpHandler(handler);

    // Check the URL for URL parameters
    String urlTokenParam = com.google.gwt.user.client.Window.Location.getParameter("token");
    if (!urlTokenParam.isEmpty()) {
        nameField.setText(urlTokenParam);
        handler.addToQueue();
    }
}

From source file:com.dianaui.universal.core.client.text.DateTimeFormatParser.java

License:Apache License

/**
 * Create an instance using {@link DateTimeFormat.PredefinedFormat#DATE_SHORT}.
 *///w w w  . j  a  v a 2s  . co m
public DateTimeFormatParser() {
    this(DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_SHORT));
}

From source file:com.dianaui.universal.core.client.ui.DateTimeBox.java

License:Apache License

public DateTimeBox(final String format) {
    this(DateTimeFormat.getFormat(format));
}

From source file:com.dianaui.universal.core.client.ui.TimeBox.java

License:Apache License

public TimeBox(String format) {
    this(DateTimeFormat.getFormat(format));
}

From source file:com.ephesoft.gxt.core.client.ui.service.columnConfig.impl.FolderManagerColumnConfigService.java

License:Open Source License

public FolderManagerColumnConfigService() {
    columnConfigList = new ArrayList<ColumnConfig<FolderManagerDTO, ?>>();
    editorsMap = new HashMap<ColumnConfig, IsField>();
    ColumnConfig<FolderManagerDTO, Boolean> modelSelector = new ColumnConfig<FolderManagerDTO, Boolean>(
            FolderManagerProperties.property.selected());

    CheckBoxCell modelSelectionCell = new CheckBoxCell();
    modelSelector.setCell(modelSelectionCell);

    modelSelector.setHeader(LocaleDictionary.getConstantValue(CoreCommonConstants.FM_SELECT_COLUMN_HEADER));
    modelSelector.setWidth(30);/*  w  w w. j  a va  2  s. c  o  m*/
    modelSelector.setFixed(true);
    modelSelector.setSortable(false);
    modelSelector.setHideable(false);

    ColumnConfig<FolderManagerDTO, String> fileName = new ColumnConfig<FolderManagerDTO, String>(
            FolderManagerProperties.property.fileName());
    fileName.setHeader(LocaleDictionary.getConstantValue(CoreCommonConstants.FM_NAME_COLUMN_HEADER));
    fileName.setHideable(false);

    ColumnConfig<FolderManagerDTO, Float> fileSize = new ColumnConfig<FolderManagerDTO, Float>(
            FolderManagerProperties.property.size());
    fileSize.setHeader(LocaleDictionary.getConstantValue(CoreCommonConstants.FM_SIZE_COLUMN_HEADER));

    ColumnConfig<FolderManagerDTO, FileType> fileType = new ColumnConfig<FolderManagerDTO, FileType>(
            FolderManagerProperties.property.kind());

    fileType.setHeader(LocaleDictionary.getConstantValue(CoreCommonConstants.FM_FILE_TYPE_COLUMN_HEADER));
    ColumnConfig<FolderManagerDTO, Date> modifiedAt = new ColumnConfig<FolderManagerDTO, Date>(
            FolderManagerProperties.property.modifiedAt());
    modifiedAt.setHeader(LocaleDictionary.getConstantValue(CoreCommonConstants.FM_MODIFIED_COLUMN_HEADER));
    modifiedAt.setCell(new DateCell(DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_MEDIUM)));

    @SuppressWarnings("unchecked")
    ColumnConfig<FolderManagerDTO, ImageResource> fileIcon = new ColumnConfig<FolderManagerDTO, ImageResource>(
            new ValueProvider() {

                @Override
                public ImageResource getValue(Object object) {
                    ImageResource image = null;
                    FolderManagerDTO dto = (FolderManagerDTO) object;
                    if (dto.getKind() == FileType.DIR) {
                        image = imageResources.icon_folder();
                    } else if (dto.getKind() == FileType.DOC) {
                        image = imageResources.icon_doc();
                    } else if (dto.getKind() == FileType.MM) {
                        image = imageResources.icon_mm();
                    } else if (dto.getKind() == FileType.IMG) {
                        image = imageResources.icon_img();
                    } else if (dto.getKind() == FileType.OTHER) {
                        image = imageResources.icon_other();
                    }
                    return image;
                }

                @Override
                public void setValue(Object object, Object value) {

                }

                @Override
                public String getPath() {
                    return null;
                }

            });
    fileIcon.setSortable(false);
    fileIcon.setHeader(LocaleDictionary.getConstantValue(CoreCommonConstants.FM_ICON_COLUMN_HEADER));
    ImageResourceCell imageCell = new ImageResourceCell() {

        @Override
        public void render(com.google.gwt.cell.client.Cell.Context context, ImageResource value,
                SafeHtmlBuilder sb) {
            super.render(context, value, sb);

        }
    };
    fileIcon.setCell(imageCell);
    columnConfigList.add(modelSelector);
    columnConfigList.add(fileIcon);
    columnConfigList.add(fileName);
    columnConfigList.add(modifiedAt);
    columnConfigList.add(fileType);
    columnConfigList.add(fileSize);
    editorsMap.put(fileName, new TextField());
}

From source file:com.google.collide.client.filehistory.TimelineNode.java

License:Open Source License

private String getFormattedDate(PredefinedFormat format) {
    String timestamp = revision.getTimestamp();
    Date date = new Date(Long.valueOf(revision.getTimestamp()));
    return DateTimeFormat.getFormat(format).format(date);
}

From source file:com.gwtplatform.dispatch.rest.client.AbstractRestAction.java

License:Apache License

private String formatDate(Date date, String pattern) {
    return DateTimeFormat.getFormat(pattern).format(date);
}

From source file:com.gwtplatform.dispatch.rest.client.core.parameters.ClientHttpParameter.java

License:Apache License

public ClientHttpParameter(Type type, String name, Object object, String dateFormat) {
    this.type = type;
    this.name = name;
    this.object = object;
    this.dateFormatter = dateFormat != null ? DateTimeFormat.getFormat(dateFormat) : null;
}