View Javadoc

1   package nl.tudelft.goal.ut2004.visualizer.gui.action;
2   
3   import javax.swing.JDialog;
4   
5   import nl.tudelft.goal.ut2004.visualizer.controller.ServerController;
6   import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
7   import cz.cuni.amis.utils.flag.FlagListener;
8   
9   /**
10   * Action that is active or inactive depending on the state of the connection to
11   * the server. When the action is active it will launch a dialoque. This
12   * dialoque will be hidden when the connection to the server is lost.
13   * 
14   * @author mpkorstanje
15   * 
16   */
17  public class ShowServerDependentDialogueAction extends ShowDialogueAction {
18  
19  	/**
20  	 * Constructs the action.
21  	 * 
22  	 * @param dialog
23  	 *            to show when the action is used.
24  	 * @param name
25  	 *            this action.
26  	 * @param description
27  	 *            to show when a user hovers on this action.
28  	 */
29  	public ShowServerDependentDialogueAction(final JDialog dialog, String name,
30  			String description) {
31  		super(dialog, name, description);
32  
33  		ServerController controller = ServerController.getInstance();
34  		controller.getServerDefinition().getServerFlag()
35  				.addListener(new FlagListener<IUT2004Server>() {
36  
37  					@Override
38  					public void flagChanged(IUT2004Server changedValue) {
39  						if (changedValue == null) {
40  							setEnabled(false);
41  							dialog.setVisible(false);
42  						} else {
43  							setEnabled(true);
44  						}
45  					}
46  				});
47  
48  		setEnabled(controller.getServer() != null);
49  	}
50  
51  }