1 19 20 package org.apache.tools.ant.module.run; 21 22 import java.awt.Component ; 23 import java.awt.event.ActionEvent ; 24 import java.io.IOException ; 25 import javax.swing.AbstractAction ; 26 import javax.swing.Action ; 27 import javax.swing.JButton ; 28 import javax.swing.JComponent ; 29 import javax.swing.JMenuItem ; 30 import javax.swing.event.ChangeEvent ; 31 import javax.swing.event.ChangeListener ; 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 45 public final class RunLastTargetAction extends AbstractAction implements ChangeListener , Presenter.Menu, Presenter.Toolbar { 46 47 public RunLastTargetAction() { 48 super(NbBundle.getMessage(RunLastTargetAction.class, "LBL_RunLastTargetAction_general")); 50 LastTargetExecuted.addChangeListener(WeakListeners.change(this, LastTargetExecuted.class)); 51 } 52 53 @Override 54 public boolean isEnabled() { 55 return LastTargetExecuted.getLastBuildScript() != null; 56 } 57 58 @Override 59 public Object getValue(String key) { 60 if (key.equals(Action.SHORT_DESCRIPTION)) { 61 String 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 e) { 73 RequestProcessor.getDefault().post(new Runnable () { 74 public void run() { 75 try { 76 LastTargetExecuted.rerun(); 77 } catch (IOException ioe) { 78 AntModule.err.notify(ioe); 79 } 80 } 81 }); 82 } 83 84 public void stateChanged(ChangeEvent e) { 85 firePropertyChange("enabled", null, Boolean.valueOf(isEnabled())); firePropertyChange(Action.SHORT_DESCRIPTION, null, null); 87 } 88 89 public JMenuItem getMenuPresenter() { 90 class SpecialMenuItem extends JMenuItem implements DynamicMenuContent { 91 public SpecialMenuItem() { 92 super(RunLastTargetAction.this); 93 } 94 public JComponent [] getMenuPresenters() { 95 String label; 96 String display = LastTargetExecuted.getProcessDisplayName(); 97 if (display != null) { 98 label = NbBundle.getMessage(RunLastTargetAction.class, "LBL_RunLastTargetAction_specific", display); 99 } else { 100 label = (String ) getValue(Action.NAME); 101 } 102 Mnemonics.setLocalizedText(this, label); 103 return new JComponent [] {this}; 104 } 105 public JComponent [] synchMenuPresenters(JComponent [] items) { 106 return getMenuPresenters(); 107 } 108 } 109 return new SpecialMenuItem(); 110 } 111 112 public Component getToolbarPresenter() { 113 JButton button = new JButton (); 114 Actions.connect(button, this); 115 return button; 116 } 117 118 } 119 | Popular Tags |