samples/extensionpoint/src-api/org/apidesign/extensionpoint/Main.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:56:12 +0200
changeset 132 3bc4c54f4bcc
parent 86 adf4440db888
child 153 b5cbb797ec0a
permissions -rw-r--r--
Truncating all examples to 80 characters per line
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@132
    15
            Collection<? extends TipOfTheDay> all = 
jtulach@132
    16
                Lookup.getDefault().lookupAll(TipOfTheDay.class);
jtulach@86
    17
            List<TipOfTheDay> arr = new ArrayList<TipOfTheDay>(all);
jtulach@86
    18
            Collections.shuffle(arr);
jtulach@86
    19
jtulach@86
    20
            String msg;
jtulach@86
    21
            String title;
jtulach@86
    22
            int type;
jtulach@86
    23
            if (arr.isEmpty()) {
jtulach@86
    24
                msg = "I do not know what to say!";
jtulach@86
    25
                title = "No provider registered";
jtulach@86
    26
                type = JOptionPane.WARNING_MESSAGE;
jtulach@86
    27
            } else {
jtulach@86
    28
                msg = arr.get(0).sayHello();
jtulach@86
    29
                title = "Selected from " + arr.size() + " providers";
jtulach@86
    30
                type = JOptionPane.INFORMATION_MESSAGE;
jtulach@86
    31
            }
jtulach@86
    32
            // END: extension.point.Query
jtulach@86
    33
jtulach@86
    34
            String again = "Once Again";
jtulach@86
    35
            String exit = "Exit";
jtulach@86
    36
            String[] options = new String[] { again, exit };
jtulach@132
    37
            int ret = JOptionPane.showOptionDialog(
jtulach@132
    38
                null, msg, title, 0, type, null, options, exit
jtulach@132
    39
            );
jtulach@86
    40
jtulach@86
    41
            if (ret != 0) {
jtulach@86
    42
                break;
jtulach@86
    43
            }
jtulach@86
    44
        }
jtulach@86
    45
        System.exit(0);
jtulach@86
    46
    }
jtulach@86
    47
}