This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 223810
Collapse All | Expand All

(-)a/cnd.utils/nbproject/project.xml (+9 lines)
Lines 6-11 Link Here
6
            <code-name-base>org.netbeans.modules.cnd.utils</code-name-base>
6
            <code-name-base>org.netbeans.modules.cnd.utils</code-name-base>
7
            <module-dependencies>
7
            <module-dependencies>
8
                <dependency>
8
                <dependency>
9
                    <code-name-base>org.netbeans.api.progress</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <release-version>1</release-version>
14
                        <specification-version>1.32</specification-version>
15
                    </run-dependency>
16
                </dependency>
17
                <dependency>
9
                    <code-name-base>org.netbeans.modules.dlight.libs.common</code-name-base>
18
                    <code-name-base>org.netbeans.modules.dlight.libs.common</code-name-base>
10
                    <build-prerequisite/>
19
                    <build-prerequisite/>
11
                    <compile-dependency/>
20
                    <compile-dependency/>
(-)a/cnd.utils/src/org/netbeans/modules/cnd/utils/ui/ModalMessageDlg.java (-181 / +156 lines)
Lines 44-274 Link Here
44
package org.netbeans.modules.cnd.utils.ui;
44
package org.netbeans.modules.cnd.utils.ui;
45
45
46
import java.awt.Dialog;
46
import java.awt.Dialog;
47
import java.awt.Dimension;
48
import java.awt.Frame;
47
import java.awt.Frame;
49
import java.awt.Rectangle;
50
import java.awt.Toolkit;
51
import java.awt.Window;
48
import java.awt.Window;
52
import java.awt.event.WindowAdapter;
49
import java.util.concurrent.ExecutionException;
53
import java.awt.event.WindowEvent;
50
import java.util.concurrent.Future;
54
import java.util.concurrent.atomic.AtomicBoolean;
51
import java.util.concurrent.atomic.AtomicBoolean;
55
import javax.swing.JDialog;
56
import javax.swing.JPanel;
57
import javax.swing.SwingUtilities;
52
import javax.swing.SwingUtilities;
53
import org.netbeans.api.progress.ProgressHandle;
54
import org.netbeans.api.progress.ProgressRunnable;
55
import org.netbeans.api.progress.ProgressUtils;
58
import org.netbeans.modules.cnd.utils.CndUtils;
56
import org.netbeans.modules.cnd.utils.CndUtils;
59
import org.netbeans.modules.cnd.utils.NamedRunnable;
57
import org.netbeans.modules.cnd.utils.NamedRunnable;
60
import org.openide.util.Cancellable;
58
import org.openide.util.Cancellable;
59
import org.openide.util.Exceptions;
61
import org.openide.util.RequestProcessor;
60
import org.openide.util.RequestProcessor;
62
import org.openide.util.RequestProcessor.Task;
63
61
64
/**
62
/**
63
 * Utility class for displaying a modal Dialog (effectively blocking (but not
64
 * freezing) UI) while running a task in background.
65
 *
66
 * Current implementation uses org.netbeans.api.progress.ProgressUtils.
67
 *
68
 * @Deprecated - Use org.netbeans.api.progress.ProgressUtils.
65
 *
69
 *
66
 * @author Vladimir Voskresensky
70
 * @author Vladimir Voskresensky
67
 */
71
 */
