01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08:
09: package de.uka.ilkd.key.gui;
10:
11: import de.uka.ilkd.key.casetool.IteratorOfModelClass;
12: import de.uka.ilkd.key.casetool.ListOfModelClass;
13: import de.uka.ilkd.key.casetool.ModelClass;
14: import de.uka.ilkd.key.util.Debug;
15:
16: /**
17: * A dialog for selecting one of a class's superclasses.
18: */
19: public class SuperclassSelectionDialog extends ClassSelectionDialog {
20:
21: private static ListOfModelClass getAllSuperclasses(
22: ModelClass subtype) {
23: ListOfModelClass result = subtype.getMyParents();
24:
25: IteratorOfModelClass it = result.iterator();
26: while (it.hasNext()) {
27: result = result.append(getAllSuperclasses(it.next()));
28: }
29:
30: return result; //TODO: eliminate duplicates
31: }
32:
33: /**
34: * Creates and displays a dialog box asking the user to select a superclass.
35: * @param subclass the class to choose a superclass of
36: */
37: public SuperclassSelectionDialog(ModelClass subclass) {
38: super ("Please select a supertype", "Supertypes of "
39: + subclass.getClassName(),
40: getAllSuperclasses(subclass), false);
41: }
42:
43: /**
44: * Returns the selected supertype, or null.
45: */
46: public ModelClass getSuperclass() {
47: ListOfModelClass selectedClasses = getSelection();
48: Debug.assertTrue(selectedClasses.size() <= 1);
49: return (selectedClasses.isEmpty() ? null : selectedClasses
50: .head());
51: }
52: }
|