1 19 20 package org.openide.actions; 21 22 23 import java.awt.Component ; 24 import java.awt.event.ActionEvent ; 25 import java.beans.PropertyChangeListener ; 26 import java.util.Collection ; 27 import javax.swing.Action ; 28 import javax.swing.JMenuItem ; 29 import org.openide.awt.Actions; 30 import org.openide.awt.JInlineMenu; 31 import org.openide.nodes.Node; 32 import org.openide.nodes.NodeOperation; 33 import org.openide.util.ContextAwareAction; 34 import org.openide.util.HelpCtx; 35 import org.openide.util.Lookup; 36 import org.openide.util.NbBundle; 37 import org.openide.util.actions.NodeAction; 38 import org.openide.util.actions.Presenter; 39 import org.openide.util.actions.SystemAction; 40 41 46 public class PropertiesAction extends NodeAction { 47 protected void performAction(Node[] activatedNodes) { 48 if (activatedNodes.length == 1) { 49 NodeOperation.getDefault().showProperties(activatedNodes[0]); 50 } else { 51 NodeOperation.getDefault().showProperties(activatedNodes); 52 } 53 } 54 55 protected boolean asynchronous() { 56 return false; 57 } 58 59 protected boolean enable(Node[] activatedNodes) { 60 return activatedNodes != null; 61 } 62 63 public JMenuItem getPopupPresenter() { 64 JMenuItem prop = new Actions.MenuItem(this, false); 65 66 CustomizeAction customizeAction = (CustomizeAction) SystemAction.get(CustomizeAction.class); 67 68 if (customizeAction.isEnabled()) { 69 JInlineMenu mi = new JInlineMenu(); 70 mi.setMenuItems(new JMenuItem [] { new Actions.MenuItem(customizeAction, false), prop }); 71 72 return mi; 73 } else { 74 return prop; 75 } 76 } 77 78 public String getName() { 79 return NbBundle.getMessage(PropertiesAction.class, "Properties"); 80 } 81 82 public HelpCtx getHelpCtx() { 83 return new HelpCtx(PropertiesAction.class); 84 } 85 86 protected String iconResource() { 87 return "org/openide/resources/actions/properties.gif"; } 89 90 public Action createContextAwareInstance(Lookup actionContext) { 91 return new DelegateAction(this, actionContext); 92 } 93 94 97 private static final class DelegateAction implements Action , Presenter.Menu, Presenter.Toolbar, Presenter.Popup { 98 99 private PropertiesAction delegate; 100 101 102 private Lookup lookup; 103 104 public DelegateAction(PropertiesAction a, Lookup actionContext) { 105 this.delegate = a; 106 this.lookup = actionContext; 107 } 108 109 private Node[] nodes() { 110 Collection c = lookup.lookupAll(Node.class); 111 112 return (Node[]) c.toArray(new Node[c.size()]); 113 } 114 115 116 public String toString() { 117 return super.toString() + "[delegate=" + delegate + "]"; } 119 120 122 public void actionPerformed(ActionEvent e) { 123 delegate.performAction(nodes()); 124 } 125 126 public void addPropertyChangeListener(PropertyChangeListener listener) { 127 } 129 130 public void removePropertyChangeListener(PropertyChangeListener listener) { 131 } 133 134 public void putValue(String key, Object o) { 135 } 136 137 public Object getValue(String key) { 138 return delegate.getValue(key); 139 } 140 141 public boolean isEnabled() { 142 return delegate.enable(nodes()); 143 } 144 145 public void setEnabled(boolean b) { 146 assert false; 147 } 148 149 public JMenuItem getMenuPresenter() { 150 return new Actions.MenuItem(this, true); 151 } 152 153 public JMenuItem getPopupPresenter() { 154 JMenuItem prop = new Actions.MenuItem(this, false); 155 156 Action customizeAction = (CustomizeAction) SystemAction.get(CustomizeAction.class); 157 158 if (lookup != null) { 160 customizeAction = ((ContextAwareAction) customizeAction).createContextAwareInstance(lookup); 161 } 162 163 if (customizeAction.isEnabled()) { 164 JInlineMenu mi = new JInlineMenu(); 165 mi.setMenuItems(new JMenuItem [] { new Actions.MenuItem(customizeAction, false), prop }); 166 167 return mi; 168 } else { 169 return prop; 170 } 171 } 172 173 public Component getToolbarPresenter() { 174 return new Actions.ToolbarButton(this); 175 } 176 } 177 } 179 | Popular Tags |