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 110465
Collapse All | Expand All

(-)f0e47b0d1a84 (+1 lines)
Added Link Here
1
org.netbeans.modules.project.ui.actions.BuildExecutionSupportImpl
(-)a/projectui/src/org/netbeans/modules/project/ui/actions/Actions.java (+3 lines)
Lines 340-343 Link Here
340
        return SystemAction.get(ActiveConfigAction.class);
340
        return SystemAction.get(ActiveConfigAction.class);
341
    }
341
    }
342
342
343
    public static Action rebuildProjectAction() {
344
        return new RunLastBuildAction();
345
    }
343
}
346
}
(-)f0e47b0d1a84 (+119 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.project.ui.actions;
41
42
import java.util.ArrayList;
43
import java.util.List;
44
import javax.swing.event.ChangeEvent;
45
import javax.swing.event.ChangeListener;
46
import org.netbeans.modules.project.uiapi.BuildExecutionSupportImplementation;
47
import org.netbeans.spi.project.ui.support.BuildExecutionSupport;
48
import org.netbeans.spi.project.ui.support.BuildExecutionSupport.Item;
49
import org.openide.util.Lookup;
50
51
/**
52
 *
53
 * @author mkleint
54
 */
55
public class BuildExecutionSupportImpl implements BuildExecutionSupportImplementation {
56
57
    private final List<ChangeListener> listeners = new ArrayList<ChangeListener>();
58
59
    private final List<BuildExecutionSupport.Item> runningItems = new ArrayList<BuildExecutionSupport.Item>();
60
    private BuildExecutionSupport.Item lastFinishedItem;
61
62
    public static BuildExecutionSupportImpl getInstance() {
63
        BuildExecutionSupportImplementation im = Lookup.getDefault().lookup(BuildExecutionSupportImplementation.class);
64
        return (BuildExecutionSupportImpl)im;
65
    }
66
67
    public void registerFinishedItem(Item item) {
68
        synchronized (runningItems) {
69
            lastFinishedItem = item;
70
            runningItems.remove(item);
71
        }
72
        fireChange();
73
    }
74
75
    public void registerRunningItem(Item item) {
76
        synchronized (runningItems) {
77
            runningItems.add(item);
78
        }
79
        fireChange();
80
    }
81
82
    public void addChangeListener(ChangeListener listener) {
83
        synchronized (listeners) {
84
            listeners.add(listener);
85
        }
86
    }
87
88
    public void removeChangeListener(ChangeListener listener) {
89
        synchronized (listeners) {
90
            listeners.remove(listener);
91
        }
92
    }
93
94
    BuildExecutionSupport.Item getLastItem() {
95
        synchronized (runningItems) {
96
            return lastFinishedItem;
97
        }
98
    }
99
100
    List<BuildExecutionSupport.Item> getRunningItems() {
101
        List<BuildExecutionSupport.Item> items = new ArrayList<BuildExecutionSupport.Item>();
102
        synchronized (runningItems) {
103
            items.addAll(runningItems);
104
        }
105
        return items;
106
    }
107
108
    private void fireChange() {
109
        List<ChangeListener> lsts;
110
        synchronized (listeners) {
111
            lsts = new ArrayList<ChangeListener>(listeners);
112
        }
113
        ChangeEvent event = new ChangeEvent(this);
114
        for (ChangeListener l : lsts) {
115
            l.stateChanged(event);
116
        }
117
    }
118
119
}
(-)a/projectui/src/org/netbeans/modules/project/ui/actions/Bundle.properties (+18 lines)
Lines 137-139 Link Here
137
CustomizeProject.save_modified_title=Save modified files
137
CustomizeProject.save_modified_title=Save modified files
138
138
139
ERR_InvalidProject=The project is either not valid or deleted
139
ERR_InvalidProject=The project is either not valid or deleted
140
141
# RunLastBuildAction
142
LBL_RunLastBuildAction_general=Re&peat Build/Run
143
# {0} - display name of previous build
144
TIP_RunLastBuildAction_specific=Repeat Build/Run: {0}
145
# {0} - display name of previous build
146
LBL_RunLastBuildAction_specific=Re&peat Build/Run: {0}
147
148
# StopBuildingAction
149
LBL_stop_building=&Stop Build/Run
150
# {0} - display name of previous build
151
LBL_stop_building_one=&Stop Build/Run: {0}
152
LBL_stop_building_many=&Stop Build/Run...
153
LBL_SBA_intro=Multiple build/run processes are running simultaneously.
154
LBL_SBA_select=&Select the processes to stop:
155
TITLE_SBA=Stop Build/Run
156
LBL_SBA_stop=Stop
157
(-)f0e47b0d1a84 (+141 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.project.ui.actions;
43
44
import java.awt.Component;
45
import java.awt.event.ActionEvent;
46
import javax.swing.AbstractAction;
47
import javax.swing.Action;
48
import javax.swing.JButton;
49
import javax.swing.JComponent;
50
import javax.swing.JMenuItem;
51
import javax.swing.event.ChangeEvent;
52
import javax.swing.event.ChangeListener;
53
import org.netbeans.modules.project.uiapi.BuildExecutionSupportImplementation;
54
import org.netbeans.spi.project.ui.support.BuildExecutionSupport;
55
import org.openide.awt.Actions;
56
import org.openide.awt.DynamicMenuContent;
57
import org.openide.awt.Mnemonics;
58
import org.openide.util.NbBundle;
59
import org.openide.util.RequestProcessor;
60
import org.openide.util.WeakListeners;
61
import org.openide.util.actions.Presenter;
62
63
/**
64
 * An action to run the last Ant build.
65
 * @see "#47925"
66
 */
67
public final class RunLastBuildAction extends AbstractAction implements ChangeListener, Presenter.Menu, Presenter.Toolbar {
68
    
69
    public RunLastBuildAction() {
70
        super(NbBundle.getMessage(RunLastBuildAction.class, "LBL_RunLastBuildAction_general")/*,
71
                new ImageIcon(Utilities.loadImage("org/apache/tools/ant/module/resources/AntIcon.gif", true))*/);
72
        BuildExecutionSupportImpl.getInstance().addChangeListener(WeakListeners.change(this, BuildExecutionSupportImplementation.class));
73
    }
74
    
75
    @Override
76
    public boolean isEnabled() {
77
        return BuildExecutionSupportImpl.getInstance().getLastItem() != null;
78
    }
79
    
80
    @Override
81
    public Object getValue(String key) {
82
        if (key.equals(Action.SHORT_DESCRIPTION)) {
83
            BuildExecutionSupport.Item item = BuildExecutionSupportImpl.getInstance().getLastItem();
84
            if (item != null) {
85
                String display = item.getDisplayName();
86
                return NbBundle.getMessage(RunLastBuildAction.class, "TIP_RunLastBuildAction_specific", display);
87
            } else {
88
                return null;
89
            }
90
        } else {
91
            return super.getValue(key);
92
        }
93
    }
94
    
95
    public void actionPerformed(ActionEvent e) {
96
        RequestProcessor.getDefault().post(new Runnable() {
97
            public void run() {
98
                BuildExecutionSupport.Item item = BuildExecutionSupportImpl.getInstance().getLastItem();
99
                if (item != null) {
100
                    item.repeatExecution();
101
                }
102
            }
103
        });
104
    }
105
106
    public void stateChanged(ChangeEvent e) {
107
        firePropertyChange("enabled", null, Boolean.valueOf(isEnabled())); // NOI18N
108
        firePropertyChange(Action.SHORT_DESCRIPTION, null, null);
109
    }
110
111
    public JMenuItem getMenuPresenter() {
112
        class SpecialMenuItem extends JMenuItem implements DynamicMenuContent {
113
            public SpecialMenuItem() {
114
                super(RunLastBuildAction.this);
115
            }
116
            public JComponent[] getMenuPresenters() {
117
                String label;
118
                BuildExecutionSupport.Item item = BuildExecutionSupportImpl.getInstance().getLastItem();
119
                if (item != null) {
120
                    String display = item.getDisplayName();
121
                    label = NbBundle.getMessage(RunLastBuildAction.class, "LBL_RunLastBuildAction_specific", display);
122
                } else {
123
                    label = (String) getValue(Action.NAME);
124
                }
125
                Mnemonics.setLocalizedText(this, label);
126
                return new JComponent[] {this};
127
            }
128
            public JComponent[] synchMenuPresenters(JComponent[] items) {
129
                return getMenuPresenters();
130
            }
131
        }
132
        return new SpecialMenuItem();
133
    }
134
135
    public Component getToolbarPresenter() {
136
        JButton button = new JButton();
137
        Actions.connect(button, this);
138
        return button;
139
    }
140
141
}
(-)f0e47b0d1a84 (+149 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.project.ui.actions;
43
44
import java.util.List;
45
import javax.swing.JComponent;
46
import javax.swing.JMenuItem;
47
import javax.swing.SwingUtilities;
48
import javax.swing.event.ChangeEvent;
49
import javax.swing.event.ChangeListener;
50
import org.netbeans.modules.project.uiapi.BuildExecutionSupportImplementation;
51
import org.netbeans.spi.project.ui.support.BuildExecutionSupport;
52
import org.openide.awt.DynamicMenuContent;
53
import org.openide.awt.Mnemonics;
54
import org.openide.util.HelpCtx;
55
import org.openide.util.NbBundle;
56
import org.openide.util.WeakListeners;
57
import org.openide.util.actions.CallableSystemAction;
58
import org.openide.util.actions.SystemAction;
59
60
/**
61
 * Action which stops the currently running Ant process.
62
 * If there is more than one, a dialog appears asking you to select one.
63
 * @author Jesse Glick
64
 * @see "issue #43143"
65
 */
66
public final class StopBuildingAction extends CallableSystemAction implements ChangeListener {
67
    
68
   public StopBuildingAction()  {
69
       super();
70
        BuildExecutionSupportImpl.getInstance().addChangeListener(WeakListeners.change(this, BuildExecutionSupportImplementation.class));
71
   }
72
73
    @Override
74
    public void performAction() {
75
        List<BuildExecutionSupport.Item> toStop = BuildExecutionSupportImpl.getInstance().getRunningItems();
76
77
        if (toStop.size() > 1) {
78
            // More than one, need to select one.
79
            toStop = StopBuildingAlert.selectProcessToKill(toStop);
80
        }
81
        for (BuildExecutionSupport.Item t : toStop) {
82
            if (t != null) {
83
                t.stopRunning();
84
            }
85
        }
86
    }
87
88
    @Override
89
    public String getName() {
90
        return NbBundle.getMessage(StopBuildingAction.class, "LBL_stop_building");
91
    }
92
93
    @Override
94
    public HelpCtx getHelpCtx() {
95
        return null;
96
    }
97
98
    @Override
99
    protected void initialize() {
100
        super.initialize();
101
        setEnabled(false); // no processes initially
102
    }
103
104
    @Override
105
    protected boolean asynchronous() {
106
        return false;
107
    }
108
    
109
    @Override
110
    public JMenuItem getMenuPresenter() {
111
        class SpecialMenuItem extends JMenuItem implements DynamicMenuContent {
112
            public SpecialMenuItem() {
113
                super(StopBuildingAction.this);
114
            }
115
            public JComponent[] getMenuPresenters() {
116
                String label = NbBundle.getMessage(StopBuildingAction.class, "LBL_stop_building");
117
                List<BuildExecutionSupport.Item> items = BuildExecutionSupportImpl.getInstance().getRunningItems();
118
                switch (items.size()) {
119
                    case 0:
120
                        label = NbBundle.getMessage(StopBuildingAction.class, "LBL_stop_building");
121
                        break;
122
                    case 1:
123
                        label = NbBundle.getMessage(StopBuildingAction.class, "LBL_stop_building_one",
124
                                items.iterator().next().getDisplayName());
125
                        break;
126
                    default:
127
                        label = NbBundle.getMessage(StopBuildingAction.class, "LBL_stop_building_many");
128
                }
129
                Mnemonics.setLocalizedText(this, label);
130
                return new JComponent[] {this};
131
            }
132
            public JComponent[] synchMenuPresenters(JComponent[] items) {
133
                return getMenuPresenters();
134
            }
135
        }
136
        return new SpecialMenuItem();
137
    }
138
139
    public void stateChanged(ChangeEvent e) {
140
        final List<BuildExecutionSupport.Item> items = BuildExecutionSupportImpl.getInstance().getRunningItems();
141
142
        SwingUtilities.invokeLater(new Runnable() {
143
            public void run() {
144
                SystemAction.get(StopBuildingAction.class).setEnabled(items.size() > 0);
145
            }
146
        });
147
    }
148
    
149
}
(-)f0e47b0d1a84 (+84 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.4" maxVersion="1.4" 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="true"/>
9
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
10
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
11
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="2"/>
12
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
13
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="1"/>
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
              <Group type="103" groupAlignment="0" max="-2" attributes="0">
22
                  <Group type="102" alignment="0" attributes="1">
23
                      <Component id="buildsScrollPane" pref="376" max="32767" attributes="1"/>
24
                      <EmptySpace max="-2" attributes="0"/>
25
                  </Group>
26
                  <Group type="102" alignment="0" attributes="0">
27
                      <Group type="103" groupAlignment="0" max="-2" attributes="0">
28
                          <Component id="buildsLabel" alignment="0" min="-2" max="-2" attributes="0"/>
29
                          <Component id="introLabel" alignment="0" max="32767" attributes="0"/>
30
                      </Group>
31
                      <EmptySpace min="-2" pref="28" max="-2" attributes="0"/>
32
                  </Group>
33
              </Group>
34
          </Group>
35
      </Group>
36
    </DimensionLayout>
37
    <DimensionLayout dim="1">
38
      <Group type="103" groupAlignment="0" attributes="0">
39
          <Group type="102" attributes="0">
40
              <EmptySpace max="-2" attributes="0"/>
41
              <Component id="introLabel" min="-2" max="-2" attributes="0"/>
42
              <EmptySpace max="-2" attributes="0"/>
43
              <Component id="buildsLabel" min="-2" max="-2" attributes="0"/>
44
              <EmptySpace max="-2" attributes="0"/>
45
              <Component id="buildsScrollPane" pref="234" max="32767" attributes="0"/>
46
              <EmptySpace max="-2" attributes="0"/>
47
          </Group>
48
      </Group>
49
    </DimensionLayout>
50
  </Layout>
51
  <SubComponents>
52
    <Component class="javax.swing.JLabel" name="introLabel">
53
      <Properties>
54
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
55
          <ResourceString bundle="org/netbeans/modules/project/ui/actions/Bundle.properties" key="LBL_SBA_intro" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
56
        </Property>
57
      </Properties>
58
      <AuxValues>
59
        <AuxValue name="generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
60
      </AuxValues>
61
    </Component>
62
    <Component class="javax.swing.JLabel" name="buildsLabel">
63
      <Properties>
64
        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
65
          <ComponentRef name="buildsList"/>
66
        </Property>
67
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
68
          <ResourceString bundle="org/netbeans/modules/project/ui/actions/Bundle.properties" key="LBL_SBA_select" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
69
        </Property>
70
      </Properties>
71
      <AuxValues>
72
        <AuxValue name="generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
73
      </AuxValues>
74
    </Component>
75
    <Container class="javax.swing.JScrollPane" name="buildsScrollPane">
76
77
      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
78
      <SubComponents>
79
        <Component class="javax.swing.JList" name="buildsList">
80
        </Component>
81
      </SubComponents>
82
    </Container>
83
  </SubComponents>
84
</Form>
(-)f0e47b0d1a84 (+193 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.project.ui.actions;
43
44
import java.awt.Component;
45
import java.text.Collator;
46
import java.util.ArrayList;
47
import java.util.Arrays;
48
import java.util.Comparator;
49
import java.util.List;
50
import java.util.SortedSet;
51
import java.util.TreeSet;
52
import javax.swing.DefaultListCellRenderer;
53
import javax.swing.DefaultListModel;
54
import javax.swing.JButton;
55
import javax.swing.JList;
56
import javax.swing.JPanel;
57
import javax.swing.event.ListSelectionEvent;
58
import javax.swing.event.ListSelectionListener;
59
import org.netbeans.spi.project.ui.support.BuildExecutionSupport;
60
import org.openide.DialogDescriptor;
61
import org.openide.DialogDisplayer;
62
import org.openide.NotifyDescriptor;
63
import org.openide.util.NbBundle;
64
65
/**
66
 * Displays an alert asking user to pick a running build to stop.
67
 * @author Jesse Glick
68
 */
69
final class StopBuildingAlert extends JPanel {
70
    
71
    static List<BuildExecutionSupport.Item> selectProcessToKill(List<BuildExecutionSupport.Item> toStop) {
72
        // Add all threads, sorted by display name.
73
        DefaultListModel model = new DefaultListModel();
74
        StopBuildingAlert alert = new StopBuildingAlert();
75
        final JList list = alert.buildsList;
76
        Comparator<BuildExecutionSupport.Item> comp = new Comparator<BuildExecutionSupport.Item>() {
77
            private final Collator coll = Collator.getInstance();
78
            public int compare(BuildExecutionSupport.Item t1, BuildExecutionSupport.Item t2) {
79
                String n1 = t1.getDisplayName();
80
                String n2 = t2.getDisplayName();
81
                int r = coll.compare(n1, n2);
82
                if (r != 0) {
83
                    return r;
84
                } else {
85
                    // Arbitrary. XXX Note that there is no way to predict which is
86
                    // which if you have more than one build running. Ideally it
87
                    // would be subsorted by creation time, probably.
88
                    return System.identityHashCode(t1) - System.identityHashCode(t2);
89
                }
90
            }
91
        };
92
        SortedSet<BuildExecutionSupport.Item> items = new TreeSet<BuildExecutionSupport.Item>(comp);
93
        items.addAll(toStop);
94
95
        for (BuildExecutionSupport.Item t : items) {
96
            model.addElement(t);
97
        }
98
        list.setModel(model);
99
        list.setSelectedIndex(0);
100
        // Make a dialog with buttons "Stop Building" and "Cancel".
101
        DialogDescriptor dd = new DialogDescriptor(alert, NbBundle.getMessage(StopBuildingAlert.class, "TITLE_SBA"));
102
        dd.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
103
        final JButton stopButton = new JButton(NbBundle.getMessage(StopBuildingAlert.class, "LBL_SBA_stop"));
104
        list.addListSelectionListener(new ListSelectionListener() {
105
            public void valueChanged(ListSelectionEvent e) {
106
                stopButton.setEnabled(list.getSelectedValue() != null);
107
            }
108
        });
109
        dd.setOptions(new Object[] {stopButton, DialogDescriptor.CANCEL_OPTION});
110
        DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
111
        List<BuildExecutionSupport.Item> toRet = new ArrayList<BuildExecutionSupport.Item>();
112
        if (dd.getValue() == stopButton) {
113
            Object[] selectedItems = list.getSelectedValues();
114
            for (Object o : selectedItems) {
115
                toRet.add((BuildExecutionSupport.Item)o);
116
            }
117
        }
118
        return toRet;
119
120
    }
121
    
122
    
123
    private StopBuildingAlert() {
124
        initComponents();
125
        buildsList.setCellRenderer(new ProcessCellRenderer());
126
    }
127
    
128
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
129
    private void initComponents() {
130
131
        introLabel = new javax.swing.JLabel();
132
        buildsLabel = new javax.swing.JLabel();
133
        buildsScrollPane = new javax.swing.JScrollPane();
134
        buildsList = new javax.swing.JList();
135
136
        org.openide.awt.Mnemonics.setLocalizedText(introLabel, org.openide.util.NbBundle.getMessage(StopBuildingAlert.class, "LBL_SBA_intro")); // NOI18N
137
138
        buildsLabel.setLabelFor(buildsList);
139
        org.openide.awt.Mnemonics.setLocalizedText(buildsLabel, org.openide.util.NbBundle.getMessage(StopBuildingAlert.class, "LBL_SBA_select")); // NOI18N
140
141
        buildsScrollPane.setViewportView(buildsList);
142
143
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
144
        this.setLayout(layout);
145
        layout.setHorizontalGroup(
146
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
147
            .add(layout.createSequentialGroup()
148
                .addContainerGap()
149
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
150
                    .add(layout.createSequentialGroup()
151
                        .add(buildsScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
152
                        .addContainerGap())
153
                    .add(layout.createSequentialGroup()
154
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
155
                            .add(buildsLabel)
156
                            .add(introLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
157
                        .add(28, 28, 28))))
158
        );
159
        layout.setVerticalGroup(
160
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
161
            .add(layout.createSequentialGroup()
162
                .addContainerGap()
163
                .add(introLabel)
164
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
165
                .add(buildsLabel)
166
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
167
                .add(buildsScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
168
                .addContainerGap())
169
        );
170
    }// </editor-fold>//GEN-END:initComponents
171
    
172
    
173
    // Variables declaration - do not modify//GEN-BEGIN:variables
174
    public javax.swing.JLabel buildsLabel;
175
    public javax.swing.JList buildsList;
176
    public javax.swing.JScrollPane buildsScrollPane;
177
    public javax.swing.JLabel introLabel;
178
    // End of variables declaration//GEN-END:variables
179
180
    private final class ProcessCellRenderer extends DefaultListCellRenderer/*<Thread>*/ {
181
        
182
        public ProcessCellRenderer() {}
183
184
        @Override
185
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
186
            BuildExecutionSupport.Item t = (BuildExecutionSupport.Item) value;
187
            String displayName = t.getDisplayName();
188
            return super.getListCellRendererComponent(list, displayName, index, isSelected, cellHasFocus);
189
        }
190
        
191
    }
192
    
193
}
(-)a/projectui/src/org/netbeans/modules/project/ui/resources/layer.xml (-1 / +13 lines)
Lines 132-137 Link Here
132
            <file name="org-netbeans-modules-project-ui-TestSingle.instance">
132
            <file name="org-netbeans-modules-project-ui-TestSingle.instance">
133
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.project.ui.actions.Actions.testSingle"/>
133
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.project.ui.actions.Actions.testSingle"/>
134
            </file>
134
            </file>
135
136
            <file name="org-netbeans-modules-project-ui-Rerun.instance">
137
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.project.ui.actions.Actions.rebuildProjectAction"/>
138
            </file>
139
            <file name="org-netbeans-modules-project-ui-actions.StopBuildingAction.instance">
140
            </file>
135
            
141
            
136
            <!-- Project tabs opening -->
142
            <!-- Project tabs opening -->
137
            <file name="org-netbeans-modules-project-ui-logical-tab-action.instance">
143
            <file name="org-netbeans-modules-project-ui-logical-tab-action.instance">
Lines 391-397 Link Here
391
                <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
397
                <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
392
                <attr name="position" intvalue="900"/>
398
                <attr name="position" intvalue="900"/>
393
            </file>
399
            </file>
394
            
400
            <file name="org-netbeans-modules-project-ui-Rerun.shadow">
401
                <attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-Rerun.instance"/>
402
                <attr name="position" intvalue="1000"/>
403
            </file>
404
            <file name="org-netbeans-modules-project-ui-actions.StopBuildingAction.instance">
405
                <attr name="position" intvalue="1100"/>
406
            </file>
395
        </folder>
407
        </folder>
396
408
397
        <folder name="RunProject">
409
        <folder name="RunProject">
(-)a/projectuiapi/apichanges.xml (+17 lines)
Lines 105-110 Link Here
105
105
106
    <changes>
106
    <changes>
107
        
107
        
108
        <change id="stop-repeat-build">
109
           <api name="general"/>
110
           <summary>Pluggable Repeat/Stop build actions</summary>
111
           <version major="1" minor="32"/>
112
           <date day="23" month="10" year="2008"/>
113
           <author login="mkleint"/>
114
           <compatibility modification="yes" semantic="compatible"/>
115
           <description>
116
               <p>
117
                    Added spi for plugging into the Repeat Build/Run and Stop Build/Run
118
                    actions that were previsouly accessible to ant based projects only.
119
               </p>
120
           </description>
121
           <class package="org.netbeans.spi.project.ui.support" name="BuildExecutionSupport"/>
122
           <issue number="110465"/>
123
        </change>
124
108
        <change id="ProjectsRootNode-badging">
125
        <change id="ProjectsRootNode-badging">
109
           <api name="general"/>
126
           <api name="general"/>
110
           <summary>Project root nodes automatically badged</summary>
127
           <summary>Project root nodes automatically badged</summary>
(-)a/projectuiapi/nbproject/project.properties (-1 / +1 lines)
Lines 39-45 Link Here
39
39
40
javac.compilerargs=-Xlint -Xlint:-serial
40
javac.compilerargs=-Xlint -Xlint:-serial
41
javac.source=1.5
41
javac.source=1.5
42
spec.version.base=1.31.0
42
spec.version.base=1.32.0
43
is.autoload=true
43
is.autoload=true
44
javadoc.arch=${basedir}/arch.xml
44
javadoc.arch=${basedir}/arch.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
(-)f0e47b0d1a84 (+59 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.project.uiapi;
41
42
import javax.swing.event.ChangeListener;
43
import org.netbeans.spi.project.ui.support.BuildExecutionSupport;
44
45
/**
46
 *
47
 * @author mkleint
48
 */
49
public interface BuildExecutionSupportImplementation {
50
51
    void registerFinishedItem(BuildExecutionSupport.Item item);
52
53
    void registerRunningItem(BuildExecutionSupport.Item item);
54
55
    void addChangeListener(ChangeListener listener);
56
57
    void removeChangeListener(ChangeListener listener);
58
59
}
(-)a/projectuiapi/src/org/netbeans/modules/project/uiapi/Utilities.java (+8 lines)
Lines 63-68 Link Here
63
        assert instance != null : "Need to have " + ActionsFactory.class.getName() + " instance in the default lookup";
63
        assert instance != null : "Need to have " + ActionsFactory.class.getName() + " instance in the default lookup";
64
        return instance;
64
        return instance;
65
    }
65
    }
66
67
    /** Gets BuildSupportImpl from the global Lookup.
68
     */
69
    public static BuildExecutionSupportImplementation getBuildExecutionSupportImplementation() {
70
        BuildExecutionSupportImplementation instance = Lookup.getDefault().lookup(BuildExecutionSupportImplementation.class);
71
        assert instance != null : "Need to have " + BuildExecutionSupportImplementation.class.getName() + " instance in the default lookup";
72
        return instance;
73
    }
66
    
74
    
67
    /** Gets the projectChooser factory from the global Lookup
75
    /** Gets the projectChooser factory from the global Lookup
68
     */
76
     */
(-)f0e47b0d1a84 (+103 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.project.ui.support;
41
42
import org.netbeans.modules.project.uiapi.Utilities;
43
44
/**
45
 * Register running and finished build/run/debug tasks for use
46
 * by generic project UI, like "Repeat Build" action or "Stop Build" action
47
 * in main menu.
48
 *
49
 * @author mkleint
50
 * @since org.netbeans.modules.projectuiapi/1 1.32
51
 */
52
public final class BuildExecutionSupport {
53
54
    private BuildExecutionSupport() {
55
        
56
    }
57
    /**
58
     * Notify that the build job was started and pass a reference to it.
59
     * It is assumed that the given job instance is registered only once.
60
     * @param item
61
     */
62
    public static void registerRunningItem(BuildExecutionSupport.Item item) {
63
        Utilities.getBuildExecutionSupportImplementation().registerRunningItem(item);
64
    }
65
66
    /**
67
     * Notify that the build job finished. The instance passed shall be the same
68
     * (or at least equal) to the one passed to registerRunningItem().
69
     * It is assumed that the given job instance is registered only once and only after the
70
     * registerRunningItem() method was called.
71
     * @param item
72
     */
73
    public static void registerFinishedItem(BuildExecutionSupport.Item item) {
74
        Utilities.getBuildExecutionSupportImplementation().registerFinishedItem(item);
75
    }
76
77
    /**
78
     * Wrapper for the build job used by <code>BuildExecutionSupport</code>
79
     */
80
    public static interface Item {
81
        /**
82
         * Display name of the build job
83
         * @return
84
         */
85
        String getDisplayName();
86
        /**
87
         * Trigger re-execution of the build job.
88
         */
89
        void repeatExecution();
90
91
        /**
92
         * Check wheather the build job has finished or not.
93
         * @return
94
         */
95
        boolean isRunning();
96
97
        /**
98
         * Request to stop the execution of the build job.
99
         */
100
        void stopRunning();
101
102
    }
103
}

Return to bug 110465