Example usage for javax.swing.text DateFormatter DateFormatter

List of usage examples for javax.swing.text DateFormatter DateFormatter

Introduction

In this page you can find the example usage for javax.swing.text DateFormatter DateFormatter.

Prototype

public DateFormatter(DateFormat format) 

Source Link

Document

Returns a DateFormatter configured with the specified Format instance.

Usage

From source file:com.mirth.connect.server.migration.Migrate3_3_0.java

private void migrateDataPrunerConfiguration() {
    boolean enabled = true;
    String time = "";
    String interval = "";
    String dayOfWeek = "";
    String dayOfMonth = "1";

    ResultSet results = null;/*ww w  .  j  a  v a  2  s.c o  m*/
    PreparedStatement statement = null;
    Connection connection = null;

    try {
        connection = getConnection();
        try {
            statement = connection
                    .prepareStatement("SELECT NAME, VALUE FROM CONFIGURATION WHERE CATEGORY = 'Data Pruner'");

            results = statement.executeQuery();
            while (results.next()) {
                String name = results.getString(1);
                String value = results.getString(2);

                if (name.equals("interval")) {
                    interval = value;
                } else if (name.equals("time")) {
                    time = value;
                } else if (name.equals("dayOfWeek")) {
                    dayOfWeek = value;
                } else if (name.equals("dayOfMonth")) {
                    dayOfMonth = value;
                }
            }
        } catch (SQLException e) {
            logger.error("Failed to read Data Pruner configuration properties.", e);
        } finally {
            DbUtils.closeQuietly(statement);
            DbUtils.closeQuietly(results);
        }

        enabled = !interval.equals("disabled");
        String pollingType = "INTERVAL";
        String pollingHour = "12";
        String pollingMinute = "0";
        boolean weekly = !StringUtils.equals(interval, "monthly");
        boolean[] activeDays = new boolean[] { true, true, true, true, true, true, true, true };

        if (enabled && !StringUtils.equals(interval, "hourly")) {
            SimpleDateFormat timeDateFormat = new SimpleDateFormat("hh:mm aa");
            DateFormatter timeFormatter = new DateFormatter(timeDateFormat);
            Date timeDate = null;

            try {
                timeDate = (Date) timeFormatter.stringToValue(time);
                Calendar timeCalendar = Calendar.getInstance();
                timeCalendar.setTime(timeDate);

                pollingType = "TIME";
                pollingHour = String.valueOf(timeCalendar.get(Calendar.HOUR_OF_DAY));
                pollingMinute = String.valueOf(timeCalendar.get(Calendar.MINUTE));

                if (StringUtils.equals(interval, "weekly")) {
                    SimpleDateFormat dayDateFormat = new SimpleDateFormat("EEEEEEEE");
                    DateFormatter dayFormatter = new DateFormatter(dayDateFormat);

                    Date dayDate = (Date) dayFormatter.stringToValue(dayOfWeek);
                    Calendar dayCalendar = Calendar.getInstance();
                    dayCalendar.setTime(dayDate);

                    activeDays = new boolean[] { false, false, false, false, false, false, false, false };
                    activeDays[dayCalendar.get(Calendar.DAY_OF_WEEK)] = true;
                }
            } catch (Exception e) {
                logger.error("Failed to get Data Pruner time properties", e);
            }
        }

        DonkeyElement pollingProperties = new DonkeyElement(
                "<com.mirth.connect.donkey.model.channel.PollConnectorProperties/>");
        pollingProperties.setAttribute("version", "3.3.0");
        pollingProperties.addChildElementIfNotExists("pollingType", pollingType);
        pollingProperties.addChildElementIfNotExists("pollOnStart", "false");
        pollingProperties.addChildElementIfNotExists("pollingFrequency", "3600000");
        pollingProperties.addChildElementIfNotExists("pollingHour", pollingHour);
        pollingProperties.addChildElementIfNotExists("pollingMinute", pollingMinute);
        pollingProperties.addChildElementIfNotExists("cronJobs");

        DonkeyElement advancedProperties = pollingProperties
                .addChildElementIfNotExists("pollConnectorPropertiesAdvanced");
        advancedProperties.addChildElementIfNotExists("weekly", weekly ? "true" : "false");

        DonkeyElement inactiveDays = advancedProperties.addChildElementIfNotExists("inactiveDays");
        if (inactiveDays != null) {
            for (int index = 0; index < 8; ++index) {
                inactiveDays.addChildElement("boolean", activeDays[index] ? "false" : "true");
            }
        }

        advancedProperties.addChildElementIfNotExists("dayOfMonth", dayOfMonth);
        advancedProperties.addChildElementIfNotExists("allDay", "true");
        advancedProperties.addChildElementIfNotExists("startingHour", "8");
        advancedProperties.addChildElementIfNotExists("startingMinute", "0");
        advancedProperties.addChildElementIfNotExists("endingHour", "17");
        advancedProperties.addChildElementIfNotExists("endingMinute", "0");

        PreparedStatement inputStatement = null;
        try {
            inputStatement = connection
                    .prepareStatement("INSERT INTO CONFIGURATION (CATEGORY, NAME, VALUE) VALUES (?, ?, ?)");

            inputStatement.setString(1, "Data Pruner");
            inputStatement.setString(2, "pollingProperties");
            inputStatement.setString(3, pollingProperties.toXml());
            inputStatement.executeUpdate();
        } catch (Exception e) {
            logger.error("Failed to insert Data Pruner configuration pollingProperties.", e);
        } finally {
            DbUtils.closeQuietly(inputStatement);
        }

        PreparedStatement updateStatement = null;
        try {
            updateStatement = connection.prepareStatement(
                    "UPDATE CONFIGURATION SET NAME = ?, VALUE = ? WHERE CATEGORY = ? AND NAME = ?");
            updateStatement.setString(1, "enabled");
            updateStatement.setString(2, enabled ? "true" : "false");
            updateStatement.setString(3, "Data Pruner");
            updateStatement.setString(4, "interval");
            updateStatement.executeUpdate();
        } finally {
            DbUtils.closeQuietly(updateStatement);
        }

        PreparedStatement deleteStatement = null;
        try {
            deleteStatement = connection
                    .prepareStatement("DELETE FROM CONFIGURATION WHERE CATEGORY = ? AND NAME IN (?, ?, ?)");
            deleteStatement.setString(1, "Data Pruner");
            deleteStatement.setString(2, "time");
            deleteStatement.setString(3, "dayOfWeek");
            deleteStatement.setString(4, "dayOfMonth");
            deleteStatement.executeUpdate();
        } finally {
            DbUtils.closeQuietly(deleteStatement);
        }
    } catch (Exception e) {
        logger.error("Failed to modify Data Pruner configuration properties", e);
    }
}

