org.eclipse.swt.widgets.DateTime

Here are the examples of the java api class org.eclipse.swt.widgets.DateTime taken from open source projects.

1. CalendarDialog#showWithEndTime()

Project: scouter
File: CalendarDialog.java
public void showWithEndTime(long stime, long etime) {
    final Shell dialog = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new GridLayout(4, false));
    dialog.setText("Date/Time");
    final DateTime calendar = new DateTime(dialog, SWT.CALENDAR);
    GridData data = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1);
    calendar.setLayoutData(data);
    int year = CastUtil.cint(DateUtil.format(stime, "yyyy"));
    int month = CastUtil.cint(DateUtil.format(stime, "MM")) - 1;
    int day = CastUtil.cint(DateUtil.format(stime, "dd"));
    calendar.setDate(year, month, day);
    calendar.setDay(day);
    Label label = new Label(dialog, SWT.NONE);
    label.setText("From");
    final DateTime startTime = new DateTime(dialog, SWT.TIME | SWT.SHORT);
    startTime.setHours(DateUtil.getHour(stime));
    startTime.setMinutes(DateUtil.getMin(stime));
    label = new Label(dialog, SWT.NONE);
    label.setText("To");
    final DateTime endTime = new DateTime(dialog, SWT.TIME | SWT.SHORT);
    endTime.setHours(DateUtil.getHour(etime));
    endTime.setMinutes(DateUtil.getMin(etime));
    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    okButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    okButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    try {
                        String fromTime = (calendar.getMonth() + 1) + "/" + calendar.getDay() + "/" + calendar.getYear() + " " + (startTime.getHours() < 10 ? "0" : "") + startTime.getHours() + ":" + (startTime.getMinutes() < 10 ? "0" : "") + startTime.getMinutes();
                        String toTime = (calendar.getMonth() + 1) + "/" + calendar.getDay() + "/" + calendar.getYear() + " " + (endTime.getHours() < 10 ? "0" : "") + endTime.getHours() + ":" + (endTime.getMinutes() < 10 ? "0" : "") + endTime.getMinutes();
                        long startTime = DateUtil.getTime(fromTime, "MM/dd/yyyy HH:mm");
                        long endTime = DateUtil.getTime(toTime, "MM/dd/yyyy HH:mm");
                        if (endTime <= startTime) {
                            MessageDialog.openWarning(dialog, "Warning", "Time range is incorrect");
                        } else {
                            if (DateUtil.isSameDay(new Date(startTime), new Date(endTime)) == false) {
                                endTime = DateUtil.getTime((calendar.getMonth() + 1) + "/" + calendar.getDay() + "/" + calendar.getYear() + " 23:59", "MM/dd/yyyy HH:mm");
                            }
                            callback.onPressedOk(startTime, endTime);
                            dialog.close();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        MessageDialog.openError(dialog, "Error", "Date format error:" + e.getMessage());
                    }
                    break;
            }
        }
    });
    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");
    cancelButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    cancelButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    callback.onPressedCancel();
                    dialog.close();
                    break;
            }
        }
    });
    dialog.setDefaultButton(okButton);
    dialog.pack();
    dialog.open();
}

2. TimeRangeDialog#show()

