KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > module > run > RunLastTargetAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.apache.tools.ant.module.run;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.io.IOException JavaDoc;
25 import javax.swing.AbstractAction JavaDoc;
26 import javax.swing.Action JavaDoc;
27 import javax.swing.JButton JavaDoc;
28 import javax.swing.JComponent JavaDoc;
29 import javax.swing.JMenuItem JavaDoc;
30 import javax.swing.event.ChangeEvent JavaDoc;
31 import javax.swing.event.ChangeListener JavaDoc;
32 import org.apache.tools.ant.module.AntModule;
33 import org.openide.awt.Actions;
34 import org.openide.awt.DynamicMenuContent;
35 import org.openide.awt.Mnemonics;
36 import org.openide.util.NbBundle;
37 import org.openide.util.RequestProcessor;
38 import org.openide.util.WeakListeners;
39 import org.openide.util.actions.Presenter;
40
41 /**
42  * An action to run the last Ant build.
43  * @see "#47925"
44  */

45 public final class RunLastTargetAction extends AbstractAction JavaDoc implements ChangeListener JavaDoc, Presenter.Menu, Presenter.Toolbar {
46     
47     public RunLastTargetAction() {
48         super(NbBundle.getMessage(RunLastTargetAction.class, "LBL_RunLastTargetAction_general")/*,
49                 new ImageIcon(Utilities.loadImage("org/apache/tools/ant/module/resources/AntIcon.gif", true))*/
);
50         LastTargetExecuted.addChangeListener(WeakListeners.change(this, LastTargetExecuted.class));
51     }
52     
53     @Override JavaDoc
54     public boolean isEnabled() {
55         return LastTargetExecuted.getLastBuildScript() != null;
56     }
57     
58     @Override JavaDoc
59     public Object JavaDoc getValue(String JavaDoc key) {
60         if (key.equals(Action.SHORT_DESCRIPTION)) {
61             String JavaDoc display = LastTargetExecuted.getProcessDisplayName();
62             if (display != null) {
63                 return NbBundle.getMessage(RunLastTargetAction.class, "TIP_RunLastTargetAction_specific", display);
64             } else {
65                 return null;
66             }
67         } else {
68             return super.getValue(key);
69         }
70     }
71     
72     public void actionPerformed(ActionEvent JavaDoc e) {
73         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
74             public void run() {
75                 try {
76                     LastTargetExecuted.rerun();
77                 } catch (IOException JavaDoc ioe) {
78                     AntModule.err.notify(ioe);
79                 }
80             }
81         });
82     }
83
84     public void stateChanged(ChangeEvent JavaDoc e) {
85         firePropertyChange("enabled", null, Boolean.valueOf(isEnabled())); // NOI18N
86
firePropertyChange(Action.SHORT_DESCRIPTION, null, null);
87     }
88
89     public JMenuItem JavaDoc getMenuPresenter() {
90         class SpecialMenuItem extends JMenuItem JavaDoc implements DynamicMenuContent {
91             public SpecialMenuItem() {
92                 super(RunLastTargetAction.this);
93             }
94             public JComponent JavaDoc[] getMenuPresenters() {
95                 String JavaDoc label;
96                 String JavaDoc display = LastTargetExecuted.getProcessDisplayName();
97                 if (display != null) {
98                     label = NbBundle.getMessage(RunLastTargetAction.class, "LBL_RunLastTargetAction_specific", display);
99                 } else {
100                     label = (String JavaDoc) getValue(Action.NAME);
101                 }
102                 Mnemonics.setLocalizedText(this, label);
103                 return new JComponent JavaDoc[] {this};
104             }
105             public JComponent JavaDoc[] synchMenuPresenters(JComponent JavaDoc[] items) {
106                 return getMenuPresenters();
107             }
108         }
109         return new SpecialMenuItem();
110     }
111
112     public Component JavaDoc getToolbarPresenter() {
113         JButton JavaDoc button = new JButton JavaDoc();
114         Actions.connect(button, this);
115         return button;
116     }
117
118 }
119
Popular Tags