68
public class ModalMessageDlg extends javax.swing.JPanel {
72
@Deprecated
69
    private static final RequestProcessor RP = new RequestProcessor(ModalMessageDlg.class.getName(), 4);
73
public final class ModalMessageDlg {
70
74
71
    /**
75
    public interface LongWorker {
72
     * allows to display modal dialog with title and message for the period of
76
73
     * long task run
77
        void doWork();
74
     * @param parent parent frame or dialog
78
75
     * @param workTask non EDT task to run
79
        void doPostRunInEDT();
76
     * @param postEDTTask EDT task to run after closing modal dialog (can be null)
77
     * @param title title of dialog
78
     * @param message message in dialog
79
     * @return
80
     */
81
    public static void runLongTask(Dialog parent,
82
            final Runnable workTask, final Runnable postEDTTask, final Cancellable canceller,
83
            String title, String message) {
84
        runLongTaskImpl(parent, workTask, postEDTTask, title, message, canceller);
85
    }
80
    }
86
81
87
    public static void runLongTask(Frame parent,
82
    private ModalMessageDlg() {
88
            final Runnable workTask, final Runnable postEDTTask, final Cancellable canceller,
89
            String title, String message) {
90
        runLongTaskImpl(parent, workTask, postEDTTask, title, message, canceller);
91
    }
83
    }
92
84
93
    /**
85
    /**
86
     * Show a modal progress dialog that blocks the main window, while running
87
     * the passed runnable on a background thread.
94
     *
88
     *
95
     * @param parent
89
     * <p> This method is thread-safe, and will block until the operation has
96
     * @param title
90
     * completed, regardless of what thread calls this method. </p>
97
     * @param message
91
     *
98
     * @param workTask if workTask is Cancellable => dialog will have Cancel button
92
     * @param parent <b>Not used</b>
99
     *                 if not => no Cancel button is shown
93
     * @param workTask a Runnable to start in non-EDT thread. Unlike
94
     * {@link ProgressUtils}'s operation this argument is never tested for the
95
     * {@link Cancellable} interface. Use <b>canceller</b> for the task
96
     * interruption facility.
97
     * @param postEDTTask a task to run in the EDT after the <b>workTask</b> is
98
     * processed. <code>null</code> is allowed. <b>NB:</b> The postEDTTask is
99
     * called either if this method is invoked from tests or if <b>workTask</b>
100
     * was <b>not cancelled</b> by pressing the cancel button.
101
     * @param canceller if not <code>null</code> a cancel button is displayed
102
     * while <b>workTask</b> is running. <br/> Note that once the cancel button
103
     * is pressed, no <b>postEDTTask</b> will be called.
104
     * @param title title of a dialog. If <b>message</b> is not null,
105
     * <b>title</b> is <b>not used</b>.
106
     * @param message message to display. Could be <code>null</code>. In this
107
     * case <b>title</b> is used.
108
     *
100
     */
109
     */
101
    public static void runLongTask(Window parent, String title, String message,
110
    public static void runLongTask(Dialog parent, final Runnable workTask,
111
            final Runnable postEDTTask, final Cancellable canceller,
112
            String title, String message) {
113
        run(workTask, postEDTTask, canceller, title, message);
114
    }
115
116
    /**
117
     * Show a modal progress dialog that blocks the main window, while running
118
     * the passed runnable on a background thread.
119
     *
120
     * @see #runLongTask(Dialog, Runnable, Runnable, Cancellable, String,
121
     * String)
122
     */
123
    public static void runLongTask(final Frame parent, final Runnable workTask,
124
            final Runnable postEDTTask, final Cancellable canceller,
125
            String title, String message) {
126
        run(workTask, postEDTTask, canceller, title, message);
127
    }
128
129
    /**
130
     * Show a modal progress dialog that blocks the main window, while running
131
     * the passed runnable on a background thread.
132
     *
133
     * <p> This is almost the same as runLongTask(Dialog, Runnable, Runnable,
134
     * Cancellable, String, String), but has one significant difference! </p>
135
     *
136
     * <p>Not only it uses a {@link LongWorker} instead of two
137
     * {@link Runnable}s, but also the {@link LongWorker#doPostRunInEDT()} is
138
     * invoked disregarding the cancellation status.</p>
139
     *
140
     * @see #runLongTask(Dialog, Runnable, Runnable, Cancellable, String,
141
     * String)
142
     */
143
    public static void runLongTask(final Window parent, final String title, final String message,
102
            final LongWorker workTask, final Cancellable canceller) {
144
            final LongWorker workTask, final Cancellable canceller) {
103
145
104
        final JDialog dialog = createDialog(parent, title);
146
        run(new Runnable() {
105
106
        final Runnable finalizer = new Runnable() {
107
            @Override
147
            @Override
108
            public void run() {
148
            public void run() {
109
                // hide dialog and run action if successfully connected
149
                workTask.doWork();
110
                dialog.setVisible(false);
150
            }
111
                dialog.dispose();
151
        }, null, canceller, title, message);
152
153
        SwingUtilities.invokeLater(new Runnable() {
154
            @Override
155
            public void run() {
112
                workTask.doPostRunInEDT();
156
                workTask.doPostRunInEDT();
113
            }
157
            }
114
        };
158
        });
159
    }
115
160
116
        JPanel panel;
161
    private static void run(final Runnable workTask, final Runnable postEDTTask,
117
        if (canceller == null) {
162
            final Cancellable canceller, final String title, String message) {
118
            panel = new ModalMessageDlgPane(message);
163
164
        if (invokedFromTests()) {
165
            // The code below is just to preserve the behaviour as it was
166
            // before switchig to the ProgressUtils...
167
            Future<?> task = RequestProcessor.getDefault().submit(new NamedRunnable(title) {
168
                @Override
169
                protected void runImpl() {
170
                    workTask.run();
171
                }
172
            });
173
            try {
174
                task.get();
175
            } catch (InterruptedException ex) {
176
                Exceptions.printStackTrace(ex);
177
            } catch (ExecutionException ex) {
178
                Exceptions.printStackTrace(ex);
179
            }
180
            if (postEDTTask != null) {
181
                SwingUtilities.invokeLater(postEDTTask);
182
            }
119
        } else {
183
        } else {
120
            Cancellable wrapper = new Cancellable() {
184
            final MyRP r;
121
                /** is invoked from a separate cancellation thread */
122
                @Override
123
                public boolean cancel() {
124
                    if (canceller.cancel()) {
125
                        // remember for return value
126
                        return true;
127
                    } else {
128
                        return false;
129
                    }
130
                }
131
            };
132
            panel = new ModalMessageDlgCancellablePane(message, wrapper);
133
        }
134
        addPanel(parent, dialog, panel);
135
185
136
        RP.post(new NamedRunnable(title) {
186
            if (canceller != null) {
137
            @Override
187
                r = new MyCRP(workTask, canceller, message);
138
            public void runImpl() {
188
            } else {
139
                try {
189
                r = new MyRP(workTask, message);
140
                    workTask.doWork();
141
                } finally {
142
                    SwingUtilities.invokeLater(finalizer);
143
                }
144
            }
190
            }
145
        });
191
146
        if (!CndUtils.isStandalone()) { // this means we run in tests
192
            ProgressUtils.showProgressDialogAndRun(r, title, true);
147
            dialog.setVisible(true);
193
194
            if (postEDTTask != null && !r.wasCancelled()) {
195
                SwingUtilities.invokeLater(workTask);
196
            }
148
        }
197
        }
149
    }
198
    }
150
199
151
    private static boolean runLongTaskImpl(Window parent, final Runnable workTask, final Runnable postEDTTask,
200
    private static boolean invokedFromTests() {
152
            final String title, String message, final Cancellable canceller) {
201
        return CndUtils.isStandalone();
153
154
        final JDialog dialog = createDialog(parent, title);
155
        final AtomicBoolean cancelled = new AtomicBoolean(false);
156
157
        final Runnable finalizer = new Runnable() {
158
            @Override
159
            public void run() {
160
                // hide dialog and run action if successfully connected
161
                dialog.setVisible(false);
162
                dialog.dispose();
163
                if (postEDTTask != null && ! cancelled.get()) {
164
                    postEDTTask.run();
165
                }
166
            }
167
        };
168
169
        JPanel panel;
170
        if (canceller == null) {
171
            panel = new ModalMessageDlgPane(message);
172
        } else {
173
            Cancellable wrapper = new Cancellable() {
174
                /** is invoked from a separate cancellation thread */
175
                @Override
176
                public boolean cancel() {
177
                    if (canceller.cancel()) {
178
                        cancelled.set(true);
179
                        SwingUtilities.invokeLater(finalizer);
180
                        return true;
181
                    } else {
182
                        return false;
183
                    }
184
                }
185
            };
186
            panel = new ModalMessageDlgCancellablePane(message, wrapper);
187
        }
188
        addPanel(parent, dialog, panel);
189
190
        final WindowAdapterImpl windowAdapterImpl = new WindowAdapterImpl(dialog, title, workTask, finalizer);
191
192
        if (CndUtils.isStandalone()) { // this means we run in tests
193
            Task task = windowAdapterImpl.submitJob();
194
            task.waitFinished();
195
        } else {
196
            dialog.addWindowListener(windowAdapterImpl);
197
            dialog.setVisible(true);
198
        }
199
        
200
        return !cancelled.get();
201
    }
202
    }
202
203
203
    private static JDialog createDialog(Window parent, String title) {
204
    private static class MyRP implements ProgressRunnable<Void> {
204
        JDialog dialog;
205
        if (parent == null) {
206
            dialog = new JDialog();
207
        } else if (parent instanceof Frame) {
208
            dialog = new JDialog((Frame)parent);
209
        } else {
210
            assert (parent instanceof Dialog);
211
            dialog = new JDialog((Dialog)parent);
212
        }
213
        dialog.setTitle(title);
214
        dialog.setModal(true);
215
        return dialog;
216
    }
217
205
218
    private static void addPanel(Window parent, JDialog dialog, JPanel panel){
206
        private final Runnable task;
219
        dialog.getContentPane().add(panel);
207
        private final String message;
220
        dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); //make sure the dialog is not closed during the project open
221
        dialog.pack();
222
208
223
        Rectangle bounds = (parent == null) ?
209
        public MyRP(final Runnable task, final String message) {
224
            new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) : parent.getBounds();
210
            this.task = task;
225
211
            this.message = message;
226
        int middleX = bounds.x + bounds.width / 2;
227
        int middleY = bounds.y + bounds.height / 2;
228
229
        Dimension size = dialog.getPreferredSize();
230
231
        dialog.setBounds(middleX - size.width / 2, middleY - size.height / 2, size.width, size.height);
232
    }
233
234
    public interface LongWorker {
235
        void doWork();
236
        void doPostRunInEDT();
237
    }
238
239
    private static class WindowAdapterImpl extends WindowAdapter {
240
241
        private final String title;
242
        private final Runnable workTask;
243
        private final Runnable finalizer;
244
        private final JDialog dialog;
245
        
246
        public WindowAdapterImpl(JDialog dialog, String title, Runnable workTask, Runnable finalizer) {
247
            this.title = title;
248
            this.workTask = workTask;
249
            this.finalizer = finalizer;
250
            this.dialog = dialog;
251
        }
212
        }
252
213
253
        @Override
214
        @Override
254
        public void windowOpened(WindowEvent e) {
215
        public Void run(final ProgressHandle handle) {
255
            dialog.removeWindowListener(this);
216
            if (message != null) {
256
            submitJob();
217
                handle.setDisplayName(message);
218
            }
219
            task.run();
220
            return null;
257
        }
221
        }
258
222
259
        private Task submitJob() {
223
        public boolean wasCancelled() {
260
            Task task = RP.post(new NamedRunnable(title) {
224
            return false;
225
        }
226
    }
261
227
262
                @Override
228
    private static class MyCRP extends MyRP implements Cancellable {
263
                public void runImpl() {
229
264
                    try {
230
        private final Cancellable canceller;
265
                        workTask.run();
231
        private final AtomicBoolean wasCancelled = new AtomicBoolean(false);
266
                    } finally {
232
267
                        SwingUtilities.invokeLater(finalizer);
233
        public MyCRP(final Runnable task, final Cancellable canceller, final String message) {
268
                    }
234
            super(task, message);
269
                }
235
            this.canceller = canceller;
270
            });
236
        }
271
            return task;
237
238
        @Override
239
        public boolean cancel() {
240
            wasCancelled.set(true);
241
            return canceller.cancel();
242
        }
243
244
        @Override
245
        public boolean wasCancelled() {
246
            return wasCancelled.get();
272
        }
247
        }
273
    }
