1 19 20 package org.openide.actions; 21 22 23 import javax.swing.event.*; 24 import org.openide.LifecycleManager; 25 import org.openide.loaders.DataObject; 26 import org.openide.util.*; 27 import org.openide.util.actions.CallableSystemAction; 28 29 35 public final class SaveAllAction extends CallableSystemAction { 36 37 private static final Object RUNNING = new Object (); 38 39 42 private ChangeListener chl; 43 44 47 protected void initialize () { 48 super.initialize (); 49 putProperty (PROP_ENABLED, Boolean.FALSE); 51 chl = new ModifiedListL(); 53 DataObject.getRegistry().addChangeListener( 54 (ChangeListener)(org.openide.util.WeakListeners.change(chl, DataObject.getRegistry ()))); 55 } 56 57 public String getName() { 58 return NbBundle.getMessage(org.openide.loaders.DataObject.class, "SaveAll"); 59 } 60 61 public HelpCtx getHelpCtx() { 62 return new HelpCtx (SaveAllAction.class); 63 } 64 65 protected String iconResource () { 66 return "org/openide/loaders/saveAll.gif"; } 68 69 public void performAction() { 70 synchronized (RUNNING) { 71 while (getProperty (RUNNING) != null) { 72 try { 73 RUNNING.wait (); 74 } catch (InterruptedException ex) { 75 Exceptions.printStackTrace(ex); 76 } 77 } 78 putProperty (RUNNING, RUNNING); 79 } 80 try { 81 LifecycleManager.getDefault().saveAll(); 82 } finally { 83 synchronized (RUNNING) { 84 putProperty (RUNNING, null); 85 RUNNING.notifyAll (); 86 } 87 88 } 89 } 90 91 protected boolean asynchronous() { 92 return true; 93 } 94 95 97 final class ModifiedListL implements ChangeListener { 98 public void stateChanged(final ChangeEvent evt) { 99 Mutex.EVENT.writeAccess(new Runnable () { 100 public void run() { 101 setEnabled(((java.util.Set )evt.getSource()).size() > 0); 102 } 103 }); 104 } 105 } } 107 | Popular Tags |