--- a/api.progress/src/org/netbeans/api/progress/ProgressHandleFactory.java Thu Dec 19 13:22:41 2013 +0100 +++ a/api.progress/src/org/netbeans/api/progress/ProgressHandleFactory.java Thu Dec 19 14:41:43 2013 +0100 @@ -44,6 +44,7 @@ package org.netbeans.api.progress; +import java.util.concurrent.atomic.AtomicBoolean; import javax.swing.Action; import javax.swing.JComponent; import javax.swing.JLabel; @@ -111,6 +112,26 @@ } /** + * Create a progress ui handle for a long lasting task. + * @param allowToCancel either null, if the task cannot be cancelled or + * an instance of {@link org.openide.util.Cancellable} that will be called when user + * triggers cancel of the task. + * @param suspendAndResume either null if this task does not + * support user initiated suspend/resume or an instance of a callback + * interface to propagate user control of progress to the task + * @param linkOutput an Action instance that links the running task in the progress bar + * to an output of the task. The action is assumed to open the apropriate component with the task's output. + * @param displayName to be shown in the progress UI + * @return an instance of {@link org.netbeans.api.progress.ProgressHandle}, initialized but not started. + * @since XXX + */ + public static ProgressHandle createHandle( + String displayName, Cancellable allowToCancel, Resumable suspendAndResume, Action linkOutput + ) { + return new ProgressHandle(new InternalHandle(displayName, allowToCancel, suspendAndResume, true, linkOutput)); + } + + /** * Get the progress bar component for use in custom dialogs, the task won't * show in the progress bar anymore. * @return the component to use in custom UI. --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ 8023922119fe Thu Dec 19 14:41:43 2013 +0100 @@ -0,0 +1,55 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, 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-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ + +package org.netbeans.api.progress; + +/** A callback interface for long running tasks that wish to give + * the user a chance to suspend them and resume later. See + * {@link ProgressHandleFactory#createHandle(java.lang.String, org.openide.util.Cancellable, org.netbeans.api.progress.Resumable, javax.swing.Action)} + * factory method that accepts it. + * + * @author Jaroslav Tulach + * @since XXX + */ +public interface Resumable { + +} --- a/api.progress/src/org/netbeans/modules/progress/spi/InternalHandle.java Thu Dec 19 13:22:41 2013 +0100 +++ a/api.progress/src/org/netbeans/modules/progress/spi/InternalHandle.java Thu Dec 19 14:41:43 2013 +0100 @@ -51,6 +51,7 @@ import javax.swing.Action; import javax.swing.JComponent; import javax.swing.JLabel; +import org.netbeans.api.progress.Resumable; import org.netbeans.progress.module.*; import org.openide.util.Cancellable; import org.openide.util.Lookup; @@ -78,6 +79,7 @@ private long timeSleepy = 0; private String lastMessage; private final Cancellable cancelable; + private final Resumable resumable; private final Action viewAction; private final boolean userInitiated; private int initialDelay = Controller.INITIAL_DELAY; @@ -98,12 +100,33 @@ Cancellable cancel, boolean userInitiated, Action view) { + this(displayName, cancel, null, userInitiated, view); + } + + /** + * + * @param displayName + * @param cancel + * @param suspendAndResume + * @param userInitiated + * @param view + * + * @since XXX + */ + public InternalHandle( + String displayName, + Cancellable cancel, + Resumable suspendAndResume, + boolean userInitiated, + Action view + ) { this.displayName = displayName; this.userInitiated = userInitiated; state = STATE_INITIALIZED; totalUnits = 0; lastMessage = null; cancelable = cancel; + this.resumable = suspendAndResume; viewAction = view; } @@ -118,6 +141,14 @@ return state; } + /** + * @return if the handle can be suspended and resumed + * @since XXX + */ + public boolean isResumable() { + return resumable != null; + } + public boolean isAllowCancel() { return cancelable != null && !isCustomPlaced(); }