@Override protected void createFieldEditors() { Group group = SWTUtil.createGroup(getFieldEditorParent(), "FreeMarker Debugger", 1); // $NON-NLS-1$ GridData gd = new GridData(GridData.FILL_HORIZONTAL); group.setLayoutData(gd); Composite composite = SWTUtil.createComposite(group, 2, 2, GridData.FILL_HORIZONTAL); StringFieldEditor passwordEditor = new StringFieldEditor( LiferayDebugCore.PREF_FM_DEBUG_PASSWORD, "Password:"******"Password is invalid."); passwordEditor.setPreferenceStore(getPreferenceStore()); addField(passwordEditor); IntegerFieldEditor portEditor = new IntegerFieldEditor( LiferayDebugCore.PREF_FM_DEBUG_PORT, "Port:", composite); // $NON-NLS-1$ portEditor.setValidRange(1025, 65535); portEditor.setEmptyStringAllowed(false); portEditor.setPreferenceStore(getPreferenceStore()); portEditor.setErrorMessage("Port value ranges from integer 1025 to 65535."); // $NON-NLS-1$ portEditor.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE); addField(portEditor); }
@Override protected void createFieldEditors() { String[][] values = new String[DATA.size()][2]; int i = 0; for (Map.Entry<GitDateFormatter.Format, FormatInfo> entry : DATA.entrySet()) { values[i][0] = entry.getValue().name; values[i][1] = entry.getKey() == null ? UIPreferences.DATE_FORMAT_CUSTOM : entry.getKey().name(); i++; } final Composite pane = getFieldEditorParent(); formatChooser = new ComboFieldEditor( UIPreferences.DATE_FORMAT_CHOICE, UIText.DateFormatPreferencePage_formatChooser_label, values, pane); addField(formatChooser); dateFormat = new StringFieldEditor( UIPreferences.DATE_FORMAT, UIText.DateFormatPreferencePage_formatInput_label, StringFieldEditor.UNLIMITED, StringFieldEditor.VALIDATE_ON_KEY_STROKE, pane) { @Override protected boolean doCheckState() { // Validate the contents. If we're disabled, we're showing some // built-in format string, which we always consider as valid. if (!getTextControl(pane).isEnabled()) { return true; } try { updatePreview(new SimpleDateFormat(getStringValue().trim())); return true; } catch (IllegalArgumentException e) { dateFormatPreview.setText(""); // $NON-NLS-1$ return false; } } @Override protected void doLoad() { // Set explicitly below } @Override protected void doStore() { // Never store invalid values, or built-in values if (getTextControl(pane).isEnabled() && doCheckState()) { super.doStore(); } } @Override public void setStringValue(String value) { super.setStringValue(value); refreshValidState(); } }; dateFormat.setEmptyStringAllowed(false); dateFormat.setErrorMessage(UIText.DateFormatPreferencePage_invalidDateFormat_message); addField(dateFormat); // We know that the layout will have two columns Label dpLabel = SWTUtils.createLabel(pane, UIText.DateFormatPreferencePage_datePreview_label); dpLabel.setLayoutData(SWTUtils.createGridData(SWT.DEFAULT, SWT.DEFAULT, false, false)); dateFormatPreview = SWTUtils.createLabel(pane, null, 1); Label dummyLabel = SWTUtils.createLabel(pane, ""); // $NON-NLS-1$ dummyLabel.setLayoutData(SWTUtils.createGridData(SWT.DEFAULT, SWT.DEFAULT, false, false)); formatExplanation = new Label(pane, SWT.LEFT | SWT.WRAP); GridData layout = SWTUtils.createGridData(SWT.DEFAULT, SWT.DEFAULT, false, true); formatExplanation.setLayoutData(layout); // Setup based on initial values. We don't get any events by the editors // on initial load! lastCustomValue = getPreferenceStore().getString(UIPreferences.DATE_FORMAT); String initialValue = getPreferenceStore().getString(UIPreferences.DATE_FORMAT_CHOICE); updateFields(initialValue); }