248
    }
274
}
249
}
(-)a/cnd.utils/src/org/netbeans/modules/cnd/utils/ui/ModalMessageDlgCancellablePane.form (-60 lines)
Lines 1-60 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
8
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
9
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
10
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
11
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
12
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
13
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
14
  </AuxValues>
15
16
  <Layout>
17
    <DimensionLayout dim="0">
18
      <Group type="103" groupAlignment="0" attributes="0">
19
          <Group type="102" attributes="0">
20
              <EmptySpace max="-2" attributes="0"/>
21
              <Group type="103" groupAlignment="0" attributes="0">
22
                  <Group type="102" attributes="0">
23
                      <Component id="lblMessage" pref="350" max="32767" attributes="0"/>
24
                      <EmptySpace max="-2" attributes="0"/>
25
                  </Group>
26
                  <Group type="102" alignment="1" attributes="0">
27
                      <Component id="btnCancel" min="-2" max="-2" attributes="0"/>
28
                      <EmptySpace min="-2" pref="136" max="-2" attributes="0"/>
29
                  </Group>
30
              </Group>
31
          </Group>
32
      </Group>
33
    </DimensionLayout>
34
    <DimensionLayout dim="1">
35
      <Group type="103" groupAlignment="0" attributes="0">
36
          <Group type="102" alignment="1" attributes="0">