Project: scouter
File: TimeRangeDialog.java
public void show(long stime, long etime) {
    final Shell dialog = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new GridLayout(4, false));
    dialog.setText("Time Range");
    UIUtil.setDialogDefaultFunctions(dialog);
    Label label = new Label(dialog, SWT.NONE);
    label.setText("From");
    final DateTime startTime = new DateTime(dialog, SWT.TIME | SWT.SHORT);
    startTime.setHours(DateUtil.getHour(stime));
    startTime.setMinutes(DateUtil.getMin(stime));
    label = new Label(dialog, SWT.NONE);
    label.setText("To");
    final DateTime endTime = new DateTime(dialog, SWT.TIME | SWT.SHORT);
    endTime.setHours(DateUtil.getHour(etime));
    endTime.setMinutes(DateUtil.getMin(etime));
    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    okButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    okButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    try {
                        String fromTime = yyyymmdd + (startTime.getHours() < 10 ? "0" : "") + startTime.getHours() + (startTime.getMinutes() < 10 ? "0" : "") + startTime.getMinutes();
                        String toTime = yyyymmdd + (endTime.getHours() < 10 ? "0" : "") + endTime.getHours() + (endTime.getMinutes() < 10 ? "0" : "") + endTime.getMinutes();
                        long stime = DateUtil.getTime(fromTime, "yyyyMMddHHmm");
                        long etime = DateUtil.getTime(toTime, "yyyyMMddHHmm");
                        if (etime <= stime) {
                            MessageDialog.openWarning(dialog, "Warning", "Time range is incorrect. ");
                        } else {
                            callback.setTimeRange(stime, etime);
                            dialog.close();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        MessageDialog.openError(dialog, "Error", "Date format error:" + e.getMessage());
                    }
                    break;
            }
        }
    });
    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");
    cancelButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    cancelButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    dialog.close();
                    break;
            }
        }
    });
    dialog.setDefaultButton(okButton);
    dialog.pack();
    dialog.open();
}

3. DualCalendarDialog#show()

Project: scouter
File: DualCalendarDialog.java
public void show(String label1, String label2, int x, int y, String yyyymmdd1, String yyyymmdd2) {
    final Shell dialog = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new GridLayout(2, true));
    dialog.setText("Date");
    UIUtil.setDialogDefaultFunctions(dialog);
    Label sDate = new Label(dialog, SWT.NONE);
    sDate.setText(label1);
    GridData data = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
    sDate.setLayoutData(data);
    final DateTime startCal = new DateTime(dialog, SWT.CALENDAR);
    data = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
    startCal.setLayoutData(data);
    Label eDate = new Label(dialog, SWT.NONE);
    eDate.setText(label2);
    data = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
    eDate.setLayoutData(data);
    final DateTime endCal = new DateTime(dialog, SWT.CALENDAR);
    data = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
    endCal.setLayoutData(data);
    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    okButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    okButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    try {
                        String sDate = (startCal.getMonth() + 1) + "/" + startCal.getDay() + "/" + startCal.getYear();
                        sDate = DateUtil.format(DateUtil.getTime(sDate, "MM/dd/yyyy"), "yyyyMMdd");
                        String eDate = (endCal.getMonth() + 1) + "/" + endCal.getDay() + "/" + endCal.getYear();
                        eDate = DateUtil.format(DateUtil.getTime(eDate, "MM/dd/yyyy"), "yyyyMMdd");
                        if (CastUtil.cint(sDate) > CastUtil.cint(eDate)) {
                            MessageDialog.openError(dialog, "Error", "End Date is later than Start Date");
                            return;
                        }
                        callback.onPressedOk(sDate, eDate);
                        dialog.close();
                    } catch (Exception e) {
                        MessageDialog.openError(dialog, "Error55", "Date format error:" + e.getMessage());
                    }
                    break;
            }
        }
    });
    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");
    cancelButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    cancelButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    callback.onPressedCancel();
                    dialog.close();
                    break;
            }
        }
    });
    dialog.setDefaultButton(okButton);
    dialog.pack();
    if (x > 0 && y > 0) {
        dialog.setLocation(x, y);
    }
    if (yyyymmdd1 != null) {
        int year = Integer.valueOf(yyyymmdd1.substring(0, 4));
        int month = Integer.valueOf(yyyymmdd1.substring(4, 6)) - 1;
        int day = Integer.valueOf(yyyymmdd1.substring(6, 8));
        startCal.setDate(year, month, day);
    }
    if (yyyymmdd2 != null) {
        int year = Integer.valueOf(yyyymmdd2.substring(0, 4));
        int month = Integer.valueOf(yyyymmdd2.substring(4, 6)) - 1;
        int day = Integer.valueOf(yyyymmdd2.substring(6, 8));
        endCal.setDate(year, month, day);
    }
    dialog.open();
}