From source file:com.mirth.connect.client.ui.browsers.event.EventBrowser.java

private Calendar getCalendar(MirthDatePicker datePicker, MirthTimePicker timePicker) throws ParseException {
    DateFormatter timeFormatter = new DateFormatter(new SimpleDateFormat("hh:mm aa"));
    Date date = datePicker.getDate();
    String time = timePicker.getDate();

    if (date != null && time != null) {
        Calendar dateCalendar = Calendar.getInstance();
        Calendar timeCalendar = Calendar.getInstance();
        Calendar dateTimeCalendar = Calendar.getInstance();

        dateCalendar.setTime(date);//from w w w. j ava2s. c  om
        timeCalendar.setTime((Date) timeFormatter.stringToValue(time));
        dateTimeCalendar.setTime(date);

        // Only set the time if the time picker is enabled. Otherwise, it will default to 00:00:00
        if (timePicker.isEnabled()) {
            dateTimeCalendar.set(Calendar.HOUR_OF_DAY, timeCalendar.get(Calendar.HOUR_OF_DAY));
            dateTimeCalendar.set(Calendar.MINUTE, timeCalendar.get(Calendar.MINUTE));
            dateTimeCalendar.set(Calendar.SECOND, timeCalendar.get(Calendar.SECOND));
        }

        return dateTimeCalendar;
    }

    return null;
}

From source file:com.pos.spatobiz.app.view.karyawan.UbahKaryawan.java

