Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 194168
Collapse All | Expand All

(-)ComboFieldEditor.java 2010-05-13 08:45:38.000000000 +0200 (+89 lines)
Lines 45-50 Link Here
45
        */
45
        */
46
       private String[][] fEntryNamesAndValues;
46
       private String[][] fEntryNamesAndValues;
47
    /**
48
     * Indicates whether the empty selection is legal;
49
     * <code>true</code> by default.
50
     */
51
    private boolean emptySelectionAllowed = true;
52
53
    /**
54
     * Cached valid state.
55
     */
56
    private boolean isValid;
57
47
       /**
58
       /**
48
        * Create the combo box field editor.
59
        * Create the combo box field editor.
49
        *
60
        *
Lines 217-220 Link Here
217
               super.setEnabled(enabled, parent);
228
               super.setEnabled(enabled, parent);
218
               getComboBoxControl(parent).setEnabled(enabled);
229
               getComboBoxControl(parent).setEnabled(enabled);
219
       }
230
       }
231
232
       /* (non-Javadoc)
233
     * Method declared on FieldEditor.
234
     */
235
    public boolean isValid() {
236
        return isValid;
237
    }
238
239
    /* (non-Javadoc)
240
     * Method declared on FieldEditor.
241
     */
242
    protected void refreshValidState() {
243
        isValid = checkState();
244
    }
245
246
    /**
247
     * Hook for subclasses to do specific state checks.
248
     * <p>
249
     * The default implementation of this framework method does
250
     * nothing and returns <code>true</code>.  Subclasses should
251
     * override this method to specific state checks.
252
     * </p>
253
     *
254
     * @return <code>true</code> if the field value is valid,
255
     *   and <code>false</code> if invalid
256
     */
257
    protected boolean doCheckState() {
258
        return true;
259
    }
260
261
    /**
262
     * Checks whether the combo input field contains a valid value or not.
263
     *
264
     * @return <code>true</code> if the field value is valid,
265
     *   and <code>false</code> if invalid
266
     */
267
    protected boolean checkState() {
268
        boolean result = false;
269
        if (emptySelectionAllowed) {
270
                       result = true;
271
               }
272
273
        if (fCombo == null) {
274
                       result = false;
275
               }
276
277
        int selectionIndex = fCombo.getSelectionIndex();
278
279
        result = (selectionIndex != -1) || emptySelectionAllowed;
280
281
        // call hook for subclasses
282
        result = result && doCheckState();
283
284
        return result;
285
    }
286
287
    /**
288
     * Returns whether an empty selection is a valid value.
289
     *
290
     * @return <code>true</code> if an empty selection is a valid value, and
291
     *  <code>false</code> if an empty selection is invalid
292
     * @see #setEmptySelectionAllowed
293
     */
294
    public boolean isEmptySelectionAllowed() {
295
        return emptySelectionAllowed;
296
    }
297
298
    /**
299
     * Sets whether the empty selection is a valid value or not.
300
     *
301
     * @param b <code>true</code> if the empty selection is allowed,
302
     *  and <code>false</code> if it is considered invalid
303
     */
304
    public void setEmptySelectionAllowed(boolean b) {
305
        emptySelectionAllowed = b;
306
    }
307
308
220
}
309
}

Return to bug 194168