4. CalendarDialog#showWithTime()

Project: scouter
File: CalendarDialog.java
public void showWithTime(int x, int y, long time) {
    final Shell dialog = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new GridLayout(4, false));
    dialog.setText("Date/Time");
    UIUtil.setDialogDefaultFunctions(dialog);
    final DateTime calendar = new DateTime(dialog, SWT.CALENDAR);
    GridData data = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1);
    calendar.setLayoutData(data);
    if (time > 0) {
        int year = CastUtil.cint(DateUtil.format(time, "yyyy"));
        int month = CastUtil.cint(DateUtil.format(time, "MM")) - 1;
        int day = CastUtil.cint(DateUtil.format(time, "dd"));
        calendar.setDate(year, month, day);
        calendar.setDay(day);
    }
    Label label = new Label(dialog, SWT.NONE);
    label.setText("From");
    final DateTime startTime = new DateTime(dialog, SWT.TIME | SWT.SHORT);
    if (time > 0) {
        int hours = CastUtil.cint(DateUtil.format(time, "HH"));
        int minutes = CastUtil.cint(DateUtil.format(time, "mm"));
        int seconds = CastUtil.cint(DateUtil.format(time, "ss"));
        startTime.setTime(hours, minutes, seconds);
    } else {
        startTime.setHours(7);
        startTime.setMinutes(0);
    }
    label = new Label(dialog, SWT.NONE);
    label.setText("To");
    final Combo afterMinutes = new Combo(dialog, SWT.DROP_DOWN | SWT.READ_ONLY);
    ArrayList<String> minuteStrList = new ArrayList<String>();
    for (AfterMinuteUnit minute : AfterMinuteUnit.values()) {
        minuteStrList.add(minute.getLabel());
    }
    afterMinutes.setItems(minuteStrList.toArray(new String[AfterMinuteUnit.values().length]));
    afterMinutes.select(0);
    afterMinutes.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    okButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    okButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    try {
                        String fromTime = (calendar.getMonth() + 1) + "/" + calendar.getDay() + "/" + calendar.getYear() + " " + startTime.getHours() + ":" + (startTime.getMinutes() < 10 ? "0" : "") + startTime.getMinutes();
                        long startTime = DateUtil.getTime(fromTime, "MM/dd/yyyy HH:mm");
                        long endTime = 0;
                        String afterMinute = afterMinutes.getText();
                        AfterMinuteUnit m = AfterMinuteUnit.fromString(afterMinute);
                        if (m != null) {
                            endTime = startTime + m.getTime();
                        }
                        if (endTime <= startTime) {
                            MessageDialog.openWarning(dialog, "Warning", "Time range is incorrect");
                        } else {
                            if (DateUtil.isSameDay(new Date(startTime), new Date(endTime)) == false) {
                                endTime = DateUtil.getTime((calendar.getMonth() + 1) + "/" + calendar.getDay() + "/" + calendar.getYear() + " 23:59", "MM/dd/yyyy HH:mm");
                            }
                            callback.onPressedOk(startTime, endTime);
                            dialog.close();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        MessageDialog.openError(dialog, "Error", "Date format error:" + e.getMessage());
                    }
                    break;
            }
        }
    });
    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");
    cancelButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    cancelButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    callback.onPressedCancel();
                    dialog.close();
                    break;
            }
        }
    });
    dialog.setDefaultButton(okButton);
    dialog.pack();
    if (x > 0 && y > 0) {
        dialog.setLocation(x, y);
    }
    dialog.open();
}

5. DateTimeEditor#createDialogArea()