/** This method is called from within the constructor to
 * initialize the form./*  ww w. j  a va2  s  .  c  om*/
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    jeniskelamin = new ButtonGroup();
    labelKode = new WhiteLabel();
    labelNama = new WhiteLabel();
    labelTanggalLahir = new WhiteLabel();
    labelAlamat = new WhiteLabel();
    textKode = new TextBoxTransfer();
    textNama = new TextBoxTransfer();
    textTanggalLahir = new DateBox();
    textAlamat = new WhiteTextArea();
    errorKode = new RedLabel();
    errorNama = new RedLabel();
    errorTanggalLahir = new RedLabel();
    errorAlamat = new RedLabel();
    textTelepon = new TextBoxTransfer();
    labelTelepon = new WhiteLabel();
    labelEmail = new WhiteLabel();
    labelJenisKelamin = new WhiteLabel();
    labelPhoto = new WhiteLabel();
    textEmail = new TextBoxTransfer();
    radioPria = new JRadioButton();
    radioWanita = new JRadioButton();
    errorTelepon = new RedLabel();
    errorEmail = new RedLabel();
    imageChooser = new ImageChooser();
    buttonBatal = new Button();
    buttonUbah = new Button();
    buttonCari = new Button();

    setBackground(new Color(0, 0, 0));

    labelKode.setHorizontalAlignment(SwingConstants.RIGHT);
    labelKode.setText("Kode :");

    labelNama.setHorizontalAlignment(SwingConstants.RIGHT);
    labelNama.setText("Nama :");

    labelTanggalLahir.setHorizontalAlignment(SwingConstants.RIGHT);
    labelTanggalLahir.setText("Tanggal Lahir :");

    labelAlamat.setHorizontalAlignment(SwingConstants.RIGHT);
    labelAlamat.setText("Alamat :");

    textTanggalLahir.setFormatterFactory(
            new DefaultFormatterFactory(new DateFormatter(DateFormat.getDateInstance(DateFormat.LONG))));
    textTanggalLahir.setPreferredSize(new Dimension(120, 24));
    textTanggalLahir.setValue(new Date());

    errorKode.setText("error kode");

    errorNama.setText("error nama");

    errorTanggalLahir.setText("error tanggal lahir");

    errorAlamat.setText("error alamat");

    labelTelepon.setHorizontalAlignment(SwingConstants.RIGHT);
    labelTelepon.setText("Telepon :");

    labelEmail.setHorizontalAlignment(SwingConstants.RIGHT);
    labelEmail.setText("Email :");

    labelJenisKelamin.setHorizontalAlignment(SwingConstants.RIGHT);
    labelJenisKelamin.setText("Jenis Kelamin :");

    labelPhoto.setHorizontalAlignment(SwingConstants.RIGHT);
    labelPhoto.setText("Photo :");

    jeniskelamin.add(radioPria);
    radioPria.setFont(new Font("Tahoma", 1, 11));
    radioPria.setForeground(new Color(255, 255, 255));
    radioPria.setSelected(true);
    radioPria.setText("Pria");
    radioPria.setOpaque(false);

    jeniskelamin.add(radioWanita);
    radioWanita.setFont(new Font("Tahoma", 1, 11));
    radioWanita.setForeground(new Color(255, 255, 255));
    radioWanita.setText("Wanita");
    radioWanita.setOpaque(false);

    errorTelepon.setText("error telepon");

    errorEmail.setText("error email");

    buttonBatal.setMnemonic('B');
    buttonBatal.setText("Batal");

    buttonUbah.setMnemonic('U');
    buttonUbah.setText("Ubah");

    buttonCari.setText("Cari");

    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout
            .createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING,
                    layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(Alignment.TRAILING, false)
                                    .addComponent(labelPhoto, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelJenisKelamin, Alignment.LEADING,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelEmail, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(layout.createParallelGroup(Alignment.TRAILING, false)
                                    .addComponent(labelTelepon, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelTanggalLahir, Alignment.LEADING,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelAlamat, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelNama, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelKode, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addPreferredGap(ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(Alignment.TRAILING)
                                    .addComponent(textAlamat, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 403,
                                            Short.MAX_VALUE)
                                    .addComponent(textNama, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 403,
                                            Short.MAX_VALUE)
                                    .addComponent(textTanggalLahir, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
                                            403, Short.MAX_VALUE)
                                    .addComponent(textTelepon, GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
                                    .addGroup(Alignment.LEADING,
                                            layout.createSequentialGroup().addComponent(radioPria)
                                                    .addPreferredGap(ComponentPlacement.UNRELATED)
                                                    .addComponent(radioWanita))
                                    .addComponent(imageChooser, Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                            253, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(textEmail, GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                            .addComponent(textKode, GroupLayout.DEFAULT_SIZE, 339,
                                                    Short.MAX_VALUE)
                                            .addPreferredGap(ComponentPlacement.UNRELATED)
                                            .addComponent(buttonCari, GroupLayout.PREFERRED_SIZE,
                                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                            .addGap(4, 4, 4)
                            .addGroup(layout.createParallelGroup(Alignment.LEADING)
                                    .addComponent(errorKode, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(errorNama, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(errorTanggalLahir, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(errorAlamat, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(errorTelepon, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(errorEmail, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                    .addGroup(Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(buttonUbah, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(buttonBatal,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)))
            .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout
            .createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(labelKode, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(textKode, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorKode, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonCari, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(labelNama, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(textNama, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorNama, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(labelTanggalLahir, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(textTanggalLahir, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorTanggalLahir, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.LEADING)
                    .addComponent(labelAlamat, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(textAlamat, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorAlamat, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(textTelepon, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelTelepon, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorTelepon, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(labelEmail, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(textEmail, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorEmail, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(labelJenisKelamin, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(radioPria).addComponent(radioWanita))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.LEADING)
                    .addComponent(labelPhoto, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(imageChooser, GroupLayout.PREFERRED_SIZE, 189, GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(buttonBatal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonUbah, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addContainerGap()));
}

From source file:com.mirth.connect.model.ServerConfiguration.java

@Override
public void migrate3_3_0(DonkeyElement element) {
    DonkeyElement librariesElement = element.addChildElement("codeTemplateLibraries");
    DonkeyElement libraryElement = librariesElement.addChildElement("codeTemplateLibrary");
    libraryElement.setAttribute("version", "3.3.0");
    libraryElement.addChildElement("id", UUID.randomUUID().toString());
    libraryElement.addChildElement("name", "Library 1");
    libraryElement.addChildElement("revision", "1");
    try {//from   w  w w .ja  va 2  s .  c om
        libraryElement
                .addChildElementFromXml(ObjectXMLSerializer.getInstance().serialize(Calendar.getInstance()))
                .setNodeName("lastModified");
    } catch (DonkeyElementException e) {
        throw new SerializerException("Failed to migrate code template library last modified date.", e);
    }
    libraryElement.addChildElement("description",
            "This library was added upon migration to version 3.3.0. It includes all pre-existing\ncode templates, and is set to be included on all pre-existing and new channels.\n\nYou should create your own new libraries and assign code templates to them as you\nsee fit. You should also link libraries to specific channels, so that you're not\nnecessarily including all code templates on all channels all the time.");
    libraryElement.addChildElement("includeNewChannels", "true");
    libraryElement.addChildElement("enabledChannelIds");
    libraryElement.addChildElement("disabledChannelIds");
    try {
        libraryElement.addChildElementFromXml(element.removeChild("codeTemplates").toXml());
    } catch (DonkeyElementException e) {
        throw new SerializerException("Failed to migrate code templates.", e);
    }

    boolean enabled = true;
    String time = "";
    String interval = "";
    String dayOfWeek = "";
    String dayOfMonth = "1";

    DonkeyElement properties = null;
    DonkeyElement pluginProperties = element.getChildElement("pluginProperties");
    if (pluginProperties != null) {
        for (DonkeyElement childElement : pluginProperties.getChildElements()) {
            String entryKey = childElement.getChildElement("string").getTextContent();
            if (entryKey.equals("Data Pruner")) {
                properties = childElement.getChildElement("properties");

                for (DonkeyElement property : properties.getChildElements()) {
                    String propertyName = property.getAttributes().item(0).getTextContent();

                    if (propertyName.equals("dayOfWeek")) {
                        dayOfWeek = property.getTextContent();
                    } else if (propertyName.equals("dayOfMonth")) {
                        dayOfMonth = property.getTextContent();
                    } else if (propertyName.equals("interval")) {
                        interval = property.getTextContent();
                    } else if (propertyName.equals("time")) {
                        time = property.getTextContent();
                    }
                }
            }
        }

        enabled = !interval.equals("disabled");
        String pollingType = "INTERVAL";
        String pollingHour = "12";
        String pollingMinute = "0";
        boolean weekly = !StringUtils.equals(interval, "monthly");
        boolean[] activeDays = new boolean[] { true, true, true, true, true, true, true, true };

        if (enabled && !StringUtils.equals(interval, "hourly")) {
            SimpleDateFormat timeDateFormat = new SimpleDateFormat("hh:mm aa");
            DateFormatter timeFormatter = new DateFormatter(timeDateFormat);
            Date timeDate = null;

            try {
                timeDate = (Date) timeFormatter.stringToValue(time);
                Calendar timeCalendar = Calendar.getInstance();
                timeCalendar.setTime(timeDate);

                pollingType = "TIME";
                pollingHour = String.valueOf(timeCalendar.get(Calendar.HOUR_OF_DAY));
                pollingMinute = String.valueOf(timeCalendar.get(Calendar.MINUTE));

                if (StringUtils.equals(interval, "weekly")) {
                    SimpleDateFormat dayDateFormat = new SimpleDateFormat("EEEEEEEE");
                    DateFormatter dayFormatter = new DateFormatter(dayDateFormat);

                    Date dayDate = (Date) dayFormatter.stringToValue(dayOfWeek);
                    Calendar dayCalendar = Calendar.getInstance();
                    dayCalendar.setTime(dayDate);

                    activeDays = new boolean[] { false, false, false, false, false, false, false, false };
                    activeDays[dayCalendar.get(Calendar.DAY_OF_WEEK)] = true;
                }
            } catch (Exception e) {
            }
        }

        try {
            DonkeyElement pollingProperties = new DonkeyElement(
                    "<com.mirth.connect.donkey.model.channel.PollConnectorProperties/>");
            pollingProperties.setAttribute("version", "3.3.0");
            pollingProperties.addChildElementIfNotExists("pollingType", pollingType);
            pollingProperties.addChildElementIfNotExists("pollOnStart", "false");
            pollingProperties.addChildElementIfNotExists("pollingFrequency", "3600000");
            pollingProperties.addChildElementIfNotExists("pollingHour", pollingHour);
            pollingProperties.addChildElementIfNotExists("pollingMinute", pollingMinute);
            pollingProperties.addChildElementIfNotExists("cronJobs");

            DonkeyElement advancedProperties = pollingProperties
                    .addChildElementIfNotExists("pollConnectorPropertiesAdvanced");
            advancedProperties.addChildElementIfNotExists("weekly", weekly ? "true" : "false");

            DonkeyElement inactiveDays = advancedProperties.addChildElementIfNotExists("inactiveDays");
            if (inactiveDays != null) {
                for (int index = 0; index < 8; ++index) {
                    inactiveDays.addChildElement("boolean", activeDays[index] ? "false" : "true");
                }
            }

            advancedProperties.addChildElementIfNotExists("dayOfMonth", dayOfMonth);
            advancedProperties.addChildElementIfNotExists("allDay", "true");
            advancedProperties.addChildElementIfNotExists("startingHour", "8");
            advancedProperties.addChildElementIfNotExists("startingMinute", "0");
            advancedProperties.addChildElementIfNotExists("endingHour", "17");
            advancedProperties.addChildElementIfNotExists("endingMinute", "0");

            DonkeyElement prunerProperty = properties.addChildElementFromXml(
                    ObjectXMLSerializer.getInstance().serialize(pollingProperties.toXml()));
            prunerProperty.setAttribute("name", "pollingProperties");

            DonkeyElement enabledProperty = properties.addChildElement("property", Boolean.toString(enabled));
            enabledProperty.setAttribute("name", "enabled");
        } catch (Exception e) {
            throw new SerializerException("Failed to migrate Data Pruner properties.", e);
        }
    }
}

From source file:com.mirth.connect.plugins.datapruner.DataPrunerService.java

private Trigger createTrigger(Properties properties) throws ParseException {
    String interval = PropertyLoader.getProperty(properties, "interval");

    if (interval.equals("disabled")) {
        return null;
    }/* w ww . ja v  a  2  s .  c o  m*/

    ScheduleBuilder<?> schedule = null;

    if (interval.equals("hourly")) {
        schedule = cronSchedule("0 0 * * * ?");
    } else {
        SimpleDateFormat timeDateFormat = new SimpleDateFormat("hh:mm aa");
        DateFormatter timeFormatter = new DateFormatter(timeDateFormat);

        String time = PropertyLoader.getProperty(properties, "time");
        Date timeDate = (Date) timeFormatter.stringToValue(time);
        Calendar timeCalendar = Calendar.getInstance();
        timeCalendar.setTime(timeDate);

        if (interval.equals("daily")) {
            schedule = dailyAtHourAndMinute(timeCalendar.get(Calendar.HOUR_OF_DAY),
                    timeCalendar.get(Calendar.MINUTE));
        } else if (interval.equals("weekly")) {
            SimpleDateFormat dayDateFormat = new SimpleDateFormat("EEEEEEEE");
            DateFormatter dayFormatter = new DateFormatter(dayDateFormat);

            String dayOfWeek = PropertyLoader.getProperty(properties, "dayOfWeek");
            Date dayDate = (Date) dayFormatter.stringToValue(dayOfWeek);
            Calendar dayCalendar = Calendar.getInstance();
            dayCalendar.setTime(dayDate);

            schedule = weeklyOnDayAndHourAndMinute(dayCalendar.get(Calendar.DAY_OF_WEEK),
                    timeCalendar.get(Calendar.HOUR_OF_DAY), timeCalendar.get(Calendar.MINUTE));
        } else if (interval.equals("monthly")) {
            SimpleDateFormat dayDateFormat = new SimpleDateFormat("DD");
            DateFormatter dayFormatter = new DateFormatter(dayDateFormat);

            String dayOfMonth = PropertyLoader.getProperty(properties, "dayOfMonth");
            Date dayDate = (Date) dayFormatter.stringToValue(dayOfMonth);
            Calendar dayCalendar = Calendar.getInstance();
            dayCalendar.setTime(dayDate);

            schedule = monthlyOnDayAndHourAndMinute(dayCalendar.get(Calendar.DAY_OF_MONTH),
                    timeCalendar.get(Calendar.HOUR_OF_DAY), timeCalendar.get(Calendar.MINUTE));
        } else {
            logger.error("Invalid pruner interval: " + interval);
            return null;
        }
    }

    return newTrigger()// @formatter:off
            .withIdentity(PRUNER_TRIGGER_KEY).withSchedule(schedule).startNow().build(); // @formatter:on
}

From source file:org.pentaho.reporting.libraries.designtime.swing.date.DateCellEditor.java

public void setDateFormat(final DateFormat timeFormat) {
    if (timeFormat == null) {
        throw new NullPointerException();
    }// w  w  w . j a  va  2 s.  c  o m

    dateField.setFormatterFactory(new JFormattedTextField.AbstractFormatterFactory() {
        public JFormattedTextField.AbstractFormatter getFormatter(final JFormattedTextField tf) {
            return new DateFormatter(timeFormat) {
                // allow to clear the field
                public Object stringToValue(final String text) throws ParseException {
                    return "".equals(text) ? null : super.stringToValue(text);
                }
            };
        }
    });

    if (timeFormat instanceof SimpleDateFormat) {
        final SimpleDateFormat dateFormat = (SimpleDateFormat) timeFormat;
        setToolTipText(dateFormat.toLocalizedPattern());
    } else {
        setToolTipText(null);
    }
    if (dateChooserPanel != null) {
        setDate(getCellEditorValue());
    }
}