author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:58:11 +0200 | |
changeset 154 | 0fd5e9c500b9 |
parent 153 | b5cbb797ec0a |
permissions | -rw-r--r-- |
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@154 | 15 |
Collection<? extends TipOfTheDay> all = |
jtulach@154 | 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@154 | 37 |
int ret = JOptionPane.showOptionDialog( |
jtulach@154 | 38 |
null, msg, title, 0, type, null, options, exit |
jtulach@154 | 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 |
} |