Project: sling
File: DateTimeEditor.java
@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    GridData parentLayoutData = new GridData(GridData.FILL_BOTH);
    parentLayoutData.widthHint = 280;
    parentLayoutData.heightHint = 280;
    composite.setLayoutData(parentLayoutData);
    GridLayout parentLayout = (GridLayout) composite.getLayout();
    parentLayout.numColumns = 2;
    Label label = new Label(composite, SWT.WRAP);
    label.setText("Modify property " + property.getName() + ":");
    GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    data.horizontalSpan = 2;
    data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
    label.setLayoutData(data);
    label.setFont(parent.getFont());
    Label hline = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.horizontalSpan = 2;
    hline.setLayoutData(layoutData);
    Label dateLabel = new Label(composite, SWT.WRAP);
    dateLabel.setText("Date:");
    layoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    layoutData.widthHint = 80;
    dateLabel.setLayoutData(layoutData);
    dateLabel.setFont(parent.getFont());
    calendar = new DateTime(composite, SWT.CALENDAR);
    layoutData = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_BEGINNING);
    layoutData.horizontalSpan = 1;
    calendar.setLayoutData(layoutData);
    calendar.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateSelection();
        }
    });
    Label timeLabel = new Label(composite, SWT.WRAP);
    timeLabel.setText("Time:");
    layoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    layoutData.widthHint = 80;
    timeLabel.setLayoutData(layoutData);
    timeLabel.setFont(parent.getFont());
    time = new DateTime(composite, SWT.TIME);
    layoutData = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_BEGINNING);
    layoutData.horizontalSpan = 1;
    time.setLayoutData(layoutData);
    time.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateSelection();
        }
    });
    hline = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.horizontalSpan = 2;
    hline.setLayoutData(layoutData);
    result = new Label(composite, SWT.WRAP);
    result.setText("Foo");
    data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    data.horizontalSpan = 2;
    result.setLayoutData(data);
    result.setFont(parent.getFont());
    // initialize value
    dateAsString = property.getValueAsString();
    c = DateTimeSupport.parseAsCalendar(dateAsString);
    calendar.setDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
    time.setTime(c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND));
    updateSelection();
    return composite;
}

6. CalendarObjTypeDialog#show()

Project: scouter
File: CalendarObjTypeDialog.java
public void show(int x, int y, long time) {
    final Shell dialog = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new GridLayout(2, true));
    dialog.setText("Date");
    UIUtil.setDialogDefaultFunctions(dialog);
    final DateTime calendar = new DateTime(dialog, SWT.CALENDAR);
    calendar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    if (time > 0) {
        String yyyymmdd = DateUtil.format(time, "yyyy-MM-dd");
        String[] date = yyyymmdd.split("-");
        calendar.setDate(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2]));
    }
    objTypeCombo = new ImageCombo(dialog, SWT.BORDER | SWT.READ_ONLY);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, false, true, 2, 1);
    gd.heightHint = 15;
    objTypeCombo.setLayoutData(gd);
    objTypeCombo.setBackground(ColorUtil.getInstance().getColor("white"));
    ArrayList<String> objTypeList = counterEngine.getAllObjectType();
    //String defObjType = this.objType!=null?this.objType:PManager.getInstance().getString(PreferenceConstants.P_PERS_WAS_SERV_DEFAULT_WAS);
    for (int i = 0; i < objTypeList.size(); i++) {
        String objType = objTypeList.get(i);
        String displayName = counterEngine.getDisplayNameObjectType(objType);
        if (StringUtil.isEmpty(displayName))
            continue;
        objTypeCombo.add(displayName, Images.getObjectIcon(objType, true, serverId));
        objTypeCombo.setData(displayName, objType);
        if (defObjType.equals(objType)) {
            objTypeCombo.select(i);
        }
    }
    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    okButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    okButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    try {
                        String objType = CastUtil.cString(objTypeCombo.getData(objTypeCombo.getText()));
                        if (StringUtil.isEmpty(objType)) {
                            MessageDialog.openError(dialog, "Requirement", "Select Object Type");
                            return;
                        }
                        String date = (calendar.getMonth() + 1) + "/" + calendar.getDay() + "/" + calendar.getYear();
                        date = DateUtil.format(DateUtil.getTime(date, "MM/dd/yyyy"), "yyyyMMdd");
                        callback.onPressedOk(date, objType);
                        dialog.close();
                    } catch (Exception e) {
                        MessageDialog.openError(dialog, "Error55", "Date format error:" + e.getMessage());
                    }
                    break;
            }
        }
    });
    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");
    cancelButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    cancelButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    dialog.close();
                    break;
            }
        }
    });
    dialog.setDefaultButton(okButton);
    dialog.pack();
    if (x > 0 && y > 0) {
        dialog.setLocation(x, y);
    }
    dialog.open();
}

