Index: apichanges.xml =================================================================== RCS file: apichanges.xml diff -N apichanges.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ apichanges.xml 18 Jul 2007 12:44:59 -0000 @@ -0,0 +1,141 @@ + + + + + + + + + + + + + Java Source UI API + + + + + + + + + + + Added support for notifying user about running background scan. + + + + + + + Added support for notifying user about running background scan. When the + background scan is running the support displays a dialog notifying user about it. + When the background scan finishes the dialog is closed and the action is executed. + + + + + + + + + + + + + Change History for the Java Source UI API + + + + + + +

Introduction

+ +

This document lists changes made to the Java Source UI API.

+ + +
+ + +

@FOOTER@

+ + +
+ +
Index: nbproject/project.properties =================================================================== RCS file: /cvs/java/sourceui/nbproject/project.properties,v retrieving revision 1.2 diff -u -r1.2 project.properties --- nbproject/project.properties 15 Jun 2007 13:45:29 -0000 1.2 +++ nbproject/project.properties 18 Jul 2007 12:44:59 -0000 @@ -1,3 +1,3 @@ javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.5 -spec.version.base=1.1 +spec.version.base=1.2 Index: nbproject/project.xml =================================================================== RCS file: /cvs/java/sourceui/nbproject/project.xml,v retrieving revision 1.3 diff -u -r1.3 project.xml --- nbproject/project.xml 15 Jun 2007 13:45:29 -0000 1.3 +++ nbproject/project.xml 18 Jul 2007 12:45:00 -0000 @@ -32,6 +32,15 @@ + org.netbeans.modules.java.platform + + + + 1 + 1.9 + + + org.netbeans.modules.java.source @@ -64,6 +73,14 @@ 1 1.13 + + + + org.openide.dialogs + + + + 7.5 Index: src/org/netbeans/api/java/source/ui/Bundle.properties =================================================================== RCS file: /cvs/java/sourceui/src/org/netbeans/api/java/source/ui/Bundle.properties,v retrieving revision 1.2 diff -u -r1.2 Bundle.properties --- src/org/netbeans/api/java/source/ui/Bundle.properties 13 Jun 2007 16:34:33 -0000 1.2 +++ src/org/netbeans/api/java/source/ui/Bundle.properties 18 Jul 2007 12:45:00 -0000 @@ -29,3 +29,5 @@ class_constant_javadoc=java.lang.Class constant. javadoc_content_not_found=Javadoc not found. Either Javadoc documentation for this item does not exist or you have not added specified Javadoc in the Java Platform Manager or the Library Manager. +LBL_CancelAction=Cancel {0} +MSG_WaitScan=Please wait, classpath scanning in progress... Index: src/org/netbeans/api/java/source/ui/ScanDialog.java =================================================================== RCS file: src/org/netbeans/api/java/source/ui/ScanDialog.java diff -N src/org/netbeans/api/java/source/ui/ScanDialog.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/api/java/source/ui/ScanDialog.java 18 Jul 2007 12:45:00 -0000 @@ -0,0 +1,132 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ +package org.netbeans.api.java.source.ui; + +import java.awt.Dialog; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.net.URL; +import java.util.concurrent.Future; +import javax.swing.JLabel; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.border.EmptyBorder; +import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.java.source.ClasspathInfo; +import org.netbeans.api.java.source.CompilationController; +import org.netbeans.api.java.source.JavaSource; +import org.netbeans.api.java.source.SourceUtils; +import org.netbeans.api.java.source.Task; +import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.util.Exceptions; +import org.openide.util.NbBundle; + +/** + * Support for notifying user about the background scan. + * @since 1.2 + * @author Tomas Zezula + */ +public class ScanDialog { + + /** + * This is a helper method to provide support for delaying invocations of actions + * depending on java model. + *
Behavior of this method is following:
+ * If classpath scanning is not in progress, runnable's run() is called.
+ * If classpath scanning is in progress, modal cancellable notification dialog with specified + * tile is opened. + * + * As soon as classpath scanning finishes, this dialog is closed and runnable's run() is called. + * This method must be called in AWT EventQueue. Runnable is performed in AWT thread. + * + * @param runnable Runnable instance which will be called. + * @param actionName Title of wait dialog. + * @return true action was cancelled
+ * false action was performed + */ + public static boolean runWhenScanFinished (final Runnable runnable, final String actionName) { + assert runnable != null; + assert actionName != null; + assert SwingUtilities.isEventDispatchThread(); + if (SourceUtils.isScanInProgress()) { + + class AL implements ActionListener { + + private Dialog dialog; + private Future monitor; + + public synchronized void start (final Future monitor) { + assert monitor != null; + this.monitor = monitor; + if (dialog != null) { + dialog.setVisible(true); + } + } + + public void actionPerformed(ActionEvent e) { + monitor.cancel(false); + close (); + } + + synchronized void close () { + if (dialog != null) { + dialog.setVisible(false); + dialog.dispose(); + dialog = null; + } + } + }; + final AL listener = new AL (); + JLabel label = new JLabel(NbBundle.getMessage(ScanDialog.class,"MSG_WaitScan"), + javax.swing.UIManager.getIcon("OptionPane.informationIcon"), SwingConstants.LEFT); + label.setBorder(new EmptyBorder(12,12,11,11)); + DialogDescriptor dd = new DialogDescriptor(label, actionName, true, new Object[]{NbBundle.getMessage(ScanDialog.class,"LBL_CancelAction",actionName)}, null, 0, null, listener); + listener.dialog = DialogDisplayer.getDefault().createDialog(dd); + listener.dialog.pack(); + final ClasspathInfo info = ClasspathInfo.create(JavaPlatform.getDefault().getBootstrapLibraries(), + ClassPathSupport.createClassPath(new URL[0]), + ClassPathSupport.createClassPath(new URL[0])); + final JavaSource js = JavaSource.create(info); + try { + Future monitor = js.runWhenScanFinished(new Task() { + public void run(CompilationController parameter) throws Exception { + SwingUtilities.invokeLater(new Runnable () { + public void run () { + listener.close(); + runnable.run(); + } + }); + } + }, true); + if (!monitor.isDone()) { + listener.start(monitor); + } + return monitor.isCancelled(); + }catch (IOException e) { + Exceptions.printStackTrace(e); + return true; + } + } else { + runnable.run(); + return false; + } + } + +}