37
              <EmptySpace pref="20" max="32767" attributes="0"/>
38
              <Component id="lblMessage" min="-2" max="-2" attributes="0"/>
39
              <EmptySpace type="separate" max="-2" attributes="0"/>
40
              <Component id="btnCancel" min="-2" max="-2" attributes="0"/>
41
              <EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
42
          </Group>
43
      </Group>
44
    </DimensionLayout>
45
  </Layout>
46
  <SubComponents>
47
    <Component class="javax.swing.JLabel" name="lblMessage">
48
    </Component>
49
    <Component class="javax.swing.JButton" name="btnCancel">
50
      <Properties>
51
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
52
          <ResourceString bundle="org/netbeans/modules/cnd/utils/ui/Bundle.properties" key="ModalMessageDlgCancellablePane.btnCancel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
53
        </Property>
54
      </Properties>
55
      <Events>
56
        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCancelActionPerformed"/>
57
      </Events>
58
    </Component>
59
  </SubComponents>
60
</Form>
(-)a/cnd.utils/src/org/netbeans/modules/cnd/utils/ui/ModalMessageDlgCancellablePane.java (-137 lines)
Lines 1-137 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
package org.netbeans.modules.cnd.utils.ui;
45
46
import javax.swing.SwingUtilities;
47
import org.openide.util.Cancellable;
48
import org.openide.util.NbBundle;
49
50
/**
51
 *
52
 * @author Vladimir Voskresensky
53
 */