7. CalendarDialog#show()

Project: scouter
File: CalendarDialog.java
public void show(int x, int y, long time) {
    final Shell dialog = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new GridLayout(2, true));
    dialog.setText("Date");
    UIUtil.setDialogDefaultFunctions(dialog);
    final DateTime calendar = new DateTime(dialog, SWT.CALENDAR);
    GridData data = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
    calendar.setLayoutData(data);
    if (time > 0) {
        String yyyymmdd = DateUtil.format(time, "yyyy-MM-dd");
        String[] date = yyyymmdd.split("-");
        calendar.setDate(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2]));
    }
    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    okButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    okButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    try {
                        String date = (calendar.getMonth() + 1) + "/" + calendar.getDay() + "/" + calendar.getYear();
                        date = DateUtil.format(DateUtil.getTime(date, "MM/dd/yyyy"), "yyyyMMdd");
                        dialog.close();
                        callback.onPressedOk(date);
                    } catch (Exception e) {
                        MessageDialog.openError(dialog, "Error55", "Date format error:" + e.getMessage());
                    }
                    break;
            }
        }
    });
    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");
    cancelButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    cancelButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Selection:
                    callback.onPressedCancel();
                    dialog.close();
                    break;
            }
        }
    });
    dialog.addListener(SWT.Close, new Listener() {

        public void handleEvent(Event event) {
            callback.onPressedCancel();
        }
    });
    dialog.setDefaultButton(okButton);
    dialog.pack();
    if (x > 0 && y > 0) {
        dialog.setLocation(x, y);
    }
    dialog.open();
}

8. MigrationTaskEditor#createControl()

Project: depan
File: MigrationTaskEditor.java
/**
   * Create the editor's GUI.
   *
   * @param parent Parent Composite.
   * @return the top level Control for the GUI.
   */
private Control createControl(Composite parent) {
    // controls
    Composite topLevel = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    topLevel.setLayout(layout);
    Label labelId = new Label(topLevel, SWT.NONE);
    id = new Text(topLevel, SWT.BORDER);
    Label labelName = new Label(topLevel, SWT.NONE);
    name = new Text(topLevel, SWT.BORDER);
    Label labelDescription = new Label(topLevel, SWT.NONE);
    description = new Text(topLevel, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
    Label labelQuarter = new Label(topLevel, SWT.NONE);
    quarter = new Text(topLevel, SWT.BORDER);
    Label labelUpdatedBy = new Label(topLevel, SWT.NONE);
    updatedBy = new Text(topLevel, SWT.BORDER);
    Label labelUpdateDate = new Label(topLevel, SWT.NONE);
    updateDate = new DateTime(topLevel, SWT.CALENDAR);
    Label labelEngineers = new Label(topLevel, SWT.None);
    Control engineersEdit = createEngineersEditor(topLevel);
    // content
    labelId.setText("ID");
    labelName.setText("Name");
    labelDescription.setText("Description");
    labelQuarter.setText("Quarter");
    labelUpdatedBy.setText("Updated by");
    labelUpdateDate.setText("Updated date");
    labelEngineers.setText("Engineers");
    // layout
    labelUpdateDate.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    labelDescription.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    labelEngineers.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    id.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    name.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    quarter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    updatedBy.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    GridData descriptionLayout = new GridData(SWT.FILL, SWT.FILL, true, false);
    descriptionLayout.heightHint = 150;
    description.setLayoutData(descriptionLayout);
    engineersEdit.setLayoutData(descriptionLayout);
    fillContent();
    return topLevel;
}