jtulach@86: package org.apidesign.extensionpoint; jtulach@86: jtulach@86: import java.util.ArrayList; jtulach@86: import java.util.Collection; jtulach@86: import java.util.Collections; jtulach@86: import java.util.List; jtulach@86: import javax.swing.JOptionPane; jtulach@86: import org.apidesign.extensionpoint.api.TipOfTheDay; jtulach@86: import org.openide.util.Lookup; jtulach@86: jtulach@86: public class Main { jtulach@86: public static void main(String[] args) { jtulach@86: for (;;) { jtulach@86: // BEGIN: extension.point.Query jtulach@132: Collection all = jtulach@132: Lookup.getDefault().lookupAll(TipOfTheDay.class); jtulach@86: List arr = new ArrayList(all); jtulach@86: Collections.shuffle(arr); jtulach@86: jtulach@86: String msg; jtulach@86: String title; jtulach@86: int type; jtulach@86: if (arr.isEmpty()) { jtulach@86: msg = "I do not know what to say!"; jtulach@86: title = "No provider registered"; jtulach@86: type = JOptionPane.WARNING_MESSAGE; jtulach@86: } else { jtulach@86: msg = arr.get(0).sayHello(); jtulach@86: title = "Selected from " + arr.size() + " providers"; jtulach@86: type = JOptionPane.INFORMATION_MESSAGE; jtulach@86: } jtulach@86: // END: extension.point.Query jtulach@86: jtulach@86: String again = "Once Again"; jtulach@86: String exit = "Exit"; jtulach@86: String[] options = new String[] { again, exit }; jtulach@132: int ret = JOptionPane.showOptionDialog( jtulach@132: null, msg, title, 0, type, null, options, exit jtulach@132: ); jtulach@86: jtulach@86: if (ret != 0) { jtulach@86: break; jtulach@86: } jtulach@86: } jtulach@86: System.exit(0); jtulach@86: } jtulach@86: }