54
/* package-local */
55
class ModalMessageDlgCancellablePane extends javax.swing.JPanel {
56
57
    private final Cancellable cancellable;
58
    private final String message;
59
60
    /** Creates new form ModalMessageDlg */
61
    /* package-local*/
62
    ModalMessageDlgCancellablePane(String message, Cancellable cancellable) {
63
        this.cancellable = cancellable;
64
        this.message = message;
65
        initComponents();
66
        lblMessage.setText(message);
67
    }
68
69
    /** This method is called from within the constructor to
70
     * initialize the form.
71
     * WARNING: Do NOT modify this code. The content of this method is
72
     * always regenerated by the Form Editor.
73
     */
74
    @SuppressWarnings("unchecked")
75
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
76
    private void initComponents() {
77
78
        lblMessage = new javax.swing.JLabel();
79
        btnCancel = new javax.swing.JButton();
80
81
        btnCancel.setText(org.openide.util.NbBundle.getMessage(ModalMessageDlgCancellablePane.class, "ModalMessageDlgCancellablePane.btnCancel.text")); // NOI18N
82
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
83
            public void actionPerformed(java.awt.event.ActionEvent evt) {
84
                btnCancelActionPerformed(evt);
85
            }
86
        });
87
88
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
89
        this.setLayout(layout);
90
        layout.setHorizontalGroup(
91
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
92
            .addGroup(layout.createSequentialGroup()
93
                .addContainerGap()
94
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
95
                    .addGroup(layout.createSequentialGroup()
96
                        .addComponent(lblMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)
97
                        .addContainerGap())
98
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
99
                        .addComponent(btnCancel)
100
                        .addGap(136, 136, 136))))
101
        );
102
        layout.setVerticalGroup(
103
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
104
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
105
                .addContainerGap(20, Short.MAX_VALUE)
106
                .addComponent(lblMessage)
107
                .addGap(18, 18, 18)
108
                .addComponent(btnCancel)
109
                .addGap(6, 6, 6))
110
        );
111
    }// </editor-fold>//GEN-END:initComponents
