samples/extensionpoint/src-api/org/apidesign/extensionpoint/Main.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:58:08 +0200
changeset 153 b5cbb797ec0a
parent 132 3bc4c54f4bcc
child 154 0fd5e9c500b9
permissions -rw-r--r--
up to line 2000
jtulach@86
     1
package org.apidesign.extensionpoint;
jtulach@86
     2
jtulach@86
     3
import java.util.ArrayList;
jtulach@86
     4
import java.util.Collection;
jtulach@86
     5
import java.util.Collections;
jtulach@86
     6
import java.util.List;
jtulach@86
     7
import javax.swing.JOptionPane;
jtulach@86
     8
import org.apidesign.extensionpoint.api.TipOfTheDay;
jtulach@86
     9
import org.openide.util.Lookup;
jtulach@86
    10
jtulach@86
    11
public class Main {
jtulach@86
    12
    public static void main(String[] args) {
jtulach@86
    13
        for (;;) {
jtulach@86
    14
            // BEGIN: extension.point.Query
jtulach@153
    15
            Collection<? extends TipOfTheDay> all = Lookup.getDefault().lookupAll(TipOfTheDay.class);
jtulach@86
    16
            List<TipOfTheDay> arr = new ArrayList<TipOfTheDay>(all);
jtulach@86
    17
            Collections.shuffle(arr);
jtulach@86
    18
jtulach@86
    19
            String msg;
jtulach@86
    20
            String title;
jtulach@86
    21
            int type;
jtulach@86
    22
            if (arr.isEmpty()) {
jtulach@86
    23
                msg = "I do not know what to say!";
jtulach@86
    24
                title = "No provider registered";
jtulach@86
    25
                type = JOptionPane.WARNING_MESSAGE;
jtulach@86
    26
            } else {
jtulach@86
    27
                msg = arr.get(0).sayHello();
jtulach@86
    28
                title = "Selected from " + arr.size() + " providers";
jtulach@86
    29
                type = JOptionPane.INFORMATION_MESSAGE;
jtulach@86
    30
            }
jtulach@86
    31
            // END: extension.point.Query
jtulach@86
    32
jtulach@86
    33
            String again = "Once Again";
jtulach@86
    34
            String exit = "Exit";
jtulach@86
    35
            String[] options = new String[] { again, exit };
jtulach@153
    36
            int ret = JOptionPane.showOptionDialog(null, msg, title, 0, type, null, options, exit);
jtulach@86
    37
jtulach@86
    38
            if (ret != 0) {
jtulach@86
    39
                break;
jtulach@86
    40
            }
jtulach@86
    41
        }
jtulach@86
    42
        System.exit(0);
jtulach@86
    43
    }
jtulach@86
    44
}