112
113
    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
114
        lblMessage.setText(NbBundle.getMessage(getClass(), "MSG_Cancelling"));
115
        btnCancel.setEnabled(false);
116
        Thread thread = new Thread(new Runnable() {
117
            @Override
118
            public void run() {
119
                if (!cancellable.cancel()) {
120
                    SwingUtilities.invokeLater(new Runnable() {
121
                        @Override
122
                        public void run() {
123
                            if (ModalMessageDlgCancellablePane.this.isVisible()) {
124
                                lblMessage.setText(NbBundle.getMessage(getClass(), "MSG_CancelFailed", message));
125
                            }
126
                        }
127
                    });
128
                }
129
            }
130
        }, ModalMessageDlg.class.getSimpleName() + " cancellation thread"); //NOI18N
131
        thread.start();
132
}//GEN-LAST:event_btnCancelActionPerformed
133
    // Variables declaration - do not modify//GEN-BEGIN:variables
134
    private javax.swing.JButton btnCancel;
135
    private javax.swing.JLabel lblMessage;
136
    // End of variables declaration//GEN-END:variables
137
}
(-)a/cnd.utils/src/org/netbeans/modules/cnd/utils/ui/ModalMessageDlgPane.form (-40 lines)
Lines 1-40 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
8
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
9
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
10
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
11
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
12
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
13
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
14
  </AuxValues>
15
16
  <Layout>
17
    <DimensionLayout dim="0">
18
      <Group type="103" groupAlignment="0" attributes="0">
19
          <Group type="102" alignment="0" attributes="0">
20
              <EmptySpace max="-2" attributes="0"/>
21
              <Component id="lblMessage" pref="350" max="32767" attributes="0"/>
22
              <EmptySpace max="-2" attributes="0"/>
23
          </Group>
24
      </Group>
25
    </DimensionLayout>
26
    <DimensionLayout dim="1">
27
      <Group type="103" groupAlignment="0" attributes="0">
28
          <Group type="102" alignment="1" attributes="0">
29
              <EmptySpace pref="28" max="32767" attributes="0"/>
30
              <Component id="lblMessage" min="-2" max="-2" attributes="0"/>
31
              <EmptySpace max="-2" attributes="0"/>
32
          </Group>
33
      </Group>
34
    </DimensionLayout>
35
  </Layout>
36
  <SubComponents>
37
    <Component class="javax.swing.JLabel" name="lblMessage">
38
    </Component>
39
  </SubComponents>
40
</Form>
(-)a/cnd.utils/src/org/netbeans/modules/cnd/utils/ui/ModalMessageDlgPane.java (-94 lines)
Lines 1-94 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
package org.netbeans.modules.cnd.utils.ui;
45
46
/**
47
 *
48
 * @author Vladimir Voskresensky
49
 */
50
/* package-local */
51
class ModalMessageDlgPane extends javax.swing.JPanel {
52
53
    /** Creates new form ModalMessageDlg */
54
    /* package-local*/
55
    ModalMessageDlgPane(String message) {
56
        initComponents();
57
        lblMessage.setText(message);
58
    }
59
60
    /** This method is called from within the constructor to
61
     * initialize the form.
62
     * WARNING: Do NOT modify this code. The content of this method is
63
     * always regenerated by the Form Editor.
64
     */
65
    @SuppressWarnings("unchecked")
66
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
67
    private void initComponents() {
68
69
        lblMessage = new javax.swing.JLabel();
70
71
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
72
        this.setLayout(layout);
73
        layout.setHorizontalGroup(
74
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
75
            .addGroup(layout.createSequentialGroup()
76
                .addContainerGap()
77
                .addComponent(lblMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)
78
                .addContainerGap())
79
        );
80
        layout.setVerticalGroup(
81
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
82
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
83
                .addContainerGap(28, Short.MAX_VALUE)
84
                .addComponent(lblMessage)
85
                .addContainerGap())
86
        );
87
    }// </editor-fold>//GEN-END:initComponents
88
89
90
    // Variables declaration - do not modify//GEN-BEGIN:variables
91
    private javax.swing.JLabel lblMessage;
92
    // End of variables declaration//GEN-END:variables
93
94
}

Return to bug 223810